1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as 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';
9 import { SEARCH_BAR_ADVANCE_FORM_NAME, searchAdvanceData } from '~/store/search-bar/search-bar-actions';
10 import { ArvadosTheme } from '~/common/custom-theme';
11 import { CloseIcon } from '~/components/icon/icon';
12 import { SearchBarAdvanceFormData } from '~/models/search-bar';
14 SearchBarTypeField, SearchBarClusterField, SearchBarProjectField, SearchBarTrashField,
15 SearchBarDateFromField, SearchBarDateToField, SearchBarPropertiesField,
16 SearchBarSaveSearchField, SearchBarQuerySearchField
17 } from '~/views-components/form-fields/search-bar-form-fields';
19 type CssRules = 'container' | 'closeIcon' | 'label' | 'buttonWrapper'
20 | 'button' | 'circularProgress' | 'searchView' | 'selectGrid';
22 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
24 padding: theme.spacing.unit * 2,
25 borderBottom: `1px solid ${theme.palette.grey["200"]}`
33 color: theme.palette.grey["500"],
34 fontSize: '0.8125rem',
54 color: theme.palette.common.black,
55 borderRadius: `0 0 ${theme.spacing.unit / 2}px ${theme.spacing.unit / 2}px`
58 marginBottom: theme.spacing.unit * 2
62 // ToDo: maybe we should remove invalid and prostine
63 interface SearchBarAdvancedViewFormDataProps {
69 // ToDo: maybe we should remove tags
70 export interface SearchBarAdvancedViewDataProps {
74 export interface SearchBarAdvancedViewActionProps {
75 closeAdvanceView: () => void;
78 type SearchBarAdvancedViewProps = SearchBarAdvancedViewActionProps & SearchBarAdvancedViewDataProps;
80 type SearchBarAdvancedViewFormProps = SearchBarAdvancedViewProps & SearchBarAdvancedViewFormDataProps
81 & InjectedFormProps & WithStyles<CssRules>;
83 const validate = (values: any) => {
84 const errors: any = {};
86 if (values.dateFrom && values.dateTo) {
87 if (new Date(values.dateFrom).getTime() > new Date(values.dateTo).getTime()) {
88 errors.dateFrom = 'Invalid date';
95 export const SearchBarAdvancedView = compose(
96 reduxForm<SearchBarAdvanceFormData, SearchBarAdvancedViewProps>({
97 form: SEARCH_BAR_ADVANCE_FORM_NAME,
99 onSubmit: (data: SearchBarAdvanceFormData, dispatch: Dispatch) => {
100 dispatch<any>(searchAdvanceData(data));
101 dispatch(reset(SEARCH_BAR_ADVANCE_FORM_NAME));
105 ({ classes, closeAdvanceView, handleSubmit, submitting, invalid, pristine, tags }: SearchBarAdvancedViewFormProps) =>
106 <Paper className={classes.searchView}>
107 <form onSubmit={handleSubmit}>
108 <Grid container direction="column" justify="flex-start" alignItems="flex-start">
109 <Grid item xs={12} container className={classes.container}>
110 <Grid item container xs={12} className={classes.selectGrid}>
111 <Grid item xs={2} className={classes.label}>Type</Grid>
113 <SearchBarTypeField />
116 <Grid item container xs={12} className={classes.selectGrid}>
117 <Grid item xs={2} className={classes.label}>Cluster</Grid>
119 <SearchBarClusterField />
122 <Grid item container xs={12}>
123 <Grid item xs={2} className={classes.label}>Project</Grid>
125 <SearchBarProjectField />
128 <Grid item container xs={12}>
129 <Grid item xs={2} className={classes.label} />
131 <SearchBarTrashField />
134 <IconButton onClick={closeAdvanceView} className={classes.closeIcon}>
138 <Grid container item xs={12} className={classes.container} spacing={16}>
139 <Grid item xs={2} className={classes.label}>Date modified</Grid>
141 <SearchBarDateFromField />
144 <SearchBarDateToField />
147 <Grid container item xs={12} className={classes.container}>
148 <SearchBarPropertiesField />
149 <Grid container item xs={12} justify="flex-start" alignItems="center" spacing={16}>
150 <Grid item xs={2} className={classes.label} />
152 <SearchBarSaveSearchField />
155 <SearchBarQuerySearchField />
158 <Grid container item xs={12} justify='flex-end'>
159 <div className={classes.buttonWrapper}>
160 <Button type="submit" className={classes.button}
161 // ToDo: create easier condition
162 // Question: do we need this condition?
163 // disabled={invalid || submitting || pristine || !!(tags && tags.values && ((tags.values.key) || (tags.values.value)) && !Object.keys(tags.values).find(el => el !== 'value' && el !== 'key'))}
169 {submitting && <CircularProgress size={20} className={classes.circularProgress} />}