X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/1080aac872d8c1d00b55a7291d88b704fc400813..c59db7f1ffae1a16a5458740510e173582e68925:/src/views-components/search-bar/search-bar-advanced-view.tsx

diff --git a/src/views-components/search-bar/search-bar-advanced-view.tsx b/src/views-components/search-bar/search-bar-advanced-view.tsx
index 583c9a0b12..a8d65a496b 100644
--- a/src/views-components/search-bar/search-bar-advanced-view.tsx
+++ b/src/views-components/search-bar/search-bar-advanced-view.tsx
@@ -7,23 +7,22 @@ import { reduxForm, reset, InjectedFormProps } from 'redux-form';
 import { compose, Dispatch } from 'redux';
 import { Paper, StyleRulesCallback, withStyles, WithStyles, Button, Grid, IconButton, CircularProgress } from '@material-ui/core';
 import { SearchView } from '~/store/search-bar/search-bar-reducer';
-import { SEARCH_BAR_ADVANCE_FORM_NAME, SearchBarAdvanceFormData } from '~/store/search-bar/search-bar-actions';
+import { SEARCH_BAR_ADVANCE_FORM_NAME, saveQuery } from '~/store/search-bar/search-bar-actions';
 import { ArvadosTheme } from '~/common/custom-theme';
 import { CloseIcon } from '~/components/icon/icon';
+import { SearchBarAdvanceFormData } from '~/models/search-bar';
 import { 
     SearchBarTypeField, SearchBarClusterField, SearchBarProjectField, SearchBarTrashField, 
-    SearchBarDataFromField, SearchBarDataToField, SearchBarKeyField, SearchBarValueField,
+    SearchBarDateFromField, SearchBarDateToField, SearchBarPropertiesField,
     SearchBarSaveSearchField, SearchBarQuerySearchField
 } from '~/views-components/form-fields/search-bar-form-fields';
 
-type CssRules = 'form' | 'container' | 'closeIcon' | 'label' | 'buttonWrapper' | 'button' | 'circularProgress';
+type CssRules = 'container' | 'closeIcon' | 'label' | 'buttonWrapper' 
+    | 'button' | 'circularProgress' | 'searchView' | 'selectGrid';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
-    form: {
-
-    },
     container: {
-        padding: theme.spacing.unit * 3,
+        padding: theme.spacing.unit * 2,
         borderBottom: `1px solid ${theme.palette.grey["200"]}`
     }, 
     closeIcon: {
@@ -37,6 +36,7 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
         alignSelf: 'center'
     },
     buttonWrapper: {
+        paddingRight: '14px',
         paddingTop: '14px',
         position: 'relative',
     },
@@ -50,6 +50,13 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
         left: 0,
         right: 0,
         margin: 'auto'
+    },
+    searchView: {
+        color: theme.palette.common.black,
+        borderRadius: `0 0 ${theme.spacing.unit / 2}px ${theme.spacing.unit / 2}px`
+    },
+    selectGrid: {
+        marginBottom: theme.spacing.unit * 2
     }
 });
 
