@airoom/nextmin-react 1.4.5 → 1.4.6

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.
@@ -259,6 +259,11 @@ export function SchemaForm({ model, schemaOverride, initialValues, submitLabel =
259
259
  const sessionRole = useMemo(() => {
260
260
  if (!effectiveUser)
261
261
  return [];
262
+ // 1. Check direct roleName field if backend provided it
263
+ const rn = effectiveUser.roleName;
264
+ if (typeof rn === 'string' && rn)
265
+ return [rn.toLowerCase()];
266
+ // 2. Fallback to existing logic
262
267
  const raw = effectiveUser.roles ?? effectiveUser.role;
263
268
  const toName = (r) => {
264
269
  if (!r)
@@ -270,10 +275,10 @@ export function SchemaForm({ model, schemaOverride, initialValues, submitLabel =
270
275
  return null;
271
276
  };
272
277
  if (Array.isArray(raw)) {
273
- return raw.map(toName).filter((s) => !!s);
278
+ return raw.map(toName).filter((s) => !!s).map(s => s.toLowerCase());
274
279
  }
275
280
  const single = toName(raw);
276
- return single ? [single] : [];
281
+ return single ? [single.toLowerCase()] : [];
277
282
  }, [effectiveUser]);
278
283
  const schema = useMemo(() => schemaOverride ??
279
284
  items.find((s) => s.modelName.toLowerCase() === model.toLowerCase()), [items, model, schemaOverride]);
@@ -14,12 +14,41 @@ export const fetchSchemas = createAsyncThunk('schemas/fetch', async () => {
14
14
  return status === 'idle';
15
15
  },
16
16
  });
17
+ const mergeSchemas = (existing, incoming) => {
18
+ if (!existing.length)
19
+ return incoming;
20
+ return incoming.map((newItem) => {
21
+ const oldItem = existing.find((s) => s.modelName === newItem.modelName);
22
+ if (!oldItem)
23
+ return newItem;
24
+ // Perform a smart merge of attributes
25
+ const mergedAttrs = { ...newItem.attributes };
26
+ let restoredCount = 0;
27
+ for (const [key, oldAttrVal] of Object.entries(oldItem.attributes)) {
28
+ const oldAttr = Array.isArray(oldAttrVal) ? oldAttrVal[0] : oldAttrVal;
29
+ const newAttrVal = mergedAttrs[key];
30
+ const newAttr = Array.isArray(newAttrVal) ? newAttrVal[0] : newAttrVal;
31
+ const isOldPrivate = oldAttr && oldAttr.private;
32
+ const isNewPrivate = newAttr && newAttr.private;
33
+ // If the old one had the private field and the new one doesn't,
34
+ // the new one is likely a "stripped" public schema. Restore the private one.
35
+ if (isOldPrivate && !isNewPrivate) {
36
+ mergedAttrs[key] = oldAttrVal;
37
+ restoredCount++;
38
+ }
39
+ }
40
+ if (restoredCount > 0) {
41
+ console.log(`[NextMin] Restored ${restoredCount} private fields for ${newItem.modelName} from previous high-quality state.`);
42
+ }
43
+ return { ...newItem, attributes: mergedAttrs };
44
+ }).concat(existing.filter((o) => !incoming.find((n) => n.modelName === o.modelName)));
45
+ };
17
46
  const schemasSlice = createSlice({
18
47
  name: 'schemas',
19
48
  initialState,
20
49
  reducers: {
21
50
  setSchemas(state, action) {
22
- state.items = action.payload;
51
+ state.items = mergeSchemas(state.items, action.payload);
23
52
  state.status = 'succeeded';
24
53
  },
25
54
  },
@@ -31,7 +60,7 @@ const schemasSlice = createSlice({
31
60
  })
32
61
  .addCase(fetchSchemas.fulfilled, (state, action) => {
33
62
  state.status = 'succeeded';
34
- state.items = action.payload;
63
+ state.items = mergeSchemas(state.items, action.payload);
35
64
  })
36
65
  .addCase(fetchSchemas.rejected, (state, action) => {
37
66
  state.status = 'failed';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@airoom/nextmin-react",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",