From f8899cd153679c24320d5d7883cb7471606bd8e6 Mon Sep 17 00:00:00 2001 From: bcolloran Date: Thu, 14 Dec 2023 11:03:19 -0800 Subject: [PATCH] svletecheck --ignore cleanup: fix most of "time-controls" folder (#3651) * fix most of "time-controls" folder * change default return value to `false` --- .github/workflows/web-test.yml | 2 +- .../time-controls/ComparisonSelector.svelte | 4 +++- .../time-controls/CustomTimeRangeInput.svelte | 4 ++-- .../time-controls/NoTimeDimensionCTA.svelte | 8 ++++++- .../time-controls/TimeControls.svelte | 6 ++--- .../time-controls/TimeGrainSelector.svelte | 3 ++- .../resource-status-utils.ts | 22 ++++++++++++++----- 7 files changed, 34 insertions(+), 15 deletions(-) diff --git a/.github/workflows/web-test.yml b/.github/workflows/web-test.yml index f94e867533c..34fe6fbf214 100644 --- a/.github/workflows/web-test.yml +++ b/.github/workflows/web-test.yml @@ -75,7 +75,7 @@ jobs: run: |- npx prettier --check "web-common/**/*" npx eslint web-common --quiet - npx svelte-check --threshold error --workspace web-common --no-tsconfig --ignore "src/components/data-graphic,src/features/dashboards/(time-series|time-controls)" + npx svelte-check --threshold error --workspace web-common --no-tsconfig --ignore "src/components/data-graphic,src/features/dashboards/time-series,src/features/dashboards/time-controls/TimeRangeSelector.svelte,src/features/dashboards/time-controls/TimeControls.svelte" - name: Prettier checks and lint for web local if: steps.filter.outputs.local == 'true' diff --git a/web-common/src/features/dashboards/time-controls/ComparisonSelector.svelte b/web-common/src/features/dashboards/time-controls/ComparisonSelector.svelte index 7d66edff846..b7e563a771c 100644 --- a/web-common/src/features/dashboards/time-controls/ComparisonSelector.svelte +++ b/web-common/src/features/dashboards/time-controls/ComparisonSelector.svelte @@ -189,7 +189,9 @@ This component needs to do the following: { - intermediateSelection = option.name; + if (option.name) { + intermediateSelection = option.name; + } }} on:select={() => { enableComparison("dimension", option.name); diff --git a/web-common/src/features/dashboards/time-controls/CustomTimeRangeInput.svelte b/web-common/src/features/dashboards/time-controls/CustomTimeRangeInput.svelte index 5a163c5b447..ae97db88be6 100644 --- a/web-common/src/features/dashboards/time-controls/CustomTimeRangeInput.svelte +++ b/web-common/src/features/dashboards/time-controls/CustomTimeRangeInput.svelte @@ -64,7 +64,7 @@ start: Date, end: Date, minTimeGrain: V1TimeGrain - ): string { + ): string | undefined { const allowedTimeGrains = getAllowedTimeGrains(start, end); const allowedMaxGrain = allowedTimeGrains[allowedTimeGrains.length - 1]; @@ -80,7 +80,7 @@ } // HAM, you left off here. - let error = undefined; + let error: string | undefined = undefined; $: if (start && end) { error = validateTimeRange( parseLocaleStringDate(start), diff --git a/web-common/src/features/dashboards/time-controls/NoTimeDimensionCTA.svelte b/web-common/src/features/dashboards/time-controls/NoTimeDimensionCTA.svelte index a640417ce86..2780ee01585 100644 --- a/web-common/src/features/dashboards/time-controls/NoTimeDimensionCTA.svelte +++ b/web-common/src/features/dashboards/time-controls/NoTimeDimensionCTA.svelte @@ -17,7 +17,13 @@ $runtime.instanceId, modelName ); - $: timestampColumns = $timestampColumnsQuery?.data; + + // CAST SAFETY: must be string[], since we filter out undefined values + $: timestampColumns = + ($timestampColumnsQuery?.data?.filter( + (x) => x !== undefined + ) as string[]) ?? []; + $: isReadOnlyDashboard = $featureFlags.readOnly === true; $: redirectToScreen = timestampColumns?.length > 0 ? "metrics" : "model"; diff --git a/web-common/src/features/dashboards/time-controls/TimeControls.svelte b/web-common/src/features/dashboards/time-controls/TimeControls.svelte index f7f3bdd8bf2..4702e8a915a 100644 --- a/web-common/src/features/dashboards/time-controls/TimeControls.svelte +++ b/web-common/src/features/dashboards/time-controls/TimeControls.svelte @@ -40,8 +40,8 @@ const queryClient = useQueryClient(); $: dashboardStore = useDashboardStore(metricViewName); - let baseTimeRange: TimeRange; - let minTimeGrain: V1TimeGrain; + let baseTimeRange: TimeRange | undefined; + let minTimeGrain: V1TimeGrain | undefined; let availableTimeZones: string[] = []; $: metaQuery = useMetaQuery($runtime.instanceId, metricViewName); @@ -61,7 +61,7 @@ !!$metaQuery?.data?.table && !!$metaQuery?.data?.timeDimension ) { - availableTimeZones = $metaQuery?.data?.availableTimeZones; + availableTimeZones = $metaQuery?.data?.availableTimeZones ?? []; /** * Remove the timezone selector if no timezone key is present diff --git a/web-common/src/features/dashboards/time-controls/TimeGrainSelector.svelte b/web-common/src/features/dashboards/time-controls/TimeGrainSelector.svelte index 79ebc7ac4df..c4767028580 100644 --- a/web-common/src/features/dashboards/time-controls/TimeGrainSelector.svelte +++ b/web-common/src/features/dashboards/time-controls/TimeGrainSelector.svelte @@ -18,7 +18,8 @@ const timeControlsStore = useTimeControlStore(getStateManagers()); $: activeTimeGrain = $timeControlsStore.selectedTimeRange?.interval; - $: activeTimeGrainLabel = TIME_GRAIN[activeTimeGrain]?.label; + $: activeTimeGrainLabel = + activeTimeGrain && TIME_GRAIN[activeTimeGrain]?.label; $: timeGrains = timeGrainOptions ? timeGrainOptions diff --git a/web-common/src/features/entity-management/resource-status-utils.ts b/web-common/src/features/entity-management/resource-status-utils.ts index b1d67244b59..50a3c3bb23f 100644 --- a/web-common/src/features/entity-management/resource-status-utils.ts +++ b/web-common/src/features/entity-management/resource-status-utils.ts @@ -44,9 +44,9 @@ export function initialResourceStatusStore( ([resourceName, projectParserResp]) => { if ( !projectParserResp.data || - projectParserResp.data.projectParser.state.parseErrors.filter( + (projectParserResp?.data?.projectParser?.state?.parseErrors?.filter( (s) => s.filePath === filePath - ).length > 0 + ).length ?? 0) > 0 ) { return ResourceStatus.Errored; } @@ -106,12 +106,17 @@ export function resourceStatusStore( ) return { status: ResourceStatus.Busy }; + const changed = + !lastUpdatedOn || + (res.data?.meta?.stateUpdatedOn !== undefined + ? res.data?.meta?.stateUpdatedOn > lastUpdatedOn + : false); + return { status: !res.data?.meta?.reconcileError ? ResourceStatus.Idle : ResourceStatus.Errored, - changed: - !lastUpdatedOn || res.data?.meta?.stateUpdatedOn > lastUpdatedOn, + changed, }; } ); @@ -144,13 +149,18 @@ export function waitForResourceUpdate( if (status.status === ResourceStatus.Busy) return; if (timer) clearTimeout(timer); + const do_end = + status.status === ResourceStatus.Idle && + status.changed !== undefined && + status.changed; + if (idled) { - end(status.status === ResourceStatus.Idle && status.changed); + end(do_end); return; } else { idled = true; timer = setTimeout(() => { - end(status.status === ResourceStatus.Idle && status.changed); + end(do_end); }, 500); } });