@vitessce/vit-s 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/dist/index.mjs +84801 -0
  2. package/{dist → dist-tsc}/index.js +2 -2
  3. package/package.json +7 -7
  4. package/src/CallbackPublisher.js +81 -0
  5. package/src/LoadingIndicator.js +34 -0
  6. package/src/TitleInfo.js +240 -0
  7. package/src/VitS.js +180 -0
  8. package/src/VitessceGrid.js +110 -0
  9. package/src/VitessceGrid.test.jsx +48 -0
  10. package/src/Warning.js +62 -0
  11. package/{dist → src}/classNames.js +0 -0
  12. package/src/component-registry.js +21 -0
  13. package/src/data/AbstractLoader.js +46 -0
  14. package/{dist → src}/data/AbstractTwoStepLoader.js +5 -4
  15. package/src/data/LoaderResult.js +8 -0
  16. package/{dist → src}/data/index.js +0 -0
  17. package/src/data/loader-registry.js +19 -0
  18. package/src/data-hook-utils.js +197 -0
  19. package/src/data-hooks.js +354 -0
  20. package/src/errors/AbstractLoaderError.js +14 -0
  21. package/src/errors/DataSourceFetchError.js +15 -0
  22. package/src/errors/DatasetNotFoundError.js +23 -0
  23. package/src/errors/LoaderNotFoundError.js +24 -0
  24. package/src/errors/LoaderValidationError.js +23 -0
  25. package/src/errors/OptionsValidationError.js +25 -0
  26. package/{dist → src}/errors/index.js +0 -0
  27. package/src/file-options-schemas-legacy.js +139 -0
  28. package/src/file-options-schemas-legacy.test.js +138 -0
  29. package/src/file-options-schemas.js +327 -0
  30. package/src/file-options-schemas.test.js +26 -0
  31. package/src/hooks.js +252 -0
  32. package/src/index.js +101 -0
  33. package/src/joint-file-types-legacy.js +298 -0
  34. package/src/joint-file-types-legacy.test.js +412 -0
  35. package/src/joint-file-types.js +171 -0
  36. package/src/joint-file-types.test.js +144 -0
  37. package/{dist/schemas.js → src/json-schemas.js} +6 -1
  38. package/{dist → src}/plugins.js +102 -70
  39. package/src/plugins.test.fixtures.js +78 -0
  40. package/src/plugins.test.js +42 -0
  41. package/src/schemas/config-0.1.0.schema.json +85 -0
  42. package/src/schemas/config-1.0.0.schema.json +733 -0
  43. package/src/schemas/config-1.0.1.schema.json +909 -0
  44. package/src/schemas/config-1.0.10.schema.json +969 -0
  45. package/src/schemas/config-1.0.11.schema.json +990 -0
  46. package/src/schemas/config-1.0.12.schema.json +997 -0
  47. package/src/schemas/config-1.0.13.schema.json +1013 -0
  48. package/src/schemas/config-1.0.14.schema.json +1048 -0
  49. package/src/schemas/config-1.0.15.schema.json +1048 -0
  50. package/src/schemas/config-1.0.16.schema.json +1069 -0
  51. package/src/schemas/config-1.0.16.schema.test.js +32 -0
  52. package/src/schemas/config-1.0.2.schema.json +911 -0
  53. package/src/schemas/config-1.0.3.schema.json +911 -0
  54. package/src/schemas/config-1.0.4.schema.json +949 -0
  55. package/src/schemas/config-1.0.5.schema.json +949 -0
  56. package/src/schemas/config-1.0.6.schema.json +950 -0
  57. package/src/schemas/config-1.0.7.schema.json +950 -0
  58. package/src/schemas/config-1.0.8.schema.json +966 -0
  59. package/src/schemas/config-1.0.9.schema.json +965 -0
  60. package/src/schemas/fixtures/cellSets.good.json +16 -0
  61. package/src/schemas/fixtures/config-1.0.1.bad.json +1 -0
  62. package/src/schemas/fixtures/config-1.0.1.bad.message.json +11 -0
  63. package/src/schemas/fixtures/config-1.0.1.good.json +37 -0
  64. package/src/schemas/fixtures/config-1.0.2.bad.json +1 -0
  65. package/src/schemas/fixtures/config-1.0.2.bad.message.json +11 -0
  66. package/src/schemas/fixtures/config-1.0.2.good.json +38 -0
  67. package/src/schemas/fixtures/config-1.0.3.bad.json +1 -0
  68. package/src/schemas/fixtures/config-1.0.3.bad.message.json +11 -0
  69. package/src/schemas/fixtures/config-1.0.3.good.json +38 -0
  70. package/src/schemas/fixtures/obsSets.bad.json +1 -0
  71. package/src/schemas/fixtures/obsSets.bad.message.json +11 -0
  72. package/src/schemas/fixtures/obsSets.good.json +16 -0
  73. package/src/schemas/fixtures/obsSetsTabular.bad.json +1 -0
  74. package/src/schemas/fixtures/obsSetsTabular.bad.message.json +11 -0
  75. package/src/schemas/fixtures/obsSetsTabular.good.json +26 -0
  76. package/src/schemas/fixtures/raster.bad.json +1 -0
  77. package/src/schemas/fixtures/raster.bad.message.json +11 -0
  78. package/src/schemas/fixtures/raster.good.json +39 -0
  79. package/src/schemas/obsSets.schema.js +195 -0
  80. package/src/schemas/obsSetsTabular.schema.js +39 -0
  81. package/src/schemas/raster.schema.js +121 -0
  82. package/src/schemas/schema-schema.sh +34 -0
  83. package/{dist → src}/schemas/schema.test-old.js +0 -1
  84. package/src/shared-mui/components.js +79 -0
  85. package/src/shared-mui/container.js +212 -0
  86. package/src/shared-mui/styles.js +110 -0
  87. package/src/shared-plot-options/CellColorEncodingOption.js +43 -0
  88. package/src/shared-plot-options/OptionSelect.js +19 -0
  89. package/src/shared-plot-options/OptionsContainer.js +26 -0
  90. package/{dist → src}/shared-plot-options/index.js +0 -0
  91. package/src/shared-plot-options/styles.js +49 -0
  92. package/src/state/hooks.js +633 -0
  93. package/src/view-config-upgraders.js +628 -0
  94. package/src/view-config-utils.js +315 -0
  95. package/src/view-config-utils.test.fixtures.js +893 -0
  96. package/src/view-config-utils.test.js +95 -0
  97. package/src/view-config-versions.js +68 -0
  98. package/src/vitessce-grid-layout/VitessceGridLayout.js +158 -0
  99. package/src/vitessce-grid-layout/VitessceGridLayout.test.jsx +56 -0
  100. package/{dist → src}/vitessce-grid-layout/index.js +0 -0
  101. package/src/vitessce-grid-layout/layout-utils.js +76 -0
  102. package/src/vitessce-grid-layout/layout-utils.test.js +167 -0
  103. package/src/vitessce-grid-utils.js +160 -0
  104. package/dist/CallbackPublisher.js +0 -68
  105. package/dist/LoadingIndicator.js +0 -27
  106. package/dist/TitleInfo.js +0 -151
  107. package/dist/VitS.js +0 -112
  108. package/dist/VitessceGrid.js +0 -59
  109. package/dist/VitessceGrid.test.js +0 -36
  110. package/dist/Warning.js +0 -45
  111. package/dist/component-registry.js +0 -16
  112. package/dist/data/AbstractLoader.js +0 -35
  113. package/dist/data/LoaderResult.js +0 -7
  114. package/dist/data/loader-registry.js +0 -15
  115. package/dist/data-hook-utils.js +0 -175
  116. package/dist/data-hooks.js +0 -241
  117. package/dist/errors/AbstractLoaderError.js +0 -13
  118. package/dist/errors/DataSourceFetchError.js +0 -13
  119. package/dist/errors/DatasetNotFoundError.js +0 -17
  120. package/dist/errors/LoaderNotFoundError.js +0 -17
  121. package/dist/errors/LoaderValidationError.js +0 -15
  122. package/dist/errors/OptionsValidationError.js +0 -15
  123. package/dist/file-options-schemas-legacy.js +0 -136
  124. package/dist/file-options-schemas-legacy.test.js +0 -126
  125. package/dist/file-options-schemas.js +0 -322
  126. package/dist/file-options-schemas.test.js +0 -23
  127. package/dist/hooks.js +0 -215
  128. package/dist/joint-file-types-legacy.js +0 -278
  129. package/dist/joint-file-types-legacy.test.js +0 -400
  130. package/dist/joint-file-types.js +0 -148
  131. package/dist/joint-file-types.test.js +0 -139
  132. package/dist/plugins.test.fixtures.js +0 -76
  133. package/dist/plugins.test.js +0 -30
  134. package/dist/schemas/config-0.1.0.schema.json +0 -84
  135. package/dist/schemas/config-1.0.0.schema.json +0 -733
  136. package/dist/schemas/config-1.0.1.schema.json +0 -909
  137. package/dist/schemas/config-1.0.10.schema.json +0 -969
  138. package/dist/schemas/config-1.0.11.schema.json +0 -990
  139. package/dist/schemas/config-1.0.12.schema.json +0 -997
  140. package/dist/schemas/config-1.0.13.schema.json +0 -1013
  141. package/dist/schemas/config-1.0.14.schema.json +0 -1048
  142. package/dist/schemas/config-1.0.15.schema.json +0 -1048
  143. package/dist/schemas/config-1.0.15.schema.test.js +0 -22
  144. package/dist/schemas/config-1.0.2.schema.json +0 -910
  145. package/dist/schemas/config-1.0.3.schema.json +0 -910
  146. package/dist/schemas/config-1.0.4.schema.json +0 -949
  147. package/dist/schemas/config-1.0.5.schema.json +0 -949
  148. package/dist/schemas/config-1.0.6.schema.json +0 -949
  149. package/dist/schemas/config-1.0.7.schema.json +0 -949
  150. package/dist/schemas/config-1.0.8.schema.json +0 -965
  151. package/dist/schemas/config-1.0.9.schema.json +0 -965
  152. package/dist/schemas/obsSets.schema.js +0 -195
  153. package/dist/schemas/obsSetsTabular.schema.js +0 -38
  154. package/dist/schemas/raster.schema.js +0 -120
  155. package/dist/shared-mui/components.js +0 -35
  156. package/dist/shared-mui/container.js +0 -211
  157. package/dist/shared-mui/styles.js +0 -73
  158. package/dist/shared-plot-options/CellColorEncodingOption.js +0 -18
  159. package/dist/shared-plot-options/OptionSelect.js +0 -12
  160. package/dist/shared-plot-options/OptionsContainer.js +0 -12
  161. package/dist/shared-plot-options/styles.js +0 -48
  162. package/dist/state/hooks.js +0 -549
  163. package/dist/view-config-upgraders.js +0 -525
  164. package/dist/view-config-utils.js +0 -286
  165. package/dist/view-config-utils.test.fixtures.js +0 -765
  166. package/dist/view-config-utils.test.js +0 -66
  167. package/dist/view-config-versions.js +0 -47
  168. package/dist/vitessce-grid-layout/VitessceGridLayout.js +0 -95
  169. package/dist/vitessce-grid-layout/VitessceGridLayout.test.js +0 -40
  170. package/dist/vitessce-grid-layout/layout-utils.js +0 -60
  171. package/dist/vitessce-grid-layout/layout-utils.test.js +0 -146
  172. package/dist/vitessce-grid-utils.js +0 -140
