Merge branch '21128-toolbar-context-menu'
[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 React from "react";
6 import { Field, 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 { SearchBarAdvancedPropertiesView } from 'views-components/search-bar/search-bar-advanced-properties-view';
12 import { PropertyKeyField, } from 'views-components/resource-properties-form/property-key-field';
13 import { PropertyValueField } from 'views-components/resource-properties-form/property-value-field';
14 import { connect } from "react-redux";
15 import { RootState } from "store/store";
16 import { ProjectInput, ProjectCommandInputParameter } from 'views/run-process-panel/inputs/project-input';
17
18 export const SearchBarTypeField = () =>
19     <Field
20         name='type'
21         component={NativeSelectField as any}
22         items={[
23             { key: '', value: 'Any' },
24             { key: ResourceKind.COLLECTION, value: 'Collection' },
25             { key: ResourceKind.PROJECT, value: 'Project' },
26             { key: ResourceKind.PROCESS, value: 'Process' }
27         ]} />;
28
29
30 interface SearchBarClusterFieldProps {
31     clusters: { key: string, value: string }[];
32 }
33
34 export const SearchBarClusterField = connect(
35     (state: RootState) => ({
36         clusters: [{ key: '', value: 'Any' }].concat(
37             state.auth.sessions
38                 .filter(s => s.loggedIn)
39                 .map(s => ({
40                     key: s.clusterId,
41                     value: s.clusterId
42                 })))
43     }))((props: SearchBarClusterFieldProps) => <Field
44         name='cluster'
45         component={NativeSelectField as any}
46         items={props.clusters} />
47     );
48
49 export const SearchBarProjectField = () =>
50     <ProjectInput required={false} input={{
51         id: "projectObject",
52         label: "Limit search to Project"
53     } as ProjectCommandInputParameter}
54         options={{ showOnlyOwned: false, showOnlyWritable: false }} />
55
56 export const SearchBarTrashField = () =>
57     <Field
58         name='inTrash'
59         component={CheckboxField}
60         label="In trash" />;
61
62 export const SearchBarPastVersionsField = () =>
63     <Field
64         name='pastVersions'
65         component={CheckboxField}
66         label="Past versions" />;
67
68 export const SearchBarDateFromField = () =>
69     <Field
70         name='dateFrom'
71         component={DateTextField as any} />;
72
73 export const SearchBarDateToField = () =>
74     <Field
75         name='dateTo'
76         component={DateTextField as any} />;
77
78 export const SearchBarPropertiesField = () =>
79     <FieldArray
80         name="properties"
81         component={SearchBarAdvancedPropertiesView as any} />;
82
83 export const SearchBarKeyField = () =>
84     <PropertyKeyField skipValidation={true} />;
85
86 export const SearchBarValueField = () =>
87     <PropertyValueField skipValidation={true} />;
88
89 export const SearchBarSaveSearchField = () =>
90     <Field
91         name='saveQuery'
92         component={CheckboxField}
93         label="Save query" />;
94
95 export const SearchBarQuerySearchField = () =>
96     <Field
97         name='queryName'
98         component={TextField as any}
99         label="Query name" />;