@asteby/metacore-runtime-react 53.24.0 → 53.26.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 +25 -0
- package/dist/action-modal-dispatcher.d.ts +3 -3
- package/dist/action-modal-dispatcher.js +31 -31
- package/dist/action-priority.d.ts +1 -1
- package/dist/activity-diff.d.ts +1 -1
- package/dist/activity-diff.js +1 -1
- package/dist/activity-timeline.d.ts +2 -2
- package/dist/activity-timeline.js +3 -3
- package/dist/activity-value-renderer.d.ts +1 -1
- package/dist/activity-value-renderer.js +3 -3
- package/dist/addon-loader.d.ts +1 -1
- package/dist/addon-loader.js +3 -3
- package/dist/addon-page-host.js +1 -1
- package/dist/addon-page-loader.d.ts +2 -2
- package/dist/addon-page-loader.js +3 -3
- package/dist/api-context.js +4 -4
- package/dist/approval-gate.d.ts +1 -1
- package/dist/approval-gate.js +5 -5
- package/dist/assist-interview.d.ts +1 -1
- package/dist/assist-interview.js +1 -1
- package/dist/attention/index.d.ts +3 -3
- package/dist/attention/index.js +3 -3
- package/dist/attention/use-nav-badges.js +2 -2
- package/dist/attribute-classes.d.ts +1 -1
- package/dist/audit-info.d.ts +1 -1
- package/dist/audit-info.js +5 -5
- package/dist/bulk-image-dialog.d.ts +1 -1
- package/dist/bulk-image-dialog.js +5 -5
- package/dist/bulk-image-import.d.ts +2 -2
- package/dist/bulk-image-import.js +1 -1
- package/dist/bulk-image-target.d.ts +1 -1
- package/dist/bulk-image-target.js +1 -1
- package/dist/bulk-image-wizard.d.ts +1 -1
- package/dist/bulk-image-wizard.js +5 -5
- package/dist/business/catalog-product-search.d.ts +1 -1
- package/dist/business/customer-picker.js +4 -4
- package/dist/business/document-editor-model.d.ts +3 -3
- package/dist/business/document-editor-model.js +4 -4
- package/dist/business/document-editor-panels.d.ts +3 -3
- package/dist/business/document-editor-panels.js +1 -1
- package/dist/business/document-editor.d.ts +2 -2
- package/dist/business/document-editor.js +22 -22
- package/dist/business/document-lines.d.ts +2 -2
- package/dist/business/document-lines.js +3 -3
- package/dist/business/field-errors.d.ts +1 -1
- package/dist/business/field-errors.js +1 -1
- package/dist/business/format.js +1 -1
- package/dist/business/index.d.ts +29 -29
- package/dist/business/index.js +29 -29
- package/dist/business/inspection-checklist.d.ts +1 -1
- package/dist/business/inspection-checklist.js +2 -2
- package/dist/business/inspection.d.ts +1 -1
- package/dist/business/inspection.js +2 -2
- package/dist/business/line-items-editor.d.ts +3 -3
- package/dist/business/line-items-editor.js +5 -5
- package/dist/business/line-items.d.ts +1 -1
- package/dist/business/line-items.js +2 -2
- package/dist/business/line-product-cell.d.ts +2 -2
- package/dist/business/line-product-cell.js +2 -2
- package/dist/business/payment-allocator.d.ts +1 -1
- package/dist/business/payment-allocator.js +2 -2
- package/dist/business/payment-capture.d.ts +1 -1
- package/dist/business/payment-capture.js +3 -3
- package/dist/business/payment.js +1 -1
- package/dist/business/print-send-dialog.js +1 -1
- package/dist/business/product-display.d.ts +1 -1
- package/dist/business/product-options.d.ts +1 -1
- package/dist/business/product-options.js +4 -4
- package/dist/business/product-picker.d.ts +1 -1
- package/dist/business/product-picker.js +3 -3
- package/dist/business/product-search.d.ts +2 -2
- package/dist/business/product-search.js +1 -1
- package/dist/business/refund-destination.d.ts +1 -1
- package/dist/business/refund-destination.js +2 -2
- package/dist/business/refund.js +1 -1
- package/dist/business/relate-documents.js +1 -1
- package/dist/business/return-wizard.d.ts +2 -2
- package/dist/business/return-wizard.js +4 -4
- package/dist/business/return.d.ts +2 -2
- package/dist/business/return.js +2 -2
- package/dist/business/vehicle-picker.js +3 -3
- package/dist/cache-coherence.js +3 -3
- package/dist/capability-providers/index.d.ts +3 -3
- package/dist/capability-providers/index.js +3 -3
- package/dist/capability-providers/provider-sortable-list.d.ts +1 -1
- package/dist/capability-providers/provider-sortable-list.js +1 -1
- package/dist/collection-cell.js +1 -1
- package/dist/column-filter-field.d.ts +1 -1
- package/dist/column-visibility.d.ts +1 -1
- package/dist/custom-stages.d.ts +2 -2
- package/dist/custom-stages.js +1 -1
- package/dist/dashboard-grid.d.ts +2 -2
- package/dist/dashboard-grid.d.ts.map +1 -1
- package/dist/dashboard-grid.js +22 -20
- package/dist/dashboard-types.d.ts +6 -0
- package/dist/dashboard-types.d.ts.map +1 -1
- package/dist/dialogs/create-record-dialog.d.ts +1 -1
- package/dist/dialogs/create-record-dialog.js +1 -1
- package/dist/dialogs/dynamic-record.d.ts +5 -5
- package/dist/dialogs/dynamic-record.js +41 -41
- package/dist/dialogs/export.d.ts +1 -1
- package/dist/dialogs/export.js +2 -2
- package/dist/dialogs/import.d.ts +1 -1
- package/dist/dialogs/import.js +3 -3
- package/dist/dialogs/inline-relation-rows.d.ts +3 -3
- package/dist/dialogs/inline-relation-rows.js +3 -3
- package/dist/dialogs/inline-relations.d.ts +3 -3
- package/dist/dialogs/inline-relations.js +3 -3
- package/dist/dialogs/normalize-submit.d.ts +1 -1
- package/dist/dialogs/normalize-submit.js +3 -3
- package/dist/dialogs/use-inline-relations.d.ts +1 -1
- package/dist/dialogs/use-inline-relations.js +3 -3
- package/dist/dialogs/view-record-dialog.d.ts +1 -1
- package/dist/dialogs/view-record-dialog.js +1 -1
- package/dist/display-value.js +1 -1
- package/dist/document/action-bar.d.ts +1 -1
- package/dist/document/action-bar.js +1 -1
- package/dist/document/document-header.d.ts +2 -2
- package/dist/document/document-header.js +2 -2
- package/dist/document/document-page.d.ts +3 -3
- package/dist/document/document-page.js +9 -9
- package/dist/document/document-timeline.d.ts +2 -2
- package/dist/document/document-timeline.js +2 -2
- package/dist/document/evaluate.d.ts +1 -1
- package/dist/document/evaluate.js +1 -1
- package/dist/document/format.d.ts +1 -1
- package/dist/document/index.d.ts +13 -13
- package/dist/document/index.js +13 -13
- package/dist/document/registry.d.ts +1 -1
- package/dist/document/secondary-bar.js +2 -2
- package/dist/document/smart-buttons.js +1 -1
- package/dist/document/status-badge.d.ts +1 -1
- package/dist/document/use-document-sources.d.ts +1 -1
- package/dist/document/use-document-sources.js +2 -2
- package/dist/document-form-dialog.d.ts +2 -2
- package/dist/document-form-dialog.js +16 -16
- package/dist/document-template-editor.js +1 -1
- package/dist/dynamic-columns-shim.d.ts +1 -1
- package/dist/dynamic-columns.d.ts +11 -3
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +52 -26
- package/dist/dynamic-crud-page.d.ts +2 -2
- package/dist/dynamic-crud-page.d.ts.map +1 -1
- package/dist/dynamic-crud-page.js +22 -19
- package/dist/dynamic-date-field.d.ts +1 -1
- package/dist/dynamic-date-field.js +1 -1
- package/dist/dynamic-form-schema.d.ts +2 -2
- package/dist/dynamic-form-schema.js +4 -4
- package/dist/dynamic-form.d.ts +10 -10
- package/dist/dynamic-form.js +24 -24
- package/dist/dynamic-icon.js +1 -1
- package/dist/dynamic-kanban.d.ts +3 -3
- package/dist/dynamic-kanban.js +25 -25
- package/dist/dynamic-line-items.d.ts +1 -1
- package/dist/dynamic-line-items.js +6 -6
- package/dist/dynamic-multi-select-field.d.ts +1 -1
- package/dist/dynamic-multi-select-field.js +7 -7
- package/dist/dynamic-relation-helpers.d.ts +1 -1
- package/dist/dynamic-relation-helpers.js +2 -2
- package/dist/dynamic-relation.d.ts +2 -2
- package/dist/dynamic-relation.js +15 -15
- package/dist/dynamic-relations.d.ts +2 -2
- package/dist/dynamic-relations.js +1 -1
- package/dist/dynamic-row-actions.d.ts +1 -1
- package/dist/dynamic-row-actions.js +5 -5
- package/dist/dynamic-select-field.d.ts +3 -3
- package/dist/dynamic-select-field.js +11 -11
- package/dist/dynamic-table.d.ts +5 -3
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +48 -36
- package/dist/dynamic-view.d.ts +4 -4
- package/dist/dynamic-view.js +7 -7
- package/dist/entity-select.js +4 -4
- package/dist/field-validation-ui.d.ts +2 -2
- package/dist/field-widget-registry.d.ts +1 -1
- package/dist/form-layout-ui.d.ts +1 -1
- package/dist/form-layout.d.ts +1 -1
- package/dist/form-layout.js +1 -1
- package/dist/genui/index.d.ts +1 -1
- package/dist/genui/index.js +1 -1
- package/dist/genui/settings-block.d.ts +1 -1
- package/dist/genui/settings-block.js +3 -3
- package/dist/host-api-client.d.ts +11 -1
- package/dist/host-api-client.d.ts.map +1 -1
- package/dist/host-api-client.js +21 -14
- package/dist/host-api.d.ts +9 -1
- package/dist/host-api.d.ts.map +1 -1
- package/dist/host-api.js +57 -2
- package/dist/hotswap-reload-policy.d.ts +1 -1
- package/dist/hotswap-reload-policy.js +1 -1
- package/dist/icon-picker-field.d.ts +1 -1
- package/dist/icon-picker-field.js +3 -3
- package/dist/icon-resolvers.d.ts +1 -1
- package/dist/icon-resolvers.js +1 -1
- package/dist/icon-spec.js +1 -1
- package/dist/index.d.ts +165 -163
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +148 -147
- package/dist/license/index.d.ts +6 -6
- package/dist/license/index.js +6 -6
- package/dist/license/license-expiry-banner.d.ts +1 -1
- package/dist/license/license-expiry-banner.js +3 -3
- package/dist/license/license-gate.d.ts +1 -1
- package/dist/license/license-gate.js +5 -5
- package/dist/license/license-status-badge.d.ts +1 -1
- package/dist/license/license-status-badge.js +1 -1
- package/dist/license/use-license-t.d.ts +1 -1
- package/dist/license/use-license-t.js +1 -1
- package/dist/license/view.d.ts +1 -1
- package/dist/license/view.js +1 -1
- package/dist/list-include.d.ts +1 -1
- package/dist/manifest-hotswap-subscriber.d.ts +1 -1
- package/dist/manifest-hotswap-subscriber.js +1 -1
- package/dist/metadata-cache.d.ts +1 -1
- package/dist/metadata-cache.js +1 -1
- package/dist/model-action-toolbar.d.ts +1 -1
- package/dist/model-action-toolbar.js +7 -7
- package/dist/model-labels.d.ts +38 -0
- package/dist/model-labels.d.ts.map +1 -0
- package/dist/model-labels.js +35 -0
- package/dist/nav-permissions.d.ts +1 -1
- package/dist/nav-permissions.js +1 -1
- package/dist/navigation-builder.d.ts +1 -1
- package/dist/navigation-builder.js +1 -1
- package/dist/option-display.d.ts +1 -1
- package/dist/option-display.js +2 -2
- package/dist/option-filter.d.ts +1 -1
- package/dist/option-when.d.ts +1 -1
- package/dist/org-runtime-provider.d.ts +2 -2
- package/dist/org-runtime-provider.js +2 -2
- package/dist/permissions-context.d.ts +1 -1
- package/dist/permissions-manager.js +4 -4
- package/dist/primitives/aging.js +1 -1
- package/dist/primitives/allocation.js +1 -1
- package/dist/primitives/approvals.d.ts +1 -1
- package/dist/primitives/contributions.js +1 -1
- package/dist/primitives/document-kinds.d.ts +1 -1
- package/dist/primitives/index.d.ts +7 -7
- package/dist/primitives/index.js +7 -7
- package/dist/primitives/panels.d.ts +1 -1
- package/dist/primitives/use-contributions.d.ts +2 -2
- package/dist/primitives/use-contributions.js +2 -2
- package/dist/print-document-button.d.ts +1 -1
- package/dist/print-document-button.js +1 -1
- package/dist/provenance.js +3 -3
- package/dist/query-batch.d.ts +1 -1
- package/dist/query-batch.js +1 -1
- package/dist/record-actions.d.ts +2 -2
- package/dist/record-actions.js +2 -2
- package/dist/record-history.d.ts +2 -2
- package/dist/record-history.js +3 -3
- package/dist/record-picker-dialog.js +3 -3
- package/dist/record-picker-option.d.ts +1 -1
- package/dist/record-picker-option.js +1 -1
- package/dist/record-picker.js +2 -2
- package/dist/record-prefill-bar.js +1 -1
- package/dist/relation-gallery.js +1 -1
- package/dist/requires-addon.d.ts +1 -1
- package/dist/rich-cells.js +2 -2
- package/dist/rich-url.js +1 -1
- package/dist/row-actions-menu.js +5 -5
- package/dist/server-error.js +2 -2
- package/dist/setup/addon-config-surface.d.ts +3 -3
- package/dist/setup/addon-config-surface.js +10 -10
- package/dist/setup/connector-blocks-model.d.ts +1 -1
- package/dist/setup/connector-blocks.d.ts +1 -1
- package/dist/setup/connector-blocks.js +6 -6
- package/dist/setup/flow-model.d.ts +1 -1
- package/dist/setup/health-card.d.ts +1 -1
- package/dist/setup/health-card.js +2 -2
- package/dist/setup/index.d.ts +12 -12
- package/dist/setup/index.js +12 -12
- package/dist/setup/records-table.d.ts +1 -1
- package/dist/setup/records-table.js +2 -2
- package/dist/setup/setup-flow.d.ts +1 -1
- package/dist/setup/setup-flow.js +7 -7
- package/dist/setup/setup-form-step.d.ts +1 -1
- package/dist/setup/setup-form-step.js +4 -4
- package/dist/setup/step-status-badge.d.ts +1 -1
- package/dist/setup/step-status-badge.js +2 -2
- package/dist/setup/tone.d.ts +1 -1
- package/dist/setup/types.d.ts +2 -2
- package/dist/sidebar-layout-manager.d.ts +1 -1
- package/dist/sidebar-layout-manager.js +2 -2
- package/dist/slot.js +1 -1
- package/dist/slots/addon-slot.js +4 -4
- package/dist/slots/index.d.ts +2 -2
- package/dist/slots/index.js +2 -2
- package/dist/stage-automations.d.ts +2 -2
- package/dist/stage-automations.js +1 -1
- package/dist/stage-layout.js +1 -1
- package/dist/stage-overrides.d.ts +1 -1
- package/dist/stage-overrides.js +1 -1
- package/dist/supervised-action.js +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/tri-state-boolean.d.ts +2 -2
- package/dist/tri-state-boolean.js +1 -1
- package/dist/types.d.ts +4 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/upload-field.d.ts +1 -1
- package/dist/upload-field.js +4 -4
- package/dist/use-addon-installed-probe.js +3 -3
- package/dist/use-addon-settings.d.ts +1 -1
- package/dist/use-addon-settings.js +1 -1
- package/dist/use-dynamic-filters.d.ts +2 -2
- package/dist/use-dynamic-filters.js +6 -6
- package/dist/use-edge-device.d.ts +1 -1
- package/dist/use-edge-device.js +2 -2
- package/dist/use-facet-loaders.d.ts +1 -1
- package/dist/use-facet-loaders.js +1 -1
- package/dist/use-flip-animation.d.ts +1 -1
- package/dist/use-flip-animation.js +1 -1
- package/dist/use-host-api-client.d.ts +2 -2
- package/dist/use-host-api-client.d.ts.map +1 -1
- package/dist/use-host-api-client.js +6 -4
- package/dist/use-option-ids.d.ts +1 -1
- package/dist/use-option-ids.js +2 -2
- package/dist/use-options-resolver.d.ts +2 -2
- package/dist/use-options-resolver.js +4 -4
- package/dist/use-org-document-templates.js +1 -1
- package/dist/use-print-document.js +1 -1
- package/dist/use-record-mutation-tick.js +1 -1
- package/dist/validator.d.ts +2 -2
- package/dist/validator.js +1 -1
- package/dist/view-system/card-spec.d.ts +1 -1
- package/dist/view-system/cards-view.d.ts +1 -1
- package/dist/view-system/cards-view.js +2 -2
- package/dist/view-system/index.d.ts +9 -9
- package/dist/view-system/index.js +9 -9
- package/dist/view-system/model-view.d.ts +3 -3
- package/dist/view-system/model-view.js +7 -7
- package/dist/view-system/saved-views.d.ts +1 -1
- package/dist/view-system/use-view-mode.d.ts +1 -1
- package/dist/view-system/view-state.d.ts +1 -1
- package/dist/view-system/view-switcher.d.ts +1 -1
- package/dist/view-system/view-toolbar.d.ts +1 -1
- package/dist/view-system/view-toolbar.js +2 -2
- package/dist/views/calendar-view.d.ts +1 -1
- package/dist/views/calendar-view.js +2 -2
- package/dist/views/chart-view.d.ts +2 -2
- package/dist/views/chart-view.js +2 -2
- package/dist/views/data-source.d.ts +2 -2
- package/dist/views/index.d.ts +3 -3
- package/dist/views/index.js +2 -2
- package/dist/views/map-view.d.ts +1 -1
- package/dist/views/map-view.js +3 -3
- package/dist/views/panels.d.ts +1 -1
- package/dist/views/panels.js +3 -3
- package/dist/views/registry.d.ts +2 -2
- package/dist/views/registry.js +12 -12
- package/dist/views/split-view.d.ts +1 -1
- package/dist/views/split-view.js +4 -4
- package/dist/views/timeline-view.d.ts +1 -1
- package/dist/views/timeline-view.js +3 -3
- package/dist/views/types.d.ts +2 -2
- package/dist/widgets/charts.d.ts +1 -1
- package/dist/widgets/charts.js +2 -2
- package/dist/widgets/lazy-charts.d.ts +1 -1
- package/dist/widgets/lazy-charts.js +2 -2
- package/dist/widgets/renderers.d.ts +2 -2
- package/dist/widgets/renderers.js +2 -2
- package/dist/widgets/widget-card.d.ts +1 -1
- package/dist/widgets/widget-card.js +2 -2
- package/dist/widgets/widget-renderer.d.ts +1 -1
- package/dist/widgets/widget-renderer.js +4 -4
- package/package.json +10 -10
- package/src/__tests__/host-api-client.test.tsx +16 -0
- package/src/__tests__/host-api.test.ts +50 -0
- package/src/__tests__/initials-avatar-cell.test.tsx +54 -0
- package/src/__tests__/load-guard.test.tsx +94 -0
- package/src/__tests__/model-labels.test.tsx +31 -0
- package/src/dashboard-grid.tsx +49 -35
- package/src/dashboard-types.ts +6 -0
- package/src/dynamic-columns.tsx +40 -9
- package/src/dynamic-crud-page.tsx +10 -7
- package/src/dynamic-table.tsx +38 -12
- package/src/host-api-client.ts +31 -14
- package/src/host-api.ts +54 -1
- package/src/index.ts +5 -1
- package/src/model-labels.ts +80 -0
- package/src/types.ts +3 -0
- package/src/use-host-api-client.ts +5 -3
package/src/dynamic-table.tsx
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
} from '@tanstack/react-table'
|
|
38
38
|
import { cn } from '@asteby/metacore-ui/lib'
|
|
39
39
|
import { preloadGlyphs } from '@asteby/metacore-ui/icons'
|
|
40
|
+
import { useLoadingGuard } from '@asteby/metacore-ui/hooks'
|
|
40
41
|
import {
|
|
41
42
|
Table,
|
|
42
43
|
TableBody,
|
|
@@ -47,6 +48,7 @@ import {
|
|
|
47
48
|
TableRow,
|
|
48
49
|
Button,
|
|
49
50
|
Skeleton,
|
|
51
|
+
LoadState,
|
|
50
52
|
AlertDialog,
|
|
51
53
|
AlertDialogAction,
|
|
52
54
|
AlertDialogCancel,
|
|
@@ -300,6 +302,8 @@ export interface DynamicTableProps {
|
|
|
300
302
|
* mode exactly as before.
|
|
301
303
|
*/
|
|
302
304
|
infiniteScroll?: boolean
|
|
305
|
+
/** Max ms a metadata/list request may stay loading before an error + retry replaces the skeleton. Default 15000; 0 disables. */
|
|
306
|
+
loadTimeoutMs?: number
|
|
303
307
|
/**
|
|
304
308
|
* Row virtualization. When the visible row model has at least N rows,
|
|
305
309
|
* only viewport rows are mounted (helps infinite scroll and large page
|
|
@@ -424,6 +428,7 @@ export function DynamicTable({
|
|
|
424
428
|
currency: currencyProp,
|
|
425
429
|
pagination: paginationMode,
|
|
426
430
|
infiniteScroll: infiniteScrollProp = false,
|
|
431
|
+
loadTimeoutMs,
|
|
427
432
|
virtualizeRows,
|
|
428
433
|
extraBulkActions,
|
|
429
434
|
hideBulkDelete,
|
|
@@ -492,6 +497,12 @@ export function DynamicTable({
|
|
|
492
497
|
// A list request that failed for a reason other than 403 (500, network,
|
|
493
498
|
// `success: false`). Shown with a retry instead of a misleading "no results".
|
|
494
499
|
const [loadError, setLoadError] = useState(false)
|
|
500
|
+
// A list request that never answers must not leave the skeleton up forever:
|
|
501
|
+
// after the guard's timeout it is shown as a load error with retry.
|
|
502
|
+
const dataGuard = useLoadingGuard(loadingData && data.length === 0, { timeoutMs: loadTimeoutMs })
|
|
503
|
+
const showLoadError = loadError || dataGuard.timedOut
|
|
504
|
+
const showDataSkeleton = loadingData && data.length === 0 && !dataGuard.timedOut
|
|
505
|
+
const [metaReload, setMetaReload] = useState(0)
|
|
495
506
|
const infPageRef = useRef(1)
|
|
496
507
|
const [optionsMap, setOptionsMap] = useState<Map<string, any[]>>(new Map())
|
|
497
508
|
|
|
@@ -896,7 +907,12 @@ export function DynamicTable({
|
|
|
896
907
|
}
|
|
897
908
|
}
|
|
898
909
|
initMetadataAndOptions()
|
|
899
|
-
}, [model]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
910
|
+
}, [model, metaReload]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
911
|
+
|
|
912
|
+
const retryMetadata = useCallback(() => {
|
|
913
|
+
metaInitRef.current = false
|
|
914
|
+
setMetaReload((n) => n + 1)
|
|
915
|
+
}, [])
|
|
900
916
|
|
|
901
917
|
// Derived from `metadata.columns[].searchable`. `null` means the kernel
|
|
902
918
|
// didn't emit the flag for any column → preserve legacy "search every
|
|
@@ -1278,6 +1294,11 @@ export function DynamicTable({
|
|
|
1278
1294
|
fetchAggregates()
|
|
1279
1295
|
}, [infiniteScroll, fetchPage, fetchData, fetchAggregates])
|
|
1280
1296
|
|
|
1297
|
+
const retryLoad = useCallback(() => {
|
|
1298
|
+
dataGuard.retry()
|
|
1299
|
+
handleRefresh()
|
|
1300
|
+
}, [dataGuard.retry, handleRefresh])
|
|
1301
|
+
|
|
1281
1302
|
// Per-row action dispatch (view/edit/delete/link/custom) + its dialogs live
|
|
1282
1303
|
// in the shared hook so DynamicKanban's card menu behaves identically.
|
|
1283
1304
|
const { handleInternalAction, dialogs: rowActionDialogs } = useDynamicRowActions({
|
|
@@ -1626,8 +1647,15 @@ export function DynamicTable({
|
|
|
1626
1647
|
</>
|
|
1627
1648
|
)
|
|
1628
1649
|
|
|
1629
|
-
if (loading) {
|
|
1650
|
+
if (loading || !metadata) {
|
|
1630
1651
|
return (
|
|
1652
|
+
<LoadState
|
|
1653
|
+
loading={loading}
|
|
1654
|
+
timeoutMs={loadTimeoutMs}
|
|
1655
|
+
error={!loading && !metadata}
|
|
1656
|
+
onRetry={retryMetadata}
|
|
1657
|
+
className='flex flex-col h-full min-h-0 w-full'
|
|
1658
|
+
skeleton={
|
|
1631
1659
|
<div className='flex flex-col h-full min-h-0 w-full'>
|
|
1632
1660
|
<div className='pb-4 shrink-0'>
|
|
1633
1661
|
<div className="flex items-center justify-between">
|
|
@@ -1653,13 +1681,11 @@ export function DynamicTable({
|
|
|
1653
1681
|
</Table>
|
|
1654
1682
|
</div>
|
|
1655
1683
|
</div>
|
|
1684
|
+
}
|
|
1685
|
+
/>
|
|
1656
1686
|
)
|
|
1657
1687
|
}
|
|
1658
1688
|
|
|
1659
|
-
if (!metadata) {
|
|
1660
|
-
return <div className="text-center text-muted-foreground py-8">Error al cargar la configuración de la tabla.</div>
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
1689
|
return (
|
|
1664
1690
|
<RowActionsModelContext.Provider value={model}>
|
|
1665
1691
|
<OptionsContext.Provider value={{ optionsMap }}>
|
|
@@ -1718,7 +1744,7 @@ export function DynamicTable({
|
|
|
1718
1744
|
))}
|
|
1719
1745
|
</TableHeader>
|
|
1720
1746
|
<TableBody>
|
|
1721
|
-
{
|
|
1747
|
+
{showDataSkeleton ? (
|
|
1722
1748
|
<TableSkeleton />
|
|
1723
1749
|
) : tableRows.length ? (
|
|
1724
1750
|
<>
|
|
@@ -1829,11 +1855,11 @@ export function DynamicTable({
|
|
|
1829
1855
|
<h3 className="text-lg font-semibold text-foreground" role="alert">{t('dynamic.forbidden_title', { defaultValue: 'Sin permiso para ver este módulo' })}</h3>
|
|
1830
1856
|
<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>
|
|
1831
1857
|
</>
|
|
1832
|
-
) :
|
|
1858
|
+
) : showLoadError ? (
|
|
1833
1859
|
<>
|
|
1834
1860
|
<h3 className="text-lg font-semibold text-foreground" role="alert">{t('dynamic.load_error_title', { defaultValue: 'No se pudieron cargar los datos' })}</h3>
|
|
1835
1861
|
<p className="text-sm text-muted-foreground">{t('dynamic.load_error_hint', { defaultValue: 'Ocurrió un error al consultar la lista. Inténtalo de nuevo.' })}</p>
|
|
1836
|
-
<Button variant="outline" size="sm" className="mt-2" onClick={
|
|
1862
|
+
<Button variant="outline" size="sm" className="mt-2" onClick={retryLoad}>{t('dynamic.retry', { defaultValue: 'Reintentar' })}</Button>
|
|
1837
1863
|
</>
|
|
1838
1864
|
) : emptyState && !hasActiveFilters ? (
|
|
1839
1865
|
emptyState
|
|
@@ -1910,7 +1936,7 @@ export function DynamicTable({
|
|
|
1910
1936
|
stacks its columns as label : value pairs with the row actions
|
|
1911
1937
|
pinned at the bottom. */}
|
|
1912
1938
|
<div ref={infMobileRoot} className='flex flex-1 min-h-0 flex-col gap-2 overflow-y-auto sm:hidden'>
|
|
1913
|
-
{
|
|
1939
|
+
{showDataSkeleton ? (
|
|
1914
1940
|
Array.from({ length: 5 }).map((_, i) => (
|
|
1915
1941
|
<div key={i} className='rounded-lg border bg-card p-3'>
|
|
1916
1942
|
<Skeleton className='h-4 w-24' />
|
|
@@ -2036,11 +2062,11 @@ export function DynamicTable({
|
|
|
2036
2062
|
<h3 className='text-base font-semibold text-foreground' role='alert'>{t('dynamic.forbidden_title', { defaultValue: 'Sin permiso para ver este módulo' })}</h3>
|
|
2037
2063
|
<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>
|
|
2038
2064
|
</>
|
|
2039
|
-
) :
|
|
2065
|
+
) : showLoadError ? (
|
|
2040
2066
|
<>
|
|
2041
2067
|
<h3 className='text-base font-semibold text-foreground' role='alert'>{t('dynamic.load_error_title', { defaultValue: 'No se pudieron cargar los datos' })}</h3>
|
|
2042
2068
|
<p className='text-sm text-muted-foreground'>{t('dynamic.load_error_hint', { defaultValue: 'Ocurrió un error al consultar la lista. Inténtalo de nuevo.' })}</p>
|
|
2043
|
-
<Button variant='outline' size='sm' onClick={
|
|
2069
|
+
<Button variant='outline' size='sm' onClick={retryLoad}>{t('dynamic.retry', { defaultValue: 'Reintentar' })}</Button>
|
|
2044
2070
|
</>
|
|
2045
2071
|
) : emptyState && !hasActiveFilters ? (
|
|
2046
2072
|
emptyState
|
package/src/host-api-client.ts
CHANGED
|
@@ -22,6 +22,17 @@ export { ApiError, isAbortError }
|
|
|
22
22
|
export interface HostRequestConfig {
|
|
23
23
|
params?: HostApiParams
|
|
24
24
|
signal?: AbortSignal
|
|
25
|
+
/**
|
|
26
|
+
* Extra headers for this call (e.g. `X-Correlation-ID`), merged over the
|
|
27
|
+
* client's `defaultHeaders`. The host drops Authorization, X-Organization-ID
|
|
28
|
+
* and the other headers it owns; they can never be overridden from here.
|
|
29
|
+
*/
|
|
30
|
+
headers?: Record<string, string>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface HostApiClientOptions {
|
|
34
|
+
/** Headers sent on every call; per-call `headers` win over them. */
|
|
35
|
+
defaultHeaders?: Record<string, string>
|
|
25
36
|
}
|
|
26
37
|
|
|
27
38
|
/** Minimal axios-like surface (what DynamicSelectField & co. call). */
|
|
@@ -83,7 +94,13 @@ function toApiError(e: unknown, signal?: AbortSignal): Error {
|
|
|
83
94
|
}
|
|
84
95
|
|
|
85
96
|
/** Build the client over the host-injected {@link HostApi}. */
|
|
86
|
-
export function createHostApiClient(api: HostApi): HostApiClient {
|
|
97
|
+
export function createHostApiClient(api: HostApi, options: HostApiClientOptions = {}): HostApiClient {
|
|
98
|
+
const defaults = options.defaultHeaders
|
|
99
|
+
// Additive: without defaults or per-call headers the config is untouched.
|
|
100
|
+
const cfg = <C extends HostRequestConfig | undefined>(c: C): C => {
|
|
101
|
+
if (!defaults) return c
|
|
102
|
+
return { ...(c ?? {}), headers: { ...defaults, ...(c?.headers ?? {}) } } as C
|
|
103
|
+
}
|
|
87
104
|
const run = async <R,>(p: () => Promise<R>, signal?: AbortSignal): Promise<R> => {
|
|
88
105
|
try {
|
|
89
106
|
return await p()
|
|
@@ -95,15 +112,15 @@ export function createHostApiClient(api: HostApi): HostApiClient {
|
|
|
95
112
|
run(async () => unwrapEnvelope<T>(await p()), signal)
|
|
96
113
|
|
|
97
114
|
const client: HostApiClient = {
|
|
98
|
-
get: (path, c) => body(() => api.get(path, c), c?.signal),
|
|
99
|
-
post: (path, b, c) => body(() => api.post(path, b, c), c?.signal),
|
|
100
|
-
put: (path, b, c) => body(() => api.put(path, b, c), c?.signal),
|
|
101
|
-
patch: (path, b, c) => body(() => api.patch(path, b, c), c?.signal),
|
|
102
|
-
delete: (path, c) => body(() => api.delete(path, c), c?.signal),
|
|
115
|
+
get: (path, c) => body(() => api.get(path, cfg(c)), c?.signal),
|
|
116
|
+
post: (path, b, c) => body(() => api.post(path, b, cfg(c)), c?.signal),
|
|
117
|
+
put: (path, b, c) => body(() => api.put(path, b, cfg(c)), c?.signal),
|
|
118
|
+
patch: (path, b, c) => body(() => api.patch(path, b, cfg(c)), c?.signal),
|
|
119
|
+
delete: (path, c) => body(() => api.delete(path, cfg(c)), c?.signal),
|
|
103
120
|
list: (path, c) =>
|
|
104
|
-
run(async () => unwrapList(await api.get(path, c)), c?.signal),
|
|
121
|
+
run(async () => unwrapList(await api.get(path, cfg(c))), c?.signal),
|
|
105
122
|
blob: (path, c) =>
|
|
106
|
-
run(() => api.get<Blob>(path, { ...c, responseType: 'blob' }), c?.signal),
|
|
123
|
+
run(() => api.get<Blob>(path, { ...cfg(c), responseType: 'blob' }), c?.signal),
|
|
107
124
|
upload: (path, file, fields, opts) => {
|
|
108
125
|
let form: FormData
|
|
109
126
|
if (typeof FormData !== 'undefined' && file instanceof FormData) {
|
|
@@ -113,7 +130,7 @@ export function createHostApiClient(api: HostApi): HostApiClient {
|
|
|
113
130
|
form.append(opts?.fileField ?? 'file', file as Blob)
|
|
114
131
|
for (const [k, v] of Object.entries(fields ?? {})) form.append(k, v)
|
|
115
132
|
}
|
|
116
|
-
return body(() => api.post(path, form, opts?.signal ? { signal: opts.signal } : undefined), opts?.signal)
|
|
133
|
+
return body(() => api.post(path, form, cfg(opts?.signal ? { signal: opts.signal } : undefined)), opts?.signal)
|
|
117
134
|
},
|
|
118
135
|
axiosLike: () => {
|
|
119
136
|
// Envelope kept (the runtime-react fields unwrap it themselves),
|
|
@@ -125,11 +142,11 @@ export function createHostApiClient(api: HostApi): HostApiClient {
|
|
|
125
142
|
return { data }
|
|
126
143
|
}, signal)
|
|
127
144
|
return {
|
|
128
|
-
get: (u, c) => raw(() => api.get(u, c), c?.signal),
|
|
129
|
-
post: (u, b, c) => raw(() => api.post(u, b, c), c?.signal),
|
|
130
|
-
put: (u, b, c) => raw(() => api.put(u, b, c), c?.signal),
|
|
131
|
-
patch: (u, b, c) => raw(() => api.patch(u, b, c), c?.signal),
|
|
132
|
-
delete: (u, c) => raw(() => api.delete(u, c), c?.signal),
|
|
145
|
+
get: (u, c) => raw(() => api.get(u, cfg(c)), c?.signal),
|
|
146
|
+
post: (u, b, c) => raw(() => api.post(u, b, cfg(c)), c?.signal),
|
|
147
|
+
put: (u, b, c) => raw(() => api.put(u, b, cfg(c)), c?.signal),
|
|
148
|
+
patch: (u, b, c) => raw(() => api.patch(u, b, cfg(c)), c?.signal),
|
|
149
|
+
delete: (u, c) => raw(() => api.delete(u, cfg(c)), c?.signal),
|
|
133
150
|
}
|
|
134
151
|
},
|
|
135
152
|
}
|
package/src/host-api.ts
CHANGED
|
@@ -77,12 +77,64 @@ function safeData(data: unknown): unknown {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Headers the host owns. A remote may add headers but never set these: they
|
|
82
|
+
* carry the credentials, the tenant scope or transport framing. Compared
|
|
83
|
+
* lowercase.
|
|
84
|
+
*/
|
|
85
|
+
export const PROTECTED_HOST_HEADERS: ReadonlySet<string> = new Set([
|
|
86
|
+
'authorization',
|
|
87
|
+
'proxy-authorization',
|
|
88
|
+
'cookie',
|
|
89
|
+
'x-organization-id',
|
|
90
|
+
'x-org-id',
|
|
91
|
+
'x-branch-id',
|
|
92
|
+
'accept-language',
|
|
93
|
+
'host',
|
|
94
|
+
'content-length',
|
|
95
|
+
'content-type',
|
|
96
|
+
'transfer-encoding',
|
|
97
|
+
'origin',
|
|
98
|
+
'referer',
|
|
99
|
+
// Reenvio / identidad de origen: el backend arma URLs publicas y decide
|
|
100
|
+
// tenant a partir de ellas.
|
|
101
|
+
'x-forwarded-host',
|
|
102
|
+
'x-forwarded-proto',
|
|
103
|
+
'x-forwarded-for',
|
|
104
|
+
'x-forwarded-port',
|
|
105
|
+
'forwarded',
|
|
106
|
+
'x-real-ip',
|
|
107
|
+
'x-storefront-domain',
|
|
108
|
+
'x-api-key',
|
|
109
|
+
'x-http-method-override',
|
|
110
|
+
])
|
|
111
|
+
const PROTECTED_HEADER_PREFIXES = ['proxy-']
|
|
112
|
+
|
|
113
|
+
/** Drop protected / malformed headers; returns undefined when none remain. */
|
|
114
|
+
export function sanitizeRemoteHeaders(
|
|
115
|
+
headers: Record<string, string> | undefined,
|
|
116
|
+
): Record<string, string> | undefined {
|
|
117
|
+
if (!headers || typeof headers !== 'object') return undefined
|
|
118
|
+
const out: Record<string, string> = {}
|
|
119
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
120
|
+
if (typeof value !== 'string') continue
|
|
121
|
+
if (!/^[A-Za-z0-9!#$%&'*+.^_`|~-]+$/.test(name)) continue
|
|
122
|
+
if (/[\r\n]/.test(value)) continue
|
|
123
|
+
const lower = name.toLowerCase()
|
|
124
|
+
if (PROTECTED_HOST_HEADERS.has(lower) || PROTECTED_HEADER_PREFIXES.some((p) => lower.startsWith(p))) continue
|
|
125
|
+
out[name] = value
|
|
126
|
+
}
|
|
127
|
+
return Object.keys(out).length ? out : undefined
|
|
128
|
+
}
|
|
129
|
+
|
|
80
130
|
function toConfig(opts?: HostApiRequestOptions): Record<string, unknown> | undefined {
|
|
81
131
|
if (!opts) return undefined
|
|
82
132
|
const config: Record<string, unknown> = {}
|
|
83
133
|
if (opts.params) config.params = opts.params
|
|
84
134
|
if (opts.signal) config.signal = opts.signal
|
|
85
135
|
if (opts.responseType === 'blob') config.responseType = 'blob'
|
|
136
|
+
const headers = sanitizeRemoteHeaders(opts.headers)
|
|
137
|
+
if (headers) config.headers = headers
|
|
86
138
|
return config
|
|
87
139
|
}
|
|
88
140
|
|
|
@@ -131,7 +183,8 @@ export function createHostApi(client: ApiClient, options: CreateHostApiOptions =
|
|
|
131
183
|
return Object.freeze({
|
|
132
184
|
get: <T,>(path: string, opts?: HostApiRequestOptions) => {
|
|
133
185
|
const args = withConfig([path], opts) as [string, { params?: Record<string, unknown> }?]
|
|
134
|
-
|
|
186
|
+
// A GET with per-call headers cannot share a POST /q: it goes on its own.
|
|
187
|
+
const batch = options.batchGets && opts?.responseType !== 'blob' && !sanitizeRemoteHeaders(opts?.headers)
|
|
135
188
|
return bodyOf<T>(batch ? batchGet(client, ...args) : client.get(...args), opts)
|
|
136
189
|
},
|
|
137
190
|
post: <T,>(path: string, body?: unknown, opts?: HostApiRequestOptions) =>
|
package/src/index.ts
CHANGED
|
@@ -304,11 +304,12 @@ export {
|
|
|
304
304
|
type PageChromeState,
|
|
305
305
|
type PageChromeStore,
|
|
306
306
|
} from './addon-page-host'
|
|
307
|
-
export { createHostApi, toHostApiError, type CreateHostApiOptions } from './host-api'
|
|
307
|
+
export { createHostApi, toHostApiError, sanitizeRemoteHeaders, PROTECTED_HOST_HEADERS, type CreateHostApiOptions } from './host-api'
|
|
308
308
|
export { HostApiProvider, type HostApiProviderProps } from './host-api-context'
|
|
309
309
|
export {
|
|
310
310
|
createHostApiClient,
|
|
311
311
|
type HostApiClient,
|
|
312
|
+
type HostApiClientOptions,
|
|
312
313
|
type HostRequestConfig,
|
|
313
314
|
type AxiosLikeClient,
|
|
314
315
|
} from './host-api-client'
|
|
@@ -910,3 +911,6 @@ export type { BulkImageTarget } from './bulk-image-target'
|
|
|
910
911
|
export type { BatchLog as BulkImageBatchLog } from './bulk-image-import'
|
|
911
912
|
export * from './attention'
|
|
912
913
|
export * from './view-system'
|
|
914
|
+
|
|
915
|
+
export { useModelLabels, resolveModelLabels, defaultSingular } from './model-labels'
|
|
916
|
+
export type { ModelLabels, ModelLabelInput, ModelLabelT } from './model-labels'
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { useTranslation } from 'react-i18next'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Model-driven labels. A backend often ships generic/English titles
|
|
6
|
+
* ("Clients", "New Client"); the SDK resolves them through i18n from the model
|
|
7
|
+
* key so the host can translate (or rebrand) per model without touching code:
|
|
8
|
+
*
|
|
9
|
+
* models.<model>.title -> list/page title ("Clientes")
|
|
10
|
+
* models.<model>.singular -> singular name ("Cliente")
|
|
11
|
+
* models.<model>.new -> create button label ("Nuevo cliente")
|
|
12
|
+
*
|
|
13
|
+
* Every key is looked up in the host's i18n resources (also addon namespaces
|
|
14
|
+
* merged by `I18nProvider`). Order: explicit override > `titleKey` from
|
|
15
|
+
* metadata > `models.<model>.*` > backend text > generic fallback. When no
|
|
16
|
+
* `models.<model>.new` exists the label is `common.new_model` interpolated
|
|
17
|
+
* with the singular name (`{{prefix}} {{name}}`), prefix overridable via
|
|
18
|
+
* `common.new`.
|
|
19
|
+
*/
|
|
20
|
+
export type ModelLabelT = (key: string, opts?: Record<string, unknown>) => string
|
|
21
|
+
|
|
22
|
+
export interface ModelLabelInput {
|
|
23
|
+
model: string
|
|
24
|
+
/** Backend title (already possibly localized). */
|
|
25
|
+
title?: string
|
|
26
|
+
/** Backend i18n key for the title (`titleKey`/`title_key`). */
|
|
27
|
+
titleKey?: string
|
|
28
|
+
/** Prefix fallback for the create label when nothing translates (default "New"). */
|
|
29
|
+
newPrefix?: string
|
|
30
|
+
titleOverride?: string
|
|
31
|
+
newLabelOverride?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ModelLabels {
|
|
35
|
+
title: string
|
|
36
|
+
singular: string
|
|
37
|
+
newLabel: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const MISSING = '\u0000'
|
|
41
|
+
|
|
42
|
+
/** Returns the translation or undefined when the key has no value. */
|
|
43
|
+
function tryKey(t: ModelLabelT, key: string | undefined): string | undefined {
|
|
44
|
+
if (!key) return undefined
|
|
45
|
+
const v = t(key, { defaultValue: MISSING })
|
|
46
|
+
return v && v !== MISSING && v !== key ? v : undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function defaultSingular(title: string): string {
|
|
50
|
+
const s = title.replace(/s$/i, '')
|
|
51
|
+
return s.charAt(0).toUpperCase() + s.slice(1)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function resolveModelLabels(t: ModelLabelT, input: ModelLabelInput): ModelLabels {
|
|
55
|
+
const { model } = input
|
|
56
|
+
const title =
|
|
57
|
+
input.titleOverride ??
|
|
58
|
+
tryKey(t, input.titleKey) ??
|
|
59
|
+
tryKey(t, `models.${model}.title`) ??
|
|
60
|
+
input.title ??
|
|
61
|
+
model
|
|
62
|
+
const singular =
|
|
63
|
+
tryKey(t, `models.${model}.singular`) ?? defaultSingular(title)
|
|
64
|
+
const newLabel =
|
|
65
|
+
input.newLabelOverride ??
|
|
66
|
+
tryKey(t, `models.${model}.new`) ??
|
|
67
|
+
`${tryKey(t, 'common.new') ?? input.newPrefix ?? 'New'} ${singular}`
|
|
68
|
+
return { title, singular, newLabel }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Hook form of {@link resolveModelLabels}, bound to the active i18n instance. */
|
|
72
|
+
export function useModelLabels(input: ModelLabelInput): ModelLabels {
|
|
73
|
+
const { t, i18n } = useTranslation()
|
|
74
|
+
const { model, title, titleKey, newPrefix, titleOverride, newLabelOverride } = input
|
|
75
|
+
return useMemo(
|
|
76
|
+
() => resolveModelLabels(t as unknown as ModelLabelT, { model, title, titleKey, newPrefix, titleOverride, newLabelOverride }),
|
|
77
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
+
[t, i18n?.language, model, title, titleKey, newPrefix, titleOverride, newLabelOverride],
|
|
79
|
+
)
|
|
80
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -198,6 +198,9 @@ export interface AuditMeta {
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
export interface TableMetadata {
|
|
201
|
+
/** i18n key for `title` (host resources win over the raw backend text). */
|
|
202
|
+
titleKey?: string
|
|
203
|
+
title_key?: string
|
|
201
204
|
title: string
|
|
202
205
|
endpoint: string
|
|
203
206
|
columns: ColumnDefinition[]
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { useMemo } from 'react'
|
|
2
2
|
import { useHostApi } from './addon-page-host'
|
|
3
|
-
import { createHostApiClient, type HostApiClient } from './host-api-client'
|
|
3
|
+
import { createHostApiClient, type HostApiClient, type HostApiClientOptions } from './host-api-client'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The addon's HTTP client, built over the host-injected HostApi. Works inside
|
|
7
7
|
* <AddonPageHost> (pages) and <HostApiProvider> (modals, pickers). Without a
|
|
8
8
|
* host it throws a clear error: there is no localStorage / fetch fallback.
|
|
9
9
|
*/
|
|
10
|
-
export function useHostApiClient(): HostApiClient {
|
|
10
|
+
export function useHostApiClient(options?: HostApiClientOptions): HostApiClient {
|
|
11
11
|
const api = useHostApi()
|
|
12
|
-
|
|
12
|
+
const key = options?.defaultHeaders ? JSON.stringify(options.defaultHeaders) : ''
|
|
13
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
|
+
return useMemo(() => createHostApiClient(api, options), [api, key])
|
|
13
15
|
}
|