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 { CustomStyleRulesCallback } from 'common/custom-theme';
9 import { Paper, Button, Grid, IconButton, CircularProgress } from '@mui/material';
10 import { WithStyles } from '@mui/styles';
11 import withStyles from '@mui/styles/withStyles';
13 SEARCH_BAR_ADVANCED_FORM_NAME, SEARCH_BAR_ADVANCED_FORM_PICKER_ID,
15 setSearchValueFromAdvancedData
16 } from 'store/search-bar/search-bar-actions';
17 import { ArvadosTheme } from 'common/custom-theme';
18 import { CloseIcon } from 'components/icon/icon';
19 import { SearchBarAdvancedFormData } from 'models/search-bar';
21 SearchBarTypeField, SearchBarClusterField, SearchBarProjectField, SearchBarTrashField,
22 SearchBarDateFromField, SearchBarDateToField, SearchBarPropertiesField,
23 SearchBarSaveSearchField, SearchBarQuerySearchField, SearchBarPastVersionsField
24 } from 'views-components/form-fields/search-bar-form-fields';
25 import { treePickerActions } from "store/tree-picker/tree-picker-actions";
27 type CssRules = 'container' | 'closeIcon' | 'label' | 'buttonWrapper'
28 | 'button' | 'circularProgress' | 'searchView' | 'selectGrid';
30 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
32 padding: theme.spacing(2),
33 borderBottom: `1px solid ${theme.palette.grey["200"]}`,
42 color: theme.palette.grey["500"],
43 fontSize: '0.8125rem',
63 color: theme.palette.common.black,
64 borderRadius: `0 0 ${theme.spacing(0.5)} ${theme.spacing(0.5)}`
67 marginBottom: theme.spacing(2)
71 // ToDo: maybe we should remove invalid and prostine
72 interface SearchBarAdvancedViewFormDataProps {
78 // ToDo: maybe we should remove tags
79 export interface SearchBarAdvancedViewDataProps {
84 export interface SearchBarAdvancedViewActionProps {
85 closeAdvanceView: () => void;
88 type SearchBarAdvancedViewProps = SearchBarAdvancedViewActionProps & SearchBarAdvancedViewDataProps;
90 type SearchBarAdvancedViewFormProps = SearchBarAdvancedViewProps & SearchBarAdvancedViewFormDataProps
91 & InjectedFormProps & WithStyles<CssRules>;
93 const validate = (values: any) => {
94 const errors: any = {};
96 if (values.dateFrom && values.dateTo) {
97 if (new Date(values.dateFrom).getTime() > new Date(values.dateTo).getTime()) {
98 errors.dateFrom = 'Invalid date';
105 export const SearchBarAdvancedView = compose(
106 reduxForm<SearchBarAdvancedFormData, SearchBarAdvancedViewProps>({
107 form: SEARCH_BAR_ADVANCED_FORM_NAME,
109 onSubmit: (data: SearchBarAdvancedFormData, dispatch: Dispatch) => {
110 dispatch<any>(searchAdvancedData(data));
111 dispatch(reset(SEARCH_BAR_ADVANCED_FORM_NAME));
112 dispatch(treePickerActions.DEACTIVATE_TREE_PICKER_NODE({ pickerId: SEARCH_BAR_ADVANCED_FORM_PICKER_ID }));
114 onChange: (data: SearchBarAdvancedFormData, dispatch: Dispatch, props: any, prevData: SearchBarAdvancedFormData) => {
115 dispatch<any>(setSearchValueFromAdvancedData(data, prevData));
119 ({ classes, closeAdvanceView, handleSubmit, submitting, invalid, pristine, tags, saveQuery }: SearchBarAdvancedViewFormProps) =>
120 <Paper className={classes.searchView}>
121 <form onSubmit={handleSubmit}>
122 <Grid container direction="column" justifyContent="flex-start" alignItems="flex-start">
123 <Grid item xs={12} container className={classes.container}>
124 <Grid item container xs={12} className={classes.selectGrid}>
125 <Grid item xs={2} className={classes.label}>Type</Grid>
127 <SearchBarTypeField />
130 <Grid item container xs={12} className={classes.selectGrid}>
131 <Grid item xs={2} className={classes.label}>Cluster</Grid>
133 <SearchBarClusterField />
136 <Grid item container xs={12}>
137 <Grid item xs={2} className={classes.label}>Project</Grid>
139 <SearchBarProjectField />
142 <Grid item container xs={12}>
143 <Grid item xs={2} className={classes.label} />
145 <SearchBarTrashField />
148 <SearchBarPastVersionsField />
151 <IconButton onClick={closeAdvanceView} className={classes.closeIcon} size="large">
155 <Grid container item xs={12} className={classes.container} spacing={2}>
156 <Grid item xs={2} className={classes.label}>Date modified</Grid>
158 <SearchBarDateFromField />
161 <SearchBarDateToField />
164 <Grid container item xs={12} className={classes.container}>
165 <SearchBarPropertiesField />
166 <Grid container item xs={12} justifyContent="flex-start" alignItems="center" spacing={2}>
167 <Grid item xs={2} className={classes.label} />
169 <SearchBarSaveSearchField />
172 {saveQuery && <SearchBarQuerySearchField />}
175 <Grid container item xs={12} justifyContent='flex-end'>
176 <div className={classes.buttonWrapper}>
177 <Button type="submit" className={classes.button}
178 // ToDo: create easier condition
179 // Question: do we need this condition?
180 // disabled={invalid || submitting || pristine || !!(tags && tags.values && ((tags.values.key) || (tags.values.value)) && !Object.keys(tags.values).find(el => el !== 'value' && el !== 'key'))}
186 {submitting && <CircularProgress size={20} className={classes.circularProgress} />}