Skip to content

Commit

Permalink
fix(search): Restore search on RoR
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Sep 28, 2023
1 parent cc0bf17 commit 1175dc3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
9 changes: 8 additions & 1 deletion client/src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,18 @@ export default function Home() {
const ror = getAffiliationRor(affiliation);
const normalizedAffiliationName = normalizedName(affiliation.name);
if (!allAffiliationsTmp?.[normalizedAffiliationName]) {
// Check matches in affiliation name and ror
let matches = `${affiliation?.name} ${ror}`?.match(regexp) ?? [];
// Normalize matched strings
matches = matches.map((name) => normalizedName(name));
// Filter matches as uniq
matches = [...new Set(matches)];
allAffiliationsTmp[normalizedAffiliationName] = {
matches: [...new Set((affiliation?.name?.match(regexp) ?? []).map((name) => normalizedName(name)))].length,
matches: matches.length,
name: affiliation.name,
nameHtml: affiliation.name.replace(regexp, '<b>$&</b>'),
ror,
rorHtml: ror?.replace(regexp, '<b>$&</b>'),
status: TO_BE_DECIDED_STATUS,
works: [],
};
Expand Down
3 changes: 2 additions & 1 deletion client/src/pages/home/views/affiliations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DataTable } from 'primereact/datatable';

import {
nameTemplate,
rorTemplate,
statusFilterTemplate,
statusTemplate,
} from '../../../utils/templates';
Expand Down Expand Up @@ -39,7 +40,7 @@ export default function AffiliationsView({
<Column selectionMode="multiple" />
<Column field="status" header="Status" body={statusTemplate} filter showFilterMenu={false} filterElement={statusFilterTemplate} />
<Column field="nameHtml" header="Affiliation" body={nameTemplate} filter filterField="name" filterMatchMode="contains" filterPlaceholder="Search by affiliation" />
<Column field="ror" header="RoR" filter />
<Column field="rorHtml" header="RoR" body={rorTemplate} filter filterField="ror" filterMatchMode="contains" filterPlaceholder="Search by RoR" />
<Column field="worksNumber" header="Number of works" sortable />
<Column field="matches" header="Number of matches" sortable />
</DataTable>
Expand Down
3 changes: 3 additions & 0 deletions client/src/utils/templates.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ const getAuthorsTooltipField = (rowData) => {

const nameTemplate = (rowData) => <span dangerouslySetInnerHTML={{ __html: rowData.nameHtml }} />;

const rorTemplate = (rowData) => <span dangerouslySetInnerHTML={{ __html: rowData.rorHtml }} />;

const getBadgeTypeByStatus = (status) => {
let type;
switch (status) {
Expand Down Expand Up @@ -146,6 +148,7 @@ export {
getAuthorsHtmlField,
getAuthorsTooltipField,
nameTemplate,
rorTemplate,
sourcesFilterTemplate,
statusFilterTemplate,
statusTemplate,
Expand Down

0 comments on commit 1175dc3

Please sign in to comment.