-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wps default date #7026
Merged
Merged
Wps default date #7026
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
95ad720
refactor the DateTimeParameterEditor to be a functional component
sixlighthouses b505800
add the proptypes check to appease the tests
sixlighthouses 015d63a
format and minor code tidy
sixlighthouses ccef646
update CHANGES.MD
sixlighthouses f6f2890
add the currentTime from timelineStack as the default date time in WP…
sixlighthouses 60b2929
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses f1ff4c1
no need to set dateValue when declaring it with useState
sixlighthouses 498c8e9
remove unnecessary call to updateParameters
sixlighthouses e43ec31
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses 9879093
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses 00ee115
check parameter.value when the DateTimeEditor reloads
sixlighthouses 214fd25
use moment to correctly format the date/time
sixlighthouses 3ea844b
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses 436634f
missing import for WebFeatureServiceCatalogGroupTraits
sixlighthouses 8623c0f
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses a69d9cc
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses 9e27b9a
add CHANGES entry
sixlighthouses 018e9c6
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses bdcb68a
clean up the initial load of DateTimeParameterEditor.jsx
sixlighthouses db00855
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses fd55170
make DateTimeParameterEditor a tsx, remove useState
sixlighthouses a285f42
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses 069aab2
clean up CHANGES
sixlighthouses 6409022
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses f5913f8
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses 13302bf
update CHANGES.md
sixlighthouses File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React, { useEffect } from "react"; | ||
import { observer } from "mobx-react"; | ||
import { runInAction } from "mobx"; | ||
import moment from "moment"; | ||
import defined from "terriajs-cesium/Source/Core/defined"; | ||
import Styles from "./parameter-editors.scss"; | ||
import CommonStrata from "../../Models/Definition/CommonStrata"; | ||
import DateTimeParameter from "../../Models/FunctionParameters/DateTimeParameter"; | ||
import Terria from "../../Models/Terria"; | ||
|
||
interface DateTimeParameterEditorProps { | ||
parameter: DateTimeParameter; | ||
terria: Terria; | ||
} | ||
|
||
const DateTimeParameterEditor: React.FC<DateTimeParameterEditorProps> = ({ | ||
parameter, | ||
terria | ||
}) => { | ||
const style = | ||
defined(parameter) && defined(parameter.value) | ||
? Styles.field | ||
: Styles.fieldDatePlaceholder; | ||
|
||
useEffect(() => { | ||
let newDateValue, newTimeValue; | ||
if (parameter.value === undefined) { | ||
const currentTime = defined(parameter.value) | ||
? parameter.value | ||
: terria.timelineStack.clock.currentTime; | ||
|
||
if (currentTime) { | ||
const ct = new Date(currentTime?.toString()); | ||
|
||
newDateValue = moment | ||
.utc(ct.toISOString()) | ||
.local() | ||
.format("YYYY-MM-DD"); | ||
newTimeValue = moment.utc(ct.toISOString()).local().format("HH:mm"); | ||
} | ||
} else { | ||
const ct = new Date(parameter.value); | ||
newDateValue = moment.utc(ct.toISOString()).local().format("YYYY-MM-DD"); | ||
newTimeValue = moment.utc(ct.toISOString()).local().format("HH:mm"); | ||
} | ||
parameter.setValue(CommonStrata.user, `${newDateValue}T${newTimeValue}`); | ||
}, [parameter, terria.timelineStack.clock.currentTime]); | ||
na9da marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const isValidTime = (time: string): boolean => { | ||
const timeFormat = /^([01]\d|2[0-3]):([0-5]\d)$/; | ||
return timeFormat.test(time); | ||
}; | ||
|
||
const isValidDate = (date: string, format = "YYYY-MM-DD"): boolean => { | ||
return moment(date, format, true).isValid(); | ||
}; | ||
|
||
const handleTimeChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const time = e.target.value; | ||
if (isValidTime(time)) { | ||
runInAction(() => { | ||
parameter.setValue(CommonStrata.user, `${dateValue}T${time}`); | ||
}); | ||
} | ||
}; | ||
|
||
const handleDateChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
if (isValidDate(e.target.value)) { | ||
runInAction(() => { | ||
parameter.setValue(CommonStrata.user, `${e.target.value}T${timeValue}`); | ||
}); | ||
} | ||
}; | ||
|
||
const value = parameter.value; | ||
const dateValue = value ? value.split("T")[0] : ""; | ||
const timeValue = value ? value.split("T")[1] : ""; | ||
|
||
return ( | ||
<div> | ||
<input | ||
className={style} | ||
type="date" | ||
value={dateValue} | ||
onChange={handleDateChange} | ||
/> | ||
<input | ||
className={style} | ||
type="time" | ||
value={timeValue} | ||
onChange={handleTimeChange} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default observer(DateTimeParameterEditor); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these need to go.