Skip to content

Commit

Permalink
feat: [PROD-13001] add option to disable out of sync scenario results…
Browse files Browse the repository at this point in the history
… banner
  • Loading branch information
csm-thu committed Jan 25, 2024
1 parent e4a9235 commit 06591ab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/services/config/WorkspaceSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const dashboardReport = z

const basicWebAppOptions = z.object({
datasetFilter: z.array(z.string().optional().nullable()).optional().nullable(),
disableOutOfSyncWarningBanner: z.boolean().optional().nullable(),
charts: z
.object({
workspaceId: z.string().optional().nullable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '../../../../state/hooks/ScenarioHooks';
import { useCurrentScenarioRunStartTime } from '../../../../state/hooks/ScenarioRunHooks';
import { useDownloadLogsFile } from '../../../../hooks/ScenarioRunHooks';
import { useWorkspaceData } from '../../../../state/hooks/WorkspaceHooks';
import { useMemo } from 'react';
import { useFormState } from 'react-hook-form';

Expand All @@ -17,6 +18,7 @@ export const useScenarioDashboardCard = () => {
const currentScenarioState = useCurrentScenarioState();
const currentScenarioRunStartTime = useCurrentScenarioRunStartTime();
const downloadCurrentScenarioRunLogs = useDownloadLogsFile();
const workspace = useWorkspaceData();

const { isDirty } = useFormState();

Expand All @@ -26,16 +28,23 @@ export const useScenarioDashboardCard = () => {
);

const isDashboardSync = useMemo(() => {
if (!currentScenarioRunStartTime) return true;
const disableOutOfSyncWarningBanner = workspace?.webApp?.options?.disableOutOfSyncWarningBanner === true;
if (disableOutOfSyncWarningBanner || !currentScenarioRunStartTime) return true;
if (isDirty) return false;

const lastUpdate = new Date(currentScenarioLastUpdate);
const startTime = new Date(currentScenarioRunStartTime);
lastUpdate.setSeconds(0);
lastUpdate.setMilliseconds(0);
startTime.setSeconds(0);
startTime.setMilliseconds(0);
return lastUpdate <= startTime;
}, [currentScenarioLastUpdate, currentScenarioRunStartTime, isDirty]);
}, [
currentScenarioLastUpdate,
currentScenarioRunStartTime,
isDirty,
workspace?.webApp?.options?.disableOutOfSyncWarningBanner,
]);

return { hasRunBeenSuccessful, isDashboardSync, downloadCurrentScenarioRunLogs };
};

0 comments on commit 06591ab

Please sign in to comment.