mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-06 01:15:28 +02:00
feat: do not show project if not multiple projects exist (#5598)
This commit is contained in:
parent
5b6a26a828
commit
74f6f15247
@ -2,7 +2,7 @@ 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 { IFilterVisibility, IFilterItem } from './FeatureToggleFilters';
|
import { IFilterVisibility, IFilterItem } from '../FeatureToggleFilters';
|
||||||
import { Box, styled } from '@mui/material';
|
import { Box, styled } from '@mui/material';
|
||||||
import { Add } from '@mui/icons-material';
|
import { Add } from '@mui/icons-material';
|
||||||
|
|
@ -0,0 +1,40 @@
|
|||||||
|
import { screen } from '@testing-library/react';
|
||||||
|
import { render } from 'utils/testRenderer';
|
||||||
|
import { testServerRoute, testServerSetup } from 'utils/testServer';
|
||||||
|
import { FeatureToggleFilters } from './FeatureToggleFilters';
|
||||||
|
|
||||||
|
const server = testServerSetup();
|
||||||
|
|
||||||
|
test('should render projects filters when more than one project', async () => {
|
||||||
|
testServerRoute(server, '/api/admin/projects', {
|
||||||
|
projects: [
|
||||||
|
{
|
||||||
|
name: 'default',
|
||||||
|
id: 'default',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'second',
|
||||||
|
id: 'Second',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<FeatureToggleFilters onChange={() => {}} state={{}} />);
|
||||||
|
|
||||||
|
await screen.findByText('Project');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not render projects filters when less than two project', async () => {
|
||||||
|
testServerRoute(server, '/api/admin/projects', {
|
||||||
|
projects: [
|
||||||
|
{
|
||||||
|
name: 'default',
|
||||||
|
id: 'default',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<FeatureToggleFilters onChange={() => {}} state={{}} />);
|
||||||
|
|
||||||
|
expect(screen.queryByText('Projects')).not.toBeInTheDocument();
|
||||||
|
});
|
@ -2,7 +2,7 @@ import { useEffect, useState, VFC } from 'react';
|
|||||||
import { Box, styled } from '@mui/material';
|
import { Box, styled } from '@mui/material';
|
||||||
import useProjects from 'hooks/api/getters/useProjects/useProjects';
|
import useProjects from 'hooks/api/getters/useProjects/useProjects';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import AddFilterButton from './AddFilterButton';
|
import AddFilterButton from './AddFilterButton/AddFilterButton';
|
||||||
import { useSegments } from 'hooks/api/getters/useSegments/useSegments';
|
import { useSegments } from 'hooks/api/getters/useSegments/useSegments';
|
||||||
import { FilterDateItem } from 'component/common/FilterDateItem/FilterDateItem';
|
import { FilterDateItem } from 'component/common/FilterDateItem/FilterDateItem';
|
||||||
import {
|
import {
|
||||||
@ -90,6 +90,8 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
|
|||||||
value: `${tag.type}:${tag.value}`,
|
value: `${tag.type}:${tag.value}`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const hasMultipleProjects = projectsOptions.length > 1;
|
||||||
|
|
||||||
const availableFilters: IFilterItem[] = [
|
const availableFilters: IFilterItem[] = [
|
||||||
{
|
{
|
||||||
label: 'State',
|
label: 'State',
|
||||||
@ -98,13 +100,17 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
|
|||||||
singularOperators: ['IS', 'IS_NOT'],
|
singularOperators: ['IS', 'IS_NOT'],
|
||||||
pluralOperators: ['IS_ANY_OF', 'IS_NONE_OF'],
|
pluralOperators: ['IS_ANY_OF', 'IS_NONE_OF'],
|
||||||
},
|
},
|
||||||
{
|
...(hasMultipleProjects
|
||||||
label: 'Project',
|
? ([
|
||||||
options: projectsOptions,
|
{
|
||||||
filterKey: 'project',
|
label: 'Project',
|
||||||
singularOperators: ['IS', 'IS_NOT'],
|
options: projectsOptions,
|
||||||
pluralOperators: ['IS_ANY_OF', 'IS_NONE_OF'],
|
filterKey: 'project',
|
||||||
},
|
singularOperators: ['IS', 'IS_NOT'],
|
||||||
|
pluralOperators: ['IS_ANY_OF', 'IS_NONE_OF'],
|
||||||
|
},
|
||||||
|
] as IFilterItem[])
|
||||||
|
: []),
|
||||||
{
|
{
|
||||||
label: 'Tags',
|
label: 'Tags',
|
||||||
options: tagsOptions,
|
options: tagsOptions,
|
||||||
@ -139,15 +145,19 @@ export const FeatureToggleFilters: VFC<IFeatureToggleFiltersProps> = ({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const hasMultipleProjects = projects.length > 1;
|
||||||
|
|
||||||
const filterVisibility: IFilterVisibility = {
|
const filterVisibility: IFilterVisibility = {
|
||||||
State: Boolean(state.state),
|
State: Boolean(state.state),
|
||||||
Project: Boolean(state.project),
|
...(hasMultipleProjects && {
|
||||||
|
Project: Boolean(state.project),
|
||||||
|
}),
|
||||||
Tags: Boolean(state.tag),
|
Tags: Boolean(state.tag),
|
||||||
Segment: Boolean(state.segment),
|
Segment: Boolean(state.segment),
|
||||||
'Created date': Boolean(state.createdAt),
|
'Created date': Boolean(state.createdAt),
|
||||||
};
|
};
|
||||||
setVisibleFilters(filterVisibility);
|
setVisibleFilters(filterVisibility);
|
||||||
}, [JSON.stringify(state)]);
|
}, [JSON.stringify(state), JSON.stringify(projects)]);
|
||||||
|
|
||||||
const hasAvailableFilters = Object.values(visibleFilters).some(
|
const hasAvailableFilters = Object.values(visibleFilters).some(
|
||||||
(value) => !value,
|
(value) => !value,
|
||||||
|
Loading…
Reference in New Issue
Block a user