From: Janicki Artur Date: Wed, 24 Oct 2018 18:29:19 +0000 (+0200) Subject: code refactoring and improve views X-Git-Tag: 1.3.0~48^2~3 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/a94211e27f3eebaea55ccba096869f70161e74ad code refactoring and improve views Feature #14276 Arvados-DCO-1.1-Signed-off-by: Janicki Artur --- 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 c658c33b..10e535c5 100644 --- a/src/views-components/search-bar/search-bar-advanced-view.tsx +++ b/src/views-components/search-bar/search-bar-advanced-view.tsx @@ -60,19 +60,24 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ } }); -interface SearchBarAdvancedViewDataProps { +interface SearchBarAdvancedViewFormDataProps { submitting: boolean; invalid: boolean; pristine: boolean; } -interface SearchBarAdvancedViewActionProps { - setView: (currentView: string) => void; - saveQuery: (data: SearchBarAdvanceFormData) => void; +export interface SearchBarAdvancedViewDataProps { tags: any; } -type SearchBarAdvancedViewProps = SearchBarAdvancedViewActionProps & SearchBarAdvancedViewDataProps +export interface SearchBarAdvancedViewActionProps { + onSetView: (currentView: string) => void; + saveQuery: (data: SearchBarAdvanceFormData) => void; +} + +type SearchBarAdvancedViewProps = SearchBarAdvancedViewActionProps & SearchBarAdvancedViewDataProps; + +type SearchBarAdvancedViewFormProps = SearchBarAdvancedViewProps & SearchBarAdvancedViewFormDataProps & InjectedFormProps & WithStyles; const validate = (values: any) => { @@ -88,7 +93,7 @@ const validate = (values: any) => { }; export const SearchBarAdvancedView = compose( - reduxForm({ + reduxForm({ form: SEARCH_BAR_ADVANCE_FORM_NAME, validate, onSubmit: (data: SearchBarAdvanceFormData, dispatch: Dispatch) => { @@ -97,7 +102,7 @@ export const SearchBarAdvancedView = compose( } }), withStyles(styles))( - ({ classes, setView, handleSubmit, submitting, invalid, pristine, tags }: SearchBarAdvancedViewProps) => + ({ classes, onSetView, handleSubmit, submitting, invalid, pristine, tags }: SearchBarAdvancedViewFormProps) =>
@@ -126,7 +131,7 @@ export const SearchBarAdvancedView = compose( - setView(SearchView.BASIC)} className={classes.closeIcon}> + onSetView(SearchView.BASIC)} className={classes.closeIcon}> diff --git a/src/views-components/search-bar/search-bar-autocomplete-view.tsx b/src/views-components/search-bar/search-bar-autocomplete-view.tsx index 48172424..dd21a0f6 100644 --- a/src/views-components/search-bar/search-bar-autocomplete-view.tsx +++ b/src/views-components/search-bar/search-bar-autocomplete-view.tsx @@ -3,8 +3,7 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; -import { Paper, StyleRulesCallback, withStyles, WithStyles, List } from '@material-ui/core'; -import { RenderAutocompleteItems } from '~/views-components/search-bar/search-bar-view'; +import { Paper, StyleRulesCallback, withStyles, WithStyles, List, ListItem, ListItemText } from '@material-ui/core'; import { GroupContentsResource } from '~/services/groups-service/groups-service'; import Highlighter from "react-highlight-words"; @@ -24,18 +23,23 @@ const styles: StyleRulesCallback = theme => { export interface SearchBarAutocompleteViewDataProps { searchResults?: GroupContentsResource[]; searchValue?: string; +} + +export interface SearchBarAutocompleteViewActionProps { navigateTo: (uuid: string) => void; } -type SearchBarAutocompleteViewProps = SearchBarAutocompleteViewDataProps & WithStyles; +type SearchBarAutocompleteViewProps = SearchBarAutocompleteViewDataProps & SearchBarAutocompleteViewActionProps & WithStyles; export const SearchBarAutocompleteView = withStyles(styles)( ({ classes, searchResults, searchValue, navigateTo }: SearchBarAutocompleteViewProps) => {searchResults && - {searchResults.map((item: GroupContentsResource) => { - return ; - })} + {searchResults.map((item: GroupContentsResource) => + + navigateTo(item.uuid)} /> + + )} } ); diff --git a/src/views-components/search-bar/search-bar-basic-view.tsx b/src/views-components/search-bar/search-bar-basic-view.tsx index 8ad0f095..9d312a05 100644 --- a/src/views-components/search-bar/search-bar-basic-view.tsx +++ b/src/views-components/search-bar/search-bar-basic-view.tsx @@ -3,59 +3,65 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; -import { Paper, StyleRulesCallback, withStyles, WithStyles, List } from '@material-ui/core'; +import { Paper, StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core'; import { SearchView } from '~/store/search-bar/search-bar-reducer'; -import { RenderRecentQueries, RenderSavedQueries } from '~/views-components/search-bar/search-bar-view'; -import { SearchBarAdvanceFormData } from '~/models/search-bar'; +import { + SearchBarRenderRecentQueries, + SearchBarRenderRecentQueriesActionProps +} from '~/views-components/search-bar/search-bar-render-recent-queries'; +import { + SearchBarRenderSavedQueries, + SearchBarRenderSavedQueriesDataProps, + SearchBarRenderSavedQueriesActionProps +} from '~/views-components/search-bar/search-bar-render-save-queries'; -type CssRules = 'advanced' | 'searchQueryList' | 'list' | 'searchView'; +type CssRules = 'advanced' | 'label' | 'root'; const styles: StyleRulesCallback = theme => { return { + root: { + color: theme.palette.common.black, + borderRadius: `0 0 ${theme.spacing.unit / 2}px ${theme.spacing.unit / 2}px` + }, advanced: { display: 'flex', justifyContent: 'flex-end', - paddingRight: theme.spacing.unit * 2, - paddingBottom: theme.spacing.unit, - fontSize: '14px', + padding: theme.spacing.unit, + fontSize: '0.875rem', cursor: 'pointer', color: theme.palette.primary.main }, - searchQueryList: { + label: { + fontSize: '0.875rem', padding: `${theme.spacing.unit / 2}px ${theme.spacing.unit}px `, - background: '#f2f2f2', - fontSize: '14px' - }, - list: { - padding: '0px' - }, - searchView: { - color: theme.palette.common.black, - borderRadius: `0 0 ${theme.spacing.unit / 2}px ${theme.spacing.unit / 2}px` + color: theme.palette.grey["900"], + background: theme.palette.grey["200"] } }; }; -interface SearchBarBasicViewProps { - setView: (currentView: string) => void; - recentQueries: () => string[]; - deleteSavedQuery: (id: number) => void; - savedQueries: SearchBarAdvanceFormData[]; +export type SearchBarBasicViewDataProps = SearchBarRenderSavedQueriesDataProps; + +export type SearchBarBasicViewActionProps = { + onSetView: (currentView: string) => void; onSearch: (searchValue: string) => void; - editSavedQuery: (data: SearchBarAdvanceFormData, id: number) => void; -} +} & SearchBarRenderRecentQueriesActionProps & SearchBarRenderSavedQueriesActionProps; + +type SearchBarBasicViewProps = SearchBarBasicViewDataProps & SearchBarBasicViewActionProps & WithStyles; export const SearchBarBasicView = withStyles(styles)( - ({ classes, setView, recentQueries, deleteSavedQuery, savedQueries, onSearch, editSavedQuery }: SearchBarBasicViewProps & WithStyles) => - -
Recent search queries
- - {recentQueries().map((query, index) => )} - -
Saved search queries
- - {savedQueries.map((query, index) => )} - -
setView(SearchView.ADVANCED)}>Advanced search
+ ({ classes, onSetView, loadRecentQueries, deleteSavedQuery, savedQueries, onSearch, editSavedQuery }: SearchBarBasicViewProps) => + +
Recent search queries
+ +
Saved search queries
+ +
onSetView(SearchView.ADVANCED)}>Advanced search
); \ No newline at end of file diff --git a/src/views-components/search-bar/search-bar-render-recent-queries.tsx b/src/views-components/search-bar/search-bar-render-recent-queries.tsx new file mode 100644 index 00000000..b248d70e --- /dev/null +++ b/src/views-components/search-bar/search-bar-render-recent-queries.tsx @@ -0,0 +1,43 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import * as React from 'react'; +import { withStyles, WithStyles, StyleRulesCallback, List, ListItem, ListItemText } from '@material-ui/core'; +import { ArvadosTheme } from '~/common/custom-theme'; + +type CssRules = 'root' | 'listItem' | 'listItemText'; + +const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ + root: { + padding: '0px' + }, + listItem: { + paddingLeft: theme.spacing.unit, + paddingRight: theme.spacing.unit * 2, + }, + listItemText: { + fontSize: '0.8125rem', + color: theme.palette.grey["900"] + } +}); + +export interface SearchBarRenderRecentQueriesActionProps { + onSearch: (searchValue: string) => void; + loadRecentQueries: () => string[]; +} + +type SearchBarRenderRecentQueriesProps = SearchBarRenderRecentQueriesActionProps & WithStyles; + +export const SearchBarRenderRecentQueries = withStyles(styles)( + ({ classes, onSearch, loadRecentQueries }: SearchBarRenderRecentQueriesProps) => + + {loadRecentQueries().map((query, index) => + + onSearch(query)} + className={classes.listItemText} /> + + )} + ); \ No newline at end of file diff --git a/src/views-components/search-bar/search-bar-render-save-queries.tsx b/src/views-components/search-bar/search-bar-render-save-queries.tsx new file mode 100644 index 00000000..5c525a7e --- /dev/null +++ b/src/views-components/search-bar/search-bar-render-save-queries.tsx @@ -0,0 +1,68 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import * as React from 'react'; +import { withStyles, WithStyles, StyleRulesCallback, List, ListItem, ListItemText, ListItemSecondaryAction, Tooltip, IconButton, Button } from '@material-ui/core'; +import { ArvadosTheme } from '~/common/custom-theme'; +import { RemoveIcon, EditSavedQueryIcon } from '~/components/icon/icon'; +import { SearchBarAdvanceFormData } from '~/models/search-bar'; + +type CssRules = 'root' | 'listItem' | 'listItemText' | 'button'; + +const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ + root: { + padding: '0px' + }, + listItem: { + paddingLeft: theme.spacing.unit, + paddingRight: theme.spacing.unit * 2 + }, + listItemText: { + fontSize: '0.8125rem', + color: theme.palette.grey["900"] + }, + button: { + padding: '6px', + marginRight: theme.spacing.unit + } +}); + +export interface SearchBarRenderSavedQueriesDataProps { + savedQueries: SearchBarAdvanceFormData[]; +} + +export interface SearchBarRenderSavedQueriesActionProps { + onSearch: (searchValue: string) => void; + deleteSavedQuery: (id: number) => void; + editSavedQuery: (data: SearchBarAdvanceFormData, id: number) => void; +} + +type SearchBarRenderSavedQueriesProps = SearchBarRenderSavedQueriesDataProps + & SearchBarRenderSavedQueriesActionProps + & WithStyles; + +export const SearchBarRenderSavedQueries = withStyles(styles)( + ({ classes, savedQueries, onSearch, editSavedQuery, deleteSavedQuery }: SearchBarRenderSavedQueriesProps) => + + {savedQueries.map((query, index) => + + onSearch(query.searchQuery)} + className={classes.listItemText} /> + + + editSavedQuery(query, index)} className={classes.button}> + + + + + deleteSavedQuery(index)} className={classes.button}> + + + + + + )} + ); \ No newline at end of file diff --git a/src/views-components/search-bar/search-bar-view.tsx b/src/views-components/search-bar/search-bar-view.tsx index 68418ba1..d5d885ea 100644 --- a/src/views-components/search-bar/search-bar-view.tsx +++ b/src/views-components/search-bar/search-bar-view.tsx @@ -11,17 +11,26 @@ import { WithStyles, Tooltip, InputAdornment, Input, - ListItem, ListItemText, ListItemSecondaryAction, ClickAwayListener } from '@material-ui/core'; import SearchIcon from '@material-ui/icons/Search'; -import { RemoveIcon, EditSavedQueryIcon } from '~/components/icon/icon'; -import { SearchView } from '~/store/search-bar/search-bar-reducer'; -import { SearchBarBasicView } from '~/views-components/search-bar/search-bar-basic-view'; -import { SearchBarAdvancedView } from '~/views-components/search-bar/search-bar-advanced-view'; -import { SearchBarAutocompleteView, SearchBarAutocompleteViewDataProps } from '~/views-components/search-bar/search-bar-autocomplete-view'; import { ArvadosTheme } from '~/common/custom-theme'; -import { SearchBarAdvanceFormData } from '~/models/search-bar'; +import { SearchView } from '~/store/search-bar/search-bar-reducer'; +import { + SearchBarBasicView, + SearchBarBasicViewDataProps, + SearchBarBasicViewActionProps +} from '~/views-components/search-bar/search-bar-basic-view'; +import { + SearchBarAutocompleteView, + SearchBarAutocompleteViewDataProps, + SearchBarAutocompleteViewActionProps +} from '~/views-components/search-bar/search-bar-autocomplete-view'; +import { + SearchBarAdvancedView, + SearchBarAdvancedViewDataProps, + SearchBarAdvancedViewActionProps +} from '~/views-components/search-bar/search-bar-advanced-view'; type CssRules = 'container' | 'containerSearchViewOpened' | 'input' | 'view'; @@ -49,89 +58,42 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => { }; }; -type SearchBarDataProps = { - searchValue: string; +export type SearchBarDataProps = SearchBarViewDataProps + & SearchBarAutocompleteViewDataProps + & SearchBarAdvancedViewDataProps + & SearchBarBasicViewDataProps; + +interface SearchBarViewDataProps { currentView: string; isPopoverOpen: boolean; - savedQueries: SearchBarAdvanceFormData[]; - tags: any; -} & SearchBarAutocompleteViewDataProps; + debounce?: number; +} + +export type SearchBarActionProps = SearchBarViewActionProps + & SearchBarAutocompleteViewActionProps + & SearchBarAdvancedViewActionProps + & SearchBarBasicViewActionProps; -interface SearchBarActionProps { +interface SearchBarViewActionProps { onSearch: (value: string) => any; searchDataOnEnter: (value: string) => void; - debounce?: number; onSetView: (currentView: string) => void; closeView: () => void; + openSearchView: () => void; saveRecentQuery: (query: string) => void; loadRecentQueries: () => string[]; - saveQuery: (data: SearchBarAdvanceFormData) => void; - deleteSavedQuery: (id: number) => void; - openSearchView: () => void; - navigateTo: (uuid: string) => void; - editSavedQuery: (data: SearchBarAdvanceFormData, id: number) => void; } -type SearchBarProps = SearchBarDataProps & SearchBarActionProps & WithStyles; +type SearchBarViewProps = SearchBarDataProps & SearchBarActionProps & WithStyles; interface SearchBarState { value: string; } -interface RenderRecentQueriesProps { - text: string; - onSearch: (searchValue: string) => void; -} - -export const RenderRecentQueries = (props: RenderRecentQueriesProps) => { - return - props.onSearch(props.text)} /> - ; -}; - -interface RenderAutocompleteItemsProps { - text: string | JSX.Element; - navigateTo: (uuid: string) => void; - uuid: string; -} - -export const RenderAutocompleteItems = (props: RenderAutocompleteItemsProps) => { - return - props.navigateTo(props.uuid)} /> - ; -}; - -interface RenderSavedQueriesProps { - text: string; - id: number; - deleteSavedQuery: (id: number) => void; - onSearch: (searchValue: string) => void; - editSavedQuery: (data: SearchBarAdvanceFormData, id: number) => void; - data: SearchBarAdvanceFormData; -} - -export const RenderSavedQueries = (props: RenderSavedQueriesProps) => { - return - props.onSearch(props.text)} /> - - - props.editSavedQuery(props.data, props.id)}> - - - - - props.deleteSavedQuery(props.id)}> - - - - - ; -}; - export const DEFAULT_SEARCH_DEBOUNCE = 1000; export const SearchBarView = withStyles(styles)( - class extends React.Component { + class extends React.Component { state: SearchBarState = { value: "" }; @@ -172,7 +134,7 @@ export const SearchBarView = withStyles(styles)( this.setState({ value: this.props.searchValue }); } - componentWillReceiveProps(nextProps: SearchBarProps) { + componentWillReceiveProps(nextProps: SearchBarViewProps) { if (nextProps.searchValue !== this.props.searchValue) { this.setState({ value: nextProps.searchValue }); } @@ -183,19 +145,27 @@ export const SearchBarView = withStyles(styles)( } getView = (currentView: string) => { - const { onSetView, loadRecentQueries, savedQueries, deleteSavedQuery, searchValue, searchResults, saveQuery, onSearch, navigateTo, editSavedQuery, tags } = this.props; + const { onSetView, loadRecentQueries, savedQueries, deleteSavedQuery, searchValue, + searchResults, saveQuery, onSearch, navigateTo, editSavedQuery, tags } = this.props; switch (currentView) { - case SearchView.BASIC: - return ; - case SearchView.ADVANCED: - return ; case SearchView.AUTOCOMPLETE: return ; + case SearchView.ADVANCED: + return ; default: - return ; + return ; } } @@ -207,6 +177,8 @@ export const SearchBarView = withStyles(styles)( this.props.loadRecentQueries(); } + // ToDo: nie pokazywac autocomplete jezeli jestesmy w advance + // currentView ze state.searchBar.currentView handleChange = (event: React.ChangeEvent) => { clearTimeout(this.timeout); this.setState({ value: event.target.value }); diff --git a/src/views-components/search-bar/search-bar.tsx b/src/views-components/search-bar/search-bar.tsx index 8f39caec..6ca588a7 100644 --- a/src/views-components/search-bar/search-bar.tsx +++ b/src/views-components/search-bar/search-bar.tsx @@ -18,10 +18,10 @@ import { editSavedQuery, searchDataOnEnter } from '~/store/search-bar/search-bar-actions'; -import { SearchBarView } from '~/views-components/search-bar/search-bar-view'; +import { SearchBarView, SearchBarActionProps, SearchBarDataProps } from '~/views-components/search-bar/search-bar-view'; import { SearchBarAdvanceFormData } from '~/models/search-bar'; -const mapStateToProps = ({ searchBar, form }: RootState) => { +const mapStateToProps = ({ searchBar, form }: RootState): SearchBarDataProps => { return { searchValue: searchBar.searchValue, currentView: searchBar.currentView, @@ -32,7 +32,7 @@ const mapStateToProps = ({ searchBar, form }: RootState) => { }; }; -const mapDispatchToProps = (dispatch: Dispatch) => ({ +const mapDispatchToProps = (dispatch: Dispatch): SearchBarActionProps => ({ onSearch: (valueSearch: string) => dispatch(searchData(valueSearch)), onSetView: (currentView: string) => dispatch(goToView(currentView)), closeView: () => dispatch(closeSearchView()),