Skip to content

Commit

Permalink
Merge pull request #1103 from kellnerd/imports-2024
Browse files Browse the repository at this point in the history
Make approval of imported entities work & other improvements
  • Loading branch information
MonkeyDo authored Jul 17, 2024
2 parents 6684575 + 155bd5e commit 7350b16
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 83 deletions.
13 changes: 2 additions & 11 deletions src/client/components/pages/import-entities/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ import ImportFooter from './footer';
import ImportTitle from './title';
import PropTypes from 'prop-types';
import React from 'react';
import {startCase} from 'lodash';


const {getImportUrl} = importHelper;
const {Alert, Col, Row} = bootstrap;
const {Col, Row} = bootstrap;


function ImportAuthorDisplayPage({importEntity, identifierTypes}) {
Expand All @@ -56,20 +55,12 @@ function ImportAuthorDisplayPage({importEntity, identifierTypes}) {
urlPrefix={urlPrefix}
/>
<hr className="margin-top-d40"/>
<Row>
<Alert
className="text-center font-weight-bold"
variant="success"
>
This {startCase(importEntity.type.toLowerCase())} has been automatically added.{' '}
Kindly approve/discard it to help us improve our data.
</Alert>
</Row>
<ImportFooter
hasVoted={importEntity.hasVoted}
importUrl={urlPrefix}
importedAt={importEntity.importedAt}
source={importEntity.source}
type={importEntity.type}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class DiscardImportEntity extends React.Component {
<h1> Discard Imported Entity </h1>
<Row className="margin-top-2">
{loadingComponent}
<Col md={6} mdOffset={3}>
<Col md={{offset: 3, span: 6}}>
{errorComponent}
<Card bg="danger">
<Card.Header>Confirm Discard</Card.Header>
Expand All @@ -103,11 +103,11 @@ class DiscardImportEntity extends React.Component {
to the imported entity page.
</Card.Body>
</Card>
<ButtonGroup justified className="margin-top-2">
<ButtonGroup className="d-flex margin-top-2">
<Button
href={getImportUrl(importEntity)}
title="Edit"
variant="default"
title="Cancel"
variant="secondary"
>
Cancel
</Button>
Expand Down
13 changes: 2 additions & 11 deletions src/client/components/pages/import-entities/edition-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ import ImportFooter from './footer';
import ImportTitle from './title';
import PropTypes from 'prop-types';
import React from 'react';
import {startCase} from 'lodash';


const {getImportUrl} = importHelper;
const {Alert, Col, Row} = bootstrap;
const {Col, Row} = bootstrap;


function ImportEditionGroupDisplayPage({importEntity, identifierTypes}) {
Expand All @@ -56,20 +55,12 @@ function ImportEditionGroupDisplayPage({importEntity, identifierTypes}) {
urlPrefix={urlPrefix}
/>
<hr className="margin-top-d40"/>
<Row>
<Alert
className="text-center font-weight-bold"
variant="success"
>
This {startCase(importEntity.type.toLowerCase())} has been automatically added.{' '}
Kindly approve/discard it to help us improve our data.
</Alert>
</Row>
<ImportFooter
hasVoted={importEntity.hasVoted}
importUrl={urlPrefix}
importedAt={importEntity.importedAt}
source={importEntity.source}
type={importEntity.type}
/>
</div>
);
Expand Down
13 changes: 2 additions & 11 deletions src/client/components/pages/import-entities/edition.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ import ImportFooter from './footer';
import ImportTitle from './title';
import PropTypes from 'prop-types';
import React from 'react';
import {startCase} from 'lodash';


const {getImportUrl} = importHelper;

const {Alert, Col, Row} = bootstrap;
const {Col, Row} = bootstrap;


function ImportEditionDisplayPage({importEntity, identifierTypes}) {
Expand All @@ -57,20 +56,12 @@ function ImportEditionDisplayPage({importEntity, identifierTypes}) {
urlPrefix={urlPrefix}
/>
<hr className="margin-top-d40"/>
<Row>
<Alert
className="text-center font-weight-bold"
variant="success"
>
This {startCase(importEntity.type.toLowerCase())} has been automatically added.{' '}
Kindly approve/discard it to help us improve our data.
</Alert>
</Row>
<ImportFooter
hasVoted={importEntity.hasVoted}
importUrl={urlPrefix}
importedAt={importEntity.importedAt}
source={importEntity.source}
type={importEntity.type}
/>
</div>
);
Expand Down
23 changes: 18 additions & 5 deletions src/client/components/pages/import-entities/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import {faCheck, faPencil, faRemove} from '@fortawesome/free-solid-svg-icons';
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
import PropTypes from 'prop-types';
import React from 'react';
import {startCase} from 'lodash';


const {formatDate} = utilsHelper;
const {
Button, ButtonGroup, Col, Row, Tooltip
Alert, Button, ButtonGroup, Col, Row, Tooltip
} = bootstrap;

function ImportFooter({importUrl, importedAt, source, hasVoted}) {
function ImportFooter({importUrl, importedAt, source, type, hasVoted}) {
const tooltip = (
<Tooltip id="tooltip">
<strong>You can only vote once to discard an import.</strong>
Expand All @@ -40,8 +41,19 @@ function ImportFooter({importUrl, importedAt, source, hasVoted}) {
return (
<div>
<Row>
<Col md={6} mdOffset={3}>
<ButtonGroup justified>
<Col>
<Alert
className="text-center font-weight-bold"
variant="success"
>
This {startCase(type.toLowerCase())} has been automatically added.{' '}
Kindly approve/discard it to help us improve our data.
</Alert>
</Col>
</Row>
<Row>
<Col className="text-center" md={{offset: 3, span: 6}}>
<ButtonGroup>
<Button
href={`${importUrl}/approve`}
title="Approve"
Expand Down Expand Up @@ -86,7 +98,8 @@ ImportFooter.propTypes = {
hasVoted: PropTypes.bool.isRequired,
importUrl: PropTypes.string.isRequired,
importedAt: PropTypes.string.isRequired,
source: PropTypes.string.isRequired
source: PropTypes.string.isRequired,
type: PropTypes.string.isRequired
};

export default ImportFooter;
13 changes: 2 additions & 11 deletions src/client/components/pages/import-entities/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ import ImportTitle from './title';
import PropTypes from 'prop-types';
import {PublisherAttributes} from '../entities/publisher';
import React from 'react';
import {startCase} from 'lodash';


const {getImportUrl} = importHelper;

const {Alert, Col, Row} = bootstrap;
const {Col, Row} = bootstrap;


function ImportPublisherDisplayPage({importEntity, identifierTypes}) {
Expand All @@ -57,20 +56,12 @@ function ImportPublisherDisplayPage({importEntity, identifierTypes}) {
urlPrefix={urlPrefix}
/>
<hr className="margin-top-d40"/>
<Row>
<Alert
className="text-center font-weight-bold"
variant="success"
>
This {startCase(importEntity.type.toLowerCase())} has been automatically added.{' '}
Kindly approve/discard it to help us improve our data.
</Alert>
</Row>
<ImportFooter
hasVoted={importEntity.hasVoted}
importUrl={urlPrefix}
importedAt={importEntity.importedAt}
source={importEntity.source}
type={importEntity.type}
/>
</div>
);
Expand Down
13 changes: 2 additions & 11 deletions src/client/components/pages/import-entities/work.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ import ImportTitle from './title';
import PropTypes from 'prop-types';
import React from 'react';
import {WorkAttributes} from '../entities/work';
import {startCase} from 'lodash';


const {getImportUrl} = importHelper;
const {Alert, Col, Row} = bootstrap;
const {Col, Row} = bootstrap;


function ImportWorkDisplayPage({importEntity, identifierTypes}) {
Expand All @@ -56,20 +55,12 @@ function ImportWorkDisplayPage({importEntity, identifierTypes}) {
urlPrefix={urlPrefix}
/>
<hr className="margin-top-d40"/>
<Row>
<Alert
className="text-center font-weight-bold"
variant="success"
>
This {startCase(importEntity.type.toLowerCase())} has been automatically added.{' '}
Kindly approve/discard it to help us improve our data.
</Alert>
</Row>
<ImportFooter
hasVoted={importEntity.hasVoted}
importUrl={urlPrefix}
importedAt={importEntity.importedAt}
source={importEntity.source}
type={importEntity.type}
/>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/pages/parts/recent-import-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function RecentImportsTable(props) {
<div> <h2 className="text-center">Click to review them!</h2> </div>
<Table
bordered
condensed
striped
size="sm"
>
<thead>
<tr>
Expand Down
10 changes: 10 additions & 0 deletions src/client/controllers/import-entity/discard-import-entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ const markup = (
);

ReactDOM.hydrate(markup, document.getElementById('target'));

/*
* As we are not exporting a component,
* we cannot use the react-hot-loader module wrapper,
* but instead directly use webpack Hot Module Replacement API
*/

if (module.hot) {
module.hot.accept();
}
10 changes: 10 additions & 0 deletions src/client/controllers/import-entity/import-entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ const markup = (


ReactDOM.hydrate(markup, document.getElementById('target'));

/*
* As we are not exporting a component,
* we cannot use the react-hot-loader module wrapper,
* but instead directly use webpack Hot Module Replacement API
*/

if (module.hot) {
module.hot.accept();
}
10 changes: 10 additions & 0 deletions src/client/controllers/import-entity/recent-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ const markup = (
);

ReactDOM.hydrate(markup, document.getElementById('target'));

/*
* As we are not exporting a component,
* we cannot use the react-hot-loader module wrapper,
* but instead directly use webpack Hot Module Replacement API
*/

if (module.hot) {
module.hot.accept();
}
5 changes: 2 additions & 3 deletions src/server/routes/entity/entity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,8 @@ function sanitizeBody(body:any) {
export async function processSingleEntity(formBody, JSONEntity, reqSession,
entityType, orm:any, editorJSON, derivedProps, isMergeOperation, transacting):Promise<any> {
const {Entity, Revision} = orm;
let body = sanitizeBody(formBody);
// Sanitize nameSection inputs
const body = sanitizeBody(formBody);
let currentEntity: {
aliasSet: {id: number} | null | undefined,
annotation: {id: number} | null | undefined,
Expand All @@ -1079,8 +1080,6 @@ export async function processSingleEntity(formBody, JSONEntity, reqSession,
try {
// Determine if a new entity is being created
const isNew = !currentEntity;
// sanitize namesection inputs
body = sanitizeBody(body);
if (isNew) {
const newEntity = await new Entity({type: entityType})
.save(null, {transacting});
Expand Down
Loading

0 comments on commit 7350b16

Please sign in to comment.