@xyo-network/react-schema 7.5.8 → 7.5.12
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.
- package/dist/browser/contexts/Schema/Provider/Memory.d.ts.map +1 -1
- package/dist/browser/hooks/useGetSchema.d.ts +8 -6
- package/dist/browser/hooks/useGetSchema.d.ts.map +1 -1
- package/dist/browser/hooks/useSchemaDefinitions.d.ts +2 -2
- package/dist/browser/hooks/useSchemaDefinitions.d.ts.map +1 -1
- package/dist/browser/hooks/useSchemaList.d.ts +1 -1
- package/dist/browser/hooks/useSchemaList.d.ts.map +1 -1
- package/dist/browser/hooks/useSchemaStats.d.ts +1 -1
- package/dist/browser/hooks/useSchemaStats.d.ts.map +1 -1
- package/dist/browser/index.mjs +309 -298
- package/dist/browser/index.mjs.map +1 -1
- package/package.json +160 -57
- package/src/components/Property/SchemaProperty.stories.tsx +0 -41
- package/src/components/Property/SchemaProperty.tsx +0 -154
- package/src/components/Property/index.ts +0 -1
- package/src/components/SelectEx/SchemaSelectEx.tsx +0 -45
- package/src/components/SelectEx/index.ts +0 -1
- package/src/components/index.ts +0 -2
- package/src/contexts/Schema/Context.ts +0 -5
- package/src/contexts/Schema/Provider/Memory.tsx +0 -31
- package/src/contexts/Schema/Provider/Props.ts +0 -4
- package/src/contexts/Schema/Provider/Route.tsx +0 -73
- package/src/contexts/Schema/Provider/index.ts +0 -3
- package/src/contexts/Schema/State.ts +0 -13
- package/src/contexts/Schema/index.ts +0 -4
- package/src/contexts/Schema/use.ts +0 -8
- package/src/contexts/index.ts +0 -1
- package/src/hooks/index.ts +0 -4
- package/src/hooks/stories/TestSchemaHooks.stories.tsx +0 -102
- package/src/hooks/useGetSchema.stories.tsx +0 -65
- package/src/hooks/useGetSchema.tsx +0 -57
- package/src/hooks/useSchemaDefinitions.tsx +0 -26
- package/src/hooks/useSchemaList.tsx +0 -35
- package/src/hooks/useSchemaStats.tsx +0 -62
- package/src/index.ts +0 -3
package/dist/browser/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/components/Property/SchemaProperty.tsx
|
|
5
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
NewReleases as NewReleasesIcon,
|
|
4
|
+
OpenInNew as OpenInNewIcon,
|
|
5
|
+
Verified as VerifiedIcon
|
|
6
|
+
} from "@mui/icons-material";
|
|
6
7
|
import { IconButton } from "@mui/material";
|
|
7
8
|
import { useAsyncEffect } from "@xylabs/react-async-effect";
|
|
8
9
|
import { FlexGrowRow } from "@xylabs/react-flexbox";
|
|
@@ -10,115 +11,128 @@ import { LinkEx } from "@xylabs/react-link";
|
|
|
10
11
|
import { useEvent } from "@xyo-network/react-event";
|
|
11
12
|
import { Property, PropertyValue } from "@xyo-network/react-property";
|
|
12
13
|
import { SchemaCache } from "@xyo-network/schema-cache";
|
|
13
|
-
import
|
|
14
|
-
|
|
14
|
+
import { useState } from "react";
|
|
15
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
+
var useResolveSchema = (schema) => {
|
|
15
17
|
const [entry, setEntry] = useState();
|
|
16
|
-
useAsyncEffect(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
useAsyncEffect(
|
|
19
|
+
async (mounted) => {
|
|
20
|
+
if (schema) {
|
|
21
|
+
const entry2 = await SchemaCache.instance.get(schema);
|
|
22
|
+
if (mounted()) {
|
|
23
|
+
setEntry(entry2);
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
]);
|
|
26
|
+
},
|
|
27
|
+
[schema]
|
|
28
|
+
);
|
|
26
29
|
return entry;
|
|
27
|
-
}
|
|
28
|
-
var SchemaProperty =
|
|
30
|
+
};
|
|
31
|
+
var SchemaProperty = ({
|
|
32
|
+
showLinkNames = true,
|
|
33
|
+
showOpenNewWindowLink = true,
|
|
34
|
+
showStatusIcon = true,
|
|
35
|
+
titleProps,
|
|
36
|
+
value,
|
|
37
|
+
...props
|
|
38
|
+
}) => {
|
|
29
39
|
const resolvedSchema = useResolveSchema(value);
|
|
30
40
|
const [buttonRef, buttonDispatch] = useEvent();
|
|
31
41
|
const [divRef, divDispatch] = useEvent();
|
|
32
|
-
const onClick =
|
|
33
|
-
dispatch?.(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
fontSize: "inherit"
|
|
56
|
-
})) : resolvedSchema === void 0 ? /* @__PURE__ */ React.createElement(IconButton, {
|
|
57
|
-
ref: buttonRef,
|
|
58
|
-
size: "small",
|
|
59
|
-
onClick: /* @__PURE__ */ __name(() => {
|
|
60
|
-
if (!buttonRef.current) {
|
|
61
|
-
console.warn("buttonRef.current is null");
|
|
62
|
-
}
|
|
63
|
-
onClick(buttonDispatch);
|
|
64
|
-
}, "onClick")
|
|
65
|
-
}, /* @__PURE__ */ React.createElement(NewReleasesIcon, {
|
|
66
|
-
color: "disabled",
|
|
67
|
-
fontSize: "inherit"
|
|
68
|
-
})) : /* @__PURE__ */ React.createElement(IconButton, {
|
|
69
|
-
rel: "noopener noreferrer",
|
|
70
|
-
size: "small",
|
|
71
|
-
target: "_blank",
|
|
72
|
-
href: resolvedSchema?.huri?.href ?? ""
|
|
73
|
-
}, /* @__PURE__ */ React.createElement(VerifiedIcon, {
|
|
74
|
-
color: "success",
|
|
75
|
-
fontSize: "inherit"
|
|
76
|
-
})) : null, value ? /* @__PURE__ */ React.createElement(FlexGrowRow, {
|
|
77
|
-
ref: divRef,
|
|
78
|
-
justifyContent: "space-between"
|
|
79
|
-
}, showLinkNames ? /* @__PURE__ */ React.createElement(LinkEx, {
|
|
80
|
-
display: "block",
|
|
81
|
-
width: "100%",
|
|
82
|
-
sx: {
|
|
83
|
-
cursor: "pointer"
|
|
84
|
-
}
|
|
85
|
-
}, /* @__PURE__ */ React.createElement(PropertyValue, {
|
|
86
|
-
value,
|
|
87
|
-
title: "view schema",
|
|
88
|
-
onClick: /* @__PURE__ */ __name(() => {
|
|
89
|
-
if (!divRef.current) {
|
|
90
|
-
console.warn("divRef.current is null");
|
|
91
|
-
}
|
|
92
|
-
onClick(divDispatch);
|
|
93
|
-
}, "onClick")
|
|
94
|
-
})) : /* @__PURE__ */ React.createElement(PropertyValue, {
|
|
95
|
-
value,
|
|
96
|
-
title: "view schema",
|
|
97
|
-
onClick: /* @__PURE__ */ __name(() => {
|
|
98
|
-
if (!divRef.current) {
|
|
99
|
-
console.warn("divRef.current is null");
|
|
42
|
+
const onClick = (dispatch, openNewWindow = false) => {
|
|
43
|
+
dispatch?.(
|
|
44
|
+
"schema",
|
|
45
|
+
"click",
|
|
46
|
+
JSON.stringify({
|
|
47
|
+
openNewWindow,
|
|
48
|
+
schema: value
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
return /* @__PURE__ */ jsxs(Property, { title: "Schema", value, tip: "Schema sent with the payload", titleProps, ...props, children: [
|
|
53
|
+
value && showStatusIcon ? resolvedSchema === null ? /* @__PURE__ */ jsx(
|
|
54
|
+
IconButton,
|
|
55
|
+
{
|
|
56
|
+
ref: buttonRef,
|
|
57
|
+
size: "small",
|
|
58
|
+
onClick: () => {
|
|
59
|
+
if (!buttonRef.current) {
|
|
60
|
+
console.warn("buttonRef.current is null");
|
|
61
|
+
}
|
|
62
|
+
onClick(buttonDispatch);
|
|
63
|
+
},
|
|
64
|
+
children: /* @__PURE__ */ jsx(NewReleasesIcon, { color: "warning", fontSize: "inherit" })
|
|
100
65
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
66
|
+
) : resolvedSchema === void 0 ? /* @__PURE__ */ jsx(
|
|
67
|
+
IconButton,
|
|
68
|
+
{
|
|
69
|
+
ref: buttonRef,
|
|
70
|
+
size: "small",
|
|
71
|
+
onClick: () => {
|
|
72
|
+
if (!buttonRef.current) {
|
|
73
|
+
console.warn("buttonRef.current is null");
|
|
74
|
+
}
|
|
75
|
+
onClick(buttonDispatch);
|
|
76
|
+
},
|
|
77
|
+
children: /* @__PURE__ */ jsx(NewReleasesIcon, { color: "disabled", fontSize: "inherit" })
|
|
109
78
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
79
|
+
) : /* @__PURE__ */ jsx(IconButton, { rel: "noopener noreferrer", size: "small", target: "_blank", href: resolvedSchema?.huri?.href ?? "", children: /* @__PURE__ */ jsx(VerifiedIcon, { color: "success", fontSize: "inherit" }) }) : null,
|
|
80
|
+
value ? /* @__PURE__ */ jsxs(FlexGrowRow, { ref: divRef, justifyContent: "space-between", children: [
|
|
81
|
+
showLinkNames ? /* @__PURE__ */ jsx(
|
|
82
|
+
LinkEx,
|
|
83
|
+
{
|
|
84
|
+
display: "block",
|
|
85
|
+
width: "100%",
|
|
86
|
+
sx: { cursor: "pointer" },
|
|
87
|
+
children: /* @__PURE__ */ jsx(
|
|
88
|
+
PropertyValue,
|
|
89
|
+
{
|
|
90
|
+
value,
|
|
91
|
+
title: "view schema",
|
|
92
|
+
onClick: () => {
|
|
93
|
+
if (!divRef.current) {
|
|
94
|
+
console.warn("divRef.current is null");
|
|
95
|
+
}
|
|
96
|
+
onClick(divDispatch);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
) : /* @__PURE__ */ jsx(
|
|
102
|
+
PropertyValue,
|
|
103
|
+
{
|
|
104
|
+
value,
|
|
105
|
+
title: "view schema",
|
|
106
|
+
onClick: () => {
|
|
107
|
+
if (!divRef.current) {
|
|
108
|
+
console.warn("divRef.current is null");
|
|
109
|
+
}
|
|
110
|
+
onClick(divDispatch);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
),
|
|
114
|
+
showOpenNewWindowLink ? /* @__PURE__ */ jsx(
|
|
115
|
+
IconButton,
|
|
116
|
+
{
|
|
117
|
+
ref: buttonRef,
|
|
118
|
+
size: "small",
|
|
119
|
+
onClick: () => {
|
|
120
|
+
if (!buttonRef.current) {
|
|
121
|
+
console.warn("buttonRef.current is null");
|
|
122
|
+
}
|
|
123
|
+
onClick(buttonDispatch, true);
|
|
124
|
+
},
|
|
125
|
+
children: /* @__PURE__ */ jsx(OpenInNewIcon, { fontSize: "inherit" })
|
|
126
|
+
}
|
|
127
|
+
) : null
|
|
128
|
+
] }) : null
|
|
129
|
+
] });
|
|
130
|
+
};
|
|
116
131
|
SchemaProperty.displayName = "SchemaProperty";
|
|
117
132
|
|
|
118
133
|
// src/components/SelectEx/SchemaSelectEx.tsx
|
|
119
134
|
import { MenuItem, Typography } from "@mui/material";
|
|
120
135
|
import { SelectEx } from "@xylabs/react-select";
|
|
121
|
-
import React4 from "react";
|
|
122
136
|
|
|
123
137
|
// src/contexts/Schema/Context.ts
|
|
124
138
|
import { createContextEx } from "@xylabs/react-shared";
|
|
@@ -126,7 +140,11 @@ var SchemaContext = createContextEx();
|
|
|
126
140
|
|
|
127
141
|
// src/contexts/Schema/Provider/Memory.tsx
|
|
128
142
|
import { exists } from "@xylabs/sdk-js";
|
|
129
|
-
import
|
|
143
|
+
import {
|
|
144
|
+
useEffect,
|
|
145
|
+
useMemo as useMemo2,
|
|
146
|
+
useState as useState5
|
|
147
|
+
} from "react";
|
|
130
148
|
|
|
131
149
|
// src/hooks/useGetSchema.tsx
|
|
132
150
|
import { useAsyncEffect as useAsyncEffect2 } from "@xylabs/react-async-effect";
|
|
@@ -134,223 +152,217 @@ import { PayloadBuilder } from "@xyo-network/payload-builder";
|
|
|
134
152
|
import { ModuleErrorSchema } from "@xyo-network/payload-model";
|
|
135
153
|
import { SchemaCache as SchemaCache2 } from "@xyo-network/schema-cache";
|
|
136
154
|
import { useState as useState2 } from "react";
|
|
137
|
-
var useGetSchemaPayload =
|
|
155
|
+
var useGetSchemaPayload = (schema) => {
|
|
138
156
|
const [notFound, setNotFound] = useState2(false);
|
|
139
157
|
const [xyoError, setXyoError] = useState2();
|
|
140
158
|
const [schemaCacheEntry, setSchemaCacheEntry] = useState2();
|
|
141
159
|
const [schemaLocal, setSchemaLocal] = useState2();
|
|
142
|
-
useAsyncEffect2(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
useAsyncEffect2(
|
|
161
|
+
async (mounted) => {
|
|
162
|
+
const firstRequest = !notFound && !schemaCacheEntry && !xyoError;
|
|
163
|
+
const schemaChanged = schema !== schemaLocal;
|
|
164
|
+
if (schema && firstRequest || schema && schemaChanged) {
|
|
165
|
+
try {
|
|
166
|
+
const schemaCacheEntry2 = await SchemaCache2.instance.get(schema);
|
|
167
|
+
if (mounted()) {
|
|
168
|
+
setSchemaCacheEntry(schemaCacheEntry2);
|
|
169
|
+
setNotFound(schemaCacheEntry2 === null || schemaCacheEntry2 === void 0);
|
|
170
|
+
}
|
|
171
|
+
} catch (e) {
|
|
172
|
+
const error = e;
|
|
173
|
+
console.error(e);
|
|
174
|
+
if (mounted()) {
|
|
175
|
+
setXyoError({
|
|
176
|
+
message: error.message,
|
|
177
|
+
schema: ModuleErrorSchema,
|
|
178
|
+
$sources: []
|
|
179
|
+
});
|
|
180
|
+
}
|
|
161
181
|
}
|
|
162
182
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
notFound,
|
|
170
|
-
schema,
|
|
171
|
-
schemaLocal,
|
|
172
|
-
schemaCacheEntry
|
|
173
|
-
]);
|
|
183
|
+
if (schemaChanged) {
|
|
184
|
+
setSchemaLocal(schema);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
[xyoError, notFound, schema, schemaLocal, schemaCacheEntry]
|
|
188
|
+
);
|
|
174
189
|
return {
|
|
175
190
|
notFound,
|
|
176
191
|
schemaHuri: schemaCacheEntry?.huri,
|
|
177
192
|
schemaPayload: schemaCacheEntry ? new PayloadBuilder(schemaCacheEntry?.payload).fields(schemaCacheEntry.payload).build() : schemaCacheEntry,
|
|
178
193
|
xyoError
|
|
179
194
|
};
|
|
180
|
-
}
|
|
195
|
+
};
|
|
181
196
|
|
|
182
197
|
// src/hooks/useSchemaDefinitions.tsx
|
|
183
198
|
import { useAsyncEffect as useAsyncEffect3 } from "@xylabs/react-async-effect";
|
|
184
199
|
import { SchemaCache as SchemaCache3 } from "@xyo-network/schema-cache";
|
|
185
200
|
import { useState as useState3 } from "react";
|
|
186
|
-
var useSchemaDefinitions =
|
|
201
|
+
var useSchemaDefinitions = (schemaList) => {
|
|
187
202
|
const [schemaPayloads, setSchemaPayloads] = useState3();
|
|
188
|
-
useAsyncEffect3(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
203
|
+
useAsyncEffect3(
|
|
204
|
+
async (mounted) => {
|
|
205
|
+
if (schemaList) {
|
|
206
|
+
const promiseResults = await Promise.allSettled(schemaList?.map(({ name }) => SchemaCache3.instance.get(name)));
|
|
207
|
+
if (mounted()) {
|
|
208
|
+
setSchemaPayloads(
|
|
209
|
+
promiseResults.map((result) => result.status === "fulfilled" ? result.value?.payload : void 0).filter((item) => item !== void 0 && item !== null)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
193
212
|
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
]);
|
|
213
|
+
},
|
|
214
|
+
[schemaList]
|
|
215
|
+
);
|
|
198
216
|
return schemaPayloads;
|
|
199
|
-
}
|
|
217
|
+
};
|
|
200
218
|
|
|
201
219
|
// src/hooks/useSchemaList.tsx
|
|
202
220
|
import { usePromise } from "@xylabs/react-promise";
|
|
203
|
-
import { SchemaListQuerySchema } from "@xyo-network/diviner-schema-list
|
|
221
|
+
import { SchemaListQuerySchema } from "@xyo-network/diviner-schema-list";
|
|
204
222
|
import { useWeakDivinerFromNode } from "@xyo-network/react-diviner";
|
|
205
223
|
import { useMemo } from "react";
|
|
206
|
-
var useSchemaList =
|
|
224
|
+
var useSchemaList = (address, nameOrAddress = "SchemaListDiviner") => {
|
|
207
225
|
const [diviner, divinerError] = useWeakDivinerFromNode(nameOrAddress);
|
|
208
|
-
const query = useMemo(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
query
|
|
226
|
-
|
|
227
|
-
return [
|
|
228
|
-
|
|
229
|
-
error
|
|
230
|
-
];
|
|
231
|
-
}, "useSchemaList");
|
|
226
|
+
const query = useMemo(
|
|
227
|
+
() => address ? [
|
|
228
|
+
{
|
|
229
|
+
address,
|
|
230
|
+
schema: SchemaListQuerySchema
|
|
231
|
+
}
|
|
232
|
+
] : void 0,
|
|
233
|
+
[address]
|
|
234
|
+
);
|
|
235
|
+
const [schemaList, error] = usePromise(
|
|
236
|
+
async () => {
|
|
237
|
+
const divinerInstance = diviner?.deref();
|
|
238
|
+
if (divinerInstance) {
|
|
239
|
+
const response = await divinerInstance.divine(query);
|
|
240
|
+
return response.at(0);
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
[diviner, divinerError, query]
|
|
244
|
+
);
|
|
245
|
+
return [schemaList, error];
|
|
246
|
+
};
|
|
232
247
|
|
|
233
248
|
// src/hooks/useSchemaStats.tsx
|
|
234
249
|
import { useAsyncEffect as useAsyncEffect4 } from "@xylabs/react-async-effect";
|
|
235
250
|
import { isDefined } from "@xylabs/sdk-js";
|
|
236
|
-
import {
|
|
251
|
+
import {
|
|
252
|
+
SchemaStatsDivinerSchema,
|
|
253
|
+
SchemaStatsQuerySchema
|
|
254
|
+
} from "@xyo-network/diviner-schema-stats";
|
|
237
255
|
import { TYPES } from "@xyo-network/node-core-types";
|
|
238
256
|
import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
239
257
|
import { useWeakDivinerFromNode as useWeakDivinerFromNode2 } from "@xyo-network/react-diviner";
|
|
240
258
|
import { useState as useState4 } from "react";
|
|
241
|
-
var useSchemaStats =
|
|
259
|
+
var useSchemaStats = (statsAddress, nameOrAddress = TYPES.SchemaStatsDiviner) => {
|
|
242
260
|
const [refresh, setRefresh] = useState4(1);
|
|
243
261
|
const [diviner, divinerError] = useWeakDivinerFromNode2(nameOrAddress);
|
|
244
262
|
const [error, setError] = useState4();
|
|
245
|
-
const refreshHistory =
|
|
263
|
+
const refreshHistory = () => setRefresh((previous) => previous + 1);
|
|
246
264
|
const [schemaList, setSchemaList] = useState4();
|
|
247
|
-
useAsyncEffect4(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
if (
|
|
252
|
-
setError(divinerError);
|
|
253
|
-
setSchemaList(void 0);
|
|
254
|
-
}
|
|
255
|
-
} else {
|
|
256
|
-
try {
|
|
257
|
-
const query = {
|
|
258
|
-
address: statsAddress,
|
|
259
|
-
schema: SchemaStatsQuerySchema
|
|
260
|
-
};
|
|
261
|
-
const schemas = (await instance.divine([
|
|
262
|
-
query
|
|
263
|
-
])).filter(isPayloadOfSchemaType(SchemaStatsDivinerSchema));
|
|
265
|
+
useAsyncEffect4(
|
|
266
|
+
async (mounted) => {
|
|
267
|
+
const instance = diviner?.deref();
|
|
268
|
+
if (isDefined(instance) && isDefined(statsAddress)) {
|
|
269
|
+
if (divinerError) {
|
|
264
270
|
if (mounted()) {
|
|
265
|
-
|
|
266
|
-
|
|
271
|
+
setError(divinerError);
|
|
272
|
+
setSchemaList(void 0);
|
|
273
|
+
}
|
|
274
|
+
} else {
|
|
275
|
+
try {
|
|
276
|
+
const query = {
|
|
277
|
+
address: statsAddress,
|
|
278
|
+
schema: SchemaStatsQuerySchema
|
|
279
|
+
};
|
|
280
|
+
const schemas = (await instance.divine([query])).filter(isPayloadOfSchemaType(SchemaStatsDivinerSchema));
|
|
281
|
+
if (mounted()) {
|
|
282
|
+
setSchemaList(schemas);
|
|
283
|
+
setError(void 0);
|
|
284
|
+
}
|
|
285
|
+
} catch (ex) {
|
|
286
|
+
setError(ex);
|
|
287
|
+
setSchemaList(void 0);
|
|
267
288
|
}
|
|
268
|
-
} catch (ex) {
|
|
269
|
-
setError(ex);
|
|
270
|
-
setSchemaList(void 0);
|
|
271
289
|
}
|
|
272
290
|
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
statsAddress
|
|
279
|
-
]);
|
|
280
|
-
return [
|
|
281
|
-
schemaList,
|
|
282
|
-
error,
|
|
283
|
-
refreshHistory
|
|
284
|
-
];
|
|
285
|
-
}, "useSchemaStats");
|
|
291
|
+
},
|
|
292
|
+
[diviner, refresh, divinerError, statsAddress]
|
|
293
|
+
);
|
|
294
|
+
return [schemaList, error, refreshHistory];
|
|
295
|
+
};
|
|
286
296
|
|
|
287
297
|
// src/contexts/Schema/Provider/Memory.tsx
|
|
288
|
-
|
|
298
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
299
|
+
var SchemaMemoryProvider = ({
|
|
300
|
+
defaultSchema,
|
|
301
|
+
knownSchemaList,
|
|
302
|
+
...props
|
|
303
|
+
}) => {
|
|
289
304
|
const [schema, setSchema] = useState5(defaultSchema);
|
|
290
305
|
const [schemaList, setSchemaList] = useState5(knownSchemaList);
|
|
291
306
|
const [fetchedSchemaStats] = useSchemaStats();
|
|
292
307
|
useEffect(() => {
|
|
293
308
|
if (fetchedSchemaStats) {
|
|
294
|
-
const
|
|
295
|
-
setSchemaList(
|
|
309
|
+
const newSchemaList = fetchedSchemaStats.map(({ name }) => name).filter(exists);
|
|
310
|
+
setSchemaList(newSchemaList);
|
|
296
311
|
}
|
|
297
|
-
}, [
|
|
298
|
-
fetchedSchemaStats
|
|
299
|
-
]);
|
|
312
|
+
}, [fetchedSchemaStats]);
|
|
300
313
|
const value = useMemo2(() => ({
|
|
301
314
|
provided: true,
|
|
302
315
|
schema,
|
|
303
316
|
schemaList: knownSchemaList ?? schemaList,
|
|
304
317
|
setSchema,
|
|
305
318
|
setSchemaList
|
|
306
|
-
}), [
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
knownSchemaList
|
|
310
|
-
]);
|
|
311
|
-
return /* @__PURE__ */ React2.createElement(SchemaContext, {
|
|
312
|
-
value,
|
|
313
|
-
...props
|
|
314
|
-
});
|
|
315
|
-
}, "SchemaMemoryProvider");
|
|
319
|
+
}), [schema, schemaList, knownSchemaList]);
|
|
320
|
+
return /* @__PURE__ */ jsx2(SchemaContext, { value, ...props });
|
|
321
|
+
};
|
|
316
322
|
|
|
317
323
|
// src/contexts/Schema/Provider/Route.tsx
|
|
318
|
-
import
|
|
324
|
+
import {
|
|
325
|
+
useCallback,
|
|
326
|
+
useEffect as useEffect2,
|
|
327
|
+
useMemo as useMemo3
|
|
328
|
+
} from "react";
|
|
319
329
|
import { useSearchParams } from "react-router-dom";
|
|
320
330
|
|
|
321
331
|
// src/contexts/Schema/use.ts
|
|
322
332
|
import { useContextEx } from "@xylabs/react-shared";
|
|
323
|
-
var useSchema =
|
|
333
|
+
var useSchema = (required = false) => {
|
|
324
334
|
return useContextEx(SchemaContext, "Schema", required);
|
|
325
|
-
}
|
|
335
|
+
};
|
|
326
336
|
|
|
327
337
|
// src/contexts/Schema/Provider/Route.tsx
|
|
328
|
-
|
|
329
|
-
|
|
338
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
339
|
+
var SchemaRouteProviderInner = ({ children }) => {
|
|
340
|
+
const {
|
|
341
|
+
schema,
|
|
342
|
+
setSchema,
|
|
343
|
+
schemaList
|
|
344
|
+
} = useSchema();
|
|
330
345
|
const [params, setParams] = useSearchParams();
|
|
331
346
|
const routeSchema = params.get("schema");
|
|
332
|
-
const setSchemaParam = useCallback(
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
replace: true
|
|
337
|
-
|
|
347
|
+
const setSchemaParam = useCallback(
|
|
348
|
+
(schema2) => {
|
|
349
|
+
if (schema2) {
|
|
350
|
+
params.set("schema", schema2);
|
|
351
|
+
setParams(params, { replace: true });
|
|
352
|
+
setSchema?.(schema2);
|
|
353
|
+
} else {
|
|
354
|
+
params.delete("network");
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
[params, setParams, setSchema]
|
|
358
|
+
);
|
|
359
|
+
const setSchemaLocal = useCallback(
|
|
360
|
+
(schema2) => {
|
|
361
|
+
setSchemaParam(schema2);
|
|
338
362
|
setSchema?.(schema2);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}, [
|
|
343
|
-
params,
|
|
344
|
-
setParams,
|
|
345
|
-
setSchema
|
|
346
|
-
]);
|
|
347
|
-
const setSchemaLocal = useCallback((schema2) => {
|
|
348
|
-
setSchemaParam(schema2);
|
|
349
|
-
setSchema?.(schema2);
|
|
350
|
-
}, [
|
|
351
|
-
setSchemaParam,
|
|
352
|
-
setSchema
|
|
353
|
-
]);
|
|
363
|
+
},
|
|
364
|
+
[setSchemaParam, setSchema]
|
|
365
|
+
);
|
|
354
366
|
useEffect2(() => {
|
|
355
367
|
if (routeSchema !== schema) {
|
|
356
368
|
if (routeSchema === void 0 && schema !== void 0) {
|
|
@@ -359,61 +371,60 @@ var SchemaRouteProviderInner = /* @__PURE__ */ __name(({ children }) => {
|
|
|
359
371
|
setSchema?.(routeSchema);
|
|
360
372
|
}
|
|
361
373
|
}
|
|
362
|
-
}, [
|
|
363
|
-
routeSchema,
|
|
364
|
-
schema,
|
|
365
|
-
setSchemaParam,
|
|
366
|
-
setSchema,
|
|
367
|
-
setSchemaLocal
|
|
368
|
-
]);
|
|
374
|
+
}, [routeSchema, schema, setSchemaParam, setSchema, setSchemaLocal]);
|
|
369
375
|
const value = useMemo3(() => ({
|
|
370
376
|
provided: true,
|
|
371
377
|
schema,
|
|
372
378
|
schemaList,
|
|
373
379
|
setSchema: setSchemaLocal
|
|
374
|
-
}), [
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
return /* @__PURE__ */ React3.createElement(SchemaMemoryProvider, {
|
|
385
|
-
knownSchemaList,
|
|
386
|
-
defaultSchema
|
|
387
|
-
}, /* @__PURE__ */ React3.createElement(SchemaRouteProviderInner, props));
|
|
388
|
-
}, "SchemaRouteProvider");
|
|
380
|
+
}), [schema, schemaList, setSchemaLocal]);
|
|
381
|
+
return /* @__PURE__ */ jsx3(SchemaContext, { value, children });
|
|
382
|
+
};
|
|
383
|
+
var SchemaRouteProvider = ({
|
|
384
|
+
knownSchemaList,
|
|
385
|
+
defaultSchema,
|
|
386
|
+
...props
|
|
387
|
+
}) => {
|
|
388
|
+
return /* @__PURE__ */ jsx3(SchemaMemoryProvider, { knownSchemaList, defaultSchema, children: /* @__PURE__ */ jsx3(SchemaRouteProviderInner, { ...props }) });
|
|
389
|
+
};
|
|
389
390
|
|
|
390
391
|
// src/components/SelectEx/SchemaSelectEx.tsx
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
},
|
|
392
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
393
|
+
var SchemaSelectEx = ({
|
|
394
|
+
onChange,
|
|
395
|
+
variant = "outlined",
|
|
396
|
+
...props
|
|
397
|
+
}) => {
|
|
398
|
+
const {
|
|
399
|
+
schema,
|
|
400
|
+
setSchema,
|
|
401
|
+
schemaList
|
|
402
|
+
} = useSchema(false);
|
|
403
|
+
return /* @__PURE__ */ jsxs2(
|
|
404
|
+
SelectEx,
|
|
405
|
+
{
|
|
406
|
+
variant,
|
|
407
|
+
size: "small",
|
|
408
|
+
value: schema ?? "none",
|
|
409
|
+
onChange: (event, child) => {
|
|
410
|
+
if (event.target.value !== schema) {
|
|
411
|
+
onChange?.(event, child);
|
|
412
|
+
setSchema?.(event.target.value);
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
renderValue: (value) => {
|
|
416
|
+
return /* @__PURE__ */ jsx4(Typography, { children: value === "none" ? "- None -" : value });
|
|
417
|
+
},
|
|
418
|
+
...props,
|
|
419
|
+
children: [
|
|
420
|
+
schemaList?.map((schema2) => {
|
|
421
|
+
return /* @__PURE__ */ jsx4(MenuItem, { value: schema2, children: schema2 }, schemaList.indexOf(schema2));
|
|
422
|
+
}),
|
|
423
|
+
/* @__PURE__ */ jsx4(MenuItem, { value: "none", children: "- None -" }, "none")
|
|
424
|
+
]
|
|
425
|
+
}
|
|
426
|
+
);
|
|
427
|
+
};
|
|
417
428
|
export {
|
|
418
429
|
SchemaContext,
|
|
419
430
|
SchemaMemoryProvider,
|