fix(edge/updates): allow group search [EE-6179] (#10408)

pull/10464/head
Chaim Lev-Ari 1 year ago committed by GitHub
parent 5a73605df2
commit 57c45838d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -273,7 +273,9 @@ export function defaultGlobalFilterFn<D, TFilter extends { search: string }>(
}
if (Array.isArray(value)) {
return value.some((item) => item.toLowerCase().includes(filterValueLower));
return value.some((item) =>
item.toString().toLowerCase().includes(filterValueLower)
);
}
return false;

@ -1,7 +1,10 @@
import { Clock, Trash2 } from 'lucide-react';
import { useMemo } from 'react';
import _ from 'lodash';
import { notifySuccess } from '@/portainer/services/notifications';
import { withLimitToBE } from '@/react/hooks/useLimitToBE';
import { useEdgeGroups } from '@/react/edge/edge-groups/queries/useEdgeGroups';
import { confirmDelete } from '@@/modals/confirm';
import { Datatable } from '@@/datatables';
@ -17,6 +20,7 @@ import { BetaAlert } from '../common/BetaAlert';
import { columns } from './columns';
import { createStore } from './datatable-store';
import { DecoratedItem } from './types';
const storageKey = 'update-schedules-list';
const settingsStore = createStore(storageKey);
@ -27,8 +31,24 @@ export function ListView() {
const tableState = useTableState(settingsStore, storageKey);
const listQuery = useList(true);
const groupsQuery = useEdgeGroups({
select: (groups) => Object.fromEntries(groups.map((g) => [g.Id, g.Name])),
});
const items: Array<DecoratedItem> = useMemo(() => {
if (!listQuery.data || !groupsQuery.data) {
return [];
}
return listQuery.data.map((item) => ({
...item,
edgeGroupNames: _.compact(
item.edgeGroupIds.map((id) => groupsQuery.data[id])
),
}));
}, [listQuery.data, groupsQuery.data]);
if (!listQuery.data) {
if (!listQuery.data || !groupsQuery.data) {
return null;
}
@ -46,7 +66,7 @@ export function ListView() {
/>
<Datatable
dataset={listQuery.data}
dataset={items}
columns={columns}
settingsManager={tableState}
title="Update & rollback"

@ -1,27 +1,18 @@
import _ from 'lodash';
import { CellContext } from '@tanstack/react-table';
import { EdgeGroup } from '@/react/edge/edge-groups/types';
import { useEdgeGroups } from '@/react/edge/edge-groups/queries/useEdgeGroups';
import { EdgeUpdateListItemResponse } from '../../queries/list';
import { DecoratedItem } from '../types';
import { columnHelper } from './helper';
export const groups = columnHelper.accessor('edgeGroupIds', {
header: 'Groups',
export const groups = columnHelper.accessor('edgeGroupNames', {
header: 'Edge Groups',
cell: GroupsCell,
});
export function GroupsCell({
getValue,
}: CellContext<EdgeUpdateListItemResponse, Array<EdgeGroup['Id']>>) {
const groupsIds = getValue();
const groupsQuery = useEdgeGroups();
const groups = _.compact(
groupsIds.map((id) => groupsQuery.data?.find((g) => g.Id === id))
);
}: CellContext<DecoratedItem, Array<string>>) {
const groups = getValue();
return groups.map((g) => g.Name).join(', ');
return groups.join(', ');
}

@ -1,5 +1,5 @@
import { createColumnHelper } from '@tanstack/react-table';
import { EdgeUpdateListItemResponse } from '../../queries/list';
import { DecoratedItem } from '../types';
export const columnHelper = createColumnHelper<EdgeUpdateListItemResponse>();
export const columnHelper = createColumnHelper<DecoratedItem>();

@ -1,6 +1,6 @@
import { buildNameColumn } from '@@/datatables/buildNameColumn';
import { EdgeUpdateListItemResponse } from '../../queries/list';
import { DecoratedItem } from '../types';
import { created } from './created';
import { groups } from './groups';
@ -9,7 +9,7 @@ import { scheduledTime } from './scheduled-time';
import { scheduleType } from './type';
export const columns = [
buildNameColumn<EdgeUpdateListItemResponse>('name', '.item'),
buildNameColumn<DecoratedItem>('name', '.item'),
scheduledTime,
groups,
scheduleType,

@ -1,7 +1,7 @@
import { CellContext } from '@tanstack/react-table';
import { EdgeUpdateListItemResponse } from '../../queries/list';
import { StatusType } from '../../types';
import { DecoratedItem } from '../types';
import { columnHelper } from './helper';
@ -15,10 +15,7 @@ function StatusCell({
row: {
original: { statusMessage },
},
}: CellContext<
EdgeUpdateListItemResponse,
EdgeUpdateListItemResponse['status']
>) {
}: CellContext<DecoratedItem, DecoratedItem['status']>) {
const status = getValue();
switch (status) {

@ -0,0 +1,5 @@
import { EdgeUpdateListItemResponse } from '../queries/list';
export type DecoratedItem = EdgeUpdateListItemResponse & {
edgeGroupNames: string[];
};
Loading…
Cancel
Save