mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 07:19:41 +02:00
refactor(k8s): namespace core logic (#12142)
Co-authored-by: testA113 <aliharriss1995@gmail.com> Co-authored-by: Anthony Lapenna <anthony.lapenna@portainer.io> Co-authored-by: James Carppe <85850129+jamescarppe@users.noreply.github.com> Co-authored-by: Ali <83188384+testA113@users.noreply.github.com>
This commit is contained in:
parent
da010f3d08
commit
ea228c3d6d
276 changed files with 9241 additions and 3361 deletions
|
@ -0,0 +1,52 @@
|
|||
import { Row } from '@tanstack/react-table';
|
||||
|
||||
import { RoleBinding } from '../RolesView/RoleBindingsDatatable/types';
|
||||
|
||||
import { ClusterRoleBinding } from './ClusterRoleBindingsDatatable/types';
|
||||
|
||||
/**
|
||||
* Transforms the rows of a table to get a unique list of namespaces to use as filter options.
|
||||
* One row can have multiple subject namespaces.
|
||||
* @param rows - The rows of the table.
|
||||
* @param id - The ID of the column containing the subject namespaces.
|
||||
* @returns An array of unique subject namespace options.
|
||||
*/
|
||||
export function filterNamespaceOptionsTransformer<
|
||||
TData extends ClusterRoleBinding | RoleBinding,
|
||||
>(rows: Row<TData>[], id: string) {
|
||||
const options = new Set<string>();
|
||||
rows.forEach(({ getValue }) => {
|
||||
const value = getValue<string[]>(id);
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
value.forEach((v) => {
|
||||
if (v && v !== '-') {
|
||||
options.add(v);
|
||||
}
|
||||
});
|
||||
});
|
||||
return Array.from(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the rows of a table based on the selected namespaces.
|
||||
* @param row - The row to filter.
|
||||
* @param _columnId - The ID of the column being filtered.
|
||||
* @param filterValue - The selected namespaces to filter by.
|
||||
* @returns True if the row should be shown, false otherwise.
|
||||
*/
|
||||
export function filterFn(
|
||||
row: Row<ClusterRoleBinding | RoleBinding>,
|
||||
_columnId: string,
|
||||
filterValue: string[]
|
||||
) {
|
||||
// when no filter is set, show all rows
|
||||
if (filterValue.length === 0) {
|
||||
return true;
|
||||
}
|
||||
const subjectNamespaces = row.original.subjects?.flatMap(
|
||||
(sub) => sub.namespace ?? []
|
||||
);
|
||||
return filterValue.some((v) => subjectNamespaces?.includes(v));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue