mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Simplify NamespaceSelectFilterPlaceholder impl
- By using the storage injectable directly Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
8b8a361b24
commit
d7474fe443
@ -9,12 +9,12 @@ import React from "react";
|
|||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import type { PlaceholderProps } from "react-select";
|
import type { PlaceholderProps } from "react-select";
|
||||||
import { components } from "react-select";
|
import { components } from "react-select";
|
||||||
import type { NamespaceStore } from "./store";
|
|
||||||
import { Select } from "../select";
|
import { Select } from "../select";
|
||||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
import type { NamespaceSelectFilterModel, NamespaceSelectFilterOption, SelectAllNamespaces } from "./namespace-select-filter-model/namespace-select-filter-model";
|
import type { NamespaceSelectFilterModel, NamespaceSelectFilterOption, SelectAllNamespaces } from "./namespace-select-filter-model/namespace-select-filter-model";
|
||||||
import namespaceSelectFilterModelInjectable from "./namespace-select-filter-model/namespace-select-filter-model.injectable";
|
import namespaceSelectFilterModelInjectable from "./namespace-select-filter-model/namespace-select-filter-model.injectable";
|
||||||
import namespaceStoreInjectable from "./store.injectable";
|
import type { StorageLayer } from "../../utils";
|
||||||
|
import selectedNamespaceStorageInjectable from "./namespace-storage.injectable";
|
||||||
|
|
||||||
interface NamespaceSelectFilterProps {
|
interface NamespaceSelectFilterProps {
|
||||||
id: string;
|
id: string;
|
||||||
@ -62,22 +62,20 @@ export const NamespaceSelectFilter = withInjectables<Dependencies, NamespaceSele
|
|||||||
export interface CustomPlaceholderProps extends PlaceholderProps<NamespaceSelectFilterOption, true> {}
|
export interface CustomPlaceholderProps extends PlaceholderProps<NamespaceSelectFilterOption, true> {}
|
||||||
|
|
||||||
interface PlaceholderDependencies {
|
interface PlaceholderDependencies {
|
||||||
namespaceStore: NamespaceStore;
|
storage: StorageLayer<string[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NonInjectedPlaceholder = observer(({ namespaceStore, ...props }: CustomPlaceholderProps & PlaceholderDependencies) => {
|
const NonInjectedPlaceholder = observer(({ storage, ...props }: CustomPlaceholderProps & PlaceholderDependencies) => {
|
||||||
const getPlaceholder = () => {
|
const getPlaceholder = () => {
|
||||||
const namespaces = namespaceStore.contextNamespaces;
|
if (storage.get().length === 0) {
|
||||||
|
|
||||||
if (namespaceStore.areAllSelectedImplicitly || namespaces.length === 0) {
|
|
||||||
return "All namespaces";
|
return "All namespaces";
|
||||||
}
|
}
|
||||||
|
|
||||||
const prefix = namespaces.length === 1
|
const prefix = storage.get().length === 1
|
||||||
? "Namespace"
|
? "Namespace"
|
||||||
: "Namespaces";
|
: "Namespaces";
|
||||||
|
|
||||||
return `${prefix}: ${namespaces.join(", ")}`;
|
return `${prefix}: ${storage.get().join(", ")}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -89,7 +87,7 @@ const NonInjectedPlaceholder = observer(({ namespaceStore, ...props }: CustomPla
|
|||||||
|
|
||||||
const Placeholder = withInjectables<PlaceholderDependencies, CustomPlaceholderProps>( NonInjectedPlaceholder, {
|
const Placeholder = withInjectables<PlaceholderDependencies, CustomPlaceholderProps>( NonInjectedPlaceholder, {
|
||||||
getProps: (di, props) => ({
|
getProps: (di, props) => ({
|
||||||
namespaceStore: di.inject(namespaceStoreInjectable),
|
|
||||||
...props,
|
...props,
|
||||||
|
storage: di.inject(selectedNamespaceStorageInjectable),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user