Skip to content

Commit

Permalink
[4/k][ui] Hide kind tags by default from asset view
Browse files Browse the repository at this point in the history
  • Loading branch information
benpankow committed Sep 6, 2024
1 parent 857f297 commit e3002a1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ import {
AssetComputeKindTag,
AssetStorageKindTag,
isCanonicalStorageKindTag,
isSystemTag,
} from '../graph/KindTags';
import {CodeReferencesMetadataEntry, IntMetadataEntry} from '../graphql/types';
import {useStateWithStorage} from '../hooks/useStateWithStorage';
import {useLaunchPadHooks} from '../launchpad/LaunchpadHooksContext';
import {isCanonicalRowCountMetadataEntry} from '../metadata/MetadataEntry';
import {
Expand All @@ -83,6 +85,41 @@ import {buildTagString} from '../ui/tagAsString';
import {buildRepoAddress} from '../workspace/buildRepoAddress';
import {workspacePathFromAddress} from '../workspace/workspacePath';

const SystemTagsToggle = ({tags}: {tags: Array<{key: string; value: string}>}) => {
const [shown, setShown] = useStateWithStorage('show-asset-definition-system-tags', Boolean);

if (!shown) {
return (
<Caption>
<ButtonLink onClick={() => setShown(true)}>
<Box flex={{alignItems: 'center'}}>
<span>Show system tags ({tags.length || 0})</span>
<Icon name="arrow_drop_down" style={{transform: 'rotate(0deg)'}} />
</Box>
</ButtonLink>
</Caption>
);
} else {
return (
<Box flex={{direction: 'column', gap: 8}}>
<Box>
{tags.map((tag, idx) => (
<Tag key={idx}>{buildTagString(tag)}</Tag>
))}
</Box>
<Caption>
<ButtonLink onClick={() => setShown(false)}>
<Box flex={{alignItems: 'center'}}>
<span>Hide system tags</span>
<Icon name="arrow_drop_down" style={{transform: 'rotate(180deg)'}} />
</Box>
</ButtonLink>
</Caption>
</Box>
);
}
};

export const AssetNodeOverview = ({
assetKey,
assetNode,
Expand Down Expand Up @@ -267,6 +304,10 @@ export const AssetNodeOverview = ({

const storageKindTag = assetNode.tags?.find(isCanonicalStorageKindTag);
const filteredTags = assetNode.tags?.filter((tag) => tag.key !== 'dagster/storage_kind');

const nonSystemTags = filteredTags?.filter((tag) => !isSystemTag(tag));
const systemTags = filteredTags?.filter(isSystemTag);

const relationIdentifierMetadata = assetNode.metadataEntries?.find(
isCanonicalRelationIdentifierEntry,
);
Expand Down Expand Up @@ -364,9 +405,16 @@ export const AssetNodeOverview = ({
)}
</AttributeAndValue>
<AttributeAndValue label="Tags">
{filteredTags &&
filteredTags.length > 0 &&
filteredTags.map((tag, idx) => <Tag key={idx}>{buildTagString(tag)}</Tag>)}
{filteredTags && filteredTags.length > 0 && (
<Box flex={{direction: 'column', gap: 8}}>
<Box>
{nonSystemTags.map((tag, idx) => (
<Tag key={idx}>{buildTagString(tag)}</Tag>
))}
</Box>
<SystemTagsToggle tags={systemTags} />
</Box>
)}
</AttributeAndValue>
<AttributeAndValue label="Source code">
{codeSource &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const isCanonicalComputeKindTag = (tag: DefinitionTag) =>
export const isCanonicalStorageKindTag = (tag: DefinitionTag) => tag.key === STORAGE_KIND_TAG;

export const isKindTag = (tag: DefinitionTag) => tag.key.startsWith(KIND_TAG_PREFIX);
export const isSystemTag = isKindTag;
export const getKindFromTag = (tag: DefinitionTag) => tag.key.slice(KIND_TAG_PREFIX.length);

export const AssetComputeKindTag = ({
Expand Down

0 comments on commit e3002a1

Please sign in to comment.