Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add set membership columns to the element view table #435

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion e2e-tests/elementView.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ test('Element View', async ({ page, browserName }) => {
await expect(selectionChip).toBeVisible();

// Check that the datatable is visible and populated
const dataTable = page.locator('div').filter({ hasText: /^LabelAge$/ }).first();
const dataTable = page.getByText(
'LabelAgeSchoolBlue HairDuff FanEvilMalePower PlantBart10yesnononoyesnoRalph8yesnononoyesnoMartin Prince10yesnononoyesnoRows per page:1001–3 of',
);
await expect(dataTable).toBeVisible();
const nameCell = await page.getByRole('cell', { name: 'Bart' });
await expect(nameCell).toBeVisible();
Expand Down
11 changes: 11 additions & 0 deletions packages/upset/src/atoms/dataAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ export const queryColumnsSelector = selector<ColumnName[]>({
&& !BUILTIN_COLS.includes(col));
},
});

/**
* Returns the boolean columns that indicate set membership
*/
export const setColumnsSelector = selector<ColumnName[]>({
key: 'set-columns',
get: ({ get }) => {
const data = get(dataAtom);
return data.setColumns;
},
});
11 changes: 9 additions & 2 deletions packages/upset/src/components/ElementView/ElementTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { Item } from '@visdesignlab/upset2-core';
import { FC, useMemo } from 'react';
import { useRecoilValue } from 'recoil';

import { attributeAtom } from '../../atoms/attributeAtom';
import { selectedItemsSelector } from '../../atoms/elementsSelectors';
import { setColumnsSelector } from '../../atoms/dataAtom';
import { attributeAtom } from '../../atoms/attributeAtom';

/**
* Hook to generate rows for the DataGrid
Expand Down Expand Up @@ -43,7 +44,13 @@ export const ElementTable: FC = () => {
const attributeColumns = useRecoilValue(attributeAtom);
const elements = useRecoilValue(selectedItemsSelector);
const rows = useRows(elements);
const columns = useColumns(['_label', ...attributeColumns]);
const setColumns = useRecoilValue(setColumnsSelector);
let columns = useColumns(['_label', ...([...attributeColumns, ...setColumns].filter((col) => !col.startsWith('_')))]);
// Add a boolean type to set columns so they display properly
columns = columns.map((col) => ({
...col,
type: setColumns.includes(col.field) ? 'boolean' : 'string',
}));

return (
<Box
Expand Down
Loading