1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

feat: select all applications (#5897)

This commit is contained in:
Mateusz Kwasniewski 2024-01-15 15:30:35 +01:00 committed by GitHub
parent 3e186f1986
commit 9ac8a466ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -40,6 +40,7 @@ export const FeatureMetrics = () => {
const selectedApplications = query.applications.filter( const selectedApplications = query.applications.filter(
(item) => item !== null, (item) => item !== null,
) as string[]; ) as string[];
const allSelected = selectedApplications.length === applications.size;
const { featureMetrics } = useFeatureMetricsRaw(featureId, hoursBack); const { featureMetrics } = useFeatureMetricsRaw(featureId, hoursBack);
@ -97,6 +98,17 @@ export const FeatureMetrics = () => {
title='Applications' title='Applications'
values={applications} values={applications}
selectedValues={selectedApplications} selectedValues={selectedApplications}
toggleValues={() => {
if (allSelected) {
setQuery({
applications: [defaultApplication],
});
} else {
setQuery({
applications: [...applications],
});
}
}}
toggleValue={(value) => { toggleValue={(value) => {
if (selectedApplications.includes(value)) { if (selectedApplications.includes(value)) {
setQuery({ setQuery({

View File

@ -1,4 +1,4 @@
import { Chip, styled } from '@mui/material'; import { Chip, Button, styled } from '@mui/material';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { focusable } from 'themes/themeStyles'; import { focusable } from 'themes/themeStyles';
@ -7,6 +7,7 @@ interface IFeatureMetricsChipsProps {
values: Set<string>; values: Set<string>;
selectedValues: string[]; selectedValues: string[];
toggleValue: (value: string) => void; toggleValue: (value: string) => void;
toggleValues?: () => void;
} }
const StyledTitle = styled('h2')(({ theme }) => ({ const StyledTitle = styled('h2')(({ theme }) => ({
@ -24,6 +25,7 @@ const StyledList = styled('ul')(({ theme }) => ({
listStyleType: 'none', listStyleType: 'none',
padding: 0, padding: 0,
minHeight: '100%', minHeight: '100%',
alignItems: 'center',
})); }));
const StyledItem = styled('li')(({ theme }) => ({ const StyledItem = styled('li')(({ theme }) => ({
@ -41,10 +43,12 @@ export const FeatureMetricsChips = ({
values, values,
selectedValues, selectedValues,
toggleValue, toggleValue,
toggleValues,
}: IFeatureMetricsChipsProps) => { }: IFeatureMetricsChipsProps) => {
const onClick = (value: string) => () => { const onClick = (value: string) => () => {
toggleValue(value); toggleValue(value);
}; };
const allSelected = values.size === selectedValues.length;
const sortedValues = useMemo(() => { const sortedValues = useMemo(() => {
return Array.from(values).sort((valueA, valueB) => { return Array.from(values).sort((valueA, valueB) => {
@ -66,6 +70,16 @@ export const FeatureMetricsChips = ({
/> />
</StyledItem> </StyledItem>
))} ))}
{toggleValues && (
<Button
size={'small'}
onClick={toggleValues}
aria-pressed={allSelected}
>
{allSelected ? 'Unselect' : 'Select all'}
</Button>
)}
</StyledList> </StyledList>
</div> </div>
); );