Skip to content

Commit

Permalink
feat: select all applications (#5897)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Jan 15, 2024
1 parent 3e186f1 commit 9ac8a46
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Expand Up @@ -40,6 +40,7 @@ export const FeatureMetrics = () => {
const selectedApplications = query.applications.filter(
(item) => item !== null,
) as string[];
const allSelected = selectedApplications.length === applications.size;

const { featureMetrics } = useFeatureMetricsRaw(featureId, hoursBack);

Expand Down Expand Up @@ -97,6 +98,17 @@ export const FeatureMetrics = () => {
title='Applications'
values={applications}
selectedValues={selectedApplications}
toggleValues={() => {
if (allSelected) {
setQuery({
applications: [defaultApplication],
});
} else {
setQuery({
applications: [...applications],
});
}
}}
toggleValue={(value) => {
if (selectedApplications.includes(value)) {
setQuery({
Expand Down
@@ -1,4 +1,4 @@
import { Chip, styled } from '@mui/material';
import { Chip, Button, styled } from '@mui/material';
import { useMemo } from 'react';
import { focusable } from 'themes/themeStyles';

Expand All @@ -7,6 +7,7 @@ interface IFeatureMetricsChipsProps {
values: Set<string>;
selectedValues: string[];
toggleValue: (value: string) => void;
toggleValues?: () => void;
}

const StyledTitle = styled('h2')(({ theme }) => ({
Expand All @@ -24,6 +25,7 @@ const StyledList = styled('ul')(({ theme }) => ({
listStyleType: 'none',
padding: 0,
minHeight: '100%',
alignItems: 'center',
}));

const StyledItem = styled('li')(({ theme }) => ({
Expand All @@ -41,10 +43,12 @@ export const FeatureMetricsChips = ({
values,
selectedValues,
toggleValue,
toggleValues,
}: IFeatureMetricsChipsProps) => {
const onClick = (value: string) => () => {
toggleValue(value);
};
const allSelected = values.size === selectedValues.length;

const sortedValues = useMemo(() => {
return Array.from(values).sort((valueA, valueB) => {
Expand All @@ -66,6 +70,16 @@ export const FeatureMetricsChips = ({
/>
</StyledItem>
))}

{toggleValues && (
<Button
size={'small'}
onClick={toggleValues}
aria-pressed={allSelected}
>
{allSelected ? 'Unselect' : 'Select all'}
</Button>
)}
</StyledList>
</div>
);
Expand Down

0 comments on commit 9ac8a46

Please sign in to comment.