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