1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { CustomStyleRulesCallback } from 'common/custom-theme';
7 import { withStyles, WithStyles, List, ListItem, ListItemText, ListItemSecondaryAction, Tooltip, IconButton } from '@material-ui/core';
8 import { ArvadosTheme } from 'common/custom-theme';
9 import { RemoveIcon, EditSavedQueryIcon } from 'components/icon/icon';
10 import { SearchBarAdvancedFormData } from 'models/search-bar';
11 import { SearchBarSelectedItem } from "store/search-bar/search-bar-reducer";
12 import { getQueryFromAdvancedData } from "store/search-bar/search-bar-actions";
14 type CssRules = 'root' | 'listItem' | 'listItemText' | 'button';
16 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
21 paddingLeft: theme.spacing(1),
22 paddingRight: theme.spacing(2)
25 fontSize: '0.8125rem',
26 color: theme.palette.grey["900"]
30 marginRight: theme.spacing(1)
34 export interface SearchBarSavedQueriesDataProps {
35 savedQueries: SearchBarAdvancedFormData[];
36 selectedItem: SearchBarSelectedItem;
39 export interface SearchBarSavedQueriesActionProps {
40 onSearch: (searchValue: string) => void;
41 deleteSavedQuery: (id: number) => void;
42 editSavedQuery: (data: SearchBarAdvancedFormData, id: number) => void;
45 type SearchBarSavedQueriesProps = SearchBarSavedQueriesDataProps
46 & SearchBarSavedQueriesActionProps
47 & WithStyles<CssRules>;
49 export const SearchBarSavedQueries = withStyles(styles)(
50 ({ classes, savedQueries, onSearch, editSavedQuery, deleteSavedQuery, selectedItem }: SearchBarSavedQueriesProps) =>
51 <List component="nav" className={classes.root}>
52 {savedQueries.map((query, index) =>
53 <ListItem button key={index} className={classes.listItem} selected={`SQ-${index}-${query.queryName}` === selectedItem.id}>
54 <ListItemText disableTypography
55 secondary={query.queryName}
56 onClick={() => onSearch(getQueryFromAdvancedData(query))}
57 className={classes.listItemText} />
58 <ListItemSecondaryAction>
59 <Tooltip title="Edit">
60 <IconButton aria-label="Edit" onClick={() => editSavedQuery(query, index)} className={classes.button}>
61 <EditSavedQueryIcon />
64 <Tooltip title="Remove">
65 <IconButton aria-label="Remove" onClick={() => deleteSavedQuery(index)} className={classes.button}>
69 </ListItemSecondaryAction>