Skip to content

Commit

Permalink
update UI to search foreach stack (#134)
Browse files Browse the repository at this point in the history
* update UI to search foreach stack

* update test

* make search scope enum
  • Loading branch information
darinyu committed Feb 1, 2024
1 parent 7778b99 commit 1013015
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 22 deletions.
3 changes: 2 additions & 1 deletion docs/feature-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ ui_backed:
| TASK_METADATA | Show metadata for each task on task view | true |
| TIMELINE_MINIMAP | Show rough presentation of lines in timeline minimap | true |
| ARTIFACT_TABLE | Show artifact table on task view | false |
| ARTIFACT_SEARCH | Enable search field in timeline view to filter tasks by artifact values | false |
| ARTIFACT_SEARCH | In timeline view, filter tasks by artifact values | false |
| FOREACH_VAR_SEARCH | In timeline view, filter tasks by foreach variable or values | false |
| DEBUG_VIEW | Expose this view in help menu as a link | true |
| CARDS | Show cards on task view | true |
| HIDE_LOGO | Hide Metaflow logo | false |
Expand Down
4 changes: 2 additions & 2 deletions src/components/SearchField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const SearchField: React.FC<SearchFieldProps> = ({
return (
<SearchFieldContainer title={t('task.search-tasks-tip') ?? ''}>
<FilterInput
sectionLabel={t('search.artifact')}
sectionLabel={t('search.filter')}
initialValue={initialValue}
onChange={handleChange}
onSubmit={handleSubmit}
Expand All @@ -50,7 +50,7 @@ const SearchField: React.FC<SearchFieldProps> = ({
autoCompleteEnabled={autoCompleteEnabled}
tip="key:value"
status={results.status}
infoMsg={t('search.artifactInfo') ?? ''}
infoMsg={t('search.filterInfo') ?? ''}
errorMsg={(results.status === 'Error' && results.errorMsg) || undefined}
/>
</SearchFieldContainer>
Expand Down
2 changes: 1 addition & 1 deletion src/components/TaskListingHeader/TaskListingHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const TaskListingHeader: React.FC<TaskListingProps> = ({
collapse={() => onToggleCollapse('collapse')}
isAnyGroupOpen={isAnyGroupOpen}
/>
{FEATURE_FLAGS.ARTIFACT_SEARCH && (
{(FEATURE_FLAGS.ARTIFACT_SEARCH || FEATURE_FLAGS.FOREACH_VAR_SEARCH) && (
<SearchField
initialValue={searchField.fieldProps.text}
onUpdate={searchField.fieldProps.setText}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSearchField/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default function useSearchField(flowID: string, runNumber: string): Searc
}, [flowID, runNumber]);

useSearchRequest({
url: `/flows/${flowID}/runs/${runNumber}/search`,
url: `/search/flows/${flowID}/runs/${runNumber}`,
searchValue: searchValue,
onUpdate,
onConnecting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { parseSearchValue } from '..';
describe('useSearchRequest', () => {
it('parseSearchValue', () => {
expect(parseSearchValue('')).to.equal(null);
expect(parseSearchValue('test')).to.eql({ key: 'test' });
expect(parseSearchValue('test:')).to.eql({ key: 'test' });
expect(parseSearchValue('test: ')).to.eql({ key: 'test' });
expect(parseSearchValue('test : ')).to.eql({ key: 'test ' });
expect(parseSearchValue('test :val')).to.eql({ key: 'test ', value: 'val' });
expect(parseSearchValue('test :val ')).to.eql({ key: 'test ', value: 'val' });
expect(parseSearchValue('test')).to.eql({ key: 'test', scope: '' });
expect(parseSearchValue('test:')).to.eql({ key: 'test', scope: '' });
expect(parseSearchValue('test: ')).to.eql({ key: 'test', scope: '' });
expect(parseSearchValue('test : ')).to.eql({ key: 'test ', scope: '' });
expect(parseSearchValue('test :val')).to.eql({ key: 'test ', value: 'val', scope: '' });
expect(parseSearchValue('test :val ')).to.eql({ key: 'test ', value: 'val', scope: '' });
});
});
29 changes: 22 additions & 7 deletions src/hooks/useSearchRequest/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMemo } from 'react';
import useWebsocketRequest, { OnOpen, OnUpdate, OnClose, OnError } from '../useWebsocketRequest';
import FEATURE_FLAGS from '../../utils/FEATURE';

export type SearchResult =
| {
Expand Down Expand Up @@ -41,18 +42,32 @@ export interface HookConfig {
enabled?: boolean;
}

interface SearchKeyValuePair {
interface SearchTerm {
key: string;
scope: string;
value?: string;
}

export const parseSearchValue = (searchValue: string): SearchKeyValuePair | null => {
enum SearchScope {
Artifact = 'ARTIFACT',
ForeachVariable = 'FOREACH_VARIABLE',
}

export const parseSearchValue = (searchValue: string): SearchTerm | null => {
const scope: string[] = [];
if (FEATURE_FLAGS.ARTIFACT_SEARCH) {
scope.push(SearchScope.Artifact);
}
if (FEATURE_FLAGS.FOREACH_VAR_SEARCH) {
scope.push(SearchScope.ForeachVariable);
}

const components = (searchValue || '').trim().split(':').filter(Boolean);
if (components.length > 0) {
if (components[1]) {
return { key: components[0], value: components[1] };
return { key: components[0], value: components[1], scope: scope.join(',') };
}
return { key: components[0] };
return { key: components[0], scope: scope.join(',') };
}
return null;
};
Expand All @@ -67,14 +82,14 @@ export default function useSearchRequest({
onOpen,
enabled = true,
}: HookConfig): void {
const searchKv = useMemo(() => {
const searchTerm = useMemo(() => {
return parseSearchValue(searchValue);
}, [searchValue]);

useWebsocketRequest<SearchResult>({
url,
queryParams: searchKv !== null ? (searchKv as unknown as Record<string, string>) : {},
enabled: searchKv !== null && enabled,
queryParams: searchTerm !== null ? (searchTerm as unknown as Record<string, string>) : {},
enabled: searchTerm !== null && enabled,
onConnecting,
onUpdate,
onClose,
Expand Down
9 changes: 5 additions & 4 deletions src/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const en = {
'std-out': 'stdout',
'std-err': 'stderr',
artifacts: 'Artifacts',
'search-tasks-tip': 'Search: artifact_name:value',
'search-tasks-tip': 'Search: name:value',
'no-logs': 'No logs',
'no-preload-logs': 'No logs. Logs will be checked again momentarily',
'logs-only-available-AWS': 'Logs were not found from AWS.',
Expand Down Expand Up @@ -201,8 +201,8 @@ const en = {

search: {
search: 'Search',
artifact: 'Artifact',
artifactInfo: 'You can wrap value "" to search for an exact match.',
filter: 'Filter',
filterInfo: 'You can wrap value "" to search for an exact match.',
'no-results': 'No search results',
'no-tasks': 'No tasks with selected settings',
'failed-to-search': 'Failed to search',
Expand Down Expand Up @@ -310,7 +310,8 @@ const en = {
TASK_METADATA_msg: 'Show metadata for each task on task view.',
TIMELINE_MINIMAP_msg: 'Show rough presentation of lines in timeline minimap.',
ARTIFACT_TABLE_msg: 'Show artifact table on task view.',
ARTIFACT_SEARCH_msg: 'Enable search field in timeline view to filter tasks by artifact values.',
ARTIFACT_SEARCH_msg: 'In timeline view, filter tasks by artifact values.',
FOREACH_VAR_SEARCH_msg: 'In timeline view, filter tasks by foreach variable or values.',
DEBUG_VIEW_msg: 'Expose this view in help menu as a link.',
CARDS_msg: 'Show cards on task view.',
HIDE_LOGO_msg: 'Hide Metaflow logo.',
Expand Down
1 change: 1 addition & 0 deletions src/utils/FEATURE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const FEATURE_FLAGS = {
TIMELINE_MINIMAP: (process.env.REACT_APP_FEATURE_TIMELINE_MINIMAP || '1') === '1',
ARTIFACT_TABLE: (process.env.REACT_APP_FEATURE_ARTIFACT_TABLE || '0') === '1',
ARTIFACT_SEARCH: (process.env.REACT_APP_FEATURE_ARTIFACT_SEARCH || '0') === '1',
FOREACH_VAR_SEARCH: (process.env.REACT_APP_FEATURE_FOREACH_VAR_SEARCH || '0') === '1',
DEBUG_VIEW: (process.env.REACT_APP_FEATURE_DEBUG_VIEW || '1') === '1',
CARDS: (process.env.REACT_APP_FEATURE_CARDS || '1') === '1',

Expand Down

0 comments on commit 1013015

Please sign in to comment.