Skip to content

Commit

Permalink
fix: use Data object in IpaCalendar
Browse files Browse the repository at this point in the history
thus be able to set invalid date from DateTimeSelector and thus enable reset of invalid dates on user settings page.

Signed-off-by: Petr Vobornik <pvoborni@redhat.com>
  • Loading branch information
pvoborni committed Sep 12, 2024
1 parent 0e44825 commit 5fedf7e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
7 changes: 6 additions & 1 deletion src/components/Form/DateTimeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,21 @@ const DateTimeSelector = (props: PropsToDateTimeSelector) => {
const newTimeText = hhMMFormat(props.datetime);
if (newTimeText !== timeText) {
setTimeText(newTimeText);
setTimeValid(true);
}

const newDateText = yyyyMMddFormat(props.datetime);
if (newDateText !== dateText) {
setDateText(newDateText);
setDateValid(true);
}
} else if (props.datetime === null) {
setDateText("");
setDateValid(true);
// the TimePicker component will unfornately reset the time to current
// time if the time is set to an empty string
setTimeText("");
setTimeText("00:00");
setTimeValid(true);
}
}, [props.datetime]);

Expand All @@ -76,6 +80,7 @@ const DateTimeSelector = (props: PropsToDateTimeSelector) => {
// The limitation is that revert might not reset the value as the source
// might still have the original value.
if (!dateValid || !timeValid) {
props.onChange(new Date(NaN));
return;
}

Expand Down
17 changes: 2 additions & 15 deletions src/components/Form/IpaCalendar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from "react";
// Utils
import {
parseFullDateStringToUTCFormat,
toGeneralizedTime,
} from "src/utils/utils";
import { parseFullDateStringToUTCFormat } from "src/utils/utils";
import {
BasicType,
IPAParamDefinition,
Expand All @@ -19,11 +16,6 @@ export interface DateParam {
__datetime__: string;
}

export interface ValueDateTime {
valueDate: string;
valueTime: string;
}

export interface ParamPropertiesDateTime {
writable: boolean;
required: boolean;
Expand Down Expand Up @@ -61,12 +53,7 @@ const IpaCalendar = (props: IPAParamDefinition) => {

const onDateChange = (date: Date | null) => {
if (props.ipaObject !== undefined && props.onChange !== undefined) {
updateIpaObject(
props.ipaObject,
props.onChange,
toGeneralizedTime(date),
props.name
);
updateIpaObject(props.ipaObject, props.onChange, date, props.name);
}
};

Expand Down

0 comments on commit 5fedf7e

Please sign in to comment.