diff --git a/tornjak-frontend/src/components/dashboard/agents-dashboard-table.js b/tornjak-frontend/src/components/dashboard/agents-dashboard-table.js index 74b770f1..a51cb204 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 ba7c9f08..28b5ab05 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" &&
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
- } -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
}