Skip to content

Commit

Permalink
kind results
Browse files Browse the repository at this point in the history
  • Loading branch information
benpankow committed Aug 23, 2024
1 parent 5ad0320 commit 8a98eb6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,13 +13,8 @@ type CountByOwner = {
assetCount: number;
};

type CountByComputeKind = {
computeKind: string;
assetCount: number;
};

type CountByStorageKind = {
storageKind: string;
type CountByKind = {
kind: string;
assetCount: number;
};

Expand All @@ -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 = {
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -207,10 +189,9 @@ export function buildAssetCountBySection(assets: AssetDefinitionMetadata[]): Ass

return {
countsByOwner,
countsByComputeKind,
countsByKind,
countPerTag,
countPerAssetGroup,
countPerCodeLocation,
countsByStorageKind,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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 = <TagIcon label={item.label} />;

Expand Down
4 changes: 2 additions & 2 deletions js_modules/dagster-ui/packages/ui-core/src/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -293,8 +282,7 @@ const secondaryDataToSearchResults = (
);
return [
...assets,
...computeKindResults,
...storageKindResults,
...kindResults,
...tagResults,
...codeLocationResults,
...ownerResults,
Expand Down

0 comments on commit 8a98eb6

Please sign in to comment.