Skip to content

Commit

Permalink
add different styling for filter results
Browse files Browse the repository at this point in the history
  • Loading branch information
clairelin135 committed Mar 8, 2024
1 parent 454c7d9 commit efb1513
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export const AssetsOverview = ({viewerName}: {viewerName?: string}) => {
<AssetGlobalLineageButton />
</Box>
</Box>
<SearchDialog searchPlaceholder="blah" isAssetSearch={true} displayAsOverlay={false} />
<SearchDialog isAssetSearch={true} displayAsOverlay={false} />
</Box>
</Box>
<Box flex={{direction: 'column'}}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {useHistory} from 'react-router-dom';
import styled from 'styled-components';

import {SearchResults} from './SearchResults';
import {SearchResult, SearchResultType} from './types';
import {SearchResult, SearchResultType, isAssetFilterSearchResultType} from './types';
import {useGlobalSearch} from './useGlobalSearch';
import {__updateSearchVisibility} from './useSearchVisibility';
import {ShortcutHandler} from '../app/ShortcutHandler';
Expand Down Expand Up @@ -89,11 +89,8 @@ function groupSearchResults(
assetResults: secondaryResults.filter(
(result) => result.item.type === SearchResultType.Asset,
),
assetFilterResults: secondaryResults.filter(
(result) =>
result.item.type === SearchResultType.AssetGroup ||
result.item.type === SearchResultType.ComputeKind ||
result.item.type === SearchResultType.CodeLocation,
assetFilterResults: secondaryResults.filter((result) =>
isAssetFilterSearchResultType(result.item.type),
),
};
} else {
Expand All @@ -112,7 +109,7 @@ export const SearchDialog = ({
isAssetSearch,
displayAsOverlay = true,
}: {
searchPlaceholder: string;
searchPlaceholder?: string;
isAssetSearch: boolean;
displayAsOverlay?: boolean;
}) => {
Expand Down
72 changes: 56 additions & 16 deletions js_modules/dagster-ui/packages/ui-core/src/search/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import {Colors, Icon, IconName, StyledTag} from '@dagster-io/ui-components';
import {Box, Colors, Icon, IconName, StyledTag} from '@dagster-io/ui-components';
import Fuse from 'fuse.js';
import * as React from 'react';
import {Link} from 'react-router-dom';
import styled from 'styled-components';

import {SearchResult, SearchResultType} from './types';
import {
AssetFilterSearchResultType,
SearchResult,
SearchResultType,
isAssetFilterSearchResultType,
} from './types';

const iconForType = (type: SearchResultType): IconName => {
const iconForType = (type: SearchResultType | AssetFilterSearchResultType): IconName => {
switch (type) {
case SearchResultType.Asset:
return 'asset';
Expand All @@ -27,11 +32,32 @@ const iconForType = (type: SearchResultType): IconName => {
return 'op';
case SearchResultType.Resource:
return 'resource';
case AssetFilterSearchResultType.CodeLocation:
return 'folder';
case AssetFilterSearchResultType.Owner:
return 'account_circle';
case AssetFilterSearchResultType.AssetGroup:
return 'asset_group';
default:
return 'source';
}
};

const assetFilterPrefixString = (type: AssetFilterSearchResultType): string => {
switch (type) {
case AssetFilterSearchResultType.CodeLocation:
return 'Code location';
case AssetFilterSearchResultType.ComputeKind:
return 'Compute kind';
case AssetFilterSearchResultType.Owner:
return 'Owner';
case AssetFilterSearchResultType.AssetGroup:
return 'Group';
default:
return '';
}
};

interface ItemProps {
isHighlight: boolean;
onClickResult: (result: Fuse.FuseResult<SearchResult>) => void;
Expand Down Expand Up @@ -108,20 +134,34 @@ const SearchResultItem = React.memo(({isHighlight, onClickResult, result}: ItemP
return (
<Item isHighlight={isHighlight} ref={element}>
<ResultLink to={item.href} onMouseDown={onClick}>
<StyledTag
$fillColor={Colors.backgroundGray()}
$interactive={false}
$textColor={Colors.textDefault()}
<Box
flex={{direction: 'row', justifyContent: 'space-between', alignItems: 'center'}}
style={{width: '100%'}}
>
<Icon
name={iconForType(item.type)}
color={isHighlight ? Colors.textDefault() : Colors.textLight()}
/>
{labelComponents.map((component) => component)}
</StyledTag>
<div style={{marginLeft: '12px'}}>
<Description isHighlight={isHighlight}>{item.description}</Description>
</div>
<Box flex={{direction: 'row', alignItems: 'center'}}>
<StyledTag
$fillColor={Colors.backgroundGray()}
$interactive={false}
$textColor={Colors.textDefault()}
>
<Icon
name={iconForType(item.type)}
color={isHighlight ? Colors.textDefault() : Colors.textLight()}
/>
{isAssetFilterSearchResultType(item.type) ? (
<SearchResultLabel>{assetFilterPrefixString(item.type)}:&nbsp;</SearchResultLabel>
) : (
<></>
)}
{labelComponents.map((component) => component)}
</StyledTag>
<div style={{marginLeft: '8px'}}>
<Description isHighlight={isHighlight}>
{item.numResults ? `${item.numResults} assets` : item.description}
</Description>
</div>
</Box>
</Box>
</ResultLink>
</Item>
);
Expand Down

0 comments on commit efb1513

Please sign in to comment.