From f36892e00fbd9bddebbb756d57c8204c4b0756f7 Mon Sep 17 00:00:00 2001 From: Marco polo Date: Tue, 11 Jun 2024 04:54:36 -1000 Subject: [PATCH] Stop reduce anti-pattern contagion 2 (#22462) ## Summary & Motivation Missed a few spots in https://github.com/dagster-io/dagster/pull/22454 ## How I Tested These Changes load the app and visit various pages without crashing + ts / jest --- .../src/components/TokenizingField.tsx | 11 ++++++----- .../src/assets/AssetLineageElements.tsx | 19 +++++++++---------- .../packages/ui-core/src/assets/AssetLink.tsx | 9 ++++++++- .../packages/ui-core/src/runs/Run.tsx | 3 ++- .../ui-core/src/search/useGlobalSearch.tsx | 6 +++--- .../src/workspace/WorkspaceContext.tsx | 3 ++- 6 files changed, 30 insertions(+), 21 deletions(-) diff --git a/js_modules/dagster-ui/packages/ui-components/src/components/TokenizingField.tsx b/js_modules/dagster-ui/packages/ui-components/src/components/TokenizingField.tsx index 11b85b80f3cd5..cdd5eb4dadfe4 100644 --- a/js_modules/dagster-ui/packages/ui-components/src/components/TokenizingField.tsx +++ b/js_modules/dagster-ui/packages/ui-components/src/components/TokenizingField.tsx @@ -188,11 +188,12 @@ export const TokenizingField = ({ // Suggest providers (eg: `pipeline:`) so users can discover the search space suggestionsArr = filteredSuggestionProviders - .reduce( - (accum: Suggestion[], s) => - s.token ? [...accum, {text: `${s.token}:`, final: false}] : accum, - [], - ) + .reduce((accum: Suggestion[], s) => { + if (s.token) { + accum.push({text: `${s.token}:`, final: false}); + } + return accum; + }, []) .filter((s) => matchesTypedText(lastPart, s)); // Suggest value completions so users can type "airline_" without the "pipeline" diff --git a/js_modules/dagster-ui/packages/ui-core/src/assets/AssetLineageElements.tsx b/js_modules/dagster-ui/packages/ui-core/src/assets/AssetLineageElements.tsx index dcb0fb7f14390..6a77130410b41 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/assets/AssetLineageElements.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/assets/AssetLineageElements.tsx @@ -42,16 +42,15 @@ const AssetLineageInfoElement = ({ {lineage_info.assetKey.path .map((p, i) => {p}) - .reduce( - (accum, curr, ii) => [ - ...accum, - ii > 0 ? ( -  {'>'}  - ) : null, - curr, - ], - [] as React.ReactNode[], - )} + .reduce((accum, curr, ii) => { + if (ii > 0) { + accum.push( +  {'>'} , + ); + } + accum.push(curr); + return accum; + }, [] as React.ReactNode[])} diff --git a/js_modules/dagster-ui/packages/ui-core/src/assets/AssetLink.tsx b/js_modules/dagster-ui/packages/ui-core/src/assets/AssetLink.tsx index ca141317207b8..464a6416feb26 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/assets/AssetLink.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/assets/AssetLink.tsx @@ -14,7 +14,14 @@ export const AssetLink = (props: { const linkUrl = url ? url : assetDetailsPathForKey({path}); const assetPath = path - .reduce((accum, elem, ii) => [...accum, ii > 0 ? ' / ' : '', elem], [] as string[]) + .reduce((accum, elem, ii) => { + if (ii > 0) { + accum.push(' / '); + } + accum.push(elem); + return accum; + }, [] as string[]) + .join('') + (isGroup ? '/' : ''); return ( diff --git a/js_modules/dagster-ui/packages/ui-core/src/runs/Run.tsx b/js_modules/dagster-ui/packages/ui-core/src/runs/Run.tsx index 0e35292c14bce..95b58bde6f340 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/runs/Run.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/runs/Run.tsx @@ -223,7 +223,8 @@ const RunWithData = ({ ? logsFilter.logQuery .filter((v) => v.token && v.token === 'query') .reduce((accum, v) => { - return [...accum, ...filterByQuery(runtimeGraph, v.value).all.map((n) => n.name)]; + accum.push(...filterByQuery(runtimeGraph, v.value).all.map((n) => n.name)); + return accum; }, [] as string[]) : []; diff --git a/js_modules/dagster-ui/packages/ui-core/src/search/useGlobalSearch.tsx b/js_modules/dagster-ui/packages/ui-core/src/search/useGlobalSearch.tsx index c476f4a82fd3e..de0f8f6dcc777 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/search/useGlobalSearch.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/search/useGlobalSearch.tsx @@ -80,8 +80,7 @@ const primaryDataToSearchResults = (input: {data?: SearchPrimaryQuery}) => { const repoLocation = locationEntry.locationOrLoadError; const repos = repoLocation.repositories; - return [ - ...accum, + accum.push( ...repos.reduce((inner, repo) => { const { name: repoName, @@ -175,7 +174,8 @@ const primaryDataToSearchResults = (input: {data?: SearchPrimaryQuery}) => { ...allResources, ]; }, [] as SearchResult[]), - ]; + ); + return accum; }, [] as SearchResult[]); return allEntries; diff --git a/js_modules/dagster-ui/packages/ui-core/src/workspace/WorkspaceContext.tsx b/js_modules/dagster-ui/packages/ui-core/src/workspace/WorkspaceContext.tsx index f296aa65f0e3d..7ddaaffd84ae6 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/workspace/WorkspaceContext.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/workspace/WorkspaceContext.tsx @@ -276,7 +276,8 @@ export const WorkspaceProvider = ({children}: {children: React.ReactNode}) => { } const repositoryLocation = locationEntry.locationOrLoadError; const reposForLocation = repoLocationToRepos(repositoryLocation); - return [...accum, ...reposForLocation]; + accum.push(...reposForLocation); + return accum; }, [] as DagsterRepoOption[]), // Sort by repo location, then by repo