Compare intervals for unsaved changes on dashboard (#112592)

This commit is contained in:
Devon Thomson 2021-09-28 16:48:11 -04:00 committed by GitHub
parent 8cf20cd82e
commit bd699aceb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View file

@ -38,6 +38,7 @@ import {
syncDashboardUrlState,
diffDashboardState,
areTimeRangesEqual,
areRefreshIntervalsEqual,
} from '../lib';
export interface UseDashboardStateProps {
@ -241,13 +242,17 @@ export const useDashboardAppState = ({
const savedTimeChanged =
lastSaved.timeRestore &&
!areTimeRangesEqual(
(!areTimeRangesEqual(
{
from: savedDashboard?.timeFrom,
to: savedDashboard?.timeTo,
},
timefilter.getTime()
);
) ||
!areRefreshIntervalsEqual(
savedDashboard?.refreshInterval,
timefilter.getRefreshInterval()
));
/**
* changes to the dashboard should only be considered 'unsaved changes' when

View file

@ -10,9 +10,10 @@ import _ from 'lodash';
import moment, { Moment } from 'moment';
import { Optional } from '@kbn/utility-types';
import { Filter, TimeRange } from '../../services/data';
import { Filter, TimeRange, RefreshInterval } from '../../services/data';
type TimeRangeCompare = Optional<TimeRange>;
type RefreshIntervalCompare = Optional<RefreshInterval>;
/**
* Converts the time to a utc formatted string. If the time is not valid (e.g. it might be in a relative format like
@ -31,9 +32,13 @@ export const convertTimeToUTCString = (time?: string | Moment): undefined | stri
}
};
export const areTimeRangesEqual = (rangeA: TimeRangeCompare, rangeB: TimeRangeCompare): boolean => {
return areTimesEqual(rangeA.from, rangeB.from) && areTimesEqual(rangeA.to, rangeB.to);
};
export const areTimeRangesEqual = (rangeA: TimeRangeCompare, rangeB: TimeRangeCompare): boolean =>
areTimesEqual(rangeA.from, rangeB.from) && areTimesEqual(rangeA.to, rangeB.to);
export const areRefreshIntervalsEqual = (
refreshA?: RefreshIntervalCompare,
refreshB?: RefreshIntervalCompare
): boolean => refreshA?.pause === refreshB?.pause && refreshA?.value === refreshB?.value;
/**
* Compares the two times, making sure they are in both compared in string format. Absolute times