Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
ericjeangirard committed Aug 21, 2024
2 parents f1b23c0 + 5b9e606 commit bbaa78b
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
config_file: .github/config/changelog.js

- name: 📦 Create release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/button-dropdown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function ButtonDropdown({ className, data, label, searchParams })
icon="save-line"
size="sm"
>
{`Export ${label}`}
{`Export ${label} (${data.length})`}
</Button>
<div className="dropdown-content">
<Button
Expand Down
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
17 changes: 9 additions & 8 deletions client/src/pages/actions/actionsOpenalexFeedback.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ export default function ActionsOpenalexFeedback({ allOpenalexCorrections }) {
}

ActionsOpenalexFeedback.propTypes = {
allOpenalexCorrections: PropTypes.arrayOf(PropTypes.shape({
affiliations: PropTypes.arrayOf(PropTypes.object),
allIds: PropTypes.arrayOf(PropTypes.object).isRequired,
datasource: PropTypes.arrayOf(PropTypes.string).isRequired,
id: PropTypes.string.isRequired,
status: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
})).isRequired,
allOpenalexCorrections: PropTypes.arrayOf(
PropTypes.shape({
rawAffiliationString: PropTypes.string.isRequired,
rorsInOpenAlex: PropTypes.arrayOf(PropTypes.object).isRequired,
correctedRors: PropTypes.string.isRequired,
worksExample: PropTypes.arrayOf(PropTypes.object).isRequired,
worksOpenAlex: PropTypes.arrayOf(PropTypes.string).isRequired,
}),
).isRequired,
};
6 changes: 6 additions & 0 deletions client/src/pages/openalexTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';

import { status } from '../config';
import OpenalexView from './openalexView';
import { getCorrections } from '../utils/openalex';
import { removeDiacritics } from '../utils/strings';

export default function OpenalexTab({ affiliations, setAllOpenalexCorrections }) {
Expand All @@ -21,6 +22,11 @@ export default function OpenalexTab({ affiliations, setAllOpenalexCorrections })
const regex = new RegExp(removeDiacritics(filteredAffiliationName));
return regex.test(affiliation.key.replace('[ source: ', '').replace(' ]', ''));
});
// recompute corrections only when the array has changed
if (filteredAffiliationsTmp.length !== filteredAffiliations.length) {
const newCorrections = getCorrections(filteredAffiliationsTmp);
setAllOpenalexCorrections(newCorrections);
}
setFilteredAffiliations(filteredAffiliationsTmp);
}, 500);
setTimer(timerTmp);
Expand Down
67 changes: 38 additions & 29 deletions client/src/pages/openalexView.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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';
import PropTypes from 'prop-types';
import { useState } from 'react';

import useToast from '../hooks/useToast';
import { getCorrections } from '../utils/openalex';
import { isRor } from '../utils/ror';
import {
correctionTemplate,
Expand All @@ -24,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 @@ -50,19 +67,12 @@ export default function OpenalexView({
});
if (isValid) {
data.rorsToCorrect = newValue;
data.hasCorrection = true;
const newCorrections = [];
allAffiliations
.filter((aff) => aff.hasCorrection)
.forEach((aff) => {
const correction = {
rawAffiliationString: aff.name,
rorsInOpenAlex: aff.rors,
correctedRors: aff.rorsToCorrect,
worksExample: aff.worksExample,
};
newCorrections.push(correction);
});
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 @@ -111,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 @@ -131,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
17 changes: 9 additions & 8 deletions client/src/pages/views/openalex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ Openalex.propTypes = {
works: PropTypes.arrayOf(PropTypes.string).isRequired,
worksNumber: PropTypes.number.isRequired,
})).isRequired,
allOpenalexCorrections: PropTypes.arrayOf(PropTypes.shape({
affiliations: PropTypes.arrayOf(PropTypes.object),
allIds: PropTypes.arrayOf(PropTypes.object).isRequired,
datasource: PropTypes.arrayOf(PropTypes.string).isRequired,
id: PropTypes.string.isRequired,
status: PropTypes.string.isRequired,
type: PropTypes.string.isRequired,
}).isRequired).isRequired,
allOpenalexCorrections: PropTypes.arrayOf(
PropTypes.shape({
rawAffiliationString: PropTypes.string.isRequired,
rorsInOpenAlex: PropTypes.arrayOf(PropTypes.object).isRequired,
correctedRors: PropTypes.string.isRequired,
worksExample: PropTypes.arrayOf(PropTypes.object).isRequired,
worksOpenAlex: PropTypes.arrayOf(PropTypes.string).isRequired,
}),
).isRequired,
setAllOpenalexCorrections: PropTypes.func.isRequired,
options: PropTypes.object.isRequired,
};
20 changes: 20 additions & 0 deletions client/src/utils/openalex.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const getCorrections = (affiliations) => {
const newCorrections = [];
affiliations
.filter((aff) => aff.hasCorrection)
.forEach((aff) => {
const correction = {
rawAffiliationString: aff.name,
rorsInOpenAlex: aff.rors,
correctedRors: aff.rorsToCorrect,
worksExample: aff.worksExample,
worksOpenAlex: aff.worksOpenAlex,
};
newCorrections.push(correction);
});
return newCorrections;
};

