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';
10 import { SearchBarSelectedItem } from "~/store/search-bar/search-bar-reducer";
12 type CssRules = 'root' | 'listItem' | 'listItemText' | 'button';
14 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
19 paddingLeft: theme.spacing.unit,
20 paddingRight: theme.spacing.unit * 2
23 fontSize: '0.8125rem',
24 color: theme.palette.grey["900"]
28 marginRight: theme.spacing.unit
32 export interface SearchBarSavedQueriesDataProps {
33 savedQueries: SearchBarAdvanceFormData[];
34 selectedItem: SearchBarSelectedItem;
37 export interface SearchBarSavedQueriesActionProps {
38 onSearch: (searchValue: string) => void;
39 deleteSavedQuery: (id: number) => void;
40 editSavedQuery: (data: SearchBarAdvanceFormData, id: number) => void;
43 type SearchBarSavedQueriesProps = SearchBarSavedQueriesDataProps
44 & SearchBarSavedQueriesActionProps
45 & WithStyles<CssRules>;
47 export const SearchBarSavedQueries = withStyles(styles)(
48 ({ classes, savedQueries, onSearch, editSavedQuery, deleteSavedQuery, selectedItem }: SearchBarSavedQueriesProps) =>
49 <List component="nav" className={classes.root}>
50 {savedQueries.map((query, index) =>
51 <ListItem button key={index} className={classes.listItem} selected={`SQ-${index}-${query.searchQuery}` === selectedItem.id}>
52 <ListItemText disableTypography
53 secondary={query.searchQuery}
54 onClick={() => onSearch(query.searchQuery)}
55 className={classes.listItemText} />
56 <ListItemSecondaryAction>
57 <Tooltip title="Edit">
58 <IconButton aria-label="Edit" onClick={() => editSavedQuery(query, index)} className={classes.button}>
59 <EditSavedQueryIcon />
62 <Tooltip title="Remove">
63 <IconButton aria-label="Remove" onClick={() => deleteSavedQuery(index)} className={classes.button}>
67 </ListItemSecondaryAction>