@@ -0,0 +1,48 @@
1
+ import '@testing-library/jest-dom';
2
+ import { cleanup, render, screen } from '@testing-library/react'
3
+ import { afterEach } from 'vitest'
4
+
5
+ import VitessceGrid from './VitessceGrid';
6
+ import {
7
+ ViewConfigProvider, createViewConfigStore,
8
+ AuxiliaryProvider, createAuxiliaryStore,
9
+ } from './state/hooks';
10
+
11
+ afterEach(() => {
12
+ cleanup()
13
+ });
14
+
15
+ describe('VitessceGrid.js', () => {
16
+ describe('<VitessceGrid />', () => {
17
+ it('renders', async () => {
18
+ const config = {
19
+ version: '1.0.0',
20
+ description: 'fake description',
21
+ datasets: [],
22
+ name: 'fake name',
23
+ layout: [
24
+ {
25
+ component: 'FakeComponent',
26
+ props: { description: 'fake prop description' },
27
+ uid: 'A',
28
+ x: 0,
29
+ y: 0,
30
+ },
31
+ ],
32
+ };
33
+
34
+ function FakeComponent() {
35
+ return <p>FakeComponent!</p>;
36
+ }
37
+ const getComponent = () => FakeComponent;
38
+ render(
39
+ <ViewConfigProvider createStore={createViewConfigStore}>
40
+ <AuxiliaryProvider createStore={createAuxiliaryStore}>
41
+ <VitessceGrid config={config} getComponent={getComponent} />
42
+ </AuxiliaryProvider>
43
+ </ViewConfigProvider>,
44
+ );
45
+ expect(await screen.findByText('FakeComponent!'));
46
+ });
47
+ });
48
+ });
package/src/Warning.js ADDED
@@ -0,0 +1,62 @@
1
+ import clsx from 'clsx';
2
+ import { makeStyles } from '@material-ui/core/styles';
3
+ import { VITESSCE_CONTAINER } from './classNames';
4
+
5
+ const useStyles = makeStyles(theme => ({
6
+ warningLayout: {
7
+ backgroundColor: theme.palette.gridLayoutBackground,
8
+ position: 'absolute',
9
+ width: '100%',
10
+ height: '100vh',
11
+ },
12
+ containerFluid: {
13
+ width: '100%',
14
+ padding: '15px',
15
+ marginRight: 'auto',
16
+ marginLeft: 'auto',
17
+ boxSizing: 'border-box',
18
+ display: 'flex',
19
+ },
20
+ row: {
21
+ flexGrow: '1',
22
+ },
23
+ card: {
24
+ border: `1px solid ${theme.palette.cardBorder}`,
25
+ flex: '1 1 auto',
26
+ minHeight: '1px',
27
+ padding: '12px',
28
+ marginTop: '8px',
29
+ marginBottom: '8px',
30
+ position: 'relative',
31
+ display: 'flex',
32
+ flexDirection: 'column',
33
+ minWidth: '0',
34
+ wordWrap: 'break-word',
35
+ backgroundClip: 'border-box',
36
+ borderRadius: '4px',
37
+ backgroundColor: theme.palette.primaryBackground,
38
+ color: theme.palette.primaryForeground,
39
+ },
40
+ }));
41
+
42
+ export function Warning(props) {
43
+ const {
44
+ title,
45
+ preformatted,
46
+ unformatted,
47
+ } = props;
48
+ const classes = useStyles();
49
+ return (
50
+ <div className={VITESSCE_CONTAINER}>
51
+ <div className={clsx(classes.warningLayout, classes.containerFluid)}>
52
+ <div className={classes.row}>
53
+ <div className={classes.card}>
54
+ <h1>{title}</h1>
55
+ {preformatted ? (<pre>{preformatted}</pre>) : null}
56
+ <p>{unformatted}</p>
57
+ </div>
58
+ </div>
59
+ </div>
60
+ </div>
61
+ );
62
+ }
File without changes
@@ -0,0 +1,21 @@
1
+ import { getPluginViewType, getPluginViewTypes } from './plugins';
2
+
3
+ // TODO(monorepo): this code can be simplified
4
+ const registry = {};
5
+
6
+ export function getComponent(name) {
7
+ let component = registry[name];
8
+ if (component === undefined) {
9
+ component = getPluginViewType(name);
10
+ if (component === undefined) {
11
+ throw new Error(
12
+ `Could not find definition for "${name}" in the core registry nor the plugin registry.`,
13
+ );
14
+ }
15
+ }
16
+ return component;
17
+ }
18
+
19
+ export function getViewTypes() {
20
+ return [...Object.keys(registry), ...getPluginViewTypes()];
21
+ }
@@ -0,0 +1,46 @@
1
+ import Ajv from 'ajv';
2
+ import { OptionsValidationError } from '../errors/index';
3
+ import { emptySchema } from '../file-options-schemas';
4
+
5
+ /**
6
+ * A loader ancestor class containing a default constructor
7
+ * and a stub for the required load() method.
8
+ */
9
+ export default class AbstractLoader {
10
+ constructor({
11
+ type, fileType,
12
+ url, requestInit,
13
+ options, coordinationValues,
14
+ }) {
15
+ this.fileType = fileType;
16
+ this.type = type;
17
+ this.url = url;
18
+ this.requestInit = requestInit;
19
+ this.options = options;
20
+ this.coordinationValues = coordinationValues;
21
+ this.optionsSchema = emptySchema;
22
+ }
23
+
24
+ validateOptions() {
25
+ const { optionsSchema, options } = this;
26
+ const validate = new Ajv().compile(optionsSchema);
27
+ const valid = validate(options || null);
28
+ if (!valid) {
29
+ return [false, validate.errors];
30
+ }
31
+ return [true, null];
32
+ }
33
+
34
+ load() {
35
+ const {
36
+ fileType, url, options,
37
+ } = this;
38
+ const [optionsAreValid, optionsFailureReason] = this.validateOptions();
39
+ if (!optionsAreValid) {
40
+ return Promise.reject(
41
+ new OptionsValidationError(fileType, url, options, optionsFailureReason),
42
+ );
43
+ }
44
+ return Promise.resolve(optionsAreValid);
45
+ }
46
+ }
@@ -1,7 +1,8 @@
1
1
  import AbstractLoader from './AbstractLoader';
