Skip to content

Commit

Permalink
format {S#|P#} display (#80)
Browse files Browse the repository at this point in the history
to include a description of the trait value
  • Loading branch information
jamesdabbs authored Dec 9, 2023
1 parent 104dd9e commit ab6e45f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/viewer/cypress/e2e/typesetting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ it('renders internal links', () => {
)

cy.get('[data-testid=output]').contains(
'Discrete topology on a two-point set is $T_0$ as noted in Discrete topology on a two-point set | $T_0$',
'Discrete topology on a two-point set is $T_0$ as noted in Discrete topology on a two-point set is $T_0$',
)
})
6 changes: 3 additions & 3 deletions packages/viewer/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export function initialize({
}

const typeset = derived(
[store.properties, store.spaces, store.theorems],
([properties, spaces, theorems]) => {
[store.properties, store.spaces, store.theorems, store.traits],
([properties, spaces, theorems, traits]) => {
trace({ event: 'build_typesetter' })
return typesetter(properties, spaces, theorems)
return typesetter(properties, spaces, theorems, traits)
},
)

Expand Down
28 changes: 23 additions & 5 deletions packages/viewer/src/parser/internalLinks.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { atom, property, space, theorem } from '@/__test__'
import { Collection, Theorems } from '@/models'
import { atom, property, space, theorem, trait } from '@/__test__'
import { Collection, Theorems, Traits } from '@/models'

import { internal } from './internalLinks'

Expand All @@ -9,7 +9,10 @@ describe('with ambient data', () => {
property({ id: 1, name: 'One' }),
property({ id: 2, name: 'Two' }),
])
const spaces = Collection.byId([space({ id: 2, name: 'Two' })])
const spaces = Collection.byId([
space({ id: 1, name: 'One' }),
space({ id: 2, name: 'Two' }),
])
const theorems: Theorems = Theorems.build(
[
theorem({
Expand All @@ -20,8 +23,16 @@ describe('with ambient data', () => {
],
properties,
)
const traits = Traits.build(
[
trait({ space: 1, property: 1, value: true }),
trait({ space: 1, property: 2, value: false }),
],
spaces,
properties,
)

const link = internal(properties, spaces, theorems)
const link = internal(properties, spaces, theorems, traits)

describe('properties', () => {
it('can link to properties', () => {
Expand Down Expand Up @@ -58,9 +69,16 @@ describe('with ambient data', () => {

describe('traits', () => {
it('can link to traits', () => {
expect(link(['S', '000001|P000001'])).toEqual({
href: '/spaces/S000001/properties/P000001',
title: 'One is One',
})
})

it('negates the display', () => {
expect(link(['S', '000001|P000002'])).toEqual({
href: '/spaces/S000001/properties/P000002',
title: 'S000001 | Two',
title: 'One is not Two',
})
})
})
Expand Down
12 changes: 10 additions & 2 deletions packages/viewer/src/parser/internalLinks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { Property, Space, Theorem } from '@/models'
import type { Property, Space, Theorem, Traits } from '@/models'
import type { Finder } from './types'

export function internal(
properties: Finder<Property>,
spaces: Finder<Space>,
theorems: Finder<Theorem>,
traits: Traits,
) {
return function linker([kind, id]: ['S' | 'P' | 'T', string]) {
switch (kind) {
Expand All @@ -15,9 +16,16 @@ export function internal(
const { sid, pid } = match.groups
const space = spaces.find(Number(sid))
const property = properties.find(Number(pid))
const trait = space && property && traits.find(space, property)
const connector =
trait?.value === true
? 'is'
: trait?.value === false
? 'is not'
: '?'
return {
href: `/spaces/S${sid}/properties/P${pid}`,
title: `${space ? space.name : 'S' + sid} | ${
title: `${space ? space.name : 'S' + sid} ${connector} ${
property ? property.name : 'P' + pid
}`,
}
Expand Down
8 changes: 6 additions & 2 deletions packages/viewer/src/parser/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parser } from '@pi-base/core'

import type { Property, Space, Theorem } from '@/models'
import type { Property, Space, Theorem, Traits } from '@/models'
import type { Finder } from './types'
import { internal } from './internalLinks'
import { external } from './externalLinks'
Expand All @@ -9,8 +9,12 @@ export function renderer(
properties: Finder<Property>,
spaces: Finder<Space>,
theorems: Finder<Theorem>,
traits: Traits,
) {
const link = { internal: internal(properties, spaces, theorems), external }
const link = {
internal: internal(properties, spaces, theorems, traits),
external,
}

const full = parser({
link,
Expand Down
6 changes: 3 additions & 3 deletions packages/viewer/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export default defineConfig({
test: {
include: ['src/**/*.{test,spec}.{js,ts}'],
coverage: {
lines: 80.25,
branches: 87.16,
statements: 80.25,
lines: 80.3,
branches: 86.91,
statements: 80.3,
functions: 81,
skipFull: true,
thresholdAutoUpdate: true,
Expand Down

0 comments on commit ab6e45f

Please sign in to comment.