export {
getCorrections,
};
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
5 changes: 4 additions & 1 deletion server/src/routes/github.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const createIssue = (issue, email) => {
body += `new_rors: ${issue.correctedRors}\n`;
const previousRoRs = issue.rorsInOpenAlex.map((e) => e.rorId).join(';');
body += `previous_rors: ${previousRoRs}\n`;
const workIds = issue.worksExample.filter((e) => e.id_type === 'openalex').map((e) => e.id_value).join(';');
let workIds = issue.worksExample.filter((e) => e.id_type === 'openalex').map((e) => e.id_value).join(';');
if (issue.worksOpenAlex) {
workIds = issue.worksOpenAlex.join(';');
}
body += `works_examples: ${workIds}\n`;
body += `contact: ${encrypt(email.split('@')[0])} @ ${email.split('@')[1]}\n`;
octokit.rest.issues.create({
Expand Down
6 changes: 5 additions & 1 deletion server/src/routes/works.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { chunkArray, countUniqueValues, range } from '../utils/utils';
import { datasetsType, deduplicateWorks, getFosmWorks, getOpenAlexPublications, groupByAffiliations } from '../utils/works';

const SEED_MAX = 2048;
const USE_CACHE = true;

const router = new express.Router();

Expand Down Expand Up @@ -48,7 +49,10 @@ const getData = async ({ options, resetCache = false }) => {
const searchId = shasum.digest('hex');
const queryId = Math.floor(Math.random() * SEED_MAX);
console.time(`0. Query ${queryId} | Retrieve cache if exists ${options.affiliationStrings}`);
const cache = await getCache({ searchId });
let cache = false;
if (USE_CACHE) {
cache = await getCache({ searchId });
}
console.timeEnd(`0. Query ${queryId} | Retrieve cache if exists ${options.affiliationStrings}`);
if (cache && !resetCache) {
const extractionDate = new Date(cache.extractionDate);
Expand Down
6 changes: 4 additions & 2 deletions server/src/utils/works.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ const groupByAffiliations = ({ options, works }) => {
if (toKeep[normalizedAffiliation]?.keepAffiliation) {
if (deduplicatedAffiliations?.[normalizedAffiliation]) {
deduplicatedAffiliations[normalizedAffiliation].works.push(id);
if (deduplicatedAffiliations[normalizedAffiliation].worksExample.length < 10) {
if (deduplicatedAffiliations[normalizedAffiliation].worksExample.length < 999) {
deduplicatedAffiliations[normalizedAffiliation].worksExample.push(work.allIds);
}
} else {
Expand All @@ -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 All @@ -498,8 +499,9 @@ const groupByAffiliations = ({ options, works }) => {
...affiliation,
id: index.toString(),
works: uniqueWorks,
worksExample: uniqueWorksExample,
worksExample: uniqueWorksExample.slice(0, 10),
worksNumber: uniqueWorks.length,
worksOpenAlex: uniqueWorksExample.filter((w) => w.id_type === 'openalex').map((w) => w.id_value || 0).filter((w) => w !== 0),
});
});
return allAffiliationsTmp;
Expand Down

0 comments on commit bbaa78b

Please sign in to comment.