Skip to content

Commit

Permalink
Merge pull request #42 from georgetown-cset/29-column-dialog-show-cor…
Browse files Browse the repository at this point in the history
…rect-active-columns

Fix bug where incorrect initial columns were selected
  • Loading branch information
niharikasingh authored Aug 14, 2023
2 parents 6523070 + c86afc4 commit 97a6db4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions web/gui-v2/src/components/AddRemoveColumnDialog.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { css } from '@emotion/react';
import {
Checkbox,
Expand Down Expand Up @@ -49,6 +49,11 @@ const styles = {
`,
};

const generateColumnState = (selected, defs) => {
const split = selected.split(',');
return Object.fromEntries(defs.map(e => [e.key, split.includes(e.key)]));
}

const AddRemoveColumnDialog = ({
columnDefinitions,
isOpen,
Expand All @@ -57,10 +62,16 @@ const AddRemoveColumnDialog = ({
updateSelectedColumns,
}) => {
const [columnsInternal, setColumnsInternal] = useState(() => {
const split = selectedColumns.split(',');
return Object.fromEntries(columnDefinitions.map(e => [e.key, split.includes(e.key)]));
return generateColumnState(selectedColumns, columnDefinitions);
});

useEffect(
() => {
setColumnsInternal(generateColumnState(selectedColumns, columnDefinitions));
},
[columnDefinitions, selectedColumns]
);

const handleCancel = () => {
updateIsOpen(false);
};
Expand Down

0 comments on commit 97a6db4

Please sign in to comment.