Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
closing cube if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Helene Rigner committed May 14, 2019
1 parent aa747ac commit 508f449
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/components/cube.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import './cube.pcss';
// The component needs to be wrapped in `forwardRef` to give access to the
// ref object assigned using the `ref` prop.
const Cube = forwardRef(({
app, tableData: { initialColumns }, closeOnClickOutside, id, isLocalStorage,
app, tableData: { initialColumns }, closeOnClickOutside, id, isLocalStorage, closeCube,
}, ref) => {
const selectableColumns = useColumnOptions(app);
const [columns, setColumns] = useState(initialColumns);
Expand Down Expand Up @@ -156,6 +156,11 @@ const Cube = forwardRef(({
if (isEmpty && addOpen.current) {
return popup;
}

if (isEmpty && closeCube) {
closeCube(id);
}

return (
<div className={`cube ${isEmpty ? 'empty' : ''}`}>
{popup}
Expand All @@ -173,6 +178,7 @@ export default Cube;
Cube.defaultProps = {
closeOnClickOutside: () => true,
isLocalStorage: false,
closeCube: undefined,
};

Cube.propTypes = {
Expand All @@ -181,4 +187,5 @@ Cube.propTypes = {
closeOnClickOutside: PropTypes.func,
id: PropTypes.number.isRequired,
isLocalStorage: PropTypes.bool,
closeCube: PropTypes.func,
};
4 changes: 0 additions & 4 deletions src/components/cube.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,5 @@
.hypercube-table {
flex: 1 1 auto;
}

.column-add-button.empty {
border-right: 1px solid #d9d9d9;
}
}
}
2 changes: 1 addition & 1 deletion src/components/cubes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function Cubes({ app, closeOnClickOutside, isLocalStorage }) {
<SVGInline className="copy" svg={copy} onClick={() => copyToClipboard(cube.id)} title="Copy hypercube def to clipboard" />
<SVGInline {...closeButton} onClick={() => removeCube(cube.id)} title="Close cube" />
</div>
<Cube ref={refs.current[cube.id]} app={app} tableData={cube} closeOnClickOutside={closeOnClickOutside} id={cube.id} isLocalStorage={isLocalStorage} />
<Cube ref={refs.current[cube.id]} app={app} tableData={cube} closeOnClickOutside={closeOnClickOutside} id={cube.id} isLocalStorage={isLocalStorage} closeCube={removeCube} />
</div>
));
return (
Expand Down

0 comments on commit 508f449

Please sign in to comment.