From 8a98eb602b2562ca55fdd335bde61ee6a612b738 Mon Sep 17 00:00:00 2001 From: benpankow Date: Thu, 22 Aug 2024 16:55:09 -0700 Subject: [PATCH] kind results --- .../packages/ui-core/src/graph/KindTags.tsx | 3 +- .../src/search/BuildAssetSearchResults.tsx | 45 ++++++------------- .../ui-core/src/search/SearchResults.tsx | 6 +-- .../packages/ui-core/src/search/types.ts | 4 +- .../ui-core/src/search/useGlobalSearch.tsx | 28 ++++-------- 5 files changed, 28 insertions(+), 58 deletions(-) diff --git a/js_modules/dagster-ui/packages/ui-core/src/graph/KindTags.tsx b/js_modules/dagster-ui/packages/ui-core/src/graph/KindTags.tsx index e8297ce46eae4..3fb520cace7a4 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/graph/KindTags.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/graph/KindTags.tsx @@ -11,13 +11,14 @@ export const COMPUTE_KIND_TAG = 'dagster/compute_kind'; export const STORAGE_KIND_TAG = 'dagster/storage_kind'; export const HIDDEN_TAG_PREFIX = '.dagster/'; +export const KIND_TAG_PREFIX = `${HIDDEN_TAG_PREFIX}kind/`; // Older code servers may be using the legacy compute kind tag, so we need to check for both export const isCanonicalComputeKindTag = (tag: DefinitionTag) => tag.key === COMPUTE_KIND_TAG || tag.key === LEGACY_COMPUTE_KIND_TAG; export const isCanonicalStorageKindTag = (tag: DefinitionTag) => tag.key === STORAGE_KIND_TAG; -export const isKindTag = (tag: DefinitionTag) => tag.key.startsWith(`${HIDDEN_TAG_PREFIX}kind/`); +export const isKindTag = (tag: DefinitionTag) => tag.key.startsWith(KIND_TAG_PREFIX); export const AssetComputeKindTag = ({ definition, diff --git a/js_modules/dagster-ui/packages/ui-core/src/search/BuildAssetSearchResults.tsx b/js_modules/dagster-ui/packages/ui-core/src/search/BuildAssetSearchResults.tsx index c5e74db2bfa58..b5b6e18802ef5 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/search/BuildAssetSearchResults.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/search/BuildAssetSearchResults.tsx @@ -1,6 +1,6 @@ import {COMMON_COLLATOR} from '../app/Util'; import {AssetTableDefinitionFragment} from '../assets/types/AssetTableFragment.types'; -import {isCanonicalStorageKindTag} from '../graph/KindTags'; +import {isCanonicalStorageKindTag, isKindTag, KIND_TAG_PREFIX} from '../graph/KindTags'; import {DefinitionTag} from '../graphql/types'; import {buildTagString} from '../ui/tagAsString'; import {buildRepoPathForHuman} from '../workspace/buildRepoAddress'; @@ -13,13 +13,8 @@ type CountByOwner = { assetCount: number; }; -type CountByComputeKind = { - computeKind: string; - assetCount: number; -}; - -type CountByStorageKind = { - storageKind: string; +type CountByKind = { + kind: string; assetCount: number; }; @@ -40,11 +35,10 @@ type CountPerCodeLocation = { type AssetCountsResult = { countsByOwner: CountByOwner[]; - countsByComputeKind: CountByComputeKind[]; + countsByKind: CountByKind[]; countPerTag: CountPerTag[]; countPerAssetGroup: CountPerGroupName[]; countPerCodeLocation: CountPerCodeLocation[]; - countsByStorageKind: CountByStorageKind[]; }; export type GroupMetadata = { @@ -81,8 +75,7 @@ class CaseInsensitiveCounters { export function buildAssetCountBySection(assets: AssetDefinitionMetadata[]): AssetCountsResult { const assetCountByOwner = new CaseInsensitiveCounters(); - const assetCountByComputeKind = new CaseInsensitiveCounters(); - const assetCountByStorageKind = new CaseInsensitiveCounters(); + const assetCountByKind = new CaseInsensitiveCounters(); const assetCountByGroup = new CaseInsensitiveCounters(); const assetCountByCodeLocation = new CaseInsensitiveCounters(); const assetCountByTag = new CaseInsensitiveCounters(); @@ -98,12 +91,12 @@ export function buildAssetCountBySection(assets: AssetDefinitionMetadata[]): Ass const computeKind = assetDefinition.computeKind; if (computeKind) { - assetCountByComputeKind.increment(computeKind); + assetCountByKind.increment(computeKind); } assetDefinition.tags.forEach((tag) => { - if (isCanonicalStorageKindTag(tag)) { - assetCountByStorageKind.increment(tag.value); + if (isKindTag(tag)) { + assetCountByKind.increment(tag.key.substring(KIND_TAG_PREFIX.length)); } else { const stringifiedTag = JSON.stringify(tag); assetCountByTag.increment(stringifiedTag); @@ -135,24 +128,13 @@ export function buildAssetCountBySection(assets: AssetDefinitionMetadata[]): Ass assetCount: count, })) .sort(({owner: ownerA}, {owner: ownerB}) => COMMON_COLLATOR.compare(ownerA, ownerB)); - const countsByComputeKind = assetCountByComputeKind - .entries() - .map(([computeKind, count]) => ({ - computeKind, - assetCount: count, - })) - .sort(({computeKind: computeKindA}, {computeKind: computeKindB}) => - COMMON_COLLATOR.compare(computeKindA, computeKindB), - ); - const countsByStorageKind = assetCountByStorageKind + const countsByKind = assetCountByKind .entries() - .map(([storageKind, count]) => ({ - storageKind, + .map(([kind, count]) => ({ + kind, assetCount: count, })) - .sort(({storageKind: storageKindA}, {storageKind: storageKindB}) => - COMMON_COLLATOR.compare(storageKindA, storageKindB), - ); + .sort(({kind: kindA}, {kind: kindB}) => COMMON_COLLATOR.compare(kindA, kindB)); const countPerTag = assetCountByTag .entries() @@ -207,10 +189,9 @@ export function buildAssetCountBySection(assets: AssetDefinitionMetadata[]): Ass return { countsByOwner, - countsByComputeKind, + countsByKind, countPerTag, countPerAssetGroup, countPerCodeLocation, - countsByStorageKind, }; } diff --git a/js_modules/dagster-ui/packages/ui-core/src/search/SearchResults.tsx b/js_modules/dagster-ui/packages/ui-core/src/search/SearchResults.tsx index 3e6fb09143492..fca6eef8898d3 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/search/SearchResults.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/search/SearchResults.tsx @@ -49,7 +49,7 @@ const iconForType = (type: SearchResultType | AssetFilterSearchResultType): Icon return 'account_circle'; case AssetFilterSearchResultType.AssetGroup: return 'asset_group'; - case AssetFilterSearchResultType.ComputeKind: + case AssetFilterSearchResultType.Kind: return 'compute_kind'; case AssetFilterSearchResultType.Tag: return 'tag'; @@ -68,7 +68,7 @@ const assetFilterPrefixString = (type: AssetFilterSearchResultType): string => { switch (type) { case AssetFilterSearchResultType.CodeLocation: return 'Code location'; - case AssetFilterSearchResultType.ComputeKind: + case AssetFilterSearchResultType.Kind: return 'Compute kind'; case AssetFilterSearchResultType.Tag: return 'Tag'; @@ -150,7 +150,7 @@ function buildSearchIcons(item: SearchResult, isHighlight: boolean): JSX.Element } } - if (item.type === AssetFilterSearchResultType.ComputeKind) { + if (item.type === AssetFilterSearchResultType.Kind) { if (KNOWN_TAGS[item.label]) { const computeKindSearchIcon = ; diff --git a/js_modules/dagster-ui/packages/ui-core/src/search/types.ts b/js_modules/dagster-ui/packages/ui-core/src/search/types.ts index 54662c475527e..4ca14760b5924 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/search/types.ts +++ b/js_modules/dagster-ui/packages/ui-core/src/search/types.ts @@ -28,7 +28,7 @@ export enum SearchResultType { export enum AssetFilterSearchResultType { // Add types with corresponding strings to distinguish // between SearchResultType.AssetGroup - ComputeKind = 'AssetFilterSearchResultType.ComputeKind', + Kind = 'AssetFilterSearchResultType.ComputeKind', Tag = 'AssetFilterSearchResultType.Tag', CodeLocation = 'AssetFilterSearchResultType.CodeLocation', Owner = 'AssetFilterSearchResultType.Owner', @@ -43,7 +43,7 @@ export function isAssetFilterSearchResultType( return ( type === AssetFilterSearchResultType.AssetGroup || type === AssetFilterSearchResultType.CodeLocation || - type === AssetFilterSearchResultType.ComputeKind || + type === AssetFilterSearchResultType.Kind || type === AssetFilterSearchResultType.StorageKind || type === AssetFilterSearchResultType.Owner || type === AssetFilterSearchResultType.Tag || 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 1ff120135ba47..22062cd993b60 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 @@ -228,24 +228,13 @@ const secondaryDataToSearchResults = ( } else { const countsBySection = buildAssetCountBySection(nodes); - const computeKindResults: SearchResult[] = countsBySection.countsByComputeKind.map( - ({computeKind, assetCount}) => ({ - label: computeKind, - description: '', - type: AssetFilterSearchResultType.ComputeKind, - href: linkToAssetTableWithKindFilter(computeKind), - numResults: assetCount, - }), - ); - const storageKindResults: SearchResult[] = countsBySection.countsByStorageKind.map( - ({storageKind, assetCount}) => ({ - label: storageKind, - description: '', - type: AssetFilterSearchResultType.StorageKind, - href: linkToAssetTableWithKindFilter(storageKind), - numResults: assetCount, - }), - ); + const kindResults: SearchResult[] = countsBySection.countsByKind.map(({kind, assetCount}) => ({ + label: kind, + description: '', + type: AssetFilterSearchResultType.Kind, + href: linkToAssetTableWithKindFilter(kind), + numResults: assetCount, + })); const tagResults: SearchResult[] = countsBySection.countPerTag.map(({tag, assetCount}) => ({ label: buildTagString(tag), @@ -293,8 +282,7 @@ const secondaryDataToSearchResults = ( ); return [ ...assets, - ...computeKindResults, - ...storageKindResults, + ...kindResults, ...tagResults, ...codeLocationResults, ...ownerResults,