@availity/mui-spaces 0.1.0
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/CHANGELOG.md +19 -0
- package/README.md +61 -0
- package/dist/index.d.mts +104 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.js +456 -0
- package/dist/index.mjs +428 -0
- package/introduction.stories.mdx +7 -0
- package/jest.config.js +7 -0
- package/package.json +59 -0
- package/project.json +41 -0
- package/src/index.ts +1 -0
- package/src/lib/Spaces.stories.tsx +75 -0
- package/src/lib/Spaces.test.tsx +265 -0
- package/src/lib/Spaces.tsx +202 -0
- package/src/lib/configurationFindMany.tsx +105 -0
- package/src/lib/helpers.test.tsx +26 -0
- package/src/lib/helpers.tsx +15 -0
- package/src/lib/spaces-data.test.tsx +57 -0
- package/src/lib/spaces-data.tsx +116 -0
- package/src/lib/spaces-types.tsx +136 -0
- package/src/lib/topApps.test.tsx +93 -0
- package/src/lib/topApps.tsx +65 -0
- package/tsconfig.json +5 -0
- package/tsconfig.spec.json +10 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.next(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.throw(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/lib/Spaces.tsx
|
|
54
|
+
import { createContext, useContext, useReducer, useEffect } from "react";
|
|
55
|
+
import { useQueries } from "@tanstack/react-query";
|
|
56
|
+
|
|
57
|
+
// src/lib/spaces-data.tsx
|
|
58
|
+
import { avWebQLApi } from "@availity/api-axios";
|
|
59
|
+
var actions = {
|
|
60
|
+
SPACES: (currentState, { spaces, spacesByConfig, spacesByPayer }) => ({
|
|
61
|
+
previousSpacesMap: spaces,
|
|
62
|
+
previousSpacesByConfigMap: spacesByConfig,
|
|
63
|
+
previousSpacesByPayerMap: spacesByPayer,
|
|
64
|
+
error: void 0,
|
|
65
|
+
loading: false
|
|
66
|
+
}),
|
|
67
|
+
ERROR: (state, { error }) => __spreadProps(__spreadValues({}, state), {
|
|
68
|
+
loading: false,
|
|
69
|
+
error
|
|
70
|
+
}),
|
|
71
|
+
LOADING: (state, { loading }) => __spreadProps(__spreadValues({}, state), {
|
|
72
|
+
loading: loading !== void 0 ? loading : !state.loading
|
|
73
|
+
})
|
|
74
|
+
};
|
|
75
|
+
var spacesReducer = (state, action) => {
|
|
76
|
+
const { type } = action;
|
|
77
|
+
return actions[type](state, action);
|
|
78
|
+
};
|
|
79
|
+
var normalizeSpaces = (spaces) => {
|
|
80
|
+
let spacesToReduce = spaces;
|
|
81
|
+
if (Array.isArray(spaces[0])) {
|
|
82
|
+
spacesToReduce = spaces[0];
|
|
83
|
+
}
|
|
84
|
+
const pairFields = ["images", "metadata", "colors", "icons", "mapping"];
|
|
85
|
+
return spacesToReduce.reduce((accum, spc) => {
|
|
86
|
+
var _b;
|
|
87
|
+
if (!spc)
|
|
88
|
+
return accum;
|
|
89
|
+
const _a = spc, { images, metadata, colors, icons, mapping } = _a, rest = __objRest(_a, ["images", "metadata", "colors", "icons", "mapping"]);
|
|
90
|
+
const normalizedSpace = __spreadValues({}, rest);
|
|
91
|
+
for (const field of pairFields) {
|
|
92
|
+
if (spc[field] && Array.isArray(spc[field])) {
|
|
93
|
+
normalizedSpace[field] = (_b = spc[field]) == null ? void 0 : _b.reduce((_accum, { name, value }) => {
|
|
94
|
+
_accum[name] = value;
|
|
95
|
+
return _accum;
|
|
96
|
+
}, {});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
accum.push(normalizedSpace);
|
|
100
|
+
return accum;
|
|
101
|
+
}, []);
|
|
102
|
+
};
|
|
103
|
+
var fetchSpaces = (_0) => __async(void 0, [_0], function* ({ query, clientId, variables }) {
|
|
104
|
+
const {
|
|
105
|
+
data: {
|
|
106
|
+
data: { configurationPagination }
|
|
107
|
+
}
|
|
108
|
+
} = yield avWebQLApi.create(
|
|
109
|
+
{
|
|
110
|
+
query,
|
|
111
|
+
variables: __spreadValues({}, variables)
|
|
112
|
+
},
|
|
113
|
+
{ headers: { "X-Client-ID": clientId } }
|
|
114
|
+
);
|
|
115
|
+
const {
|
|
116
|
+
pageInfo: { currentPage, hasNextPage },
|
|
117
|
+
items
|
|
118
|
+
} = configurationPagination;
|
|
119
|
+
return {
|
|
120
|
+
items,
|
|
121
|
+
currentPage,
|
|
122
|
+
hasNextPage
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
var fetchAllSpaces = (_0) => __async(void 0, [_0], function* ({
|
|
126
|
+
query,
|
|
127
|
+
clientId,
|
|
128
|
+
variables,
|
|
129
|
+
_spaces = []
|
|
130
|
+
}) {
|
|
131
|
+
const { items, currentPage, hasNextPage } = yield fetchSpaces({ query, clientId, variables });
|
|
132
|
+
_spaces.push(...items);
|
|
133
|
+
if (hasNextPage) {
|
|
134
|
+
const vars = __spreadProps(__spreadValues({}, variables), {
|
|
135
|
+
page: currentPage + 1
|
|
136
|
+
});
|
|
137
|
+
return fetchAllSpaces({ query, clientId, variables: vars, _spaces });
|
|
138
|
+
}
|
|
139
|
+
return _spaces;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// src/lib/configurationFindMany.tsx
|
|
143
|
+
var configurationFindMany_default = `query configurationFindMany($ids: [String!], $payerIDs: [ID!], $types: [TypeEnum!]) {
|
|
144
|
+
configurationPagination(filter: { ids: $ids, payerIds: $payerIDs, types: $types }) {
|
|
145
|
+
pageInfo {
|
|
146
|
+
hasNextPage
|
|
147
|
+
currentPage
|
|
148
|
+
}
|
|
149
|
+
items {
|
|
150
|
+
... on Configuration {
|
|
151
|
+
configurationId
|
|
152
|
+
name
|
|
153
|
+
shortName
|
|
154
|
+
type
|
|
155
|
+
activeDate
|
|
156
|
+
isNew
|
|
157
|
+
description
|
|
158
|
+
payerIDs
|
|
159
|
+
parentIDs
|
|
160
|
+
metadataPairs {
|
|
161
|
+
name
|
|
162
|
+
value
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
... on Node {
|
|
167
|
+
id
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
... on Alert {
|
|
171
|
+
link {
|
|
172
|
+
text
|
|
173
|
+
target
|
|
174
|
+
url
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
... on Container {
|
|
179
|
+
link {
|
|
180
|
+
text
|
|
181
|
+
target
|
|
182
|
+
url
|
|
183
|
+
}
|
|
184
|
+
images {
|
|
185
|
+
tile
|
|
186
|
+
promotional
|
|
187
|
+
logo
|
|
188
|
+
billboard
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
... on PayerSpace {
|
|
193
|
+
link {
|
|
194
|
+
text
|
|
195
|
+
target
|
|
196
|
+
url
|
|
197
|
+
}
|
|
198
|
+
images {
|
|
199
|
+
tile
|
|
200
|
+
logo
|
|
201
|
+
billboard
|
|
202
|
+
}
|
|
203
|
+
url
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
... on Application {
|
|
207
|
+
link {
|
|
208
|
+
text
|
|
209
|
+
target
|
|
210
|
+
url
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
... on Resource {
|
|
215
|
+
link {
|
|
216
|
+
text
|
|
217
|
+
target
|
|
218
|
+
url
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
... on Navigation {
|
|
223
|
+
icons {
|
|
224
|
+
dashboard
|
|
225
|
+
navigation
|
|
226
|
+
}
|
|
227
|
+
images {
|
|
228
|
+
promotional
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
... on Learning {
|
|
233
|
+
images {
|
|
234
|
+
promotional
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
... on Proxy {
|
|
239
|
+
url
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
... on File {
|
|
243
|
+
url
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}`;
|
|
248
|
+
|
|
249
|
+
// src/lib/Spaces.tsx
|
|
250
|
+
import { jsx } from "react/jsx-runtime";
|
|
251
|
+
var INITIAL_STATE = {
|
|
252
|
+
loading: true
|
|
253
|
+
};
|
|
254
|
+
var SpacesContext = createContext(INITIAL_STATE);
|
|
255
|
+
var useSpacesContext = () => useContext(SpacesContext);
|
|
256
|
+
var Spaces = ({
|
|
257
|
+
query = configurationFindMany_default,
|
|
258
|
+
variables = { types: ["PAYERSPACE"] },
|
|
259
|
+
clientId,
|
|
260
|
+
children,
|
|
261
|
+
payerIds,
|
|
262
|
+
spaceIds,
|
|
263
|
+
spaces: spacesFromProps
|
|
264
|
+
}) => {
|
|
265
|
+
const [{ previousSpacesMap, previousSpacesByConfigMap, previousSpacesByPayerMap, loading, error }, dispatch] = useReducer(spacesReducer, INITIAL_STATE);
|
|
266
|
+
const spacesMap = new Map(previousSpacesMap);
|
|
267
|
+
const configIdsMap = new Map(previousSpacesByConfigMap);
|
|
268
|
+
const payerIdsMap = new Map(previousSpacesByPayerMap);
|
|
269
|
+
const spaceIdsToQuery = /* @__PURE__ */ new Set();
|
|
270
|
+
const payerIdsToQuery = /* @__PURE__ */ new Set();
|
|
271
|
+
if (spacesFromProps && spacesFromProps.length > 0) {
|
|
272
|
+
for (const space of spacesFromProps) {
|
|
273
|
+
if (space.id && !spacesMap.has(space.id)) {
|
|
274
|
+
spacesMap.set(space.id, space);
|
|
275
|
+
}
|
|
276
|
+
if (space.configurationId && !configIdsMap.has(space.configurationId)) {
|
|
277
|
+
configIdsMap.set(space.configurationId, space);
|
|
278
|
+
}
|
|
279
|
+
if (space.payerIDs) {
|
|
280
|
+
for (const pId of space.payerIDs) {
|
|
281
|
+
const currentSpacesForPayerId = payerIdsMap.get(pId);
|
|
282
|
+
if (currentSpacesForPayerId) {
|
|
283
|
+
payerIdsMap.set(pId, [...currentSpacesForPayerId, space]);
|
|
284
|
+
} else {
|
|
285
|
+
payerIdsMap.set(pId, [space]);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (spaceIds && spaceIds.length > 0) {
|
|
292
|
+
for (const id of spaceIds) {
|
|
293
|
+
if (!(spacesMap.has(id) || configIdsMap.has(id))) {
|
|
294
|
+
spaceIdsToQuery.add(id);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (payerIds && payerIds.length > 0) {
|
|
299
|
+
for (const pid of payerIds) {
|
|
300
|
+
if (!payerIdsMap.has(pid)) {
|
|
301
|
+
payerIdsToQuery.add(pid);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const spaceIdVars = __spreadProps(__spreadValues({}, variables), { ids: [...spaceIdsToQuery.keys()] });
|
|
306
|
+
const payerIdVars = __spreadProps(__spreadValues({}, variables), { payerIds: [...payerIdsToQuery.keys()] });
|
|
307
|
+
const [
|
|
308
|
+
{ data: spacesBySpaceIds, isFetching: isLoadingBySpaceIds, error: errorBySpaceIds },
|
|
309
|
+
{ data: spacesByPayerIds, isFetching: isLoadingByPayerIds, error: errorByPayerIds }
|
|
310
|
+
] = useQueries({
|
|
311
|
+
queries: [
|
|
312
|
+
{
|
|
313
|
+
queryKey: ["id", spaceIdVars],
|
|
314
|
+
queryFn: () => fetchAllSpaces({ query, clientId, variables: spaceIdVars }),
|
|
315
|
+
enabled: spaceIdsToQuery.size > 0
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
queryKey: ["id", payerIdVars],
|
|
319
|
+
queryFn: () => fetchAllSpaces({ query, clientId, variables: payerIdVars }),
|
|
320
|
+
enabled: payerIdsToQuery.size > 0
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
});
|
|
324
|
+
useEffect(() => {
|
|
325
|
+
if (errorByPayerIds || errorBySpaceIds) {
|
|
326
|
+
dispatch({
|
|
327
|
+
type: "ERROR",
|
|
328
|
+
error: (errorByPayerIds == null ? void 0 : errorByPayerIds.message) || (errorBySpaceIds == null ? void 0 : errorBySpaceIds.message),
|
|
329
|
+
loading: false
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}, [errorByPayerIds, errorBySpaceIds]);
|
|
333
|
+
useEffect(() => {
|
|
334
|
+
dispatch({
|
|
335
|
+
type: "LOADING",
|
|
336
|
+
loading: true
|
|
337
|
+
});
|
|
338
|
+
if (spaceIdsToQuery.size === 0 && payerIdsToQuery.size === 0) {
|
|
339
|
+
dispatch({
|
|
340
|
+
type: "LOADING",
|
|
341
|
+
loading: false
|
|
342
|
+
});
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (spacesBySpaceIds) {
|
|
346
|
+
for (const space of spacesBySpaceIds) {
|
|
347
|
+
if (!spacesMap.has(space.id)) {
|
|
348
|
+
spacesMap.set(space.id, space);
|
|
349
|
+
}
|
|
350
|
+
if (!configIdsMap.has(space.configurationId)) {
|
|
351
|
+
configIdsMap.set(space.configurationId, space);
|
|
352
|
+
}
|
|
353
|
+
if (space.payerIDs) {
|
|
354
|
+
for (const pId of space.payerIDs) {
|
|
355
|
+
const currentSpacesForPayerId = payerIdsMap.get(pId);
|
|
356
|
+
if (currentSpacesForPayerId) {
|
|
357
|
+
payerIdsMap.set(pId, [...currentSpacesForPayerId, space]);
|
|
358
|
+
} else {
|
|
359
|
+
payerIdsMap.set(pId, [space]);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (payerIdsToQuery.size > 0) {
|
|
366
|
+
if (spacesByPayerIds) {
|
|
367
|
+
for (const space of spacesByPayerIds) {
|
|
368
|
+
if (!spacesMap.has(space.id)) {
|
|
369
|
+
spacesMap.set(space.id, space);
|
|
370
|
+
}
|
|
371
|
+
if (!configIdsMap.has(space.configurationId)) {
|
|
372
|
+
configIdsMap.set(space.configurationId, space);
|
|
373
|
+
}
|
|
374
|
+
if (space.payerIDs) {
|
|
375
|
+
for (const pId of space.payerIDs) {
|
|
376
|
+
const currentSpacesForPayerId = payerIdsMap.get(pId);
|
|
377
|
+
if (currentSpacesForPayerId) {
|
|
378
|
+
payerIdsMap.set(pId, [...currentSpacesForPayerId, space]);
|
|
379
|
+
} else {
|
|
380
|
+
payerIdsMap.set(pId, [space]);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
dispatch({
|
|
388
|
+
type: "SPACES",
|
|
389
|
+
spaces: spacesMap,
|
|
390
|
+
spacesByConfig: configIdsMap,
|
|
391
|
+
spacesByPayer: payerIdsMap,
|
|
392
|
+
loading: false
|
|
393
|
+
});
|
|
394
|
+
}, [spacesBySpaceIds, spacesByPayerIds, payerIds, spaceIds]);
|
|
395
|
+
return /* @__PURE__ */ jsx(
|
|
396
|
+
SpacesContext.Provider,
|
|
397
|
+
{
|
|
398
|
+
children,
|
|
399
|
+
value: {
|
|
400
|
+
spaces: spacesMap,
|
|
401
|
+
spacesByConfig: configIdsMap,
|
|
402
|
+
spacesByPayer: payerIdsMap,
|
|
403
|
+
loading: loading || isLoadingByPayerIds || isLoadingBySpaceIds,
|
|
404
|
+
error
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
);
|
|
408
|
+
};
|
|
409
|
+
var useSpaces = (...ids) => {
|
|
410
|
+
const { spaces, spacesByConfig, spacesByPayer } = useSpacesContext();
|
|
411
|
+
const idsIsEmpty = !ids || ids.length === 0;
|
|
412
|
+
const callerIsExpectingFirstSpace = (ids == null ? void 0 : ids.length) === 1 && ids[0] === void 0;
|
|
413
|
+
const shouldReturnAllSpaces = idsIsEmpty || callerIsExpectingFirstSpace;
|
|
414
|
+
if (shouldReturnAllSpaces) {
|
|
415
|
+
console.warn(`You did not pass in an ID to find a space, returning all spaces.`);
|
|
416
|
+
return spaces && normalizeSpaces([...spaces.values()]);
|
|
417
|
+
}
|
|
418
|
+
const matchedSpaces = ids.map((id) => (spaces == null ? void 0 : spaces.get(id)) || (spacesByConfig == null ? void 0 : spacesByConfig.get(id)) || (spacesByPayer == null ? void 0 : spacesByPayer.get(id)));
|
|
419
|
+
const normalized = normalizeSpaces(matchedSpaces);
|
|
420
|
+
return normalized;
|
|
421
|
+
};
|
|
422
|
+
export {
|
|
423
|
+
INITIAL_STATE,
|
|
424
|
+
Spaces,
|
|
425
|
+
SpacesContext,
|
|
426
|
+
useSpaces,
|
|
427
|
+
useSpacesContext
|
|
428
|
+
};
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@availity/mui-spaces",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Availity MUI Spaces Component - part of the @availity/element design system",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"typescript",
|
|
8
|
+
"availity",
|
|
9
|
+
"mui"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://availity.github.io/element/?path=/docs/components-spaces-introduction--docs",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Availity/element/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/Availity/element.git",
|
|
18
|
+
"directory": "packages/spaces"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "Availity Developers <AVOSS@availity.com>",
|
|
22
|
+
"browser": "./dist/index.js",
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"module": "./dist/index.mjs",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
28
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
29
|
+
"clean": "rm -rf dist",
|
|
30
|
+
"clean:nm": "rm -rf node_modules",
|
|
31
|
+
"publish": "yarn npm publish --tolerate-republish --access public",
|
|
32
|
+
"publish:canary": "yarn npm publish --access public --tag canary"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@mui/material": "^5.15.15",
|
|
36
|
+
"react": "18.2.0",
|
|
37
|
+
"react-dom": "18.2.0",
|
|
38
|
+
"tsup": "^8.0.2",
|
|
39
|
+
"typescript": "^5.4.5"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@mui/material": "^5.11.9",
|
|
43
|
+
"react": ">=16.3.0"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@availity/api-axios": "^8.0.7",
|
|
50
|
+
"@availity/message-core": "^6.1.2",
|
|
51
|
+
"@availity/mui-button": "^0.6.7",
|
|
52
|
+
"@availity/mui-modal": "^0.1.3",
|
|
53
|
+
"@availity/mui-typography": "^0.1.8",
|
|
54
|
+
"@tanstack/react-query": "^5.32.0",
|
|
55
|
+
"dayjs": "^1.11.10",
|
|
56
|
+
"qs": "^6.12.1",
|
|
57
|
+
"react-markdown": "^9.0.1"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mui-spaces",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/spaces/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"targets": {
|
|
8
|
+
"lint": {
|
|
9
|
+
"executor": "@nx/eslint:lint",
|
|
10
|
+
"options": {
|
|
11
|
+
"eslintConfig": ".eslintrc.json",
|
|
12
|
+
"silent": false,
|
|
13
|
+
"fix": false,
|
|
14
|
+
"cache": true,
|
|
15
|
+
"cacheLocation": "./node_modules/.cache/spaces/.eslintcache",
|
|
16
|
+
"maxWarnings": -1,
|
|
17
|
+
"quiet": false,
|
|
18
|
+
"noEslintrc": false,
|
|
19
|
+
"hasTypeAwareRules": true,
|
|
20
|
+
"cacheStrategy": "metadata"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"test": {
|
|
24
|
+
"executor": "@nx/jest:jest",
|
|
25
|
+
"outputs": ["{workspaceRoot}/coverage/spaces"],
|
|
26
|
+
"options": {
|
|
27
|
+
"jestConfig": "packages/spaces/jest.config.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"version": {
|
|
31
|
+
"executor": "@jscutlery/semver:version",
|
|
32
|
+
"options": {
|
|
33
|
+
"preset": "conventional",
|
|
34
|
+
"commitMessageFormat": "chore({projectName}): release version ${version} [skip ci]",
|
|
35
|
+
"tagPrefix": "@availity/{projectName}@",
|
|
36
|
+
"trackDeps": true,
|
|
37
|
+
"skipCommitTypes": ["docs"]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/Spaces';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Each exported component in the package should have its own stories file
|
|
2
|
+
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
|
+
import { Paper } from '@availity/mui-paper';
|
|
5
|
+
import { Typography } from '@availity/mui-typography';
|
|
6
|
+
import { Divider } from '@availity/mui-divider';
|
|
7
|
+
import { Stack } from '@availity/mui-layout';
|
|
8
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
9
|
+
import { Spaces, useSpaces, useSpacesContext } from './Spaces';
|
|
10
|
+
import { SpacesProps } from './spaces-types';
|
|
11
|
+
|
|
12
|
+
const meta: Meta<typeof Spaces> = {
|
|
13
|
+
title: 'Components/Spaces/Spaces',
|
|
14
|
+
component: Spaces,
|
|
15
|
+
tags: ['autodocs'],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default meta;
|
|
19
|
+
|
|
20
|
+
const queryClient = new QueryClient();
|
|
21
|
+
|
|
22
|
+
const SpaceComponent = ({ spaceId }: { spaceId: string }) => {
|
|
23
|
+
const spaces = useSpaces(spaceId);
|
|
24
|
+
|
|
25
|
+
const space = spaces?.find((space) => space.configurationId === spaceId);
|
|
26
|
+
return (
|
|
27
|
+
<div>
|
|
28
|
+
<span id={`space-for-${spaceId}`}>
|
|
29
|
+
{space ? `Space ${space?.configurationId} is in provider` : `Space ${spaceId} is not in provider`}
|
|
30
|
+
</span>
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const SpaceContainer = ({ children }: { children?: React.ReactNode }): JSX.Element => {
|
|
36
|
+
const { loading } = useSpacesContext();
|
|
37
|
+
return loading ? <span>loading...</span> : <div>{children}</div>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const _Spaces: StoryObj<typeof Spaces> = {
|
|
41
|
+
render: (args: SpacesProps) => {
|
|
42
|
+
return (
|
|
43
|
+
<QueryClientProvider client={queryClient}>
|
|
44
|
+
<Spaces {...args}>
|
|
45
|
+
<SpaceContainer>
|
|
46
|
+
<Stack spacing={2}>
|
|
47
|
+
<Paper>
|
|
48
|
+
<Typography>Space 1 was passed in the props.</Typography>
|
|
49
|
+
<SpaceComponent spaceId="1" />
|
|
50
|
+
</Paper>
|
|
51
|
+
<Paper>
|
|
52
|
+
<Typography>Space 2 was fetched from the api via the spaceId passed in the props.</Typography>
|
|
53
|
+
<SpaceComponent spaceId="2" />
|
|
54
|
+
</Paper>
|
|
55
|
+
<Paper>
|
|
56
|
+
<Typography>Space 3 was not returned.</Typography>
|
|
57
|
+
<SpaceComponent spaceId="3" />
|
|
58
|
+
</Paper>
|
|
59
|
+
<Paper>
|
|
60
|
+
<Typography>Space 11 was fetched from the api via the payerId passed in the props.</Typography>
|
|
61
|
+
<SpaceComponent spaceId="11" />
|
|
62
|
+
</Paper>
|
|
63
|
+
</Stack>
|
|
64
|
+
</SpaceContainer>
|
|
65
|
+
</Spaces>
|
|
66
|
+
</QueryClientProvider>
|
|
67
|
+
);
|
|
68
|
+
},
|
|
69
|
+
args: {
|
|
70
|
+
clientId: 'my-client-id',
|
|
71
|
+
spaces: [{ id: '1', configurationId: '1', type: 'space', name: 'Space 1' }],
|
|
72
|
+
spaceIds: ['2'],
|
|
73
|
+
payerIds: ['a'],
|
|
74
|
+
},
|
|
75
|
+
};
|