Skip to content

Commit

Permalink
Web console: don't assume that activeTasks is an array (#17254)
Browse files Browse the repository at this point in the history
  • Loading branch information
vogievetsky authored Oct 4, 2024
1 parent 2ffe7b1 commit babf7f2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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';

import './module-pane.scss';

function fillInDefaults(
parameterValues: Record<string, any>,
parameterValues: ParameterValues,
parameters: Record<string, ParameterDefinition>,
querySource: QuerySource,
): Record<string, any> {
Expand All @@ -46,8 +46,8 @@ export interface ModulePaneProps {
where: SqlExpression;
setWhere(where: SqlExpression): void;

parameterValues: Record<string, any>;
setParameterValues(parameters: Record<string, any>): void;
parameterValues: ParameterValues;
setParameterValues(parameters: ParameterValues): void;
runSqlQuery(query: string | SqlQuery): Promise<QueryResult>;
}

Expand Down
10 changes: 6 additions & 4 deletions web-console/src/views/explore-view/explore-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface ExploreStateValue {
showSourceQuery?: boolean;
where: SqlExpression;
moduleId: string;
parameterValues: Record<string, any>;
parameterValues: ParameterValues;
}

export class ExploreState {
Expand All @@ -64,7 +64,7 @@ export class ExploreState {
public readonly showSourceQuery: boolean;
public readonly where: SqlExpression;
public readonly moduleId: string;
public readonly parameterValues: Record<string, any>;
public readonly parameterValues: ParameterValues;

public readonly parsedSource: SqlQuery | undefined;
public readonly parseError: string | undefined;
Expand Down Expand Up @@ -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({
Expand Down
17 changes: 10 additions & 7 deletions web-console/src/views/explore-view/explore-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const ExploreView = React.memo(function ExploreView() {
}
}, [module, parameterValues, querySourceState.data]);

function setModuleId(moduleId: string, parameterValues: Record<string, any>) {
function setModuleId(moduleId: string, parameterValues: ParameterValues) {
if (exploreState.moduleId === moduleId) return;
setExploreState(exploreState.change({ moduleId, parameterValues }));
}
Expand Down Expand Up @@ -326,7 +326,7 @@ export const ExploreView = React.memo(function ExploreView() {
<ModulePicker
selectedModuleId={moduleId}
onSelectedModuleIdChange={newModuleId => {
const newParameterValues = getStickyParameterValuesForModule(newModuleId);
let newParameterValues = getStickyParameterValuesForModule(newModuleId);

const oldModule = ModuleRepository.getModule(moduleId);
const newModule = ModuleRepository.getModule(newModuleId);
Expand All @@ -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,
),
};
}
}

Expand Down
6 changes: 3 additions & 3 deletions web-console/src/views/explore-view/models/parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import type { QuerySource } from './query-source';

export type OptionValue = string | number;

export type ModuleFunctor<T> = T | ((options: { parameterValues: Record<string, any> }) => T);
export type ModuleFunctor<T> = T | ((options: { parameterValues: ParameterValues }) => T);

export function evaluateFunctor<T>(fn: ModuleFunctor<T>, parameterValues: Record<string, any>): T {
export function evaluateFunctor<T>(fn: ModuleFunctor<T>, parameterValues: ParameterValues): T {
if (typeof fn === 'function') {
return (fn as any)({ parameterValues });
} else {
Expand Down Expand Up @@ -144,7 +144,7 @@ export function getModuleOptionLabel(
);
}

export type ParameterValues = Record<string, any>;
export type ParameterValues = Readonly<Record<string, any>>;
export type Parameters = Record<string, ParameterDefinition>;

// -----------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions web-console/src/views/supervisors-view/supervisors-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}): `;
Expand Down

0 comments on commit babf7f2

Please sign in to comment.