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, reset, InjectedFormProps } 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 { SearchView } from '~/store/search-bar/search-bar-reducer';
10 import { SEARCH_BAR_ADVANCE_FORM_NAME, saveQuery } from '~/store/search-bar/search-bar-actions';
11 import { ArvadosTheme } from '~/common/custom-theme';
12 import { CloseIcon } from '~/components/icon/icon';
13 import { SearchBarAdvanceFormData } from '~/models/search-bar';
15 SearchBarTypeField, SearchBarClusterField, SearchBarProjectField, SearchBarTrashField,
16 SearchBarDateFromField, SearchBarDateToField, SearchBarPropertiesField,
17 SearchBarSaveSearchField, SearchBarQuerySearchField
18 } from '~/views-components/form-fields/search-bar-form-fields';
20 type CssRules = 'container' | 'closeIcon' | 'label' | 'buttonWrapper'
21 | 'button' | 'circularProgress' | 'searchView' | 'selectGrid';
23 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
25 padding: theme.spacing.unit * 2,
26 borderBottom: `1px solid ${theme.palette.grey["200"]}`
34 color: theme.palette.grey["500"],
35 fontSize: '0.8125rem',
55 color: theme.palette.common.black,
56 borderRadius: `0 0 ${theme.spacing.unit / 2}px ${theme.spacing.unit / 2}px`
59 marginBottom: theme.spacing.unit * 2
63 interface SearchBarAdvancedViewDataProps {
69 interface SearchBarAdvancedViewActionProps {
70 setView: (currentView: string) => void;
71 saveQuery: (data: SearchBarAdvanceFormData) => void;
74 type SearchBarAdvancedViewProps = SearchBarAdvancedViewActionProps & SearchBarAdvancedViewDataProps
75 & InjectedFormProps & WithStyles<CssRules>;
77 const validate = (values: any) => {
78 const errors: any = {};
80 if (values.dateFrom && values.dateTo ) {
81 if (new Date(values.dateFrom).getTime() > new Date(values.dateTo).getTime()) {
82 errors.dateFrom = 'Invalid date';
89 export const SearchBarAdvancedView = compose(
90 reduxForm<SearchBarAdvanceFormData, SearchBarAdvancedViewActionProps>({
91 form: SEARCH_BAR_ADVANCE_FORM_NAME,
93 onSubmit: (data: SearchBarAdvanceFormData, dispatch: Dispatch) => {
94 dispatch<any>(saveQuery(data));
95 dispatch(reset(SEARCH_BAR_ADVANCE_FORM_NAME));
99 ({ classes, setView, handleSubmit, submitting, invalid, pristine }: SearchBarAdvancedViewProps) =>
100 <Paper className={classes.searchView}>
101 <form onSubmit={handleSubmit}>
102 <Grid container direction="column" justify="flex-start" alignItems="flex-start">
103 <Grid item xs={12} container className={classes.container}>
104 <Grid item container xs={12} className={classes.selectGrid}>
105 <Grid item xs={2} className={classes.label}>Type</Grid>
107 <SearchBarTypeField />
110 <Grid item container xs={12} className={classes.selectGrid}>
111 <Grid item xs={2} className={classes.label}>Cluster</Grid>
113 <SearchBarClusterField />
116 <Grid item container xs={12}>
117 <Grid item xs={2} className={classes.label}>Project</Grid>
119 <SearchBarProjectField />
122 <Grid item container xs={12}>
123 <Grid item xs={2} className={classes.label} />
125 <SearchBarTrashField />
128 <IconButton onClick={() => setView(SearchView.BASIC)} className={classes.closeIcon}>
132 <Grid container item xs={12} className={classes.container} spacing={16}>
133 <Grid item xs={2} className={classes.label}>Date modified</Grid>
135 <SearchBarDateFromField />
138 <SearchBarDateToField />
141 <Grid container item xs={12} className={classes.container}>
142 <SearchBarPropertiesField />
143 <Grid container item xs={12} justify="flex-start" alignItems="center" spacing={16}>
144 <Grid item xs={2} className={classes.label} />
146 <SearchBarSaveSearchField />
149 <SearchBarQuerySearchField />
152 <Grid container item xs={12} justify='flex-end'>
153 <div className={classes.buttonWrapper}>
154 <Button type="submit" className={classes.button}
155 disabled={invalid || submitting || pristine}
161 {submitting && <CircularProgress size={20} className={classes.circularProgress} />}