Skip to content

Commit

Permalink
add owners and result count
Browse files Browse the repository at this point in the history
  • Loading branch information
clairelin135 committed Mar 8, 2024
1 parent bd89800 commit c5d9429
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,28 @@ type CountPerCodeLocation = {
assetCount: number;
};

function buildAssetCountBySection(assets: AssetTableFragment[]): AssetCountsResult {
type AssetDefinitionMetadata = {
definition: {
owners: Array<
{__typename: 'UserAssetOwner'; email: string} | {__typename: 'TeamAssetOwner'; team: string}
>;
computeKind: string | null;
groupName: string | null;
repository: {
name: string;
location: {name: string};
};
} | null;
};

export function buildAssetCountBySection(assets: AssetDefinitionMetadata[]): AssetCountsResult {
const assetCountByOwner: Record<string, number> = {};
const assetCountByComputeKind: Record<string, number> = {};
const assetCountByGroup: Record<string, number> = {};
const assetCountByCodeLocation: Record<string, number> = {};

// TODO guard against the query data not containing the above fields?

assets
.filter((asset) => asset.definition)
.forEach((asset) => {
Expand Down
1 change: 1 addition & 0 deletions js_modules/dagster-ui/packages/ui-core/src/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type SearchResult = {
href: string;
type: SearchResultType;
tags?: string;
numResults?: number;
};

export type ReadyResponse = {type: 'ready'};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 55 additions & 49 deletions js_modules/dagster-ui/packages/ui-core/src/search/useGlobalSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {useIndexedDBCachedQuery} from './useIndexedDBCachedQuery';
import {PYTHON_ERROR_FRAGMENT} from '../app/PythonErrorFragment';
import {displayNameForAssetKey, isHiddenAssetGroupJob} from '../asset-graph/Utils';
import {buildAssetCountBySection} from '../assets/AssetsOverview';
import {assetDetailsPathForKey} from '../assets/assetDetailsPathForKey';
import {buildRepoPathForHuman} from '../workspace/buildRepoAddress';
import {workspacePath} from '../workspace/workspacePath';
Expand Down Expand Up @@ -147,62 +148,53 @@ const secondaryDataToSearchResults = (input: {data?: SearchSecondaryQuery}) => {
}

const {nodes} = data.assetsOrError;
const assetCountByComputeKind: Set<string> = new Set();
const assetCountByCodeLocation: Set<string> = new Set();
const assetGroups: Set<string> = new Set();

nodes
.filter((asset) => asset.definition)
.forEach((asset) => {
const assetDefinition = asset.definition!;

if (assetDefinition.computeKind) {
assetCountByComputeKind.add(assetDefinition.computeKind);
}

if (assetDefinition.repository) {
const locationName = assetDefinition.repository.location.name;
const repositoryName = assetDefinition.repository.name;
assetCountByCodeLocation.add(buildRepoPathForHuman(repositoryName, locationName));
}

if (assetDefinition.groupName) {
const groupName = assetDefinition.groupName;
const locationName = assetDefinition.repository.location.name;
const repositoryName = assetDefinition.repository.name;
assetGroups.add(JSON.stringify({groupName, repositoryName, locationName}));
}
});

const computeKindResults: SearchResult[] = Array.from(assetCountByComputeKind.values()).map(
(computeKind) => {
return {
label: computeKind,
description: 'Compute kind',
type: SearchResultType.ComputeKind,
href: '/assets',
};
},
);

const codeLocationResults: SearchResult[] = Array.from(assetCountByCodeLocation.values()).map(
(repoPath) => ({
label: repoPath,
const countsBySection = buildAssetCountBySection(nodes);

const computeKindResults: SearchResult[] = Object.entries(
countsBySection.countsByComputeKind,
).map(([computeKind, count]) => ({
label: computeKind,
description: 'Compute kind',
type: SearchResultType.ComputeKind,
href: '/assets',
numResults: count,
}));

const codeLocationResults: SearchResult[] = countsBySection.countPerCodeLocation.map(
(codeLocationAssetCount) => ({
label: buildRepoPathForHuman(
codeLocationAssetCount.repoAddress.name,
codeLocationAssetCount.repoAddress.location,
),
description: 'Code location',
type: SearchResultType.CodeLocation,
href: '/assets',
numResults: codeLocationAssetCount.assetCount,
}),
);

const groupResults: SearchResult[] = Array.from(assetGroups).map((group) => {
const {groupName, repositoryName, locationName} = JSON.parse(group);
return {
label: groupName,
description: `Asset group in ${buildRepoPathForHuman(repositoryName, locationName)}`,
const groupResults: SearchResult[] = countsBySection.countPerAssetGroup.map(
(groupAssetCount) => ({
label: groupAssetCount.groupMetadata.groupName,
description: `Asset group in ${buildRepoPathForHuman(
groupAssetCount.groupMetadata.repositoryName,
groupAssetCount.groupMetadata.repositoryLocationName,
)}`,
type: SearchResultType.AssetGroup,
href: workspacePath(repositoryName, locationName, `/asset-groups/${groupName}`),
};
});
href: '/assets',
}),
);

const ownerResults: SearchResult[] = Object.entries(countsBySection.countsByOwner).map(
([owner, count]) => ({
label: owner,
description: 'Owner',
type: SearchResultType.Asset,
href: '/assets',
numResults: count,
}),
);

const assets = nodes
.filter(({definition}) => definition !== null)
Expand All @@ -216,7 +208,13 @@ const secondaryDataToSearchResults = (input: {data?: SearchSecondaryQuery}) => {
};
});

return [...assets, ...computeKindResults, ...codeLocationResults, ...groupResults];
return [
...assets,
...computeKindResults,
...codeLocationResults,
...ownerResults,
...groupResults,
];
};

const fuseOptions = {
Expand Down Expand Up @@ -450,6 +448,14 @@ export const SEARCH_SECONDARY_QUERY = gql`
id
computeKind
groupName
owners {
... on TeamAssetOwner {
team
}
... on UserAssetOwner {
email
}
}
repository {
id
name
Expand Down

0 comments on commit c5d9429

Please sign in to comment.