Skip to content

Commit

Permalink
undo change openalex
Browse files Browse the repository at this point in the history
  • Loading branch information
ericjeangirard committed Aug 21, 2024
1 parent 1334293 commit 5b9e606
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 26 deletions.
6 changes: 5 additions & 1 deletion client/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ const status = {
const correction = {
corrected: {
badgeType: 'error',
label: 'CORRECTION',
label: 'MODIFIED',
},
reset: {
badgeType: 'info',
label: 'CANCEL',
},
notcorrected: {
badgeType: 'info',
Expand Down
53 changes: 36 additions & 17 deletions client/src/pages/openalexView.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Col, Row, Toggle } from '@dataesr/dsfr-plus';
import { Button, Col, Row, Toggle } from '@dataesr/dsfr-plus';
import { Column } from 'primereact/column';
import { DataTable } from 'primereact/datatable';
import { InputTextarea } from 'primereact/inputtextarea';
Expand All @@ -25,11 +25,27 @@ export default function OpenalexView({
const [selectionPageOnly, setSelectionPageOnly] = useState(true);

const cellEditor = (options) => (
<InputTextarea
type="text"
value={options.value}
onChange={(e) => options.editorCallback(e.target.value)}
/>
<Row gutters>
<Col>
<InputTextarea
type="text"
id="mytext"
value={options.value}
onChange={(e) => options.editorCallback(e.target.value)}
/>
</Col>
<Col>
<Button
variant="info"
size="sm"
disabled={options.rowData.rors.map((r) => r.rorId).join(';') === options.value}
icon="delete-line"
onClick={() => { options.editorCallback(options.rowData.rors.map((r) => r.rorId).join(';')); }}
>
UNDO
</Button>
</Col>
</Row>
);
const { toast } = useToast();

Expand All @@ -51,7 +67,11 @@ export default function OpenalexView({
});
if (isValid) {
data.rorsToCorrect = newValue;
data.hasCorrection = true;
if (data.rors.map((r) => r.rorId).join(';') !== newValue) {
data.hasCorrection = true;
} else {
data.hasCorrection = false;
}
const newCorrections = getCorrections(allAffiliations);
setAllOpenalexCorrections(newCorrections);
}
Expand Down Expand Up @@ -101,7 +121,7 @@ export default function OpenalexView({
paginatorLeft={paginatorLeft}
paginatorPosition="top bottom"
paginatorTemplate="RowsPerPageDropdown FirstPageLink PrevPageLink CurrentPageReport NextPageLink LastPageLink"
rows={100}
rows={50}
rowsPerPageOptions={[50, 100, 200, 500]}
scrollable
selectionPageOnly={selectionPageOnly}
Expand All @@ -121,39 +141,38 @@ export default function OpenalexView({
/>
<Column
field="rorHtml"
sortField="rorsNumber"
header="RoR computed by OpenAlex"
body={rorTemplate}
style={{ maxWidth: '200px' }}
sortable
/>
<Column
field="rorsToCorrect"
header="Click to improve / edit RoRs"
body={correctionTemplate}
style={{ maxWidth: '200px' }}
style={{ maxWidth: '190px' }}
editor={(options) => cellEditor(options)}
/>
<Column
rowEditor
headerStyle={{ width: '10%', minWidth: '8rem' }}
bodyStyle={{ textAlign: 'center' }}
style={{ maxWidth: '80px' }}
/>
<Column
field="hasCorrection"
header="Modified by user?"
body={hasCorrectionTemplate}
style={{ maxWidth: '120px' }}
style={{ maxWidth: '110px' }}
sortable
/>
<Column
field="worksExamples"
header="Examples of works"
sortField="worksNumber"
header="Works"
body={worksExampleTemplate}
style={{ maxWidth: '200px' }}
/>
<Column
field="worksNumber"
header="Number of works"
style={{ maxWidth: '100px' }}
style={{ maxWidth: '150px' }}
sortable
/>
</DataTable>
Expand Down
31 changes: 23 additions & 8 deletions client/src/utils/templates.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ const statusRowFilterTemplate = (options) => (
const getIdsTemplate = (ids) => {
let html = '<ul>';
ids.forEach((id) => {
html += `<li key="${id.id_value}">${id.id_type}: `;
html += `<li key="${id.id_value}"> `;
const idLink = getIdLink(id.id_type, id.id_value);
html += idLink ? `<a target="_blank" href="${idLink}">${id.id_value}</a>` : `<span>${id.id_value}</span>`;
let idValueDisplay = '';
if (id.id_value.length > 18) {
idValueDisplay = id.id_value.slice(0, 18).concat('..');
}
html += idLink ? `<a target="_blank" href="${idLink}">${idValueDisplay}</a>` : `<span>${id.id_value}</span>`;
html += '</li>';
});
html += '</ul>';
Expand Down Expand Up @@ -118,16 +122,18 @@ const datasourceTemplate = (rowData) => {

const correctionTemplate = (rowData) => {
let html = '';
html = html.concat('<ul>');
const rorsToCorrect = rowData.rorsToCorrect.split(';').map((item) => item.trim()).filter((item) => item.length > 0);
if (rorsToCorrect.length > 0) {
html = html.concat('<ul>');
rorsToCorrect.forEach((ror) => {
html = html.concat(`<li key="ror-${ror}">${ror}</li>`);
});
html = html.concat('</ul>');
if (rowData.hasCorrection) {
html = `<strong>${ html }</strong>`;
}
} else {
html = html.concat('<li key="noror"> </li>');
}
html = html.concat('</ul>');
if (rowData.hasCorrection) {
html = `<strong>${ html }</strong>`;
}
return <span dangerouslySetInnerHTML={{ __html: html }} />;
};
Expand All @@ -136,8 +142,17 @@ const nameTemplate = (rowData) => <span dangerouslySetInnerHTML={{ __html: rowDa

const statusTemplate = (rowData) => <Badge variant={status[rowData?.status ?? rowData]?.badgeType}>{status[rowData?.status ?? rowData]?.label}</Badge>;

const resetCorrection = (rowData, allAffiliations) => {
console.log('ttt', rowData);
const row = { rowData };
row.rowData.hasCorrection = false;
row.rowData.rorsToCorrect = rowData.rors.map((e) => e.rorId).join(';');
};

const hasCorrectionTemplate = (rowData) => (rowData?.hasCorrection
? <Badge variant={correction.corrected.badgeType}>{correction.corrected.label}</Badge>
? (
<Badge variant={correction.corrected.badgeType}>{correction.corrected.label}</Badge>
)
: '');

export {
Expand Down
1 change: 1 addition & 0 deletions server/src/utils/works.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ const groupByAffiliations = ({ options, works }) => {
name: affiliation.rawAffiliation,
nameHtml: toKeep[normalizedAffiliation].displayAffiliation,
rors: affiliation.rors || [],
rorsNumber: affiliation.rors?.length || 0,
rorsToCorrect: (affiliation.rorsToCorrect || []).join(';'),
source: affiliation.source,
status: 'tobedecided',
Expand Down

0 comments on commit 5b9e606

Please sign in to comment.