@asteby/metacore-runtime-react 39.1.0 → 39.1.1
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 +6 -0
- package/LICENSE +201 -0
- package/dist/dynamic-form-schema.d.ts +1 -1
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +32 -4
- package/package.json +7 -7
- package/src/__tests__/dynamic-table-forbidden.test.tsx +67 -0
- package/src/dynamic-table.tsx +51 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @asteby/metacore-runtime-react
|
|
2
2
|
|
|
3
|
+
## 39.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a05f1bb: DynamicTable: un 403 en el endpoint de lista ya no se enmascara como "No se encontraron resultados"; muestra "Sin permiso para ver este módulo" (i18n `dynamic.forbidden_title` / `dynamic.forbidden_hint`) sin disparar refetch.
|
|
8
|
+
|
|
3
9
|
## 39.1.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Asteby, Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -6,7 +6,7 @@ import type { ActionFieldDef, FieldOptionsConfig, OptionDef, VisibleWhen } from
|
|
|
6
6
|
*/
|
|
7
7
|
export declare function registerValidator(slug: string, fn: (s: z.ZodString) => z.ZodString): void;
|
|
8
8
|
export declare function buildZodSchema(fields: ActionFieldDef[]): z.ZodObject<{
|
|
9
|
-
[x: string]: z.
|
|
9
|
+
[x: string]: z.ZodTypeAny;
|
|
10
10
|
}, z.core.$strip>;
|
|
11
11
|
/**
|
|
12
12
|
* Returns the line-items columns of a repeatable-group field, tolerating both
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-table.d.ts","sourceRoot":"","sources":["../src/dynamic-table.tsx"],"names":[],"mappings":"AAiBA,OAAO,EAKH,KAAK,SAAS,EAajB,MAAM,uBAAuB,CAAA;AAgC9B,OAAO,KAAK,EAAsB,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAuGnF,MAAM,WAAW,iBAAiB;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB;;;;;;;;;OASG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC5B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;IAC7C;;;;;OAKG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;IAC/B,cAAc,CAAC,EAAE,GAAG,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACpC,YAAY,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,CAAA;IAC/B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;IACrC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,UAAU,CAAA;IACjC;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACpC;
|
|
1
|
+
{"version":3,"file":"dynamic-table.d.ts","sourceRoot":"","sources":["../src/dynamic-table.tsx"],"names":[],"mappings":"AAiBA,OAAO,EAKH,KAAK,SAAS,EAajB,MAAM,uBAAuB,CAAA;AAgC9B,OAAO,KAAK,EAAsB,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAuGnF,MAAM,WAAW,iBAAiB;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB;;;;;;;;;OASG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC5B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;IAC7C;;;;;OAKG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;IAC/B,cAAc,CAAC,EAAE,GAAG,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACpC,YAAY,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,CAAA;IAC/B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;IACrC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,UAAU,CAAA;IACjC;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;CACpC;AAQD,wBAAgB,YAAY,CAAC,EACzB,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,aAAoB,EACpB,UAAU,EACV,UAAU,EACV,aAAkB,EAClB,iBAAiB,EACjB,QAAQ,EACR,UAAU,EACV,cAAc,EACd,cAAc,EACd,YAAiB,EACjB,iBAA4C,EAC5C,QAAQ,EACR,QAAQ,EACR,UAAU,EAAE,cAAc,EAC1B,cAAc,EAAE,kBAA0B,EAC1C,cAAc,GACjB,EAAE,iBAAiB,+BAgiDnB"}
|
package/dist/dynamic-table.js
CHANGED
|
@@ -107,6 +107,11 @@ function writeStoredPageSize(model, size) {
|
|
|
107
107
|
// quota / private mode — persistence is a nicety, never fatal
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
+
/** True when an api-client error is an HTTP 403 (axios-style or fetch-style). */
|
|
111
|
+
function isForbiddenError(error) {
|
|
112
|
+
const e = error;
|
|
113
|
+
return e?.response?.status === 403 || e?.status === 403;
|
|
114
|
+
}
|
|
110
115
|
export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync = true, hideImport, hideExport, hiddenColumns = [], allowedActionKeys, onAction, onRowClick, refreshTrigger, defaultFilters, extraColumns = [], getDynamicColumns = defaultGetDynamicColumns, timeZone, currency, pagination: paginationMode, infiniteScroll: infiniteScrollProp = false, virtualizeRows, }) {
|
|
111
116
|
// The explicit `pagination` prop wins; the legacy `infiniteScroll` boolean
|
|
112
117
|
// still selects the mode when `pagination` is absent (back-compat).
|
|
@@ -141,6 +146,10 @@ export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync
|
|
|
141
146
|
// even if meta.total says otherwise (count/list drift would otherwise
|
|
142
147
|
// keep the sentinel re-firing forever). Reset by any page-1 fetch.
|
|
143
148
|
const [infExhausted, setInfExhausted] = useState(false);
|
|
149
|
+
// The list endpoint answered 403: the user lacks read permission on this
|
|
150
|
+
// model. Rendered as "no permission" instead of masquerading as an empty
|
|
151
|
+
// list. Purely display state — never a fetch dependency (no refetch loop).
|
|
152
|
+
const [forbidden, setForbidden] = useState(false);
|
|
144
153
|
const infPageRef = useRef(1);
|
|
145
154
|
const [optionsMap, setOptionsMap] = useState(new Map());
|
|
146
155
|
const [exportOpen, setExportOpen] = useState(false);
|
|
@@ -711,6 +720,7 @@ export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync
|
|
|
711
720
|
...buildFilterParams(),
|
|
712
721
|
};
|
|
713
722
|
const res = await api.get(endpoint || `/data/${model}`, { params });
|
|
723
|
+
setForbidden(false);
|
|
714
724
|
if (res.data.success) {
|
|
715
725
|
const rows = res.data.data || [];
|
|
716
726
|
setData(rows);
|
|
@@ -724,7 +734,14 @@ export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync
|
|
|
724
734
|
}
|
|
725
735
|
}
|
|
726
736
|
catch (error) {
|
|
727
|
-
|
|
737
|
+
if (isForbiddenError(error)) {
|
|
738
|
+
setForbidden(true);
|
|
739
|
+
setData([]);
|
|
740
|
+
setRowCount(0);
|
|
741
|
+
}
|
|
742
|
+
else {
|
|
743
|
+
console.error('Error al cargar los datos', error);
|
|
744
|
+
}
|
|
728
745
|
}
|
|
729
746
|
finally {
|
|
730
747
|
setLoadingData(false);
|
|
@@ -770,6 +787,7 @@ export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync
|
|
|
770
787
|
const res = (await api.get(endpoint || `/data/${model}`, {
|
|
771
788
|
params,
|
|
772
789
|
}));
|
|
790
|
+
setForbidden(false);
|
|
773
791
|
if (res.data.success) {
|
|
774
792
|
const rows = res.data.data || [];
|
|
775
793
|
setData((prev) => (append ? dedupeById(prev, rows) : rows));
|
|
@@ -787,7 +805,17 @@ export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync
|
|
|
787
805
|
}
|
|
788
806
|
}
|
|
789
807
|
catch (error) {
|
|
790
|
-
|
|
808
|
+
if (isForbiddenError(error)) {
|
|
809
|
+
setForbidden(true);
|
|
810
|
+
if (!append) {
|
|
811
|
+
setData([]);
|
|
812
|
+
setRowCount(0);
|
|
813
|
+
}
|
|
814
|
+
setInfExhausted(true);
|
|
815
|
+
}
|
|
816
|
+
else {
|
|
817
|
+
console.error('Error al cargar los datos', error);
|
|
818
|
+
}
|
|
791
819
|
}
|
|
792
820
|
finally {
|
|
793
821
|
if (append)
|
|
@@ -1225,7 +1253,7 @@ export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync
|
|
|
1225
1253
|
const isActionsColumn = cell.column.id === 'actions';
|
|
1226
1254
|
const isSelectColumn = cell.column.id === 'select';
|
|
1227
1255
|
return (_jsx(TableCell, { style: cell.column.columnDef.size ? { width: cell.column.columnDef.size } : undefined, className: cn('py-2', isActionsColumn && 'sticky right-0 bg-card shadow-[-2px_0_5px_-2px_rgba(0,0,0,0.1)]'), onClick: (isActionsColumn || isSelectColumn) ? (e) => e.stopPropagation() : undefined, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
|
|
1228
|
-
}) }, row.id)))), aggregateColumns.length > 0 && Object.keys(footerTotals).length > 0 && (_jsx(TableRow, { className: 'border-0 hover:bg-transparent', children: _jsx(TableCell, { colSpan: columns.length, className: 'h-full p-0' }) }))] })) : (_jsx(TableRow, { className: 'border-b-0 hover:bg-transparent', children: _jsx(TableCell, { colSpan: columns.length, className: 'h-full p-0', children: _jsxs("div", { className: "flex h-full py-12 flex-col items-center justify-center gap-2 text-muted-foreground", children: [_jsx("div", { className: "flex h-20 w-20 items-center justify-center rounded-full bg-muted/50", children: _jsx(Inbox, { className: "h-10 w-10" }) }),
|
|
1256
|
+
}) }, row.id)))), aggregateColumns.length > 0 && Object.keys(footerTotals).length > 0 && (_jsx(TableRow, { className: 'border-0 hover:bg-transparent', children: _jsx(TableCell, { colSpan: columns.length, className: 'h-full p-0' }) }))] })) : (_jsx(TableRow, { className: 'border-b-0 hover:bg-transparent', children: _jsx(TableCell, { colSpan: columns.length, className: 'h-full p-0', children: _jsxs("div", { className: "flex h-full py-12 flex-col items-center justify-center gap-2 text-muted-foreground", children: [_jsx("div", { className: "flex h-20 w-20 items-center justify-center rounded-full bg-muted/50", children: _jsx(Inbox, { className: "h-10 w-10" }) }), _jsx("div", { className: "flex flex-col items-center gap-1", children: forbidden ? (_jsxs(_Fragment, { children: [_jsx("h3", { className: "text-lg font-semibold text-foreground", role: "alert", children: t('dynamic.forbidden_title', { defaultValue: 'Sin permiso para ver este módulo' }) }), _jsx("p", { className: "text-sm text-muted-foreground", children: t('dynamic.forbidden_hint', { defaultValue: 'Tu rol no tiene acceso de lectura a estos datos. Pide acceso a un administrador.' }) })] })) : (_jsxs(_Fragment, { children: [_jsx("h3", { className: "text-lg font-semibold text-foreground", children: "No se encontraron resultados" }), _jsx("p", { className: "text-sm text-muted-foreground", children: "No hay datos para mostrar en este momento." })] })) })] }) }) })) }), aggregateColumns.length > 0 && Object.keys(footerTotals).length > 0 && (_jsx(TableFooter, { className: "bg-transparent", children: _jsx(TableRow, { className: "hover:bg-transparent", children: table.getVisibleLeafColumns().map((leaf, idx) => {
|
|
1229
1257
|
const col = (metadata?.columns ?? []).find((c) => c.key === leaf.id);
|
|
1230
1258
|
const isFirst = idx === 0;
|
|
1231
1259
|
const stickyBase = 'sticky bottom-0 z-10 border-t bg-background py-2 font-semibold';
|
|
@@ -1265,7 +1293,7 @@ export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync
|
|
|
1265
1293
|
(typeof header === 'string' ? header : cell.column.id);
|
|
1266
1294
|
return (_jsxs("div", { className: 'flex items-start justify-between gap-3 text-sm', children: [_jsx("span", { className: 'shrink-0 text-muted-foreground', children: label }), _jsx("span", { className: 'min-w-0 overflow-hidden break-words text-right font-medium [&_[data-slot=badge]]:max-w-full [&_[data-slot=badge]]:whitespace-normal [&_[data-slot=badge]]:text-start', children: flexRender(cell.column.columnDef.cell, cell.getContext()) })] }, cell.id));
|
|
1267
1295
|
}), actionsCell && (_jsx("div", { className: 'flex justify-end border-t pt-2', onClick: onRowClick ? (e) => e.stopPropagation() : undefined, children: flexRender(actionsCell.column.columnDef.cell, actionsCell.getContext()) }))] }, row.id));
|
|
1268
|
-
}))) : (_jsxs("div", { className: 'flex flex-col items-center justify-center gap-2 rounded-lg border bg-card py-12 text-muted-foreground', children: [_jsx("div", { className: 'flex h-16 w-16 items-center justify-center rounded-full bg-muted/50', children: _jsx(Inbox, { className: 'h-8 w-8' }) }), _jsx("h3", { className: 'text-base font-semibold text-foreground', children: "No se encontraron resultados" }), _jsx("p", { className: 'text-sm text-muted-foreground', children: "No hay datos para mostrar en este momento." })] })), infiniteScroll && (_jsxs(_Fragment, { children: [loadingMore && (_jsx(Skeleton, { className: 'h-16 w-full shrink-0', "data-testid": 'table-loading-more-mobile' })), _jsx("div", { ref: infMobileSentinel, className: 'h-1 w-full shrink-0', "aria-hidden": true })] }))] }), _jsx("div", { className: 'shrink-0 pt-4', children: infiniteScroll ? (data.length > 0 && (_jsx("p", { className: 'text-center text-xs text-muted-foreground tabular-nums', children: t('common.showingCount', {
|
|
1296
|
+
}))) : (_jsxs("div", { className: 'flex flex-col items-center justify-center gap-2 rounded-lg border bg-card py-12 text-muted-foreground', children: [_jsx("div", { className: 'flex h-16 w-16 items-center justify-center rounded-full bg-muted/50', children: _jsx(Inbox, { className: 'h-8 w-8' }) }), forbidden ? (_jsxs(_Fragment, { children: [_jsx("h3", { className: 'text-base font-semibold text-foreground', role: 'alert', children: t('dynamic.forbidden_title', { defaultValue: 'Sin permiso para ver este módulo' }) }), _jsx("p", { className: 'text-sm text-muted-foreground', children: t('dynamic.forbidden_hint', { defaultValue: 'Tu rol no tiene acceso de lectura a estos datos. Pide acceso a un administrador.' }) })] })) : (_jsxs(_Fragment, { children: [_jsx("h3", { className: 'text-base font-semibold text-foreground', children: "No se encontraron resultados" }), _jsx("p", { className: 'text-sm text-muted-foreground', children: "No hay datos para mostrar en este momento." })] }))] })), infiniteScroll && (_jsxs(_Fragment, { children: [loadingMore && (_jsx(Skeleton, { className: 'h-16 w-full shrink-0', "data-testid": 'table-loading-more-mobile' })), _jsx("div", { ref: infMobileSentinel, className: 'h-1 w-full shrink-0', "aria-hidden": true })] }))] }), _jsx("div", { className: 'shrink-0 pt-4', children: infiniteScroll ? (data.length > 0 && (_jsx("p", { className: 'text-center text-xs text-muted-foreground tabular-nums', children: t('common.showingCount', {
|
|
1269
1297
|
defaultValue: '{{count}} de {{total}}',
|
|
1270
1298
|
count: data.length,
|
|
1271
1299
|
total: rowCount,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asteby/metacore-runtime-react",
|
|
3
|
-
"version": "39.1.
|
|
3
|
+
"version": "39.1.1",
|
|
4
4
|
"description": "React runtime for metacore hosts — renders addon contributions dynamically",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
"zod": "^4.3.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
+
"@asteby/metacore-sdk": "^3.8.0",
|
|
30
|
+
"@asteby/metacore-ui": "^2.18.1",
|
|
29
31
|
"@tanstack/react-query": ">=5",
|
|
30
32
|
"@tanstack/react-router": ">=1.100",
|
|
31
33
|
"@tanstack/react-table": ">=8",
|
|
@@ -37,9 +39,7 @@
|
|
|
37
39
|
"react-dom": ">=18",
|
|
38
40
|
"react-i18next": ">=13",
|
|
39
41
|
"sonner": ">=1.7",
|
|
40
|
-
"zustand": ">=5"
|
|
41
|
-
"@asteby/metacore-sdk": "^3.8.0",
|
|
42
|
-
"@asteby/metacore-ui": "^2.18.1"
|
|
42
|
+
"zustand": ">=5"
|
|
43
43
|
},
|
|
44
44
|
"peerDependenciesMeta": {
|
|
45
45
|
"@tanstack/react-router": {
|
|
@@ -50,6 +50,8 @@
|
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
+
"@asteby/metacore-sdk": "3.8.0",
|
|
54
|
+
"@asteby/metacore-ui": "2.18.1",
|
|
53
55
|
"@tanstack/react-query": "^5.95.0",
|
|
54
56
|
"@tanstack/react-router": "^1.168.0",
|
|
55
57
|
"@tanstack/react-table": "^8.20.0",
|
|
@@ -67,9 +69,7 @@
|
|
|
67
69
|
"tsx": "^4.21.0",
|
|
68
70
|
"typescript": "^6.0.0",
|
|
69
71
|
"vitest": "^4.0.0",
|
|
70
|
-
"zustand": "^5.0.0"
|
|
71
|
-
"@asteby/metacore-sdk": "3.8.0",
|
|
72
|
-
"@asteby/metacore-ui": "2.18.1"
|
|
72
|
+
"zustand": "^5.0.0"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"build": "tsc -p tsconfig.json",
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
//
|
|
3
|
+
// Un 403 en el endpoint de lista NO debe verse como "sin resultados": se
|
|
4
|
+
// muestra "Sin permiso para ver este módulo" y no hay bucle de refetch.
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
7
|
+
|
|
8
|
+
vi.mock('@tanstack/react-router', () => ({ useNavigate: () => () => {} }))
|
|
9
|
+
|
|
10
|
+
import { ApiProvider, type ApiClient } from '../api-context'
|
|
11
|
+
import { useMetadataCache } from '../metadata-cache'
|
|
12
|
+
import { DynamicCRUDPage } from '../dynamic-crud-page'
|
|
13
|
+
import type { TableMetadata } from '../types'
|
|
14
|
+
|
|
15
|
+
afterEach(cleanup)
|
|
16
|
+
|
|
17
|
+
const meta = {
|
|
18
|
+
title: 'Ajustes',
|
|
19
|
+
endpoint: '/data/stock_adjustments',
|
|
20
|
+
columns: [],
|
|
21
|
+
actions: [],
|
|
22
|
+
perPageOptions: [10],
|
|
23
|
+
defaultPerPage: 10,
|
|
24
|
+
searchPlaceholder: 'Buscar...',
|
|
25
|
+
enableCRUDActions: false,
|
|
26
|
+
hasActions: false,
|
|
27
|
+
} as unknown as TableMetadata
|
|
28
|
+
|
|
29
|
+
function mount(listBehavior: 'forbidden' | 'empty', model: string) {
|
|
30
|
+
useMetadataCache.getState().setMetadata(model, meta)
|
|
31
|
+
let listCalls = 0
|
|
32
|
+
const client: ApiClient = {
|
|
33
|
+
get: vi.fn(async (url: string) => {
|
|
34
|
+
if (url.startsWith('/metadata/table/')) return { data: { success: true, data: meta } }
|
|
35
|
+
listCalls++
|
|
36
|
+
if (listBehavior === 'forbidden') {
|
|
37
|
+
throw Object.assign(new Error('403'), { response: { status: 403 } })
|
|
38
|
+
}
|
|
39
|
+
return { data: { success: true, data: [], meta: { total: 0 } } }
|
|
40
|
+
}),
|
|
41
|
+
post: vi.fn(async () => ({ data: { success: true, data: null } })),
|
|
42
|
+
put: vi.fn(async () => ({ data: { success: true, data: null } })),
|
|
43
|
+
delete: vi.fn(async () => ({ data: { success: true, data: null } })),
|
|
44
|
+
}
|
|
45
|
+
render(
|
|
46
|
+
<ApiProvider client={client}>
|
|
47
|
+
<DynamicCRUDPage model={model} />
|
|
48
|
+
</ApiProvider>,
|
|
49
|
+
)
|
|
50
|
+
return () => listCalls
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe('DynamicTable — 403 en la lista', () => {
|
|
54
|
+
it('muestra "Sin permiso" y no "No se encontraron resultados"', async () => {
|
|
55
|
+
const calls = mount('forbidden', 'forb_a')
|
|
56
|
+
expect((await screen.findAllByText('Sin permiso para ver este módulo')).length).toBeGreaterThan(0)
|
|
57
|
+
expect(screen.queryByText('No se encontraron resultados')).toBeNull()
|
|
58
|
+
await new Promise((r) => setTimeout(r, 200))
|
|
59
|
+
expect(calls()).toBeLessThanOrEqual(2) // sin bucle de refetch
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('lista vacía real sigue diciendo "No se encontraron resultados"', async () => {
|
|
63
|
+
mount('empty', 'forb_b')
|
|
64
|
+
expect((await screen.findAllByText('No se encontraron resultados')).length).toBeGreaterThan(0)
|
|
65
|
+
expect(screen.queryByText('Sin permiso para ver este módulo')).toBeNull()
|
|
66
|
+
})
|
|
67
|
+
})
|
package/src/dynamic-table.tsx
CHANGED
|
@@ -260,6 +260,12 @@ export interface DynamicTableProps {
|
|
|
260
260
|
virtualizeRows?: boolean | number
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
/** True when an api-client error is an HTTP 403 (axios-style or fetch-style). */
|
|
264
|
+
function isForbiddenError(error: unknown): boolean {
|
|
265
|
+
const e = error as { response?: { status?: number }; status?: number } | null
|
|
266
|
+
return e?.response?.status === 403 || e?.status === 403
|
|
267
|
+
}
|
|
268
|
+
|
|
263
269
|
export function DynamicTable({
|
|
264
270
|
model,
|
|
265
271
|
endpoint,
|
|
@@ -322,6 +328,10 @@ export function DynamicTable({
|
|
|
322
328
|
// even if meta.total says otherwise (count/list drift would otherwise
|
|
323
329
|
// keep the sentinel re-firing forever). Reset by any page-1 fetch.
|
|
324
330
|
const [infExhausted, setInfExhausted] = useState(false)
|
|
331
|
+
// The list endpoint answered 403: the user lacks read permission on this
|
|
332
|
+
// model. Rendered as "no permission" instead of masquerading as an empty
|
|
333
|
+
// list. Purely display state — never a fetch dependency (no refetch loop).
|
|
334
|
+
const [forbidden, setForbidden] = useState(false)
|
|
325
335
|
const infPageRef = useRef(1)
|
|
326
336
|
const [optionsMap, setOptionsMap] = useState<Map<string, any[]>>(new Map())
|
|
327
337
|
|
|
@@ -859,6 +869,7 @@ export function DynamicTable({
|
|
|
859
869
|
...buildFilterParams(),
|
|
860
870
|
}
|
|
861
871
|
const res = await api.get(endpoint || `/data/${model}`, { params }) as { data: ApiResponse<any[]> }
|
|
872
|
+
setForbidden(false)
|
|
862
873
|
if (res.data.success) {
|
|
863
874
|
const rows = res.data.data || []
|
|
864
875
|
setData(rows)
|
|
@@ -874,7 +885,13 @@ export function DynamicTable({
|
|
|
874
885
|
}
|
|
875
886
|
}
|
|
876
887
|
} catch (error) {
|
|
877
|
-
|
|
888
|
+
if (isForbiddenError(error)) {
|
|
889
|
+
setForbidden(true)
|
|
890
|
+
setData([])
|
|
891
|
+
setRowCount(0)
|
|
892
|
+
} else {
|
|
893
|
+
console.error('Error al cargar los datos', error)
|
|
894
|
+
}
|
|
878
895
|
} finally {
|
|
879
896
|
setLoadingData(false)
|
|
880
897
|
}
|
|
@@ -922,6 +939,7 @@ export function DynamicTable({
|
|
|
922
939
|
const res = (await api.get(endpoint || `/data/${model}`, {
|
|
923
940
|
params,
|
|
924
941
|
})) as { data: ApiResponse<any[]> }
|
|
942
|
+
setForbidden(false)
|
|
925
943
|
if (res.data.success) {
|
|
926
944
|
const rows = res.data.data || []
|
|
927
945
|
setData((prev) => (append ? dedupeById(prev, rows) : rows))
|
|
@@ -941,7 +959,16 @@ export function DynamicTable({
|
|
|
941
959
|
setInfExhausted(rows.length < infPageSize)
|
|
942
960
|
}
|
|
943
961
|
} catch (error) {
|
|
944
|
-
|
|
962
|
+
if (isForbiddenError(error)) {
|
|
963
|
+
setForbidden(true)
|
|
964
|
+
if (!append) {
|
|
965
|
+
setData([])
|
|
966
|
+
setRowCount(0)
|
|
967
|
+
}
|
|
968
|
+
setInfExhausted(true)
|
|
969
|
+
} else {
|
|
970
|
+
console.error('Error al cargar los datos', error)
|
|
971
|
+
}
|
|
945
972
|
} finally {
|
|
946
973
|
if (append) setLoadingMore(false)
|
|
947
974
|
else setLoadingData(false)
|
|
@@ -1546,8 +1573,17 @@ export function DynamicTable({
|
|
|
1546
1573
|
<Inbox className="h-10 w-10" />
|
|
1547
1574
|
</div>
|
|
1548
1575
|
<div className="flex flex-col items-center gap-1">
|
|
1549
|
-
|
|
1550
|
-
|
|
1576
|
+
{forbidden ? (
|
|
1577
|
+
<>
|
|
1578
|
+
<h3 className="text-lg font-semibold text-foreground" role="alert">{t('dynamic.forbidden_title', { defaultValue: 'Sin permiso para ver este módulo' })}</h3>
|
|
1579
|
+
<p className="text-sm text-muted-foreground">{t('dynamic.forbidden_hint', { defaultValue: 'Tu rol no tiene acceso de lectura a estos datos. Pide acceso a un administrador.' })}</p>
|
|
1580
|
+
</>
|
|
1581
|
+
) : (
|
|
1582
|
+
<>
|
|
1583
|
+
<h3 className="text-lg font-semibold text-foreground">No se encontraron resultados</h3>
|
|
1584
|
+
<p className="text-sm text-muted-foreground">No hay datos para mostrar en este momento.</p>
|
|
1585
|
+
</>
|
|
1586
|
+
)}
|
|
1551
1587
|
</div>
|
|
1552
1588
|
</div>
|
|
1553
1589
|
</TableCell>
|
|
@@ -1736,8 +1772,17 @@ export function DynamicTable({
|
|
|
1736
1772
|
<div className='flex h-16 w-16 items-center justify-center rounded-full bg-muted/50'>
|
|
1737
1773
|
<Inbox className='h-8 w-8' />
|
|
1738
1774
|
</div>
|
|
1739
|
-
|
|
1740
|
-
|
|
1775
|
+
{forbidden ? (
|
|
1776
|
+
<>
|
|
1777
|
+
<h3 className='text-base font-semibold text-foreground' role='alert'>{t('dynamic.forbidden_title', { defaultValue: 'Sin permiso para ver este módulo' })}</h3>
|
|
1778
|
+
<p className='text-sm text-muted-foreground'>{t('dynamic.forbidden_hint', { defaultValue: 'Tu rol no tiene acceso de lectura a estos datos. Pide acceso a un administrador.' })}</p>
|
|
1779
|
+
</>
|
|
1780
|
+
) : (
|
|
1781
|
+
<>
|
|
1782
|
+
<h3 className='text-base font-semibold text-foreground'>No se encontraron resultados</h3>
|
|
1783
|
+
<p className='text-sm text-muted-foreground'>No hay datos para mostrar en este momento.</p>
|
|
1784
|
+
</>
|
|
1785
|
+
)}
|
|
1741
1786
|
</div>
|
|
1742
1787
|
)}
|
|
1743
1788
|
{infiniteScroll && (
|