1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { withStyles, WithStyles, StyleRulesCallback, List, ListItem, ListItemText, ListItemSecondaryAction, Tooltip, IconButton } from '@material-ui/core';
7 import { ArvadosTheme } from '~/common/custom-theme';
8 import { RemoveIcon, EditSavedQueryIcon } from '~/components/icon/icon';
9 import { SearchBarAdvanceFormData } from '~/models/search-bar';
11 type CssRules = 'root' | 'listItem' | 'listItemText' | 'button';
13 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
18 paddingLeft: theme.spacing.unit,
19 paddingRight: theme.spacing.unit * 2
22 fontSize: '0.8125rem',
23 color: theme.palette.grey["900"]
27 marginRight: theme.spacing.unit
31 export interface SearchBarSavedQueriesDataProps {
32 savedQueries: SearchBarAdvanceFormData[];
35 export interface SearchBarSavedQueriesActionProps {
36 onSearch: (searchValue: string) => void;
37 deleteSavedQuery: (id: number) => void;
38 editSavedQuery: (data: SearchBarAdvanceFormData, id: number) => void;
41 type SearchBarSavedQueriesProps = SearchBarSavedQueriesDataProps
42 & SearchBarSavedQueriesActionProps
43 & WithStyles<CssRules>;
45 export const SearchBarSavedQueries = withStyles(styles)(
46 ({ classes, savedQueries, onSearch, editSavedQuery, deleteSavedQuery }: SearchBarSavedQueriesProps) =>
47 <List component="nav" className={classes.root}>
48 {savedQueries.map((query, index) =>
49 <ListItem button key={index} className={classes.listItem}>
50 <ListItemText disableTypography
51 secondary={query.searchQuery}
52 onClick={() => onSearch(query.searchQuery)}
53 className={classes.listItemText} />
54 <ListItemSecondaryAction>
55 <Tooltip title="Edit">
56 <IconButton aria-label="Edit" onClick={() => editSavedQuery(query, index)} className={classes.button}>
57 <EditSavedQueryIcon />
60 <Tooltip title="Remove">
61 <IconButton aria-label="Remove" onClick={() => deleteSavedQuery(index)} className={classes.button}>
65 </ListItemSecondaryAction>