Skip to content
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 26 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 24 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 Jan 5, 2024
b505800
add the proptypes check to appease the tests
sixlighthouses Jan 5, 2024
015d63a
format and minor code tidy
sixlighthouses Jan 8, 2024
ccef646
update CHANGES.MD
sixlighthouses Jan 8, 2024
f6f2890
add the currentTime from timelineStack as the default date time in WP…
sixlighthouses Jan 10, 2024
60b2929
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses Jan 10, 2024
f1ff4c1
no need to set dateValue when declaring it with useState
sixlighthouses Jan 10, 2024
498c8e9
remove unnecessary call to updateParameters
sixlighthouses Jan 24, 2024
e43ec31
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses Mar 14, 2024
9879093
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses Mar 15, 2024
00ee115
check parameter.value when the DateTimeEditor reloads
sixlighthouses Mar 18, 2024
214fd25
use moment to correctly format the date/time
sixlighthouses Mar 19, 2024
3ea844b
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses Mar 19, 2024
436634f
missing import for WebFeatureServiceCatalogGroupTraits
sixlighthouses Mar 19, 2024
8623c0f
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses Apr 16, 2024
a69d9cc
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses Apr 17, 2024
9e27b9a
add CHANGES entry
sixlighthouses Apr 17, 2024
018e9c6
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses Apr 30, 2024
bdcb68a
clean up the initial load of DateTimeParameterEditor.jsx
sixlighthouses May 1, 2024
db00855
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses May 1, 2024
fd55170
make DateTimeParameterEditor a tsx, remove useState
sixlighthouses May 2, 2024
a285f42
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses May 2, 2024
069aab2
clean up CHANGES
sixlighthouses May 3, 2024
6409022
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses May 3, 2024
f5913f8
Merge remote-tracking branch 'origin/main' into wps-default-date
sixlighthouses May 26, 2024
13302bf
update CHANGES.md
sixlighthouses May 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

#### next release (8.7.2)

- Fix WPS date time widget reset bug
- Set default date for WPS date time widget on load
- Add NumberParameterEditor to enable WPS AllowedValues Ranges to be set and use DefaultValue
- [The next improvement]

#### 8.7.1 - 2024-04-16

Expand Down
91 changes: 0 additions & 91 deletions lib/ReactViews/Analytics/DateTimeParameterEditor.jsx

This file was deleted.

97 changes: 97 additions & 0 deletions lib/ReactViews/Analytics/DateTimeParameterEditor.tsx
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);