Skip to content

Commit

Permalink
feat: add icons to filters (#5640)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus authored Dec 14, 2023
1 parent bfa82d7 commit fbb5dd9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
const availableFilters: IFilterItem[] = [
{
label: 'State',
icon: 'hexagon',
options: stateOptions,
filterKey: 'state',
singularOperators: ['IS', 'IS_NOT'],
Expand All @@ -62,6 +63,7 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
? ([
{
label: 'Project',
icon: 'topic',
options: projectsOptions,
filterKey: 'project',
singularOperators: ['IS', 'IS_NOT'],
Expand All @@ -71,6 +73,7 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
: []),
{
label: 'Tags',
icon: 'label',
options: tagsOptions,
filterKey: 'tag',
singularOperators: ['INCLUDE', 'DO_NOT_INCLUDE'],
Expand All @@ -83,6 +86,7 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
},
{
label: 'Segment',
icon: 'donut_large',
options: segmentsOptions,
filterKey: 'segment',
singularOperators: ['INCLUDE', 'DO_NOT_INCLUDE'],
Expand All @@ -95,6 +99,7 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
},
{
label: 'Created date',
icon: 'today',
options: [],
filterKey: 'createdAt',
dateOperators: ['IS_ON_OR_AFTER', 'IS_BEFORE'],
Expand Down
39 changes: 32 additions & 7 deletions frontend/src/component/filter/AddFilterButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,43 @@ import React, { useState } from 'react';
import Button from '@mui/material/Button';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import { styled } from '@mui/material';
import { Add } from '@mui/icons-material';
import { Icon, styled } from '@mui/material';
import { Add, HelpOutline, Topic } from '@mui/icons-material';
import { Box } from '@mui/system';
import { IFilterItem } from './Filters/Filters';

const StyledButton = styled(Button)(({ theme }) => ({
padding: theme.spacing(0, 1.25, 0, 1.25),
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 {
visibleOptions: string[];
setVisibleOptions: (filters: string[]) => void;
hiddenOptions: string[];
setHiddenOptions: (filters: string[]) => void;
availableFilters: IFilterItem[];
}

const AddFilterButton = ({
visibleOptions,
setVisibleOptions,
hiddenOptions,
setHiddenOptions,
availableFilters,
}: IAddFilterButtonProps) => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);

Expand Down Expand Up @@ -53,11 +70,19 @@ const AddFilterButton = ({
open={Boolean(anchorEl)}
onClose={handleClose}
>
{visibleOptions.map((label) => (
<MenuItem key={label} onClick={() => onSelect(label)}>
{label}
</MenuItem>
))}
{visibleOptions.map((label) => {
const filter = availableFilters.find(
(f) => f.label === label,
);
return (
<MenuItem key={label} onClick={() => onSelect(label)}>
<StyledIconContainer>
<StyledIcon>{filter?.icon}</StyledIcon>
{label}
</StyledIconContainer>
</MenuItem>
);
})}
</Menu>
</div>
);
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/component/filter/Filters/Filters.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ test('shoulder render all available filters', async () => {
const availableFilters: IFilterItem[] = [
{
label: 'Filter1',
icon: '',
options: [],
filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'],
pluralOperators: ['IRRELEVANT'],
},
{
label: 'Filter2',
icon: '',
options: [],
filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'],
pluralOperators: ['IRRELEVANT'],
},
{
label: 'Filter3',
icon: '',
options: [],
filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'],
Expand All @@ -45,13 +48,15 @@ test('should keep filters order when adding a new filter', async () => {
const availableFilters: IFilterItem[] = [
{
label: 'State',
icon: '',
options: [],
filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'],
pluralOperators: ['IRRELEVANT'],
},
{
label: 'Tags',
icon: '',
options: [],
filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'],
Expand Down Expand Up @@ -86,13 +91,15 @@ test('should remove selected item from the add filter list', async () => {
const availableFilters: IFilterItem[] = [
{
label: 'State',
icon: '',
options: [],
filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'],
pluralOperators: ['IRRELEVANT'],
},
{
label: 'Tags',
icon: '',
options: [],
filterKey: 'irrelevantKey',
singularOperators: ['IRRELEVANT'],
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/component/filter/Filters/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface IFilterProps {

type IBaseFilterItem = {
label: string;
icon: string;
options: {
label: string;
value: string;
Expand Down Expand Up @@ -138,6 +139,7 @@ export const Filters: VFC<IFilterProps> = ({
condition={hasAvailableFilters}
show={
<AddFilterButton
availableFilters={availableFilters}
visibleOptions={unselectedFilters}
setVisibleOptions={setUnselectedFilters}
hiddenOptions={selectedFilters}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const ProjectOverviewFilters: VFC<IProjectOverviewFilters> = ({
const availableFilters: IFilterItem[] = [
{
label: 'Tags',
icon: 'label',
options: tagsOptions,
filterKey: 'tag',
singularOperators: ['INCLUDE', 'DO_NOT_INCLUDE'],
Expand All @@ -39,6 +40,7 @@ export const ProjectOverviewFilters: VFC<IProjectOverviewFilters> = ({
},
{
label: 'Created date',
icon: 'today',
options: [],
filterKey: 'createdAt',
dateOperators: ['IS_ON_OR_AFTER', 'IS_BEFORE'],
Expand Down
6 changes: 0 additions & 6 deletions src/lib/services/client-metrics/last-seen/last-seen-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import { ILastSeenStore } from './types/last-seen-store-type';

const TABLE = 'last_seen_at_metrics';

export interface FeaturesTable {
feature_name: string;
last_seen_at: Date;
environment: string;
}

const prepareLastSeenInput = (data: LastSeenInput[]) => {
const now = new Date();

Expand Down

0 comments on commit fbb5dd9

Please sign in to comment.