1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Removing "filterItems" prop from ItemListLayout

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-02-11 12:08:06 +03:00
parent 5b3f71a5cb
commit d06a2c6b4b
3 changed files with 17 additions and 20 deletions

View File

@ -34,6 +34,10 @@ export class HelmCharts extends Component<Props> {
return helmChartStore.getByName(chartName, repo); return helmChartStore.getByName(chartName, repo);
} }
get items() {
return helmChartStore.items.filter(item => !item.deprecated);
}
showDetails = (chart: HelmChart) => { showDetails = (chart: HelmChart) => {
if (!chart) { if (!chart) {
navigation.merge(helmChartsURL()); navigation.merge(helmChartsURL());
@ -72,9 +76,7 @@ export class HelmCharts extends Component<Props> {
(chart: HelmChart) => chart.getAppVersion(), (chart: HelmChart) => chart.getAppVersion(),
(chart: HelmChart) => chart.getKeywords(), (chart: HelmChart) => chart.getKeywords(),
]} ]}
filterItems={[ items={this.items}
(items: HelmChart[]) => items.filter(item => !item.deprecated)
]}
customizeHeader={() => ( customizeHeader={() => (
<SearchInputUrl placeholder={`Search Helm Charts`} /> <SearchInputUrl placeholder={`Search Helm Charts`} />
)} )}

View File

@ -33,6 +33,15 @@ export class CrdList extends React.Component {
return crdGroupsUrlParam.get(); return crdGroupsUrlParam.get();
} }
get items() {
const selectedGroups = this.groups;
const storeItems = crdStore.items;
return selectedGroups.length ?
storeItems.filter(item => selectedGroups.includes(item.getGroup())) :
storeItems;
}
onSelectGroup(group: string) { onSelectGroup(group: string) {
const groups = new Set(this.groups); const groups = new Set(this.groups);
@ -62,11 +71,7 @@ export class CrdList extends React.Component {
store={crdStore} store={crdStore}
sortingCallbacks={sortingCallbacks} sortingCallbacks={sortingCallbacks}
searchFilters={Object.values(sortingCallbacks)} searchFilters={Object.values(sortingCallbacks)}
filterItems={[ items={this.items}
(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</>;

View File

@ -45,7 +45,6 @@ export interface ItemListLayoutProps<T extends ItemObject = ItemObject> {
isClusterScoped?: boolean; isClusterScoped?: boolean;
hideFilters?: boolean; hideFilters?: boolean;
searchFilters?: SearchFilter<T>[]; searchFilters?: SearchFilter<T>[];
filterItems?: ItemsFilter<T>[];
// header (title, filtering, searching, etc.) // header (title, filtering, searching, etc.)
showHeader?: boolean; showHeader?: boolean;
@ -86,7 +85,6 @@ const defaultProps: Partial<ItemListLayoutProps> = {
copyClassNameFromHeadCells: true, copyClassNameFromHeadCells: true,
preloadStores: true, preloadStores: true,
dependentStores: [], dependentStores: [],
filterItems: [],
hasDetailsView: true, hasDetailsView: true,
onDetails: noop, onDetails: noop,
virtual: true virtual: true
@ -196,14 +194,8 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
return filters.reduce((items, filter) => filter(items), items); return filters.reduce((items, filter) => filter(items), items);
} }
@computed get allItems() {
const { filterItems, store } = this.props;
return this.applyFilters(filterItems, store.items);
}
@computed get items() { @computed get items() {
const { allItems, filters, filterCallbacks } = this; const { filters, filterCallbacks } = this;
const filterItems: ItemsFilter[] = []; const filterItems: ItemsFilter[] = [];
const filterGroups = groupBy<Filter>(filters, ({ type }) => type); const filterGroups = groupBy<Filter>(filters, ({ type }) => type);
@ -215,9 +207,7 @@ export class ItemListLayout extends React.Component<ItemListLayoutProps> {
} }
}); });
const items = this.props.items ?? allItems; return this.applyFilters(filterItems, this.props.items);
return this.applyFilters(filterItems, items);
} }
@autobind() @autobind()