Skip to content

Commit 2f510a5

Browse files
authored
fix: filtering properties related to a space (#74)
by indexing the correct related trait type
1 parent ce242af commit 2f510a5

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

packages/viewer/cypress/e2e/space.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,14 @@ it('links to traits', () => {
1919

2020
cy.location('pathname').should('eq', '/spaces/S000004/properties/P000010')
2121
})
22+
23+
it('filters traits', () => {
24+
cy.visit('spaces/S000004/properties')
25+
deduce()
26+
27+
cy.get('[placeholder=Filter]').type('comp')
28+
29+
cy.get('.related-traits > tbody > tr')
30+
.first()
31+
.should('have.text', '16 Compact ')
32+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../cypress/fixtures/main.min.json

packages/viewer/src/components/Properties/Spaces.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
}
1111
</script>
1212

13-
<Related {related}>
14-
<span slot="title">Space</span>
15-
13+
<Related mode="spaces" {related}>
1614
<Link.Space slot="id" let:space {space}>{space.id}</Link.Space>
1715

1816
<Link.Space slot="name" let:space {space} />

packages/viewer/src/components/Spaces/Properties.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
}
1111
</script>
1212

13-
<Related {related}>
14-
<span slot="title">Property</span>
15-
13+
<Related mode="properties" {related}>
1614
<Link.Property slot="id" let:property {property}>{property.id}</Link.Property>
1715

1816
<Link.Property slot="name" let:property {property} />

packages/viewer/src/components/Traits/Related.svelte

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import { Value } from '../Traits'
55
import context from '@/context'
66
import type { Property, Space, Trait, Traits } from '@/models'
7+
import { capitalize } from '@/util'
78
89
export let related: (traits: Traits) => [Space, Property, Trait][]
10+
export let mode: 'spaces' | 'properties'
911
1012
const { traits } = context()
1113
@@ -17,7 +19,10 @@
1719
}
1820
1921
$: all = related($traits)
20-
$: index = new Fuse(all, { keys: ['0.name'] })
22+
// all has type [Space, Property, Trait][]
23+
// we need to index names in different positions depending on which kind we
24+
// are displaying
25+
$: index = new Fuse(all, { keys: [`${mode === 'spaces' ? 0 : 1}.name`] })
2126
$: searched = filter ? index.search(filter).map(r => r.item) : all
2227
$: filtered = searched.filter(
2328
([_space, _property, t]) => showDeduced || t.asserted,
@@ -46,11 +51,11 @@
4651
</div>
4752
</div>
4853

49-
<table class="table">
54+
<table class="table related-traits">
5055
<thead>
5156
<tr>
5257
<th>Id</th>
53-
<th><slot name="title" /></th>
58+
<th>{capitalize(mode)}</th>
5459
<th>Value</th>
5560
<th>Source</th>
5661
</tr>

0 commit comments

Comments
 (0)