mirror of https://github.com/portainer/portainer
fix(templates): show type selector [EE-6370] (#10694)
parent
db46dc553f
commit
c40931b31c
|
@ -1,6 +1,6 @@
|
||||||
import { Edit } from 'lucide-react';
|
import { Edit } from 'lucide-react';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
|
|
||||||
import { DatatableHeader } from '@@/datatables/DatatableHeader';
|
import { DatatableHeader } from '@@/datatables/DatatableHeader';
|
||||||
import { Table } from '@@/datatables';
|
import { Table } from '@@/datatables';
|
||||||
|
@ -23,7 +23,7 @@ const store = createPersistedStore<ListState>(tableKey, undefined, (set) => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export function AppTemplatesList({
|
export function AppTemplatesList({
|
||||||
templates,
|
templates: initialTemplates,
|
||||||
onSelect,
|
onSelect,
|
||||||
selectedId,
|
selectedId,
|
||||||
disabledTypes,
|
disabledTypes,
|
||||||
|
@ -38,11 +38,25 @@ export function AppTemplatesList({
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
|
|
||||||
const listState = useTableState(store, tableKey);
|
const listState = useTableState(store, tableKey);
|
||||||
|
|
||||||
|
const templates = useMemo(() => {
|
||||||
|
if (!initialTemplates) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fixedCategories?.length) {
|
||||||
|
return initialTemplates;
|
||||||
|
}
|
||||||
|
|
||||||
|
return initialTemplates.filter((template) =>
|
||||||
|
fixedCategories.some((category) => template.Categories.includes(category))
|
||||||
|
);
|
||||||
|
}, [fixedCategories, initialTemplates]);
|
||||||
|
|
||||||
const filteredTemplates = useSortAndFilterTemplates(
|
const filteredTemplates = useSortAndFilterTemplates(
|
||||||
templates || [],
|
templates || [],
|
||||||
listState,
|
listState,
|
||||||
disabledTypes,
|
disabledTypes
|
||||||
fixedCategories
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const pagedTemplates =
|
const pagedTemplates =
|
||||||
|
@ -58,7 +72,7 @@ export function AppTemplatesList({
|
||||||
description={
|
description={
|
||||||
<Filters
|
<Filters
|
||||||
listState={listState}
|
listState={listState}
|
||||||
templates={filteredTemplates || []}
|
templates={templates || []}
|
||||||
onChange={() => setPage(0)}
|
onChange={() => setPage(0)}
|
||||||
disabledTypes={disabledTypes}
|
disabledTypes={disabledTypes}
|
||||||
fixedCategories={fixedCategories}
|
fixedCategories={fixedCategories}
|
||||||
|
|
|
@ -7,20 +7,19 @@ import { ListState } from './types';
|
||||||
export function useSortAndFilterTemplates(
|
export function useSortAndFilterTemplates(
|
||||||
templates: Array<TemplateViewModel>,
|
templates: Array<TemplateViewModel>,
|
||||||
listState: ListState & { search: string },
|
listState: ListState & { search: string },
|
||||||
disabledTypes: Array<TemplateViewModel['Type']> = [],
|
disabledTypes: Array<TemplateViewModel['Type']> = []
|
||||||
fixedCategories: Array<string> = []
|
|
||||||
) {
|
) {
|
||||||
const filterByCategory = useCallback(
|
const filterByCategory = useCallback(
|
||||||
(item: TemplateViewModel) => {
|
(item: TemplateViewModel) => {
|
||||||
if (!listState.category && !fixedCategories.length) {
|
if (!listState.category) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _.compact([...fixedCategories, listState.category]).every(
|
return _.compact([listState.category]).every((category) =>
|
||||||
(category) => item.Categories.includes(category)
|
item.Categories.includes(category)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[fixedCategories, listState.category]
|
[listState.category]
|
||||||
);
|
);
|
||||||
|
|
||||||
const filterBySearch = useCallback(
|
const filterBySearch = useCallback(
|
||||||
|
|
Loading…
Reference in New Issue