2
+
2
3
  export default class AbstractTwoStepLoader extends AbstractLoader {
3
- constructor(dataSource, params) {
4
- super(params);
5
- this.dataSource = dataSource;
6
- }
4
+ constructor(dataSource, params) {
5
+ super(params);
6
+ this.dataSource = dataSource;
7
+ }
7
8
  }
@@ -0,0 +1,8 @@
1
+
2
+ export default class LoaderResult {
3
+ constructor(data, url, coordinationValues = null) {
4
+ this.data = data;
5
+ this.url = url;
6
+ this.coordinationValues = coordinationValues;
7
+ }
8
+ }
File without changes
@@ -0,0 +1,19 @@
1
+ import {
2
+ getLoaderClassesForPluginFileType,
3
+ } from '../plugins';
4
+
5
+ export const fileTypeToLoaderAndSource = {};
6
+
7
+ export function getSourceAndLoaderFromFileType(type) {
8
+ if (fileTypeToLoaderAndSource[type]) {
9
+ return fileTypeToLoaderAndSource[type];
10
+ }
11
+ const pluginFileType = getLoaderClassesForPluginFileType(type);
12
+ if (pluginFileType) {
13
+ return pluginFileType;
14
+ }
15
+ // Fallback to JSON.
16
+ // TODO(monorepo)
17
+ // return [JsonSource, JsonLoader];
18
+ return [null, null];
19
+ }
@@ -0,0 +1,197 @@
1
+ import { useState, useEffect } from 'react';
2
+ import equal from 'fast-deep-equal';
3
+ import { capitalize } from '@vitessce/utils';
4
+ import { STATUS } from '@vitessce/constants-internal';
5
+ import { useMatchingLoader, useMatchingLoaders, useSetWarning } from './state/hooks';
6
+ import {
7
+ AbstractLoaderError,
8
+ LoaderNotFoundError,
9
+ } from './errors/index';
10
+ import { getDefaultCoordinationValues } from './plugins';
11
+
12
+ /**
13
+ * Warn via publishing to the console
14
+ * and to the global warning store.
15
+ * @param {AbstractLoaderError} error An error instance.
16
+ */
17
+ export function warn(error, setWarning) {
18
+ setWarning(error.message);
19
+ console.warn(error.message);
20
+ console.error(error.stack);
21
+ if (error instanceof AbstractLoaderError) {
22
+ error.warnInConsole();
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Initialize values in the coordination space.
28
+ * @param {object} values Object where
29
+ * keys are coordination type names,
30
+ * values are initial coordination values.
31
+ * @param {object} setters Object where
32
+ * keys are coordination type names with the prefix 'set',
33
+ * values are coordination setter functions.
34
+ * @param {object} initialValues Object where
35
+ * keys are coordination type names and keys are values.
36
+ */
37
+ export function initCoordinationSpace(values, setters, initialValues) {
38
+ if (!values || !setters) {
39
+ return;
40
+ }
41
+ const defaultCoordinationValues = getDefaultCoordinationValues();
42
+ Object.entries(values).forEach(([coordinationType, value]) => {
43
+ const setterName = `set${capitalize(coordinationType)}`;
44
+ const setterFunc = setters[setterName];
45
+ const initialValue = initialValues && initialValues[coordinationType];
46
+ const shouldInit = equal(initialValue, defaultCoordinationValues[coordinationType]);
47
+ if (shouldInit && setterFunc) {
48
+ setterFunc(value);
49
+ }
50
+ });
51
+ }
52
+
53
+
54
+ /**
55
+ * Get data from a cells data type loader,
56
+ * updating "ready" and URL state appropriately.
57
+ * Throw warnings if the data is marked as required.
58
+ * Subscribe to loader updates.
59
+ * @param {object} loaders The object mapping
60
+ * datasets and data types to loader instances.
61
+ * @param {string} dataset The key for a dataset,
62
+ * used to identify which loader to use.
63
+ * @param {function} addUrl A function to call to update
64
+ * the URL list.
65
+ * @param {boolean} isRequired Should a warning be thrown if
66
+ * loading is unsuccessful?
67
+ * @param {object} coordinationSetters Object where
68
+ * keys are coordination type names with the prefix 'set',
69
+ * values are coordination setter functions.
70
+ * @param {object} initialCoordinationValues Object where
71
+ * keys are coordination type names with the prefix 'initialize',
72
+ * values are initialization preferences as boolean values.
73
+ * @returns {array} [cells, cellsCount] where
74
+ * cells is an object and cellsCount is the
75
+ * number of items in the cells object.
76
+ */
77
+ export function useDataType(
78
+ dataType, loaders, dataset, addUrl, isRequired,
79
+ coordinationSetters, initialCoordinationValues, matchOn,
80
+ ) {
81
+ const [data, setData] = useState({});
82
+ const [status, setStatus] = useState(STATUS.LOADING);
83
+
84
+ const setWarning = useSetWarning();
85
+ const loader = useMatchingLoader(loaders, dataset, dataType, matchOn);
86
+
87
+ useEffect(() => {
88
+ if (loader) {
89
+ setStatus(STATUS.LOADING);
90
+ loader.load().catch(e => warn(e, setWarning)).then((payload) => {
91
+ if (!payload) return;
92
+ const { data: payloadData, url, coordinationValues } = payload;
93
+ setData(payloadData);
94
+ if (Array.isArray(url)) {
95
+ url.forEach(([val, name]) => {
96
+ addUrl(val, name);
97
+ });
98
+ } else if (url) {
99
+ addUrl(url, dataType);
100
+ }
101
+ initCoordinationSpace(
102
+ coordinationValues,
103
+ coordinationSetters,
104
+ initialCoordinationValues,
105
+ );
106
+ setStatus(STATUS.SUCCESS);
107
+ });
108
+ } else {
109
+ setData({});
110
+ if (isRequired) {
111
+ warn(new LoaderNotFoundError(loaders, dataset, dataType, matchOn), setWarning);
112
+ setStatus(STATUS.ERROR);
113
+ } else {
114
+ setStatus(STATUS.SUCCESS);
115
+ }
116
+ }
117
+ // eslint-disable-next-line react-hooks/exhaustive-deps
118
+ }, [loader]);
119
+
120
+ return [data, status];
121
+ }
122
+
123
+ /**
124
+ * Get data from a cells data type loader,
125
+ * updating "ready" and URL state appropriately.
126
+ * Throw warnings if the data is marked as required.
127
+ * Subscribe to loader updates.
128
+ * @param {object} loaders The object mapping
129
+ * datasets and data types to loader instances.
130
+ * @param {string} dataset The key for a dataset,
131
+ * used to identify which loader to use.
132
+ * @param {function} addUrl A function to call to update
133
+ * the URL list.
134
+ * @param {boolean} isRequired Should a warning be thrown if
135
+ * loading is unsuccessful?
136
+ * @param {object} coordinationSetters Object where
137
+ * keys are coordination type names with the prefix 'set',
138
+ * values are coordination setter functions.
139
+ * @param {object} initialCoordinationValues Object where
140
+ * keys are coordination type names with the prefix 'initialize',
141
+ * values are initialization preferences as boolean values.
142
+ * @returns {array} [cells, cellsCount] where
143
+ * cells is an object and cellsCount is the
144
+ * number of items in the cells object.
145
+ */
146
+ export function useDataTypeMulti(
147
+ dataType, loaders, dataset, addUrl, isRequired,
148
+ coordinationSetters, initialCoordinationValues, matchOnObj,
149
+ ) {
150
+ const [data, setData] = useState({});
151
+ const [status, setStatus] = useState(STATUS.LOADING);
152
+
153
+ const setWarning = useSetWarning();
154
+ const matchingLoaders = useMatchingLoaders(loaders, dataset, dataType, matchOnObj);
155
+
156
+ useEffect(() => {
157
+ if (matchingLoaders) {
158
+ setStatus(STATUS.LOADING);
159
+ Object.entries(matchingLoaders).forEach(([scopeKey, loader]) => {
160
+ if (loader) {
161
+ loader.load().catch(e => warn(e, setWarning)).then((payload) => {
162
+ if (!payload) return;
163
+ const { data: payloadData, url, coordinationValues } = payload;
164
+ setData((prev) => {
165
+ // eslint-disable-next-line no-param-reassign
166
+ prev[scopeKey] = payloadData;
167
+ return prev;
168
+ });
169
+ addUrl(url, dataType);
170
+ initCoordinationSpace(
171
+ coordinationValues,
172
+ coordinationSetters,
173
+ initialCoordinationValues,
174
+ );
175
+ setStatus(STATUS.SUCCESS);
176
+ });
177
+ }
178
+ });
179
+ } else {
180
+ setData({});
181
+ if (isRequired) {
182
+ warn(new LoaderNotFoundError(loaders, dataset, dataType, matchOnObj), setWarning);
183
+ setStatus(STATUS.ERROR);
184
+ } else {
185
+ setStatus(STATUS.SUCCESS);
186
+ }
187
+ }
188
+ // eslint-disable-next-line react-hooks/exhaustive-deps
189
+ }, [matchingLoaders]);
190
+
191
+ return [data, status];
192
+ }
193
+
194
+ export function useHasLoader(loaders, dataset, dataType, matchOn) {
195
+ const loader = useMatchingLoader(loaders, dataset, dataType, matchOn);
196
+ return loader !== null;
197
+ }