17119: Merge branch 'master' into 17119-support-filter-groups
[arvados.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 } 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 { HomeTreePicker } from '~/views-components/projects-tree-picker/home-tree-picker';
12 import { SEARCH_BAR_ADVANCED_FORM_PICKER_ID } from '~/store/search-bar/search-bar-actions';
13 import { SearchBarAdvancedPropertiesView } from '~/views-components/search-bar/search-bar-advanced-properties-view';
14 import { TreeItem } from "~/components/tree/tree";
15 import { ProjectsTreePickerItem } from "~/views-components/projects-tree-picker/generic-projects-tree-picker";
16 import { PropertyKeyField, } from '~/views-components/resource-properties-form/property-key-field';
17 import { PropertyValueField } from '~/views-components/resource-properties-form/property-value-field';
18 import { connect } from "react-redux";
19 import { RootState } from "~/store/store";
20
21 export const SearchBarTypeField = () =>
22     <Field
23         name='type'
24         component={NativeSelectField}
25         items={[
26             { key: '', value: 'Any' },
27             { key: ResourceKind.COLLECTION, value: 'Collection' },
28             { key: ResourceKind.PROJECT, value: 'Project' },
29             { key: ResourceKind.PROCESS, value: 'Process' }
30         ]} />;
31
32
33 interface SearchBarClusterFieldProps {
34     clusters: { key: string, value: string }[];
35 }
36
37 export const SearchBarClusterField = connect(
38     (state: RootState) => ({
39         clusters: [{key: '', value: 'Any'}].concat(
40             state.auth.sessions
41                 .filter(s => s.loggedIn)
42                 .map(s => ({
43                     key: s.clusterId,
44                     value: s.clusterId
45                 })))
46     }))((props: SearchBarClusterFieldProps) => <Field
47         name='cluster'
48         component={NativeSelectField}
49         items={props.clusters}/>
50     );
51
52 export const SearchBarProjectField = () =>
53     <Field
54         name='projectUuid'
55         component={ProjectsPicker} />;
56
57 const ProjectsPicker = (props: WrappedFieldProps) =>
58     <div style={{ height: '100px', display: 'flex', flexDirection: 'column', overflow: 'overlay' }}>
59         <HomeTreePicker
60             pickerId={SEARCH_BAR_ADVANCED_FORM_PICKER_ID}
61             toggleItemActive={
62                 (_: any, { id }: TreeItem<ProjectsTreePickerItem>) => {
63                     props.input.onChange(id);
64                 }
65             } />
66     </div>;
67
68 export const SearchBarTrashField = () =>
69     <Field
70         name='inTrash'
71         component={CheckboxField}
72         label="In trash" />;
73
74 export const SearchBarPastVersionsField = () =>
75     <Field
76         name='pastVersions'
77         component={CheckboxField}
78         label="Past versions" />;
79
80 export const SearchBarDateFromField = () =>
81     <Field
82         name='dateFrom'
83         component={DateTextField} />;
84
85 export const SearchBarDateToField = () =>
86     <Field
87         name='dateTo'
88         component={DateTextField} />;
89
90 export const SearchBarPropertiesField = () =>
91     <FieldArray
92         name="properties"
93         component={SearchBarAdvancedPropertiesView} />;
94
95 export const SearchBarKeyField = () =>
96     <PropertyKeyField skipValidation={true} />;
97
98 export const SearchBarValueField = () =>
99     <PropertyValueField skipValidation={true} />;
100
101 export const SearchBarSaveSearchField = () =>
102     <Field
103         name='saveQuery'
104         component={CheckboxField}
105         label="Save query" />;
106
107 export const SearchBarQuerySearchField = () =>
108     <Field
109         name='queryName'
110         component={TextField}
111         label="Query name" />;