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

BRU-1063 Column reordering bug #32

Merged
merged 1 commit into from
Apr 4, 2024
Merged
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
47 changes: 29 additions & 18 deletions frontend/src/components/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,33 +165,46 @@ const Table: React.FC<Props> = (props) => {
async function hideColumn(key: string) {
if (key == undefined) return;

const newHiddenColumns = [...hiddenColumns, key];
const newOrderedColumns = orderedColumns.filter(
(column) => !newHiddenColumns.includes(column),
);

await updateTable({
id: table!.id,
update: {
configuration: {
...table!.configuration,
hidden_columns: [...hiddenColumns, key],
hidden_columns: newHiddenColumns,
ordered_columns: newOrderedColumns,
},
},
});

setHiddenColumns([...hiddenColumns, key]);
setHiddenColumns(newHiddenColumns);
setOrderedColumns(newOrderedColumns);
}

async function unhideColumn(key: string) {
if (key == undefined) return;
async function unhideColumn(key: string, index?: number) {
if (key == undefined || index == undefined) return;

const newHiddenColumns = hiddenColumns.filter((column) => column != key);
const newOrderedColumns = orderedColumns.slice();
newOrderedColumns.splice(index + 1, 0, key);

await updateTable({
id: table!.id,
update: {
configuration: {
...table!.configuration,
hidden_columns: hiddenColumns.filter((column) => column != key),
hidden_columns: newHiddenColumns,
ordered_columns: newOrderedColumns,
},
},
});

setHiddenColumns(hiddenColumns.filter((column) => column != key));
setHiddenColumns(newHiddenColumns);
setOrderedColumns(newOrderedColumns);
}

function renderMenu(key: string) {
Expand All @@ -208,7 +221,7 @@ const Table: React.FC<Props> = (props) => {
onClick={() => orderTableData("desc", key)}
text="Order Desc"
/>
{_.keys(tableData.columns).length - hiddenColumns.length > 1 && (
{orderedColumns.length > 1 && (
<MenuItem
icon="eye-off"
onClick={() => hideColumn(key)}
Expand All @@ -222,7 +235,7 @@ const Table: React.FC<Props> = (props) => {
<MenuItem
key={column}
text={column}
onClick={() => unhideColumn(column)}
onClick={() => unhideColumn(column, index)}
/>
))}
</Menu>
Expand Down Expand Up @@ -353,16 +366,14 @@ const Table: React.FC<Props> = (props) => {
enableFocusedCell={true}
// loadingOptions={[TableLoadingOption.CELLS]}
>
{orderedColumns
.filter((key) => !_.includes(hiddenColumns, key))
.map((key) => (
<Column
key={key}
name={key}
cellRenderer={genericCellRenderer(key)}
columnHeaderCellRenderer={genericHeaderCellRenderer(key)}
/>
))}
{orderedColumns.map((key) => (
<Column
key={key}
name={key}
cellRenderer={genericCellRenderer(key)}
columnHeaderCellRenderer={genericHeaderCellRenderer(key)}
/>
))}
</Table2>
</>
);
Expand Down
Loading