Wizard: fix datepicker reset glitch (MS-8610)

If the reset button is clicked, there is a glitch that shows error state
for a moment. This commit removes the glitch by setting the snapshot
date even for invalid values, and removes the workaround that was
previously added.
This commit is contained in:
Anna Vítová 2025-05-29 16:47:43 +02:00 committed by Anna Vítová
parent a93a163afb
commit 6ec6f33fda
3 changed files with 10 additions and 7 deletions

View file

@ -138,10 +138,7 @@ export default function Snapshot() {
onClick={async () => { onClick={async () => {
//Patternfly DatePicker seems to only clear error text if value is reset to '', //Patternfly DatePicker seems to only clear error text if value is reset to '',
// if you have an invalid date (2000-01-010000) and try to reset it, it must be set to '' first // if you have an invalid date (2000-01-010000) and try to reset it, it must be set to '' first
dispatch(changeSnapshotDate('')); dispatch(changeSnapshotDate(yyyyMMddFormat(new Date())));
setTimeout(() => {
dispatch(changeSnapshotDate(yyyyMMddFormat(new Date())));
}, 1);
}} }}
> >
Reset Reset

View file

@ -748,10 +748,10 @@ export const wizardSlice = createSlice({
changeSnapshotDate: (state, action: PayloadAction<string>) => { changeSnapshotDate: (state, action: PayloadAction<string>) => {
const yyyyMMDDRegex = /^\d{4}-\d{2}-\d{2}$/; const yyyyMMDDRegex = /^\d{4}-\d{2}-\d{2}$/;
const date = new Date(action.payload); const date = new Date(action.payload);
if (action.payload === '') { if (yyyyMMDDRegex.test(action.payload) && !isNaN(date.getTime())) {
state.snapshotting.snapshotDate = '';
} else if (yyyyMMDDRegex.test(action.payload) && !isNaN(date.getTime())) {
state.snapshotting.snapshotDate = date.toISOString(); state.snapshotting.snapshotDate = date.toISOString();
} else {
state.snapshotting.snapshotDate = action.payload;
} }
}, },
changeTemplate: (state, action: PayloadAction<string>) => { changeTemplate: (state, action: PayloadAction<string>) => {

View file

@ -254,6 +254,12 @@ describe('repository snapshot tab - ', () => {
}); });
// reset fills in the current date, so it should not be disabled // reset fills in the current date, so it should not be disabled
await clickReset(); await clickReset();
// works even for invalid values
await updateDatePickerWithValue('xxx');
await waitFor(() => {
expect(nextBtn).toBeDisabled();
});
await clickReset();
await waitFor(() => { await waitFor(() => {
expect(nextBtn).toBeEnabled(); expect(nextBtn).toBeEnabled();
}); });