mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix namespace-select.tsx
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
b2fa542d59
commit
9c388dc499
@ -18,25 +18,16 @@ import namespaceStoreInjectable from "./namespace-store/namespace-store.injectab
|
|||||||
|
|
||||||
export type NamespaceSelectSort = (left: string, right: string) => number;
|
export type NamespaceSelectSort = (left: string, right: string) => number;
|
||||||
|
|
||||||
export interface NamespaceSelectProps<IsMulti extends boolean> extends SelectProps<string, IsMulti> {
|
export interface NamespaceSelectProps<IsMulti extends boolean> extends Omit<SelectProps<{ namespace: string }, IsMulti>, "options" | "value"> {
|
||||||
showIcons?: boolean;
|
showIcons?: boolean;
|
||||||
sort?: NamespaceSelectSort;
|
sort?: NamespaceSelectSort;
|
||||||
options?: undefined;
|
value: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
namespaceStore: NamespaceStore;
|
namespaceStore: NamespaceStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatNamespaceOptionWithIcon(namespace: string) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Icon small material="layers" />
|
|
||||||
{namespace}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getOptions(namespaceStore: NamespaceStore, sort: NamespaceSelectSort | undefined) {
|
function getOptions(namespaceStore: NamespaceStore, sort: NamespaceSelectSort | undefined) {
|
||||||
return computed(() => {
|
return computed(() => {
|
||||||
const baseOptions = namespaceStore.items.map(ns => ns.getName());
|
const baseOptions = namespaceStore.items.map(ns => ns.getName());
|
||||||
@ -45,7 +36,7 @@ function getOptions(namespaceStore: NamespaceStore, sort: NamespaceSelectSort |
|
|||||||
baseOptions.sort(sort);
|
baseOptions.sort(sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseOptions;
|
return baseOptions.map(namespace => ({ namespace }));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +46,7 @@ const NonInjectedNamespaceSelect = observer(({
|
|||||||
formatOptionLabel,
|
formatOptionLabel,
|
||||||
sort,
|
sort,
|
||||||
className,
|
className,
|
||||||
|
value,
|
||||||
...selectProps
|
...selectProps
|
||||||
}: Dependencies & NamespaceSelectProps<boolean>) => {
|
}: Dependencies & NamespaceSelectProps<boolean>) => {
|
||||||
const [baseOptions, setBaseOptions] = useState(getOptions(namespaceStore, sort));
|
const [baseOptions, setBaseOptions] = useState(getOptions(namespaceStore, sort));
|
||||||
@ -65,7 +57,17 @@ const NonInjectedNamespaceSelect = observer(({
|
|||||||
<Select
|
<Select
|
||||||
className={cssNames("NamespaceSelect", className)}
|
className={cssNames("NamespaceSelect", className)}
|
||||||
menuClass="NamespaceSelectMenu"
|
menuClass="NamespaceSelectMenu"
|
||||||
formatOptionLabel={showIcons ? formatNamespaceOptionWithIcon : undefined}
|
formatOptionLabel={showIcons
|
||||||
|
? ({ namespace }) => (
|
||||||
|
<>
|
||||||
|
<Icon small material="layers" />
|
||||||
|
{namespace}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
getOptionLabel={({ namespace }) => namespace}
|
||||||
|
value={value ? ({ namespace: value }) : null}
|
||||||
options={baseOptions.get()}
|
options={baseOptions.get()}
|
||||||
{...selectProps}
|
{...selectProps}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -182,7 +182,7 @@ export class RoleBindingDialog extends React.Component<RoleBindingDialogProps> {
|
|||||||
isDisabled={this.isEditing}
|
isDisabled={this.isEditing}
|
||||||
value={this.bindingNamespace}
|
value={this.bindingNamespace}
|
||||||
autoFocus={!this.isEditing}
|
autoFocus={!this.isEditing}
|
||||||
onChange={namespace => this.bindingNamespace = namespace}
|
onChange={opt => this.bindingNamespace = opt ? opt.namespace : null}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<SubTitle title="Role Reference" />
|
<SubTitle title="Role Reference" />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user