Skip to content

Commit 454cf5e

Browse files
committed
Sort predicates alphabetically #4 (Add option to sort statements alphabetically)
1 parent 85590b6 commit 454cf5e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/lib/Body.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@ import { Alert, Box, Divider } from '@mui/material'
22
import React, { useMemo } from 'react'
33
import { useViewerContext } from './viewer-context'
44
import Predicate from './Predicate'
5+
import { formatIRI } from './format'
56

67
function Body (): JSX.Element {
7-
const { data, iri } = useViewerContext()
8+
const viewerCtx = useViewerContext()
9+
const { data, iri } = viewerCtx
810
if (iri === undefined) throw new Error('Body: context is missing information')
911

1012
const predicates = useMemo(() => data?.[iri], [data])
1113
const entries = useMemo(() => {
1214
if (predicates === undefined) return undefined
1315
return Object.entries(predicates)
16+
// Sort predicates alphabetically
17+
.sort(([a], [b]) => {
18+
const fmtA = formatIRI(viewerCtx, a)
19+
const fmtB = formatIRI(viewerCtx, b)
20+
return fmtA.localeCompare(fmtB)
21+
})
1422
}, [predicates])
1523

1624
if (entries === undefined) {

0 commit comments

Comments
 (0)