1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

feat: add icons to filters (#5640)

This commit is contained in:
Jaanus Sellin 2023-12-14 15:06:26 +02:00 committed by GitHub
parent bfa82d79bf
commit fbb5dd9022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 13 deletions

View File

@ -53,6 +53,7 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
const availableFilters: IFilterItem[] = [ const availableFilters: IFilterItem[] = [
{ {
label: 'State', label: 'State',
icon: 'hexagon',
options: stateOptions, options: stateOptions,
filterKey: 'state', filterKey: 'state',
singularOperators: ['IS', 'IS_NOT'], singularOperators: ['IS', 'IS_NOT'],
@ -62,6 +63,7 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
? ([ ? ([
{ {
label: 'Project', label: 'Project',
icon: 'topic',
options: projectsOptions, options: projectsOptions,
filterKey: 'project', filterKey: 'project',
singularOperators: ['IS', 'IS_NOT'], singularOperators: ['IS', 'IS_NOT'],
@ -71,6 +73,7 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
: []), : []),
{ {
label: 'Tags', label: 'Tags',
icon: 'label',
options: tagsOptions, options: tagsOptions,
filterKey: 'tag', filterKey: 'tag',
singularOperators: ['INCLUDE', 'DO_NOT_INCLUDE'], singularOperators: ['INCLUDE', 'DO_NOT_INCLUDE'],
@ -83,6 +86,7 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
}, },
{ {
label: 'Segment', label: 'Segment',
icon: 'donut_large',
options: segmentsOptions, options: segmentsOptions,
filterKey: 'segment', filterKey: 'segment',
singularOperators: ['INCLUDE', 'DO_NOT_INCLUDE'], singularOperators: ['INCLUDE', 'DO_NOT_INCLUDE'],
@ -95,6 +99,7 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
}, },
{ {
label: 'Created date', label: 'Created date',
icon: 'today',
options: [], options: [],
filterKey: 'createdAt', filterKey: 'createdAt',
dateOperators: ['IS_ON_OR_AFTER', 'IS_BEFORE'], dateOperators: ['IS_ON_OR_AFTER', 'IS_BEFORE'],

View File

@ -2,19 +2,35 @@ import React, { useState } from 'react';
import Button from '@mui/material/Button'; import Button from '@mui/material/Button';
import Menu from '@mui/material/Menu'; import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem'; import MenuItem from '@mui/material/MenuItem';
import { styled } from '@mui/material'; import { Icon, styled } from '@mui/material';
import { Add } from '@mui/icons-material'; import { Add, HelpOutline, Topic } from '@mui/icons-material';
import { Box } from '@mui/system';
import { IFilterItem } from './Filters/Filters';
const StyledButton = styled(Button)(({ theme }) => ({ const StyledButton = styled(Button)(({ theme }) => ({
padding: theme.spacing(0, 1.25, 0, 1.25), padding: theme.spacing(0, 1.25, 0, 1.25),
height: theme.spacing(3.75), height: theme.spacing(3.75),
})); }));
const StyledIconContainer = styled(Box)(({ theme }) => ({
display: 'flex',
alignItems: 'center',
gap: theme.spacing(1),
}));
const StyledIcon = styled(Icon)(({ theme }) => ({
color: theme.palette.action.active,
'&.material-symbols-outlined': {
fontSize: theme.spacing(2),
},
}));
interface IAddFilterButtonProps { interface IAddFilterButtonProps {
visibleOptions: string[]; visibleOptions: string[];
setVisibleOptions: (filters: string[]) => void; setVisibleOptions: (filters: string[]) => void;
hiddenOptions: string[]; hiddenOptions: string[];
setHiddenOptions: (filters: string[]) => void; setHiddenOptions: (filters: string[]) => void;
availableFilters: IFilterItem[];
} }
const AddFilterButton = ({ const AddFilterButton = ({
@ -22,6 +38,7 @@ const AddFilterButton = ({
setVisibleOptions, setVisibleOptions,
hiddenOptions, hiddenOptions,
setHiddenOptions, setHiddenOptions,
availableFilters,
}: IAddFilterButtonProps) => { }: IAddFilterButtonProps) => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
@ -53,11 +70,19 @@ const AddFilterButton = ({
open={Boolean(anchorEl)} open={Boolean(anchorEl)}
onClose={handleClose} onClose={handleClose}
> >
{visibleOptions.map((label) => ( {visibleOptions.map((label) => {
<MenuItem key={label} onClick={() => onSelect(label)}> const filter = availableFilters.find(
{label} (f) => f.label === label,
</MenuItem> );
))} return (
<MenuItem key={label} onClick={() => onSelect(label)}>
<StyledIconContainer>
<StyledIcon>{filter?.icon}</StyledIcon>
{label}
</StyledIconContainer>
</MenuItem>
);
})}
</Menu> </Menu>
</div> </div>
); );

View File

@ -7,6 +7,7 @@ test('shoulder render all available filters', async () => {
const availableFilters: IFilterItem[] = [ const availableFilters: IFilterItem[] = [
{ {
label: 'Filter1', label: 'Filter1',
icon: '',
options: [], options: [],
filterKey: 'irrelevantKey', filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'], singularOperators: ['IRRELEVANT'],
@ -14,6 +15,7 @@ test('shoulder render all available filters', async () => {
}, },
{ {
label: 'Filter2', label: 'Filter2',
icon: '',
options: [], options: [],
filterKey: 'irrelevantKey', filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'], singularOperators: ['IRRELEVANT'],
@ -21,6 +23,7 @@ test('shoulder render all available filters', async () => {
}, },
{ {
label: 'Filter3', label: 'Filter3',
icon: '',
options: [], options: [],
filterKey: 'irrelevantKey', filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'], singularOperators: ['IRRELEVANT'],
@ -45,6 +48,7 @@ test('should keep filters order when adding a new filter', async () => {
const availableFilters: IFilterItem[] = [ const availableFilters: IFilterItem[] = [
{ {
label: 'State', label: 'State',
icon: '',
options: [], options: [],
filterKey: 'irrelevantKey', filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'], singularOperators: ['IRRELEVANT'],
@ -52,6 +56,7 @@ test('should keep filters order when adding a new filter', async () => {
}, },
{ {
label: 'Tags', label: 'Tags',
icon: '',
options: [], options: [],
filterKey: 'irrelevantKey', filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'], singularOperators: ['IRRELEVANT'],
@ -86,6 +91,7 @@ test('should remove selected item from the add filter list', async () => {
const availableFilters: IFilterItem[] = [ const availableFilters: IFilterItem[] = [
{ {
label: 'State', label: 'State',
icon: '',
options: [], options: [],
filterKey: 'irrelevantKey', filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'], singularOperators: ['IRRELEVANT'],
@ -93,6 +99,7 @@ test('should remove selected item from the add filter list', async () => {
}, },
{ {
label: 'Tags', label: 'Tags',
icon: '',
options: [], options: [],
filterKey: 'irrelevantKey', filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'], singularOperators: ['IRRELEVANT'],

View File

@ -25,6 +25,7 @@ interface IFilterProps {
type IBaseFilterItem = { type IBaseFilterItem = {
label: string; label: string;
icon: string;
options: { options: {
label: string; label: string;
value: string; value: string;
@ -138,6 +139,7 @@ export const Filters: VFC<IFilterProps> = ({
condition={hasAvailableFilters} condition={hasAvailableFilters}
show={ show={
<AddFilterButton <AddFilterButton
availableFilters={availableFilters}
visibleOptions={unselectedFilters} visibleOptions={unselectedFilters}
setVisibleOptions={setUnselectedFilters} setVisibleOptions={setUnselectedFilters}
hiddenOptions={selectedFilters} hiddenOptions={selectedFilters}

View File

@ -27,6 +27,7 @@ export const ProjectOverviewFilters: VFC<IProjectOverviewFilters> = ({
const availableFilters: IFilterItem[] = [ const availableFilters: IFilterItem[] = [
{ {
label: 'Tags', label: 'Tags',
icon: 'label',
options: tagsOptions, options: tagsOptions,
filterKey: 'tag', filterKey: 'tag',
singularOperators: ['INCLUDE', 'DO_NOT_INCLUDE'], singularOperators: ['INCLUDE', 'DO_NOT_INCLUDE'],
@ -39,6 +40,7 @@ export const ProjectOverviewFilters: VFC<IProjectOverviewFilters> = ({
}, },
{ {
label: 'Created date', label: 'Created date',
icon: 'today',
options: [], options: [],
filterKey: 'createdAt', filterKey: 'createdAt',
dateOperators: ['IS_ON_OR_AFTER', 'IS_BEFORE'], dateOperators: ['IS_ON_OR_AFTER', 'IS_BEFORE'],

View File

@ -8,12 +8,6 @@ import { ILastSeenStore } from './types/last-seen-store-type';
const TABLE = 'last_seen_at_metrics'; const TABLE = 'last_seen_at_metrics';
export interface FeaturesTable {
feature_name: string;
last_seen_at: Date;
environment: string;
}
const prepareLastSeenInput = (data: LastSeenInput[]) => { const prepareLastSeenInput = (data: LastSeenInput[]) => {
const now = new Date(); const now = new Date();