@@ -61,32 +68,46 @@ interface SearchBarAdvancedViewDataProps {
 
 interface SearchBarAdvancedViewActionProps {
     setView: (currentView: string) => void;
+    saveQuery: (data: SearchBarAdvanceFormData) => void;
 }
 
 type SearchBarAdvancedViewProps = SearchBarAdvancedViewActionProps & SearchBarAdvancedViewDataProps 
     & InjectedFormProps & WithStyles<CssRules>;
 
+const validate = (values: any) => {
+    const errors: any = {};
+
+    if (values.dateFrom && values.dateTo ) {
+        if (new Date(values.dateFrom).getTime() > new Date(values.dateTo).getTime()) {
+            errors.dateFrom = 'Invalid date';
+        }
+    } 
+
+    return errors;
+};
+
 export const SearchBarAdvancedView = compose(
     reduxForm<SearchBarAdvanceFormData, SearchBarAdvancedViewActionProps>({
         form: SEARCH_BAR_ADVANCE_FORM_NAME,
+        validate,
         onSubmit: (data: SearchBarAdvanceFormData, dispatch: Dispatch) => {
-            console.log('data: ', data);
+            dispatch<any>(saveQuery(data));
             dispatch(reset(SEARCH_BAR_ADVANCE_FORM_NAME));
         }
     }),
     withStyles(styles))(
-        ({ classes, setView, handleSubmit, invalid, submitting, pristine }: SearchBarAdvancedViewProps) =>
-            <Paper>
-                <form onSubmit={handleSubmit} className={classes.form}>
+        ({ classes, setView, handleSubmit, submitting, invalid, pristine }: SearchBarAdvancedViewProps) =>
+            <Paper className={classes.searchView}>
+                <form onSubmit={handleSubmit}>
                     <Grid container direction="column" justify="flex-start" alignItems="flex-start">
                         <Grid item xs={12} container className={classes.container}>
-                            <Grid item container xs={12}>
+                            <Grid item container xs={12} className={classes.selectGrid}>
                                 <Grid item xs={2} className={classes.label}>Type</Grid>
                                 <Grid item xs={5}>
                                     <SearchBarTypeField />
                                 </Grid>
                             </Grid>
-                            <Grid item container xs={12}>
+                            <Grid item container xs={12} className={classes.selectGrid}>
                                 <Grid item xs={2} className={classes.label}>Cluster</Grid>
                                 <Grid item xs={5}>
                                     <SearchBarClusterField />
@@ -108,34 +129,18 @@ export const SearchBarAdvancedView = compose(
                                 <CloseIcon />
                             </IconButton>
                         </Grid>
-                        <Grid container item xs={12} className={classes.container}>
-                            <Grid item xs={2} className={classes.label}>Data modified</Grid>
-                            <Grid item xs={3}>
-                                <SearchBarDataFromField />
+                        <Grid container item xs={12} className={classes.container} spacing={16}>
+                            <Grid item xs={2} className={classes.label}>Date modified</Grid>
+                            <Grid item xs={4}>
+                                <SearchBarDateFromField />
                             </Grid>
-                            <Grid item xs={3}>
-                                <SearchBarDataToField />
+                            <Grid item xs={4}>
+                                <SearchBarDateToField />
                             </Grid>
                         </Grid>
                         <Grid container item xs={12} className={classes.container}>
-                            <Grid container item xs={12}>
-                                <Grid item xs={2} className={classes.label}>Properties</Grid>
-                                <Grid item xs={4}>
-                                    <SearchBarKeyField />
-                                </Grid>
-                                <Grid item xs={4}>
-                                    <SearchBarValueField />
-                                </Grid>
-                                <Grid container item xs={2} justify='flex-end' alignItems="center">
-                                    <Button className={classes.button}
-                                        color="primary"
-                                        size='small'
-                                        variant="contained">
-                                        Add
-                                    </Button>
-                                </Grid>
-                            </Grid>
-                            <Grid container item xs={12} justify="flex-start" alignItems="center">
+                            <SearchBarPropertiesField />
+                            <Grid container item xs={12} justify="flex-start" alignItems="center" spacing={16}>
                                 <Grid item xs={2} className={classes.label} />
                                 <Grid item xs={4}>
                                     <SearchBarSaveSearchField />
@@ -147,6 +152,7 @@ export const SearchBarAdvancedView = compose(
                             <Grid container item xs={12} justify='flex-end'>
                                 <div className={classes.buttonWrapper}>
                                     <Button type="submit" className={classes.button}
+                                        disabled={invalid || submitting || pristine}
                                         color="primary"
                                         size='small'
                                         variant="contained">
@@ -158,4 +164,5 @@ export const SearchBarAdvancedView = compose(
                         </Grid>
                     </Grid>
                 </form>
-            </Paper>);
+        </Paper>
+    );
