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 4 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;
},
});
13 changes: 10 additions & 3 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 @@ -40,10 +41,16 @@ function useColumns(columns: string[]) {
* Table to display elements
*/
export const ElementTable: FC = () => {
const attributeColumns = useRecoilValue(attributeAtom);
const attColumns = useRecoilValue(attributeAtom);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer that this is fully spelled out. Makes things more readable (for me who never works in the code)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with jack here

const elements = useRecoilValue(selectedItemsSelector);
const rows = useRows(elements);
const columns = useColumns(['_label', ...attributeColumns]);
const setColumns = useRecoilValue(setColumnsSelector);
let columns = useColumns(['_label', ...([...attColumns, ...setColumns].filter((col) => !col.startsWith('_')))]);
// Sort set columns to the right of other columns & add a boolean type to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this sort? Looks like it just adds type

Copy link
Member

@JakeWags JakeWags Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "sorting" here is really just the spread operator, putting the setColumns at the end of the list.
@JackWilb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, that comment is outdated; there used to be an explicit sort function but that was removed when I started using spread instead. Comment updated.

columns = columns.map((col) => ({
...col,
type: setColumns.includes(col.field) ? 'boolean' : 'string',
}));

return (
<Box
Expand Down
Loading