From 2ffe7b177cf9932d2d556cf4bc081cd8d8211ce3 Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Fri, 4 Oct 2024 13:02:15 -0700 Subject: [PATCH] Explore view fix spin when applying defaults (#17252) --- .../components/module-pane/module-pane.tsx | 9 ++++++-- .../resource-pane/resource-pane.tsx | 21 +++++++++++++++++-- .../src/views/explore-view/explore-view.tsx | 10 +++++---- 3 files changed, 32 insertions(+), 8 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 4e216e3ac38..b57a078ed73 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 @@ -18,7 +18,7 @@ import { ResizeSensor } from '@blueprintjs/core'; import type { QueryResult, SqlExpression, SqlQuery } from '@druid-toolkit/query'; -import React, { useState } from 'react'; +import React, { useMemo, useState } from 'react'; import type { ParameterDefinition, QuerySource } from '../../models'; import { effectiveParameterDefault, Stage } from '../../models'; @@ -65,6 +65,11 @@ export const ModulePane = function ModulePane(props: ModulePaneProps) { const module = ModuleRepository.getModule(moduleId); + const parameterValuesWithDefaults = useMemo(() => { + if (!module) return {}; + return fillInDefaults(parameterValues, module.parameters, querySource); + }, [parameterValues, module, querySource]); + let content: React.ReactNode; if (module) { const modelIssue = undefined; // AutoForm.issueWithModel(moduleTileConfig.config, module.configFields); @@ -76,7 +81,7 @@ export const ModulePane = function ModulePane(props: ModulePaneProps) { querySource, where, setWhere, - parameterValues: fillInDefaults(parameterValues, module.parameters, querySource), + parameterValues: parameterValuesWithDefaults, setParameterValues, runSqlQuery, }); diff --git a/web-console/src/views/explore-view/components/resource-pane/resource-pane.tsx b/web-console/src/views/explore-view/components/resource-pane/resource-pane.tsx index 2de75e32d86..ba21199ce62 100644 --- a/web-console/src/views/explore-view/components/resource-pane/resource-pane.tsx +++ b/web-console/src/views/explore-view/components/resource-pane/resource-pane.tsx @@ -44,6 +44,19 @@ import { NestedColumnDialog } from './nested-column-dialog/nested-column-dialog' import './resource-pane.scss'; +function makeNiceTitle(name: string): string { + return name + .replace(/^[ _-]+|[ _-]+$/g, '') + .replace(/(^|[_-]+)\w/g, s => { + // 'hello_world-love' -> 'Hello World Love' + return s.replace(/[_-]+/, ' ').toUpperCase(); + }) + .replace(/[a-z0-9][A-Z]/g, s => { + // 'HelloWorld' -> 'Hello World' + return s[0] + ' ' + s[1]; + }); +} + interface ColumnEditorOpenOn { expression?: SqlExpression; columnToDuplicate?: string; @@ -99,11 +112,15 @@ export const ResourcePane = function ResourcePane(props: ResourcePaneProps) { content={ applyUtil(makeNiceTitle)} + /> + applyUtil(x => x.toUpperCase())} /> applyUtil(x => x.toLowerCase())} /> diff --git a/web-console/src/views/explore-view/explore-view.tsx b/web-console/src/views/explore-view/explore-view.tsx index 05f6ee69325..fead1b5c7b2 100644 --- a/web-console/src/views/explore-view/explore-view.tsx +++ b/web-console/src/views/explore-view/explore-view.tsx @@ -28,6 +28,7 @@ import copy from 'copy-to-clipboard'; import React, { useEffect, useMemo, useRef, useState } from 'react'; import { useStore } from 'zustand'; +import { Loader } from '../../components'; import { ShowValueDialog } from '../../dialogs/show-value-dialog/show-value-dialog'; import { useHashAndLocalStorageHybridState, useQueryManager } from '../../hooks'; import { Api, AppToaster } from '../../singletons'; @@ -422,10 +423,9 @@ export const ExploreView = React.memo(function ExploreView() { onDropColumn={onShowColumn} onDropMeasure={onShowMeasure} > - {querySourceState.error && ( + {querySourceState.error ? (
{querySourceState.getErrorMessage()}
- )} - {querySource && ( + ) : querySource ? ( - )} + ) : querySourceState.loading ? ( + + ) : undefined}
{module && (