|
|
@ -7,13 +7,17 @@ import { InputGroup } from '@@/form-components/InputGroup';
|
|
|
|
|
|
|
|
|
|
|
|
import { Namespace } from './types';
|
|
|
|
import { Namespace } from './types';
|
|
|
|
|
|
|
|
|
|
|
|
function transformNamespaces(namespaces: Namespace[], showSystem: boolean) {
|
|
|
|
function transformNamespaces(namespaces: Namespace[], showSystem?: boolean) {
|
|
|
|
return namespaces
|
|
|
|
const transformedNamespaces = namespaces.map(({ Name, IsSystem }) => ({
|
|
|
|
.filter((ns) => showSystem || !ns.IsSystem)
|
|
|
|
label: IsSystem ? `${Name} - system` : Name,
|
|
|
|
.map(({ Name, IsSystem }) => ({
|
|
|
|
value: Name,
|
|
|
|
label: IsSystem ? `${Name} - system` : Name,
|
|
|
|
isSystem: IsSystem,
|
|
|
|
value: Name,
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
if (showSystem === undefined) {
|
|
|
|
|
|
|
|
return transformedNamespaces;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// only filter when showSystem is set
|
|
|
|
|
|
|
|
return transformedNamespaces.filter((ns) => showSystem || !ns.isSystem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function NamespaceFilter({
|
|
|
|
export function NamespaceFilter({
|
|
|
@ -25,19 +29,22 @@ export function NamespaceFilter({
|
|
|
|
namespaces: Namespace[];
|
|
|
|
namespaces: Namespace[];
|
|
|
|
value: string;
|
|
|
|
value: string;
|
|
|
|
onChange: (value: string) => void;
|
|
|
|
onChange: (value: string) => void;
|
|
|
|
showSystem: boolean;
|
|
|
|
showSystem?: boolean;
|
|
|
|
}) {
|
|
|
|
}) {
|
|
|
|
const transformedNamespaces = transformNamespaces(namespaces, showSystem);
|
|
|
|
const transformedNamespaces = transformNamespaces(namespaces, showSystem);
|
|
|
|
|
|
|
|
|
|
|
|
// sync value with displayed namespaces
|
|
|
|
// sync value with displayed namespaces
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
const names = transformedNamespaces.map((ns) => ns.value);
|
|
|
|
const names = transformedNamespaces.map((ns) => ns.value);
|
|
|
|
if (value && !names.find((ns) => ns === value)) {
|
|
|
|
const isSelectedNamespaceFound = names.some((ns) => ns === value);
|
|
|
|
onChange(
|
|
|
|
if (value && !isSelectedNamespaceFound) {
|
|
|
|
names.length > 0 ? names.find((ns) => ns === 'default') || names[0] : ''
|
|
|
|
const newNamespaceValue =
|
|
|
|
);
|
|
|
|
names.length > 0
|
|
|
|
|
|
|
|
? names.find((ns) => ns === 'default') || names[0]
|
|
|
|
|
|
|
|
: '';
|
|
|
|
|
|
|
|
onChange(newNamespaceValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [value, onChange, transformedNamespaces]);
|
|
|
|
}, [value, onChange, transformedNamespaces, showSystem]);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<InputGroup>
|
|
|
|
<InputGroup>
|
|
|
|