Merge pull request #7226 from backstage/samiramkr/add-search-settings-plugin
add filter to featureFlag page
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-user-settings': patch
|
||||
---
|
||||
|
||||
Add search to FeatureFlags
|
||||
@@ -15,7 +15,13 @@
|
||||
*/
|
||||
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import { List } from '@material-ui/core';
|
||||
import {
|
||||
List,
|
||||
TextField,
|
||||
IconButton,
|
||||
Grid,
|
||||
Typography,
|
||||
} from '@material-ui/core';
|
||||
import { EmptyFlags } from './EmptyFlags';
|
||||
import { FlagItem } from './FeatureFlagsItem';
|
||||
|
||||
@@ -25,6 +31,7 @@ import {
|
||||
useApi,
|
||||
} from '@backstage/core-plugin-api';
|
||||
import { InfoCard } from '@backstage/core-components';
|
||||
import ClearIcon from '@material-ui/icons/Clear';
|
||||
|
||||
export const UserSettingsFeatureFlags = () => {
|
||||
const featureFlagsApi = useApi(featureFlagsApiRef);
|
||||
@@ -35,6 +42,8 @@ export const UserSettingsFeatureFlags = () => {
|
||||
);
|
||||
|
||||
const [state, setState] = useState<Record<string, boolean>>(initialFlagState);
|
||||
const [filterInput, setFilterInput] = useState<string>('');
|
||||
const inputRef = React.useRef<HTMLElement>();
|
||||
|
||||
const toggleFlag = useCallback(
|
||||
(flagName: string) => {
|
||||
@@ -59,10 +68,60 @@ export const UserSettingsFeatureFlags = () => {
|
||||
return <EmptyFlags />;
|
||||
}
|
||||
|
||||
const clearFilterInput = () => {
|
||||
setFilterInput('');
|
||||
inputRef?.current?.focus();
|
||||
};
|
||||
|
||||
let filteredFeatureFlags = Array.from(featureFlags);
|
||||
|
||||
const filterInputParts = filterInput
|
||||
.split(/\s/)
|
||||
.map(part => part.trim().toLowerCase());
|
||||
|
||||
filterInputParts.forEach(
|
||||
part =>
|
||||
(filteredFeatureFlags = filteredFeatureFlags.filter(featureFlag =>
|
||||
featureFlag.name.toLowerCase().includes(part),
|
||||
)),
|
||||
);
|
||||
|
||||
const Header = () => (
|
||||
<Grid container style={{ justifyContent: 'space-between' }}>
|
||||
<Grid item xs={6} md={8}>
|
||||
<Typography variant="h5">Feature Flags</Typography>
|
||||
</Grid>
|
||||
{featureFlags.length >= 10 && (
|
||||
<Grid item xs={6} md={4}>
|
||||
<TextField
|
||||
label="Filter"
|
||||
style={{ display: 'flex', justifyContent: 'flex-end' }}
|
||||
inputRef={ref => ref && ref.focus()}
|
||||
InputProps={{
|
||||
...(filterInput.length && {
|
||||
endAdornment: (
|
||||
<IconButton
|
||||
aria-label="Clear filter"
|
||||
onClick={clearFilterInput}
|
||||
edge="end"
|
||||
>
|
||||
<ClearIcon />
|
||||
</IconButton>
|
||||
),
|
||||
}),
|
||||
}}
|
||||
onChange={e => setFilterInput(e.target.value)}
|
||||
value={filterInput}
|
||||
/>
|
||||
</Grid>
|
||||
)}
|
||||
</Grid>
|
||||
);
|
||||
|
||||
return (
|
||||
<InfoCard title="Feature Flags">
|
||||
<InfoCard title={<Header />}>
|
||||
<List dense>
|
||||
{featureFlags.map(featureFlag => {
|
||||
{filteredFeatureFlags.map(featureFlag => {
|
||||
const enabled = Boolean(state[featureFlag.name]);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user