From 8273a343b6375fef39fb7efffa5c11e88a375007 Mon Sep 17 00:00:00 2001 From: Maia Iyer Date: Thu, 12 Aug 2021 18:35:05 -0400 Subject: [PATCH] review - adjusting field widths and error messages --- .../dashboard/agents-dashboard-table.js | 2 +- .../src/components/entry-create.js | 109 ++++++++++-------- .../src/components/spiffe-helper.js | 3 +- tornjak-frontend/src/components/style.css | 15 +-- 4 files changed, 71 insertions(+), 58 deletions(-) diff --git a/tornjak-frontend/src/components/dashboard/agents-dashboard-table.js b/tornjak-frontend/src/components/dashboard/agents-dashboard-table.js index 74b770f..a51cb20 100644 --- a/tornjak-frontend/src/components/dashboard/agents-dashboard-table.js +++ b/tornjak-frontend/src/components/dashboard/agents-dashboard-table.js @@ -80,7 +80,7 @@ class AgentDashboardTable extends React.Component { return []; } - let agentEntriesDict = this.SpiffeHelper.getAgentsEntries(this.props.globalAgents.globalAgentsList, this.props.globalEntries.globalEntriesList) + let agentEntriesDict = this.SpiffeHelper.getAgentsEntries(this.props.globalAgents.globalAgentsList, this.props.globalEntries.globalEntriesList) // TODO this.props.globalEntries.globalEntriesList may be undefined if there are no entries return this.props.globalAgents.globalAgentsList.map(currentAgent => { return this.getChildEntries(currentAgent, agentEntriesDict); }) diff --git a/tornjak-frontend/src/components/entry-create.js b/tornjak-frontend/src/components/entry-create.js index ba7c9f0..28b5ab0 100644 --- a/tornjak-frontend/src/components/entry-create.js +++ b/tornjak-frontend/src/components/entry-create.js @@ -1,7 +1,7 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import axios from 'axios'; -import { Dropdown, TextInput, MultiSelect, Checkbox, TextArea, NumberInput, DatePicker, DatePickerInput, TimePicker } from 'carbon-components-react'; +import { Dropdown, TextInput, MultiSelect, Checkbox, TextArea, NumberInput } from 'carbon-components-react'; import GetApiServerUri from './helpers'; import IsManager from './is_manager'; import TornjakApi from './tornjak-api-helpers'; @@ -43,7 +43,6 @@ class CreateEntry extends Component { this.onChangeDownStream = this.onChangeDownStream.bind(this); this.onChangeDnsNames = this.onChangeDnsNames.bind(this); this.onSubmit = this.onSubmit.bind(this); - this.setState = this.setState.bind(this); this.state = { name: "", @@ -67,9 +66,10 @@ class CreateEntry extends Component { expiryOption: "None", expiryOptionList: ["None", "Seconds Since Epoch", "Date/Time"], expiryDate: "1/1/2021", - expiryTime: "13:01", + expiryTime: "00:00", expiresAt: 0, - expiryBad: false, + expiryUnsafe: false, + expiryInvalid: false, dnsNames: [], federatesWith: [], downstream: false, @@ -223,21 +223,15 @@ class CreateEntry extends Component { }); } - isValidJSTime(seconds) { - const JSMaxSafeTime = 8640000000000 + isValidExpiryTime(seconds) { + const JSMaxSafeTime = 8640000000000 // JS cannot represent times safely larger than this return seconds > 0 && seconds <= JSMaxSafeTime } expiryTimeUpdate(seconds) { - if (!this.isValidJSTime(seconds)) { - this.setState({ - expiryBad: true, - }) - return - } this.setState({ - expiryBad: false, - expiresAt: seconds + expiresAt: seconds, + expiryUnsafe: !this.isValidExpiryTime(seconds) }) } @@ -247,20 +241,28 @@ class CreateEntry extends Component { } // TODO some odd behavior with dates like February 33 exists - isValidDate(d) { // date is successfully translated + isValidDate(d) { // date is successfully translated in Javascript return d instanceof Date && isFinite(d) } updateValidDateAndTime(d, t) { var testDate = new Date(d + ", " + t) + this.setState({ // should always reflect what the user sees + expiryDate: d, + expiryTime: t + }) if (this.isValidDate(testDate)) { this.setState({ - expiryDate: d, - expiryTime: t + expiryInvalid: false, }) var seconds = Math.round(testDate / 1000) this.expiryTimeUpdate(seconds) - } + console.log(d, t, this.state.expiryDate, this.state.expiryTime) + return + } + this.setState({ + expiryInvalid: true, + }) } onChangeExpiresAtDate(e) { @@ -683,51 +685,60 @@ class CreateEntry extends Component { {this.state.expiryOption !== "None" &&
{this.state.expiryOption === "Seconds Since Epoch" &&
- +
+ +
} {this.state.expiryOption === "Date/Time" &&
- - - +
} - {this.state.expiryBad && -
-

Warning: expiry time either in invalid format, is negative, or is too large. Submitting this time may result in undefined behavior.

- {this.state.expiryOption === "Seconds Since Epoch" && -

Seconds must be positive and less than 8640000000000

- } - {this.state.expiryOption === "Date/Time" && -

Date must be past January 1, 1970 @ 12:00AM GMT

- } -
+
+ + + } + {(this.state.expiryUnsafe || this.state.expiryInvalid) && +
+

Warning: expiry time either in invalid format, is negative, or is too large. Submitting this time may result in undefined behavior.

+ {this.state.expiryOption === "Seconds Since Epoch" && this.state.expiryUnsafe && +

Seconds must be positive and less than 8640000000000

+ } + {this.state.expiryOption === "Date/Time" && this.state.expiryUnsafe && +

Date must be past January 1, 1970 @ 12:00AM GMT

+ } + {this.state.expiryOption === "Date/Time" && this.state.expiryInvalid && +

Date or time format is invalid

}
} diff --git a/tornjak-frontend/src/components/spiffe-helper.js b/tornjak-frontend/src/components/spiffe-helper.js index 4426a33..c75357c 100644 --- a/tornjak-frontend/src/components/spiffe-helper.js +++ b/tornjak-frontend/src/components/spiffe-helper.js @@ -116,7 +116,8 @@ class SpiffeHelper extends Component { // performance is impacted. getAgentsEntries (agents, entries) { if (typeof entries === 'undefined') { - return {}; + console.log("spiffe-helper.js: getAgentEntries: this should not happen, entries undefined`") + //return {}; } let nodeEntries = entries.filter(e => e.parent_id.path === "/spire/server"); var lambdas = []; diff --git a/tornjak-frontend/src/components/style.css b/tornjak-frontend/src/components/style.css index 460e126..506ffd3 100644 --- a/tornjak-frontend/src/components/style.css +++ b/tornjak-frontend/src/components/style.css @@ -126,47 +126,48 @@ .ttl-input { margin-right: 20px; margin-bottom: 20px; - width: 300px + width: 200px } .expiresAt-input { margin-right: 20px; margin-bottom: 20px; - width: 700px; + width: 600px; } .expiry-drop-down { display: inline-block; vertical-align: top; margin-right: 20px; - width: 240px; + width: 200px; } .expiryEntryFields { display: inline-block; vertical-align: top; - width: 400px; + width: 200px; } .expiryOption-field { display: inline-block; vertical-align: top; - width: 400px; + width: 500px; } .expiryOption-entry { margin-right: 20px; display: inline-block; vertical-align: top; + width: 200px; } .federates-with-input-field { margin-bottom: 20px; - width: 55%; + width: 420px; } .dnsnames-input-field { margin-bottom: 20px; - width: 55%; + width: 420px; } .servers-drp-dwn {