@asteby/metacore-runtime-react 29.2.10 → 29.2.11
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
CHANGED
|
@@ -42,13 +42,14 @@ export declare const formatAggregateTotal: (col: ColumnDefinition, value: unknow
|
|
|
42
42
|
* State-machine gate for per-row actions.
|
|
43
43
|
*
|
|
44
44
|
* An action that declares a non-empty `requiresState` (camelCase) / `requires_state`
|
|
45
|
-
* (snake_case, as served by some backends) is only surfaced for rows whose
|
|
46
|
-
* field
|
|
47
|
-
*
|
|
45
|
+
* (snake_case, as served by some backends) is only surfaced for rows whose
|
|
46
|
+
* lifecycle field (`status` or `state`) is contained in that array. This hides
|
|
47
|
+
* e.g. "Recibir" (requiresState: ['confirmed','partial']) on a purchase order
|
|
48
|
+
* still in `draft`.
|
|
48
49
|
*
|
|
49
50
|
* Null-safe & non-regressive:
|
|
50
51
|
* - action without requiresState (or empty array) → always shown.
|
|
51
|
-
* - row with
|
|
52
|
+
* - row with neither `status` nor `state` → all actions shown.
|
|
52
53
|
*/
|
|
53
54
|
export declare const isActionAllowedForRowState: (action: any, row: any) => boolean;
|
|
54
55
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-columns.d.ts","sourceRoot":"","sources":["../src/dynamic-columns.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,UAAU,CAAA;AAwC9C,OAAO,KAAK,EAAiB,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE9D,OAAO,KAAK,EAER,iBAAiB,EACpB,MAAM,wBAAwB,CAAA;AAE/B,qEAAqE;AACrE,MAAM,WAAW,qBAAqB;IAClC;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IACtC;;;;OAIG;IACH,UAAU,CAAC,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;IACd,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CACxC,CAqBA,CAAA;AAED,wBAAgB,4BAA4B,CACxC,OAAO,GAAE,qBAA0B,GACpC,iBAAiB,CA+mBnB;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,iBACL,CAAA"}
|
package/dist/dynamic-columns.js
CHANGED
|
@@ -106,24 +106,39 @@ const CodeCell = ({ text, maxLength }) => {
|
|
|
106
106
|
};
|
|
107
107
|
return (_jsxs("div", { className: "group flex items-center gap-1.5", children: [_jsx("code", { className: "rounded bg-muted px-1.5 py-0.5 font-mono text-xs text-foreground/80", title: text, children: display }), _jsx("button", { type: "button", onClick: onCopy, className: "opacity-0 transition-opacity group-hover:opacity-100 text-muted-foreground hover:text-foreground", "aria-label": "Copiar", title: "Copiar", children: copied ? (_jsx(icons.Check, { className: "h-3.5 w-3.5 text-green-500" })) : (_jsx(icons.Copy, { className: "h-3.5 w-3.5" })) })] }));
|
|
108
108
|
};
|
|
109
|
+
/**
|
|
110
|
+
* Lifecycle column used by `requiresState`: prefer `status` (workshop, vehicles,
|
|
111
|
+
* …) and fall back to `state` (purchases, inventory transfers, …). Empty string
|
|
112
|
+
* is treated as missing so a blank `status` does not hide a populated `state`.
|
|
113
|
+
*/
|
|
114
|
+
const rowLifecycleState = (row) => {
|
|
115
|
+
const status = row?.status;
|
|
116
|
+
if (status !== undefined && status !== null && status !== '')
|
|
117
|
+
return status;
|
|
118
|
+
const state = row?.state;
|
|
119
|
+
if (state !== undefined && state !== null && state !== '')
|
|
120
|
+
return state;
|
|
121
|
+
return undefined;
|
|
122
|
+
};
|
|
109
123
|
/**
|
|
110
124
|
* State-machine gate for per-row actions.
|
|
111
125
|
*
|
|
112
126
|
* An action that declares a non-empty `requiresState` (camelCase) / `requires_state`
|
|
113
|
-
* (snake_case, as served by some backends) is only surfaced for rows whose
|
|
114
|
-
* field
|
|
115
|
-
*
|
|
127
|
+
* (snake_case, as served by some backends) is only surfaced for rows whose
|
|
128
|
+
* lifecycle field (`status` or `state`) is contained in that array. This hides
|
|
129
|
+
* e.g. "Recibir" (requiresState: ['confirmed','partial']) on a purchase order
|
|
130
|
+
* still in `draft`.
|
|
116
131
|
*
|
|
117
132
|
* Null-safe & non-regressive:
|
|
118
133
|
* - action without requiresState (or empty array) → always shown.
|
|
119
|
-
* - row with
|
|
134
|
+
* - row with neither `status` nor `state` → all actions shown.
|
|
120
135
|
*/
|
|
121
136
|
export const isActionAllowedForRowState = (action, row) => {
|
|
122
137
|
const requires = action?.requiresState ?? action?.requires_state;
|
|
123
138
|
if (!Array.isArray(requires) || requires.length === 0)
|
|
124
139
|
return true;
|
|
125
|
-
const status = row
|
|
126
|
-
if (status === undefined
|
|
140
|
+
const status = rowLifecycleState(row);
|
|
141
|
+
if (status === undefined)
|
|
127
142
|
return true;
|
|
128
143
|
return requires.map(String).includes(String(status));
|
|
129
144
|
};
|
package/package.json
CHANGED
|
@@ -48,4 +48,24 @@ describe('isActionAllowedForRowState', () => {
|
|
|
48
48
|
expect(isActionAllowedForRowState(action, { status: 2 })).toBe(true)
|
|
49
49
|
expect(isActionAllowedForRowState(action, { status: '3' })).toBe(false)
|
|
50
50
|
})
|
|
51
|
+
|
|
52
|
+
it('falls back to row.state when status is absent (purchases, transfers)', () => {
|
|
53
|
+
const receive = { key: 'receive_goods', requiresState: ['confirmed', 'partial'] }
|
|
54
|
+
expect(isActionAllowedForRowState(receive, { state: 'draft' })).toBe(false)
|
|
55
|
+
expect(isActionAllowedForRowState(receive, { state: 'confirmed' })).toBe(true)
|
|
56
|
+
expect(isActionAllowedForRowState(receive, { state: 'partial' })).toBe(true)
|
|
57
|
+
expect(isActionAllowedForRowState(receive, { state: 'received' })).toBe(false)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('prefers status over state when both are set', () => {
|
|
61
|
+
const action = { key: 'start', requiresState: ['reception'] }
|
|
62
|
+
expect(isActionAllowedForRowState(action, { status: 'reception', state: 'draft' })).toBe(true)
|
|
63
|
+
expect(isActionAllowedForRowState(action, { status: 'in_progress', state: 'reception' })).toBe(false)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('ignores empty status and uses state instead', () => {
|
|
67
|
+
const action = { key: 'confirm', requiresState: ['draft'] }
|
|
68
|
+
expect(isActionAllowedForRowState(action, { status: '', state: 'draft' })).toBe(true)
|
|
69
|
+
expect(isActionAllowedForRowState(action, { status: '', state: 'confirmed' })).toBe(false)
|
|
70
|
+
})
|
|
51
71
|
})
|
package/src/dynamic-columns.tsx
CHANGED
|
@@ -204,23 +204,37 @@ const CodeCell: React.FC<{ text: string; maxLength?: number }> = ({ text, maxLen
|
|
|
204
204
|
)
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Lifecycle column used by `requiresState`: prefer `status` (workshop, vehicles,
|
|
209
|
+
* …) and fall back to `state` (purchases, inventory transfers, …). Empty string
|
|
210
|
+
* is treated as missing so a blank `status` does not hide a populated `state`.
|
|
211
|
+
*/
|
|
212
|
+
const rowLifecycleState = (row: any): unknown => {
|
|
213
|
+
const status = row?.status
|
|
214
|
+
if (status !== undefined && status !== null && status !== '') return status
|
|
215
|
+
const state = row?.state
|
|
216
|
+
if (state !== undefined && state !== null && state !== '') return state
|
|
217
|
+
return undefined
|
|
218
|
+
}
|
|
219
|
+
|
|
207
220
|
/**
|
|
208
221
|
* State-machine gate for per-row actions.
|
|
209
222
|
*
|
|
210
223
|
* An action that declares a non-empty `requiresState` (camelCase) / `requires_state`
|
|
211
|
-
* (snake_case, as served by some backends) is only surfaced for rows whose
|
|
212
|
-
* field
|
|
213
|
-
*
|
|
224
|
+
* (snake_case, as served by some backends) is only surfaced for rows whose
|
|
225
|
+
* lifecycle field (`status` or `state`) is contained in that array. This hides
|
|
226
|
+
* e.g. "Recibir" (requiresState: ['confirmed','partial']) on a purchase order
|
|
227
|
+
* still in `draft`.
|
|
214
228
|
*
|
|
215
229
|
* Null-safe & non-regressive:
|
|
216
230
|
* - action without requiresState (or empty array) → always shown.
|
|
217
|
-
* - row with
|
|
231
|
+
* - row with neither `status` nor `state` → all actions shown.
|
|
218
232
|
*/
|
|
219
233
|
export const isActionAllowedForRowState = (action: any, row: any): boolean => {
|
|
220
234
|
const requires: unknown = action?.requiresState ?? action?.requires_state
|
|
221
235
|
if (!Array.isArray(requires) || requires.length === 0) return true
|
|
222
|
-
const status = row
|
|
223
|
-
if (status === undefined
|
|
236
|
+
const status = rowLifecycleState(row)
|
|
237
|
+
if (status === undefined) return true
|
|
224
238
|
return requires.map(String).includes(String(status))
|
|
225
239
|
}
|
|
226
240
|
|