mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
crd listing fixes
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
31fe837dd1
commit
07055bfb39
@ -29,23 +29,31 @@ enum columnId {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class CrdList extends React.Component {
|
export class CrdList extends React.Component {
|
||||||
@computed get groups(): string[] {
|
get selectedGroups(): string[] {
|
||||||
return crdGroupsUrlParam.get();
|
return crdGroupsUrlParam.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelectGroup(group: string) {
|
@computed get items() {
|
||||||
const groups = new Set(this.groups);
|
if (this.selectedGroups.length) {
|
||||||
|
return crdStore.items.filter(item => this.selectedGroups.includes(item.getGroup()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return crdStore.items; // show all by default
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleSelection(group: string) {
|
||||||
|
const groups = new Set(crdGroupsUrlParam.get());
|
||||||
|
|
||||||
if (groups.has(group)) {
|
if (groups.has(group)) {
|
||||||
groups.delete(group); // toggle selection
|
groups.delete(group);
|
||||||
} else {
|
} else {
|
||||||
groups.add(group);
|
groups.add(group);
|
||||||
}
|
}
|
||||||
crdGroupsUrlParam.set(Array.from(groups));
|
crdGroupsUrlParam.set([...groups]);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const selectedGroups = this.groups;
|
const { items, selectedGroups } = this;
|
||||||
const sortingCallbacks = {
|
const sortingCallbacks = {
|
||||||
[columnId.kind]: (crd: CustomResourceDefinition) => crd.getResourceKind(),
|
[columnId.kind]: (crd: CustomResourceDefinition) => crd.getResourceKind(),
|
||||||
[columnId.group]: (crd: CustomResourceDefinition) => crd.getGroup(),
|
[columnId.group]: (crd: CustomResourceDefinition) => crd.getGroup(),
|
||||||
@ -60,13 +68,9 @@ export class CrdList extends React.Component {
|
|||||||
className="CrdList"
|
className="CrdList"
|
||||||
isClusterScoped={true}
|
isClusterScoped={true}
|
||||||
store={crdStore}
|
store={crdStore}
|
||||||
|
items={items}
|
||||||
sortingCallbacks={sortingCallbacks}
|
sortingCallbacks={sortingCallbacks}
|
||||||
searchFilters={Object.values(sortingCallbacks)}
|
searchFilters={Object.values(sortingCallbacks)}
|
||||||
filterItems={[
|
|
||||||
(items: CustomResourceDefinition[]) => {
|
|
||||||
return selectedGroups.length ? items.filter(item => selectedGroups.includes(item.getGroup())) : items;
|
|
||||||
}
|
|
||||||
]}
|
|
||||||
renderHeaderTitle="Custom Resources"
|
renderHeaderTitle="Custom Resources"
|
||||||
customizeHeader={() => {
|
customizeHeader={() => {
|
||||||
let placeholder = <>All groups</>;
|
let placeholder = <>All groups</>;
|
||||||
@ -81,7 +85,8 @@ export class CrdList extends React.Component {
|
|||||||
className="group-select"
|
className="group-select"
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
options={Object.keys(crdStore.groups)}
|
options={Object.keys(crdStore.groups)}
|
||||||
onChange={({ value: group }: SelectOption) => this.onSelectGroup(group)}
|
onChange={({ value: group }: SelectOption) => this.toggleSelection(group)}
|
||||||
|
closeMenuOnSelect={false}
|
||||||
controlShouldRenderValue={false}
|
controlShouldRenderValue={false}
|
||||||
formatOptionLabel={({ value: group }: SelectOption) => {
|
formatOptionLabel={({ value: group }: SelectOption) => {
|
||||||
const isSelected = selectedGroups.includes(group);
|
const isSelected = selectedGroups.includes(group);
|
||||||
|
|||||||
@ -45,6 +45,7 @@ export interface ItemListLayoutProps<T extends ItemObject = ItemObject> {
|
|||||||
isClusterScoped?: boolean;
|
isClusterScoped?: boolean;
|
||||||
hideFilters?: boolean;
|
hideFilters?: boolean;
|
||||||
searchFilters?: SearchFilter<T>[];
|
searchFilters?: SearchFilter<T>[];
|
||||||
|
/** @deprecated */
|
||||||
filterItems?: ItemsFilter<T>[];
|
filterItems?: ItemsFilter<T>[];
|
||||||
|
|
||||||
// header (title, filtering, searching, etc.)
|
// header (title, filtering, searching, etc.)
|
||||||
|
|||||||
@ -64,7 +64,8 @@ export class SidebarItem extends React.Component<SidebarItemProps> {
|
|||||||
<div className={classNames} data-test-id={id}>
|
<div className={classNames} data-test-id={id}>
|
||||||
<NavLink
|
<NavLink
|
||||||
to={url}
|
to={url}
|
||||||
className={cssNames("nav-item flex gaps align-center", { active: isActive, expandable: isExpandable })}
|
isActive={() => isActive}
|
||||||
|
className={cssNames("nav-item flex gaps align-center", { expandable: isExpandable })}
|
||||||
onClick={isExpandable ? prevDefault(toggleExpand) : undefined}>
|
onClick={isExpandable ? prevDefault(toggleExpand) : undefined}>
|
||||||
{icon}
|
{icon}
|
||||||
<span className="link-text box grow">{text}</span>
|
<span className="link-text box grow">{text}</span>
|
||||||
@ -75,7 +76,7 @@ export class SidebarItem extends React.Component<SidebarItemProps> {
|
|||||||
</NavLink>
|
</NavLink>
|
||||||
{isExpandable && expanded && (
|
{isExpandable && expanded && (
|
||||||
<ul className={cssNames("sub-menu", { active: isActive })}>
|
<ul className={cssNames("sub-menu", { active: isActive })}>
|
||||||
{subMenus.map(({ url, title, routePath }) => {
|
{subMenus.map(({ title, routePath, url = routePath }) => {
|
||||||
const subItemId = `${id}${routePath}`;
|
const subItemId = `${id}${routePath}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -84,7 +85,7 @@ export class SidebarItem extends React.Component<SidebarItemProps> {
|
|||||||
id={subItemId}
|
id={subItemId}
|
||||||
url={url}
|
url={url}
|
||||||
text={title}
|
text={title}
|
||||||
isActive={isActiveRoute({ exact: true, path: routePath })}
|
isActive={isActiveRoute({ path: url, exact: true })}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@ -66,6 +66,7 @@ export class Sidebar extends React.Component<Props> {
|
|||||||
url={crdURL({ query: { groups: group } })}
|
url={crdURL({ query: { groups: group } })}
|
||||||
subMenus={submenus}
|
subMenus={submenus}
|
||||||
text={group}
|
text={group}
|
||||||
|
isActive={false}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -145,7 +146,7 @@ export class Sidebar extends React.Component<Props> {
|
|||||||
focusable={false}
|
focusable={false}
|
||||||
className="pin-icon"
|
className="pin-icon"
|
||||||
tooltip="Compact view"
|
tooltip="Compact view"
|
||||||
material={compact ? "keyboard_arrow_left" : "keyboard_arrow_right"}
|
material={compact ? "keyboard_arrow_right" : "keyboard_arrow_left"}
|
||||||
onClick={toggle}
|
onClick={toggle}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user