Skip to content

Commit

Permalink
chore: show proper plural word in button- Remove 'Editions', 'Works'
Browse files Browse the repository at this point in the history
  • Loading branch information
prabalsingh24 committed Jun 29, 2020
1 parent 6ca917a commit 089c4dd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
29 changes: 20 additions & 9 deletions src/client/components/pages/collection.js
Expand Up @@ -35,6 +35,14 @@ function getEntityTable(entityType) {
return tables[entityType];
}

function getEntityKey(entityType) {
const keys = {
Edition: 'editions',
Work: 'works'
};
return keys[entityType];
}

class CollectionPage extends React.Component {
constructor(props) {
super(props);
Expand All @@ -47,6 +55,8 @@ class CollectionPage extends React.Component {
this.handleRemoveEntities = this.handleRemoveEntities.bind(this);
}

entityKey = getEntityKey(this.props.collection.entityType);

toggleRow(bbid) {
// eslint-disable-next-line react/no-access-state-in-setstate
const oldSelected = this.state.selectedEntities;
Expand Down Expand Up @@ -75,14 +85,21 @@ class CollectionPage extends React.Component {
});
}
else {
this.setState({error: 'No Editions Selected'});
this.setState({error: `No ${this.entityKey} selected`});
}
}

render() {
const errorComponent = this.state.error ?
<Alert bsStyle="danger">{this.state.error}</Alert> : null;
const EntityTable = getEntityTable(this.props.collection.entityType);
const propsForTable = {
[this.entityKey]: this.props.entities,
selectedEntities: this.state.selectedEntities,
showAdd: false,
showCheckboxes: this.props.showCheckboxes,
toggleRow: this.toggleRow
};
return (
<div>
<Row className="entity-display-background">
Expand Down Expand Up @@ -112,13 +129,7 @@ class CollectionPage extends React.Component {
}
</div>
</Row>
<EntityTable
entities={this.props.entities}
selectedEntities={this.state.selectedEntities}
showAdd={false}
showCheckboxes={this.props.showCheckboxes}
toggleRow={this.toggleRow}
/>
<EntityTable{...propsForTable}/>
{errorComponent}
{
this.props.showCheckboxes ?
Expand All @@ -128,7 +139,7 @@ class CollectionPage extends React.Component {
onClick={this.handleRemoveEntities}
>
<FontAwesomeIcon icon="times"/>
&nbsp;Remove Selected Editions
&nbsp;Remove selected {this.entityKey}
</Button> : null
}
</div>
Expand Down
5 changes: 2 additions & 3 deletions src/client/components/pages/entities/edition-table.js
Expand Up @@ -87,9 +87,8 @@ EditionTableRow.defaultProps = {
toggleRow: null
};

function EditionTable({entities, entity, showAdd, showCheckboxes, selectedEntities, toggleRow}) {
function EditionTable({editions, entity, showAdd, showCheckboxes, selectedEntities, toggleRow}) {
let tableContent;
const editions = entities;
if (editions.length) {
tableContent = (
<React.Fragment>
Expand Down Expand Up @@ -167,7 +166,7 @@ function EditionTable({entities, entity, showAdd, showCheckboxes, selectedEntiti
}
EditionTable.displayName = 'EditionTable';
EditionTable.propTypes = {
entities: PropTypes.array.isRequired,
editions: PropTypes.array.isRequired,
entity: PropTypes.object,
selectedEntities: PropTypes.array,
showAdd: PropTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/pages/entities/edition.js
Expand Up @@ -142,8 +142,8 @@ function EditionDisplayPage({entity, identifierTypes}) {
{!entity.deleted &&
<React.Fragment>
<WorksTable
entities={worksContainedByEdition}
entity={entity}
works={worksContainedByEdition}
/>
<EntityLinks
entity={entity}
Expand Down
7 changes: 3 additions & 4 deletions src/client/components/pages/entities/work-table.js
Expand Up @@ -69,9 +69,8 @@ WorkTableRow.defaultProps = {
toggleRow: null
};

function WorkTable({entity, entities, showAdd, showCheckboxes, selectedEntities, toggleRow}) {
function WorkTable({entity, works, showAdd, showCheckboxes, selectedEntities, toggleRow}) {
let tableContent;
const works = entities;
if (works.length) {
tableContent = (
<React.Fragment>
Expand Down Expand Up @@ -146,12 +145,12 @@ function WorkTable({entity, entities, showAdd, showCheckboxes, selectedEntities,
}
WorkTable.displayName = 'WorkTable';
WorkTable.propTypes = {
entities: PropTypes.array.isRequired,
entity: PropTypes.object,
selectedEntities: PropTypes.array,
showAdd: PropTypes.bool,
showCheckboxes: PropTypes.bool,
toggleRow: PropTypes.func
toggleRow: PropTypes.func,
works: PropTypes.array.isRequired
};
WorkTable.defaultProps = {
entity: null,
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/pages/entities/work.js
Expand Up @@ -94,7 +94,7 @@ function WorkDisplayPage({entity, identifierTypes}) {
{!entity.deleted &&
<React.Fragment>
<EditionTable
entities={editionsContainWork}
editions={editionsContainWork}
entity={entity}
/>
<EntityLinks
Expand Down

0 comments on commit 089c4dd

Please sign in to comment.