15856: Unifies project tree component code into one subdir.
[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 SearchBarDateFromField = () =>
75     <Field
76         name='dateFrom'
77         component={DateTextField} />;
78
79 export const SearchBarDateToField = () =>
80     <Field
81         name='dateTo'
82         component={DateTextField} />;
83
84 export const SearchBarPropertiesField = () =>
85     <FieldArray
86         name="properties"
87         component={SearchBarAdvancedPropertiesView} />;
88
89 export const SearchBarKeyField = () =>
90     <PropertyKeyField skipValidation={true} />;
91
92 export const SearchBarValueField = () =>
93     <PropertyValueField skipValidation={true} />;
94
95 export const SearchBarSaveSearchField = () =>
96     <Field
97         name='saveQuery'
98         component={CheckboxField}
99         label="Save query" />;
100
101 export const SearchBarQuerySearchField = () =>
102     <Field
103         name='queryName'
104         component={TextField}
105         label="Query name" />;