1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { reduxForm, InjectedFormProps, reset } from 'redux-form';
7 import { compose, Dispatch } from 'redux';
8 import { Paper, StyleRulesCallback, withStyles, WithStyles, Button, Grid, IconButton, CircularProgress } from '@material-ui/core';
10 SEARCH_BAR_ADVANCED_FORM_NAME, SEARCH_BAR_ADVANCED_FORM_PICKER_ID,
12 setSearchValueFromAdvancedData
13 } from 'store/search-bar/search-bar-actions';
14 import { ArvadosTheme } from 'common/custom-theme';
15 import { CloseIcon } from 'components/icon/icon';
16 import { SearchBarAdvancedFormData } from 'models/search-bar';
18 SearchBarTypeField, SearchBarClusterField, SearchBarProjectField, SearchBarTrashField,
19 SearchBarDateFromField, SearchBarDateToField, SearchBarPropertiesField,
20 SearchBarSaveSearchField, SearchBarQuerySearchField, SearchBarPastVersionsField
21 } from 'views-components/form-fields/search-bar-form-fields';
22 import { treePickerActions } from "store/tree-picker/tree-picker-actions";
24 type CssRules = 'container' | 'closeIcon' | 'label' | 'buttonWrapper'
25 | 'button' | 'circularProgress' | 'searchView' | 'selectGrid';
27 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
29 padding: theme.spacing.unit * 2,
30 borderBottom: `1px solid ${theme.palette.grey["200"]}`,
39 color: theme.palette.grey["500"],
40 fontSize: '0.8125rem',
60 color: theme.palette.common.black,
61 borderRadius: `0 0 ${theme.spacing.unit / 2}px ${theme.spacing.unit / 2}px`
64 marginBottom: theme.spacing.unit * 2
68 // ToDo: maybe we should remove invalid and prostine
69 interface SearchBarAdvancedViewFormDataProps {
75 // ToDo: maybe we should remove tags
76 export interface SearchBarAdvancedViewDataProps {
81 export interface SearchBarAdvancedViewActionProps {
82 closeAdvanceView: () => void;
85 type SearchBarAdvancedViewProps = SearchBarAdvancedViewActionProps & SearchBarAdvancedViewDataProps;
87 type SearchBarAdvancedViewFormProps = SearchBarAdvancedViewProps & SearchBarAdvancedViewFormDataProps
88 & InjectedFormProps & WithStyles<CssRules>;
90 const validate = (values: any) => {
91 const errors: any = {};
93 if (values.dateFrom && values.dateTo) {
94 if (new Date(values.dateFrom).getTime() > new Date(values.dateTo).getTime()) {
95 errors.dateFrom = 'Invalid date';
102 export const SearchBarAdvancedView = compose(
103 reduxForm<SearchBarAdvancedFormData, SearchBarAdvancedViewProps>({
104 form: SEARCH_BAR_ADVANCED_FORM_NAME,
106 onSubmit: (data: SearchBarAdvancedFormData, dispatch: Dispatch) => {
107 dispatch<any>(searchAdvancedData(data));
108 dispatch(reset(SEARCH_BAR_ADVANCED_FORM_NAME));
109 dispatch(treePickerActions.DEACTIVATE_TREE_PICKER_NODE({ pickerId: SEARCH_BAR_ADVANCED_FORM_PICKER_ID }));
111 onChange: (data: SearchBarAdvancedFormData, dispatch: Dispatch, props: any, prevData: SearchBarAdvancedFormData) => {
112 dispatch<any>(setSearchValueFromAdvancedData(data, prevData));
116 ({ classes, closeAdvanceView, handleSubmit, submitting, invalid, pristine, tags, saveQuery }: SearchBarAdvancedViewFormProps) =>
117 <Paper className={classes.searchView}>
118 <form onSubmit={handleSubmit}>
119 <Grid container direction="column" justify="flex-start" alignItems="flex-start">
120 <Grid item xs={12} container className={classes.container}>
121 <Grid item container xs={12} className={classes.selectGrid}>
122 <Grid item xs={2} className={classes.label}>Type</Grid>
124 <SearchBarTypeField />
127 <Grid item container xs={12} className={classes.selectGrid}>
128 <Grid item xs={2} className={classes.label}>Cluster</Grid>
130 <SearchBarClusterField />
133 <Grid item container xs={12}>
134 <Grid item xs={2} className={classes.label}>Project</Grid>
136 <SearchBarProjectField />
139 <Grid item container xs={12}>
140 <Grid item xs={2} className={classes.label} />
142 <SearchBarTrashField />
145 <SearchBarPastVersionsField />
148 <IconButton onClick={closeAdvanceView} className={classes.closeIcon}>
152 <Grid container item xs={12} className={classes.container} spacing={16}>
153 <Grid item xs={2} className={classes.label}>Date modified</Grid>
155 <SearchBarDateFromField />
158 <SearchBarDateToField />
161 <Grid container item xs={12} className={classes.container}>
162 <SearchBarPropertiesField />
163 <Grid container item xs={12} justify="flex-start" alignItems="center" spacing={16}>
164 <Grid item xs={2} className={classes.label} />
166 <SearchBarSaveSearchField />
169 {saveQuery && <SearchBarQuerySearchField />}
172 <Grid container item xs={12} justify='flex-end'>
173 <div className={classes.buttonWrapper}>
174 <Button type="submit" className={classes.button}
175 // ToDo: create easier condition
176 // Question: do we need this condition?
177 // disabled={invalid || submitting || pristine || !!(tags && tags.values && ((tags.values.key) || (tags.values.value)) && !Object.keys(tags.values).find(el => el !== 'value' && el !== 'key'))}
183 {submitting && <CircularProgress size={20} className={classes.circularProgress} />}