Skip to content

Commit db58ffd

Browse files
committed
Remove obsolete AttrValuesStore#getSingle()
1 parent 39c1aa2 commit db58ffd

File tree

7 files changed

+28
-37
lines changed

7 files changed

+28
-37
lines changed

packages/app/src/providers/DataProvider.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { isGroup } from '@h5web/shared/guards';
2-
import { type Entity } from '@h5web/shared/hdf5-models';
32
import { getNameFromPath } from '@h5web/shared/hdf5-utils';
43
import { createFetchStore } from '@h5web/shared/react-suspense-fetch';
54
import {
@@ -9,10 +8,8 @@ import {
98
useMemo,
109
} from 'react';
1110

12-
import { hasAttribute } from '../utils';
1311
import { type DataProviderApi } from './api';
1412
import {
15-
type AttrName,
1613
type AttrValuesStore,
1714
type EntitiesStore,
1815
type ValuesStore,
@@ -70,18 +67,10 @@ function DataProvider(props: PropsWithChildren<Props>) {
7067
}, [api]);
7168

7269
const attrValuesStore = useMemo(() => {
73-
const store = createFetchStore(
70+
return createFetchStore(
7471
api.getAttrValues.bind(api),
7572
(a, b) => a.path === b.path,
7673
);
77-
78-
return Object.assign(store, {
79-
getSingle: (entity: Entity, attrName: AttrName) => {
80-
return hasAttribute(entity, attrName)
81-
? attrValuesStore.get(entity)[attrName]
82-
: undefined;
83-
},
84-
});
8574
}, [api]);
8675

8776
return (

packages/app/src/providers/models.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ import { type NxAttribute } from '../vis-packs/nexus/models';
1515

1616
export type EntitiesStore = FetchStore<string, ProvidedEntity>;
1717
export type ValuesStore = FetchStore<ValuesStoreParams, unknown>;
18+
export type AttrValuesStore = FetchStore<Entity, AttributeValues>;
1819

1920
export interface ValuesStoreParams {
2021
dataset: Dataset<ScalarShape | ArrayShape>;
2122
selection?: string | undefined;
2223
}
2324

24-
export interface AttrValuesStore extends FetchStore<Entity, AttributeValues> {
25-
getSingle: (entity: Entity, attrName: AttrName) => unknown;
26-
}
27-
2825
export type ImageAttribute = 'CLASS' | 'IMAGE_SUBCLASS';
2926
export type AttrName = NxAttribute | ImageAttribute | '_FillValue';
3027

packages/app/src/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { assertValue } from '@h5web/shared/guards';
22
import {
3+
type ArrayShape,
34
type Attribute,
45
type Entity,
6+
type ScalarShape,
57
type Value,
68
} from '@h5web/shared/hdf5-models';
79

@@ -18,11 +20,9 @@ export function findAttribute(
1820
return entity.attributes.find((attr) => attr.name === attributeName);
1921
}
2022

21-
export function getAttributeValue<A extends Attribute>(
22-
entity: Entity,
23-
attribute: A,
24-
attrValuesStore: AttrValuesStore,
25-
): Value<A> {
23+
export function getAttributeValue<
24+
A extends Attribute<ScalarShape | ArrayShape>,
25+
>(entity: Entity, attribute: A, attrValuesStore: AttrValuesStore): Value<A> {
2626
const value = attrValuesStore.get(entity)[attribute.name];
2727
assertValue(value, attribute);
2828
return value;

packages/app/src/vis-packs/core/visualizations.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Entity } from '@h5web/shared/hdf5-models';
1+
import { type AttributeValues, type Entity } from '@h5web/shared/hdf5-models';
22
import {
33
arrayShape,
44
boolType,
@@ -20,14 +20,13 @@ import { type AttrValuesStore } from '../../providers/models';
2020
import { CORE_VIS } from './visualizations';
2121

2222
const mockStore = {
23-
getSingle: (entity: Entity, attributeName: string): unknown => {
24-
const attr = entity.attributes.find(({ name }) => name === attributeName);
25-
if (!attr) {
26-
return undefined;
27-
}
28-
29-
assertMockAttribute(attr);
30-
return attr.value;
23+
get: (entity: Entity): AttributeValues => {
24+
return Object.fromEntries(
25+
entity.attributes.map((attr) => {
26+
assertMockAttribute(attr);
27+
return [attr.name, attr.value];
28+
}),
29+
);
3130
},
3231
};
3332

packages/app/src/vis-packs/core/visualizations.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
hasPrintableCompoundType,
1010
hasPrintableType,
1111
hasScalarShape,
12+
hasStringType,
1213
} from '@h5web/shared/guards';
1314
import { type Dataset } from '@h5web/shared/hdf5-models';
1415
import {
@@ -148,9 +149,10 @@ export const CORE_VIS = {
148149
ConfigProvider: RgbConfigProvider,
149150
supportsDataset: (dataset, attrValuesStore) => {
150151
const classAttr = findAttribute(dataset, 'CLASS');
151-
const classVal = classAttr
152-
? getAttributeValue(dataset, classAttr, attrValuesStore)
153-
: undefined;
152+
const classVal =
153+
classAttr && hasScalarShape(classAttr) && hasStringType(classAttr)
154+
? getAttributeValue(dataset, classAttr, attrValuesStore)
155+
: undefined;
154156

155157
return (
156158
classVal === 'IMAGE' &&

packages/app/src/vis-packs/nexus/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
assertScalarShape,
99
assertStringType,
1010
hasArrayShape,
11+
hasNonNullShape,
1112
hasScalarShape,
1213
hasStringType,
1314
isAxisScaleType,
@@ -151,7 +152,7 @@ export function findAssociatedDatasets(
151152
attrValuesStore: AttrValuesStore,
152153
): (Dataset<ArrayShape> | undefined)[] {
153154
const attr = findAttribute(group, type);
154-
if (!attr || !hasStringType(attr)) {
155+
if (!attr || !hasNonNullShape(attr) || !hasStringType(attr)) {
155156
return [];
156157
}
157158

packages/app/src/vis-packs/nexus/visualizations.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
hasMinDims,
44
hasNumDims,
55
hasNumericType,
6+
hasScalarShape,
7+
hasStringType,
68
} from '@h5web/shared/guards';
79
import {
810
type ArrayShape,
@@ -93,9 +95,10 @@ export const NX_DATA_VIS = {
9395
ConfigProvider: RgbConfigProvider,
9496
supports: (_, signal, interpretation, attrValuesStore) => {
9597
const classAttr = findAttribute(signal, 'CLASS');
96-
const classVal = classAttr
97-
? getAttributeValue(signal, classAttr, attrValuesStore)
98-
: undefined;
98+
const classVal =
99+
classAttr && hasScalarShape(classAttr) && hasStringType(classAttr)
100+
? getAttributeValue(signal, classAttr, attrValuesStore)
101+
: undefined;
99102

100103
return (
101104
(interpretation === NxInterpretation.RGB || classVal === 'IMAGE') &&

0 commit comments

Comments
 (0)