Merge branch '14434-display-workflow-name'
[arvados-workbench2.git] / src / views-components / form-fields / search-bar-form-fields.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from "react";
6 import { Field, WrappedFieldProps, FieldArray, formValues } from 'redux-form';
7 import { TextField, DateTextField } from "~/components/text-field/text-field";
8 import { CheckboxField } from '~/components/checkbox-field/checkbox-field';
9 import { NativeSelectField } from '~/components/select-field/select-field';
10 import { ResourceKind } from '~/models/resource';
11 import { ClusterObjectType } from '~/models/search-bar';
12 import { HomeTreePicker } from '~/views-components/projects-tree-picker/home-tree-picker';
13 import { SEARCH_BAR_ADVANCE_FORM_PICKER_ID } from '~/store/search-bar/search-bar-actions';
14 import { SearchBarAdvancedPropertiesView } from '~/views-components/search-bar/search-bar-advanced-properties-view';
15 import { TreeItem } from "~/components/tree/tree";
16 import { ProjectsTreePickerItem } from "~/views-components/projects-tree-picker/generic-projects-tree-picker";
17 import { PropertyKeyInput } from '~/views-components/resource-properties-form/property-key-field';
18 import { PropertyValueInput, PropertyValueFieldProps } from '~/views-components/resource-properties-form/property-value-field';
19 import { VocabularyProp, connectVocabulary } from '~/views-components/resource-properties-form/property-field-common';
20 import { compose } from 'redux';
21
22 export const SearchBarTypeField = () =>
23     <Field
24         name='type'
25         component={NativeSelectField}
26         items={[
27             { key: '', value: 'Any' },
28             { key: ResourceKind.COLLECTION, value: 'Collection' },
29             { key: ResourceKind.PROJECT, value: 'Project' },
30             { key: ResourceKind.PROCESS, value: 'Process' }
31         ]} />;
32
33 export const SearchBarClusterField = () =>
34     <Field
35         name='cluster'
36         component={NativeSelectField}
37         items={[
38             { key: '', value: 'Any' },
39             { key: ClusterObjectType.INDIANAPOLIS, value: 'Indianapolis' },
40             { key: ClusterObjectType.KAISERAUGST, value: 'Kaiseraugst' },
41             { key: ClusterObjectType.PENZBERG, value: 'Penzberg' }
42         ]} />;
43
44 export const SearchBarProjectField = () =>
45     <Field
46         name='projectUuid'
47         component={ProjectsPicker} />;
48
49 const ProjectsPicker = (props: WrappedFieldProps) =>
50     <div style={{ height: '100px', display: 'flex', flexDirection: 'column', overflow: 'overlay' }}>
51         <HomeTreePicker
52             pickerId={SEARCH_BAR_ADVANCE_FORM_PICKER_ID}
53             toggleItemActive={
54                 (_: any, { id }: TreeItem<ProjectsTreePickerItem>) => {
55                     props.input.onChange(id);
56                 }
57             } />
58     </div>;
59
60 export const SearchBarTrashField = () =>
61     <Field
62         name='inTrash'
63         component={CheckboxField}
64         label="In trash" />;
65
66 export const SearchBarDateFromField = () =>
67     <Field
68         name='dateFrom'
69         component={DateTextField} />;
70
71 export const SearchBarDateToField = () =>
72     <Field
73         name='dateTo'
74         component={DateTextField} />;
75
76 export const SearchBarPropertiesField = () =>
77     <FieldArray
78         name="properties"
79         component={SearchBarAdvancedPropertiesView} />;
80
81 export const SearchBarKeyField = connectVocabulary(
82     ({ vocabulary }: VocabularyProp) =>
83         <Field
84             name='key'
85             component={PropertyKeyInput}
86             vocabulary={vocabulary} />);
87
88 export const SearchBarValueField = compose(
89     connectVocabulary,
90     formValues({ propertyKey: 'key' })
91 )(
92     (props: PropertyValueFieldProps) =>
93         <Field
94             name='value'
95             component={PropertyValueInput}
96             {...props} />);
97
98 export const SearchBarSaveSearchField = () =>
99     <Field
100         name='saveQuery'
101         component={CheckboxField}
102         label="Save query" />;
103
104 export const SearchBarQuerySearchField = () =>
105     <Field
106         name='queryName'
107         component={TextField}
108         label="Query name" />;