1
0
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:
Sebastian Malton 2022-04-12 14:49:37 -04:00
parent b2fa542d59
commit 9c388dc499
2 changed files with 16 additions and 14 deletions

View File

@ -18,25 +18,16 @@ import namespaceStoreInjectable from "./namespace-store/namespace-store.injectab
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;
sort?: NamespaceSelectSort;
options?: undefined;
value: string | null;
}
interface Dependencies {
namespaceStore: NamespaceStore;
}
export function formatNamespaceOptionWithIcon(namespace: string) {
return (
<>
<Icon small material="layers" />
{namespace}
</>
);
}
function getOptions(namespaceStore: NamespaceStore, sort: NamespaceSelectSort | undefined) {
return computed(() => {
const baseOptions = namespaceStore.items.map(ns => ns.getName());
@ -45,7 +36,7 @@ function getOptions(namespaceStore: NamespaceStore, sort: NamespaceSelectSort |
baseOptions.sort(sort);
}
return baseOptions;
return baseOptions.map(namespace => ({ namespace }));
});
}
@ -55,6 +46,7 @@ const NonInjectedNamespaceSelect = observer(({
formatOptionLabel,
sort,
className,
value,
...selectProps
}: Dependencies & NamespaceSelectProps<boolean>) => {
const [baseOptions, setBaseOptions] = useState(getOptions(namespaceStore, sort));
@ -65,7 +57,17 @@ const NonInjectedNamespaceSelect = observer(({
<Select
className={cssNames("NamespaceSelect", className)}
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()}
{...selectProps}
/>

View File

@ -182,7 +182,7 @@ export class RoleBindingDialog extends React.Component<RoleBindingDialogProps> {
isDisabled={this.isEditing}
value={this.bindingNamespace}
autoFocus={!this.isEditing}
onChange={namespace => this.bindingNamespace = namespace}
onChange={opt => this.bindingNamespace = opt ? opt.namespace : null}
/>
<SubTitle title="Role Reference" />