From babf7f2ef6546f206a799d77e8a2ddc337c1f88b Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Fri, 4 Oct 2024 16:01:13 -0700 Subject: [PATCH] Web console: don't assume that activeTasks is an array (#17254) --- .../components/module-pane/module-pane.tsx | 8 ++++---- .../src/views/explore-view/explore-state.ts | 10 ++++++---- .../src/views/explore-view/explore-view.tsx | 17 ++++++++++------- .../src/views/explore-view/models/parameter.ts | 6 +++--- .../views/supervisors-view/supervisors-view.tsx | 8 ++++++-- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/web-console/src/views/explore-view/components/module-pane/module-pane.tsx b/web-console/src/views/explore-view/components/module-pane/module-pane.tsx index b57a078ed732..b360effc87c1 100644 --- a/web-console/src/views/explore-view/components/module-pane/module-pane.tsx +++ b/web-console/src/views/explore-view/components/module-pane/module-pane.tsx @@ -20,7 +20,7 @@ import { ResizeSensor } from '@blueprintjs/core'; import type { QueryResult, SqlExpression, SqlQuery } from '@druid-toolkit/query'; import React, { useMemo, useState } from 'react'; -import type { ParameterDefinition, QuerySource } from '../../models'; +import type { ParameterDefinition, ParameterValues, QuerySource } from '../../models'; import { effectiveParameterDefault, Stage } from '../../models'; import { ModuleRepository } from '../../module-repository/module-repository'; import { Issue } from '../issue/issue'; @@ -28,7 +28,7 @@ import { Issue } from '../issue/issue'; import './module-pane.scss'; function fillInDefaults( - parameterValues: Record, + parameterValues: ParameterValues, parameters: Record, querySource: QuerySource, ): Record { @@ -46,8 +46,8 @@ export interface ModulePaneProps { where: SqlExpression; setWhere(where: SqlExpression): void; - parameterValues: Record; - setParameterValues(parameters: Record): void; + parameterValues: ParameterValues; + setParameterValues(parameters: ParameterValues): void; runSqlQuery(query: string | SqlQuery): Promise; } diff --git a/web-console/src/views/explore-view/explore-state.ts b/web-console/src/views/explore-view/explore-state.ts index 087c03ce8ea7..07a53d6de702 100644 --- a/web-console/src/views/explore-view/explore-state.ts +++ b/web-console/src/views/explore-view/explore-state.ts @@ -42,7 +42,7 @@ interface ExploreStateValue { showSourceQuery?: boolean; where: SqlExpression; moduleId: string; - parameterValues: Record; + parameterValues: ParameterValues; } export class ExploreState { @@ -64,7 +64,7 @@ export class ExploreState { public readonly showSourceQuery: boolean; public readonly where: SqlExpression; public readonly moduleId: string; - public readonly parameterValues: Record; + public readonly parameterValues: ParameterValues; public readonly parsedSource: SqlQuery | undefined; public readonly parseError: string | undefined; @@ -178,8 +178,10 @@ export class ExploreState { parameterValues = {}; } else { moduleId = 'grouping-table'; - parameterValues = this.moduleId === moduleId ? this.parameterValues : {}; - parameterValues.splitColumns = [ExpressionMeta.fromColumn(column)]; + parameterValues = { + ...(this.moduleId === moduleId ? this.parameterValues : {}), + splitColumns: [ExpressionMeta.fromColumn(column)], + }; } return this.change({ diff --git a/web-console/src/views/explore-view/explore-view.tsx b/web-console/src/views/explore-view/explore-view.tsx index fead1b5c7b2e..546c47b190b1 100644 --- a/web-console/src/views/explore-view/explore-view.tsx +++ b/web-console/src/views/explore-view/explore-view.tsx @@ -186,7 +186,7 @@ export const ExploreView = React.memo(function ExploreView() { } }, [module, parameterValues, querySourceState.data]); - function setModuleId(moduleId: string, parameterValues: Record) { + function setModuleId(moduleId: string, parameterValues: ParameterValues) { if (exploreState.moduleId === moduleId) return; setExploreState(exploreState.change({ moduleId, parameterValues })); } @@ -326,7 +326,7 @@ export const ExploreView = React.memo(function ExploreView() { { - const newParameterValues = getStickyParameterValuesForModule(newModuleId); + let newParameterValues = getStickyParameterValuesForModule(newModuleId); const oldModule = ModuleRepository.getModule(moduleId); const newModule = ModuleRepository.getModule(newModuleId); @@ -349,11 +349,14 @@ export const ExploreView = React.memo(function ExploreView() { ); if (!target) continue; - newParameterValues[target[0]] = adjustTransferValue( - parameterValue, - oldParameterDefinition.type, - target[1].type, - ); + newParameterValues = { + ...newParameterValues, + [target[0]]: adjustTransferValue( + parameterValue, + oldParameterDefinition.type, + target[1].type, + ), + }; } } diff --git a/web-console/src/views/explore-view/models/parameter.ts b/web-console/src/views/explore-view/models/parameter.ts index f4a5f622d737..7884a32ed8de 100644 --- a/web-console/src/views/explore-view/models/parameter.ts +++ b/web-console/src/views/explore-view/models/parameter.ts @@ -26,9 +26,9 @@ import type { QuerySource } from './query-source'; export type OptionValue = string | number; -export type ModuleFunctor = T | ((options: { parameterValues: Record }) => T); +export type ModuleFunctor = T | ((options: { parameterValues: ParameterValues }) => T); -export function evaluateFunctor(fn: ModuleFunctor, parameterValues: Record): T { +export function evaluateFunctor(fn: ModuleFunctor, parameterValues: ParameterValues): T { if (typeof fn === 'function') { return (fn as any)({ parameterValues }); } else { @@ -144,7 +144,7 @@ export function getModuleOptionLabel( ); } -export type ParameterValues = Record; +export type ParameterValues = Readonly>; export type Parameters = Record; // ----------------------------------------------------- diff --git a/web-console/src/views/supervisors-view/supervisors-view.tsx b/web-console/src/views/supervisors-view/supervisors-view.tsx index 5988dff1031a..f963e449b48a 100644 --- a/web-console/src/views/supervisors-view/supervisors-view.tsx +++ b/web-console/src/views/supervisors-view/supervisors-view.tsx @@ -843,10 +843,14 @@ export class SupervisorsView extends React.PureComponent< accessor: 'stats', Cell: ({ value, original }) => { if (!value) return; - const activeTaskIds: string[] | undefined = deepGet( + const activeTasks: SupervisorStatusTask[] | undefined = deepGet( original, 'status.payload.activeTasks', - )?.map((t: SupervisorStatusTask) => t.id); + ); + const activeTaskIds: string[] | undefined = Array.isArray(activeTasks) + ? activeTasks.map((t: SupervisorStatusTask) => t.id) + : undefined; + const c = getTotalSupervisorStats(value, statsKey, activeTaskIds); const seconds = getRowStatsKeySeconds(statsKey); const totalLabel = `Total (past ${statsKey}): `;