Skip to content

Commit

Permalink
✨ Clicking on child row shows payload
Browse files Browse the repository at this point in the history
Click on a child row with a reference ID shows the payload for that ID
  • Loading branch information
abgeorge7 committed Mar 4, 2020
1 parent 9e437ed commit 9c4cf3f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
29 changes: 29 additions & 0 deletions src/components/tables/ReferenceTable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import {Modal} from 'semantic-ui-react';
import {getReferencedBy} from '../../utils/api';
import SortableTable from './SortableTable';
import './ReferenceTable.css';
Expand All @@ -10,6 +11,7 @@ class ReferenceTable extends React.Component {
this.state = {
loadingReferences: false,
referenceData: [],
showChildModal: null,
};
}

Expand Down Expand Up @@ -58,6 +60,14 @@ class ReferenceTable extends React.Component {
});
};

onChildRowClick = child => {
this.setState({showChildModal: child});
};

closeModal = () => {
this.setState({showChildModal: null});
};

render() {
return (
<div className="reference-table">
Expand All @@ -73,7 +83,26 @@ class ReferenceTable extends React.Component {
headerCells={this.props.tableHeaders}
data={this.state.referenceData}
rowChildren={true}
onChildRowClick={this.onChildRowClick}
/>
<Modal
open={!!this.state.showChildModal}
onClose={() => this.closeModal()}
dimmer="inverted"
>
<Modal.Header>
{this.state.showChildModal
? this.state.showChildModal.id
: null}
</Modal.Header>
<Modal.Content>
<Modal.Description>
<pre>
{JSON.stringify(this.state.showChildModal, null, 2)}
</pre>
</Modal.Description>
</Modal.Content>
</Modal>
</div>
) : null}
</div>
Expand Down
6 changes: 0 additions & 6 deletions src/components/tables/SortableTable.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,3 @@
.sortable-table td:hover {
background-color: var(--d3b-hoverblue);
}

.sortable-table__child-row:hover,
.sortable-table__child-row td:hover {
background-color: inherit !important;
cursor: default;
}
7 changes: 6 additions & 1 deletion src/components/tables/SortableTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ class SortableTable extends React.Component {
key={`${child.id}-${j}`}
className="sortable-table__child-row"
>
<Table.Cell colSpan="4">
<Table.Cell
colSpan={headerCells.length}
onClick={() => this.props.onChildRowClick(child)}
>
<p>{child.id}</p>
</Table.Cell>
</Table.Row>
Expand Down Expand Up @@ -140,13 +143,15 @@ SortableTable.propTypes = {
),
rowChildren: PropTypes.bool,
onRowClick: PropTypes.func,
onChildRowClick: PropTypes.func,
};

SortableTable.defaultProps = {
headerCells: [],
data: [],
rowChildren: false,
onRowClick: () => {},
onChildRowClick: () => {},
};

export default SortableTable;

0 comments on commit 9c4cf3f

Please sign in to comment.