Skip to content

Commit

Permalink
- Modify Search Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
haideriqbal committed Jul 26, 2024
1 parent 29ded3d commit e89d7a1
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions frontend/src/pages/ontologies/OntologiesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ export default function OntologiesPage() {
() => [
{
accessorFn: (ontology) => ontology.getName(), //access nested data with dot notation
id: 'name',
header: 'Ontology',
size: 50,
Cell: ({row}) => {
Cell: ({row, renderedCellValue}) => {
const name = row.original.getName();
const logo = row.original.getLogoURL();
const ontoId = row.original.getOntologyId();
Expand All @@ -44,28 +45,30 @@ export default function OntologiesPage() {
}
/>
) : null}
{name ? <div>{name}</div> : null}
<div>{renderedCellValue}</div>
</div>
);
} else return ontoId;
},
},
{
accessorFn: (ontology) => ontology.getOntologyId().toUpperCase(),
id: 'id',
header: 'ID',
size: 20,
Cell: ({row}) => {
Cell: ({row, renderedCellValue}) => {
return (
<div style={{width: '50px'}}>
<div className="bg-link-default text-white rounded-md px-2 py-1 w-fit font-bold break-keep">
{row.original.getOntologyId().toUpperCase()}
{renderedCellValue}
</div>
</div>
);
},
},
{
accessorFn: (ontology) => ontology.getDescription(), //normal accessorKey
id: 'description',
header: 'Description',
size: 300,
enableGlobalFilter: false,
Expand Down Expand Up @@ -129,7 +132,27 @@ export default function OntologiesPage() {
const table = useMaterialReactTable({
columns,
data: ontologies,
initialState: { showGlobalFilter: true },
initialState: {
showGlobalFilter: true,
sorting: [
{
id: 'id', //sort by id by default on page load
desc: false,
},
],
},
filterFns: {
myCustomFilter: (row, id, filterValue) => {
if (!filterValue) return true;

const valueById = row.original.getOntologyId().toLowerCase();
const valueByName = row.original.getName().toLowerCase();

if (valueById.includes(filterValue.toLowerCase())) return true;
return valueByName.includes(filterValue.toLowerCase());
},
},
globalFilterFn: 'myCustomFilter',
enableFullScreenToggle: false,
enableDensityToggle: false,
enableHiding: false,
Expand Down

0 comments on commit e89d7a1

Please sign in to comment.