@openmrs/esm-report-builder 0.1.1-pre.101
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/.eslintignore +5 -0
- package/.eslintrc.js +19 -0
- package/.prettierrc +8 -0
- package/.tx/config +12 -0
- package/LICENSE +401 -0
- package/README.md +336 -0
- package/__mocks__/react-i18next.js +12 -0
- package/dist/128.css +1 -0
- package/dist/128.css.map +1 -0
- package/dist/128.js +338 -0
- package/dist/128.js.map +1 -0
- package/dist/1480.js +1 -0
- package/dist/1480.js.map +1 -0
- package/dist/1646.js +1 -0
- package/dist/1646.js.map +1 -0
- package/dist/1869.js +1 -0
- package/dist/1869.js.map +1 -0
- package/dist/1877.js +1 -0
- package/dist/1877.js.map +1 -0
- package/dist/2131.js +1 -0
- package/dist/2131.js.map +1 -0
- package/dist/2317.js +1 -0
- package/dist/2317.js.map +1 -0
- package/dist/2408.js +1 -0
- package/dist/2408.js.map +1 -0
- package/dist/2416.js +1 -0
- package/dist/2416.js.map +1 -0
- package/dist/282.js +1 -0
- package/dist/282.js.map +1 -0
- package/dist/2881.js +1 -0
- package/dist/2881.js.map +1 -0
- package/dist/2997.js +1 -0
- package/dist/2997.js.map +1 -0
- package/dist/3378.js +1 -0
- package/dist/3378.js.map +1 -0
- package/dist/3963.js +1 -0
- package/dist/3963.js.map +1 -0
- package/dist/4106.js +1 -0
- package/dist/4106.js.map +1 -0
- package/dist/4111.js +1 -0
- package/dist/4111.js.map +1 -0
- package/dist/4171.css +1 -0
- package/dist/4171.css.map +1 -0
- package/dist/4171.js +43 -0
- package/dist/4171.js.map +1 -0
- package/dist/434.js +1 -0
- package/dist/434.js.map +1 -0
- package/dist/4348.js +1 -0
- package/dist/4348.js.map +1 -0
- package/dist/4383.js +1 -0
- package/dist/4383.js.map +1 -0
- package/dist/4658.js +1 -0
- package/dist/4658.js.map +1 -0
- package/dist/4668.js +1 -0
- package/dist/4668.js.map +1 -0
- package/dist/4928.js +1 -0
- package/dist/4928.js.map +1 -0
- package/dist/5098.js +1 -0
- package/dist/5098.js.map +1 -0
- package/dist/5117.js +1 -0
- package/dist/5117.js.map +1 -0
- package/dist/5132.js +1 -0
- package/dist/5132.js.map +1 -0
- package/dist/5145.js +1 -0
- package/dist/5145.js.map +1 -0
- package/dist/550.js +1 -0
- package/dist/550.js.map +1 -0
- package/dist/5503.js +1 -0
- package/dist/5503.js.map +1 -0
- package/dist/556.js +1 -0
- package/dist/556.js.map +1 -0
- package/dist/5644.js +1 -0
- package/dist/5644.js.map +1 -0
- package/dist/5940.js +1 -0
- package/dist/5940.js.map +1 -0
- package/dist/6047.js +1 -0
- package/dist/6047.js.map +1 -0
- package/dist/6237.js +1 -0
- package/dist/6237.js.map +1 -0
- package/dist/6371.js +1 -0
- package/dist/6371.js.map +1 -0
- package/dist/6377.js +1 -0
- package/dist/6377.js.map +1 -0
- package/dist/6444.js +1 -0
- package/dist/6444.js.map +1 -0
- package/dist/6508.js +1 -0
- package/dist/6508.js.map +1 -0
- package/dist/6652.js +1 -0
- package/dist/6652.js.map +1 -0
- package/dist/6686.js +1 -0
- package/dist/6686.js.map +1 -0
- package/dist/6724.js +1 -0
- package/dist/6724.js.map +1 -0
- package/dist/6867.js +19 -0
- package/dist/6867.js.map +1 -0
- package/dist/6904.js +1 -0
- package/dist/6904.js.map +1 -0
- package/dist/7045.js +1 -0
- package/dist/7045.js.map +1 -0
- package/dist/7175.js +1 -0
- package/dist/7175.js.map +1 -0
- package/dist/7182.js +1 -0
- package/dist/7182.js.map +1 -0
- package/dist/7475.js +1 -0
- package/dist/7475.js.map +1 -0
- package/dist/7742.js +1 -0
- package/dist/7742.js.map +1 -0
- package/dist/7912.js +1 -0
- package/dist/7912.js.map +1 -0
- package/dist/8251.js +1 -0
- package/dist/8251.js.map +1 -0
- package/dist/8358.js +1 -0
- package/dist/8358.js.map +1 -0
- package/dist/8359.js +1 -0
- package/dist/8359.js.map +1 -0
- package/dist/8695.js +1 -0
- package/dist/8695.js.map +1 -0
- package/dist/903.js +1 -0
- package/dist/903.js.map +1 -0
- package/dist/9072.js +1 -0
- package/dist/9072.js.map +1 -0
- package/dist/9806.js +1 -0
- package/dist/9806.js.map +1 -0
- package/dist/997.js +1 -0
- package/dist/997.js.map +1 -0
- package/dist/openmrs-esm-report-builder.js +3 -0
- package/dist/openmrs-esm-report-builder.js.buildmanifest.json +1433 -0
- package/dist/openmrs-esm-report-builder.js.map +1 -0
- package/dist/routes.json +1 -0
- package/e2e/core/env.ts +5 -0
- package/e2e/core/global-setup.ts +34 -0
- package/e2e/core/test.ts +21 -0
- package/e2e/pages/app-shell.page.ts +35 -0
- package/e2e/pages/etl-sources.page.ts +36 -0
- package/e2e/pages/report-sections.page.ts +21 -0
- package/e2e/pages/section-preview.modal.ts +29 -0
- package/e2e/specs/etl-sources.spec.ts +51 -0
- package/e2e/specs/navigation.spec.ts +13 -0
- package/e2e/specs/section-preview-validation.spec.ts +38 -0
- package/e2e/specs/section-preview.spec.ts +94 -0
- package/e2e/support/github/Dockerfile +32 -0
- package/e2e/support/github/Dockerfile.dockerignore +13 -0
- package/e2e/support/github/docker-compose.yml +31 -0
- package/e2e/support/github/run-e2e-docker-env.sh +131 -0
- package/e2e/support/github/spa-assemble-config.json +6 -0
- package/e2e/tsconfig.json +11 -0
- package/example.env +5 -0
- package/linelist_report_builder_design_spec.md +816 -0
- package/package.json +98 -0
- package/playwright.config.ts +28 -0
- package/rspack.config.js +2 -0
- package/src/__debug__/all-designs.test.tsx +33 -0
- package/src/admin-card-link.extension.module.scss +55 -0
- package/src/admin-card-link.extension.tsx +24 -0
- package/src/components/admin/admin-page.component.tsx +75 -0
- package/src/components/admin/age-categories-page.component.tsx +109 -0
- package/src/components/admin/age-groups-page.component.tsx +146 -0
- package/src/components/admin/etl-browser/columns-tab.component.tsx +80 -0
- package/src/components/admin/etl-browser/etl-browser-page.component.tsx +309 -0
- package/src/components/admin/etl-browser/etl-browser.component.scss +424 -0
- package/src/components/admin/etl-browser/metadata-tab.component.tsx +65 -0
- package/src/components/admin/etl-browser/preview-grid.component.tsx +189 -0
- package/src/components/admin/etl-browser/relationships-tab.component.tsx +21 -0
- package/src/components/admin/etl-browser/sources-tree.component.tsx +118 -0
- package/src/components/admin/etl-browser/table-detail.component.tsx +124 -0
- package/src/components/admin/etl-browser/table-info-strip.component.tsx +51 -0
- package/src/components/admin/etl-browser/table-list.component.tsx +136 -0
- package/src/components/admin/etl-browser/use-table-preview.ts +47 -0
- package/src/components/admin/etl-sources-page.component.tsx +355 -0
- package/src/components/admin/etl-tasks-page.component.scss +370 -0
- package/src/components/admin/etl-tasks-page.component.tsx +768 -0
- package/src/components/admin/report-categories-page.component.tsx +267 -0
- package/src/components/admin/report-library-page.component.tsx +551 -0
- package/src/components/ai-support/ai-assist-button.component.tsx +30 -0
- package/src/components/ai-support/ai-assist-modal.component.tsx +81 -0
- package/src/components/ai-support/ai.service.ts +21 -0
- package/src/components/ai-support/ai.types.ts +12 -0
- package/src/components/app-shell/report-builder-shell.component.tsx +242 -0
- package/src/components/app-shell/report-builder-shell.scss +18 -0
- package/src/components/dashboards/dashboard-config.schema.ts +97 -0
- package/src/components/dashboards/dashboard-form-modal.component.tsx +150 -0
- package/src/components/dashboards/dashboards-admin.scss +62 -0
- package/src/components/dashboards/dashboards-page.component.tsx +153 -0
- package/src/components/dashboards/dashboards-table.component.tsx +130 -0
- package/src/components/dashboards/sections/dashboard-autoinclude.section.tsx +75 -0
- package/src/components/dashboards/sections/dashboard-basics.section.tsx +80 -0
- package/src/components/dashboards/sections/dashboard-json.section.tsx +79 -0
- package/src/components/dashboards/sections/dashboard-sections-editor.section.tsx +130 -0
- package/src/components/dashboards/sections/dashboard-widgets-editor.section.tsx +184 -0
- package/src/components/data-themes/data-theme-form.component.tsx +59 -0
- package/src/components/data-themes/data-theme-modal.component.tsx +349 -0
- package/src/components/data-themes/data-themes-page.component.tsx +139 -0
- package/src/components/data-themes/data-themes-table.component.tsx +98 -0
- package/src/components/data-themes/icon-registry.ts +35 -0
- package/src/components/data-themes/sections/data-theme-basics.section.tsx +63 -0
- package/src/components/data-themes/sections/data-theme-condition-columns.section.tsx +397 -0
- package/src/components/data-themes/sections/data-theme-fields-editor.section.tsx +125 -0
- package/src/components/data-themes/sections/data-theme-metadata.section.tsx +245 -0
- package/src/components/data-themes/sections/data-theme-preview.section.tsx +115 -0
- package/src/components/data-themes/sections/data-theme-source.section.tsx +184 -0
- package/src/components/data-visualizer/components/cqi-components/cqi-data-table.component.tsx +214 -0
- package/src/components/data-visualizer/components/cqi-components/cqi-elements.ts +203 -0
- package/src/components/data-visualizer/components/cqi-components/detail.component.tsx +110 -0
- package/src/components/data-visualizer/components/cqi-components/detail.scss +22 -0
- package/src/components/data-visualizer/components/data-table/data-table.component.tsx +208 -0
- package/src/components/data-visualizer/components/data-table/data-tables.scss +206 -0
- package/src/components/data-visualizer/components/empty-state/empty-state-illustration.component.tsx +53 -0
- package/src/components/data-visualizer/components/header/header.component.tsx +43 -0
- package/src/components/data-visualizer/components/header/header.scss +71 -0
- package/src/components/data-visualizer/components/model/confirm.component.tsx +40 -0
- package/src/components/data-visualizer/components/panel/panel.component.tsx +20 -0
- package/src/components/data-visualizer/components/panel/panel.scss +25 -0
- package/src/components/data-visualizer/components/popover/modifier-panel.tsx +53 -0
- package/src/components/data-visualizer/constants.ts +445 -0
- package/src/components/data-visualizer/data-visualizer-illustration.component.tsx +31 -0
- package/src/components/data-visualizer/data-visualizer.component.tsx +1935 -0
- package/src/components/data-visualizer/data-visualizer.resource.ts +462 -0
- package/src/components/data-visualizer/data-visualizer.scss +448 -0
- package/src/components/data-visualizer/declarations.d.ts +131 -0
- package/src/components/data-visualizer/parameter-inputs/boolean-parameter-input.component.tsx +34 -0
- package/src/components/data-visualizer/parameter-inputs/concept-parameter-input.component.tsx +81 -0
- package/src/components/data-visualizer/parameter-inputs/date-parameter-input.component.tsx +110 -0
- package/src/components/data-visualizer/parameter-inputs/date-range-input.component.scss +47 -0
- package/src/components/data-visualizer/parameter-inputs/date-range-input.component.tsx +228 -0
- package/src/components/data-visualizer/parameter-inputs/identifier-type-parameter-input.component.tsx +69 -0
- package/src/components/data-visualizer/parameter-inputs/list-parameter-input.component.tsx +73 -0
- package/src/components/data-visualizer/parameter-inputs/location-parameter-input.component.tsx +81 -0
- package/src/components/data-visualizer/parameter-inputs/number-parameter-input.component.tsx +40 -0
- package/src/components/data-visualizer/parameter-inputs/person-attribute-parameter-input.component.tsx +71 -0
- package/src/components/data-visualizer/parameter-inputs/text-parameter-input.component.tsx +52 -0
- package/src/components/data-visualizer/report-parameter-modal.component.tsx +383 -0
- package/src/components/data-visualizer/types.ts +206 -0
- package/src/components/etl-monitor/builder/builder-state-machine.ts +381 -0
- package/src/components/etl-monitor/builder/design-registry.tsx +139 -0
- package/src/components/etl-monitor/builder/etl-monitor-builder-context.tsx +702 -0
- package/src/components/etl-monitor/builder/etl-monitor-builder-modal.component.tsx +461 -0
- package/src/components/etl-monitor/builder/etl-monitor-builder-modal.scss +256 -0
- package/src/components/etl-monitor/builder/etl-monitor-builder-page.component.tsx +387 -0
- package/src/components/etl-monitor/builder/etl-monitor-builder-page.scss +976 -0
- package/src/components/etl-monitor/builder/generated-config-panel.component.tsx +168 -0
- package/src/components/etl-monitor/builder/generated-config-panel.scss +198 -0
- package/src/components/etl-monitor/builder/index.ts +5 -0
- package/src/components/etl-monitor/builder/monitor-preview.tsx +124 -0
- package/src/components/etl-monitor/builder/steps/data-source-step.component.tsx +667 -0
- package/src/components/etl-monitor/builder/steps/data-source-step.scss +284 -0
- package/src/components/etl-monitor/builder/steps/design-samples.ts +278 -0
- package/src/components/etl-monitor/builder/steps/design-step.component.tsx +299 -0
- package/src/components/etl-monitor/builder/steps/design-step.scss +479 -0
- package/src/components/etl-monitor/builder/steps/fields-step.component.tsx +859 -0
- package/src/components/etl-monitor/builder/steps/fields-step.scss +459 -0
- package/src/components/etl-monitor/builder/steps/general-step.component.tsx +288 -0
- package/src/components/etl-monitor/builder/steps/general-step.scss +103 -0
- package/src/components/etl-monitor/builder/steps/index.ts +5 -0
- package/src/components/etl-monitor/builder/steps/preview-step.component.tsx +245 -0
- package/src/components/etl-monitor/builder/steps/preview-step.scss +236 -0
- package/src/components/etl-monitor/etl-monitor-card-shell.component.tsx +154 -0
- package/src/components/etl-monitor/etl-monitor-card-shell.scss +103 -0
- package/src/components/etl-monitor/etl-monitor-dashboard.component.tsx +227 -0
- package/src/components/etl-monitor/etl-monitor-dashboard.scss +148 -0
- package/src/components/etl-monitor/etl-monitor-status-card.component.tsx +192 -0
- package/src/components/etl-monitor/etl-monitors-page.component.tsx +621 -0
- package/src/components/etl-monitor/renderers/DetailsRenderer.tsx +2 -0
- package/src/components/etl-monitor/renderers/ErrorLogRenderer.tsx +2 -0
- package/src/components/etl-monitor/renderers/EtlMonitorWidget.tsx +97 -0
- package/src/components/etl-monitor/renderers/MetricsGridRenderer.tsx +2 -0
- package/src/components/etl-monitor/renderers/MonitorRenderer.tsx +175 -0
- package/src/components/etl-monitor/renderers/ProgressRenderer.tsx +2 -0
- package/src/components/etl-monitor/renderers/StatusCardRenderer.tsx +2 -0
- package/src/components/etl-monitor/renderers/SummaryCardRenderer.tsx +2 -0
- package/src/components/etl-monitor/renderers/TableRenderer.tsx +2 -0
- package/src/components/etl-monitor/renderers/component-icons.tsx +33 -0
- package/src/components/etl-monitor/renderers/components/details-renderer.tsx +195 -0
- package/src/components/etl-monitor/renderers/components/error-log-renderer.tsx +104 -0
- package/src/components/etl-monitor/renderers/components/index.ts +6 -0
- package/src/components/etl-monitor/renderers/components/log-renderer.tsx +86 -0
- package/src/components/etl-monitor/renderers/components/metrics-grid-renderer.tsx +133 -0
- package/src/components/etl-monitor/renderers/components/progress-renderer.tsx +188 -0
- package/src/components/etl-monitor/renderers/components/status-card-renderer.tsx +247 -0
- package/src/components/etl-monitor/renderers/components/summary-card-renderer.tsx +160 -0
- package/src/components/etl-monitor/renderers/components/table-renderer.tsx +175 -0
- package/src/components/etl-monitor/renderers/components/time-series-renderer.tsx +310 -0
- package/src/components/etl-monitor/renderers/data-transformer.ts +361 -0
- package/src/components/etl-monitor/renderers/index.ts +11 -0
- package/src/components/etl-monitor/renderers/legacy-monitor-renderer.tsx +69 -0
- package/src/components/etl-monitor/renderers/monitor-renderer.tsx +6 -0
- package/src/components/etl-monitor/renderers/monitor-renderers.scss +1621 -0
- package/src/components/etl-monitor/renderers/monitor-widget-card.component.tsx +54 -0
- package/src/components/etl-monitor/renderers/monitor-widget-card.scss +16 -0
- package/src/components/etl-monitor/renderers/v2-monitor-renderer.tsx +227 -0
- package/src/components/import-export/artifact-groups.ts +153 -0
- package/src/components/import-export/export-report-modal.component.tsx +265 -0
- package/src/components/import-export/import-export-page.component.tsx +610 -0
- package/src/components/import-export/import-export.styles.scss +825 -0
- package/src/components/import-export/import-package-modal.component.tsx +401 -0
- package/src/components/import-export/index.ts +3 -0
- package/src/components/indicators/README.md +24 -0
- package/src/components/indicators/base-indicator-basic-fields.component.tsx +18 -0
- package/src/components/indicators/base-indicator-basics.section.tsx +54 -0
- package/src/components/indicators/base-indicator-countby.section.tsx +25 -0
- package/src/components/indicators/base-indicator-criteria.section.tsx +83 -0
- package/src/components/indicators/base-indicator-details-form.component.tsx +80 -0
- package/src/components/indicators/base-indicator-theme-unit-fields.component.tsx +39 -0
- package/src/components/indicators/create-base-indicator-modal.component.tsx +623 -0
- package/src/components/indicators/create-composite-base-indicator-modal.component.tsx +295 -0
- package/src/components/indicators/create-custom-indicator-modal.component.tsx +548 -0
- package/src/components/indicators/create-final-indicator-modal.component.tsx +285 -0
- package/src/components/indicators/custom-condition-input.component.tsx +310 -0
- package/src/components/indicators/diagnosis-filters-form.component.tsx +101 -0
- package/src/components/indicators/disaggregation-panel.component.tsx +93 -0
- package/src/components/indicators/handler/concept-search-multiselect.component.tsx +153 -0
- package/src/components/indicators/handler/question-answer-concept-search.component.tsx +336 -0
- package/src/components/indicators/indicator-run-preview-modal.component.tsx +391 -0
- package/src/components/indicators/indicator-search-select.component.tsx +297 -0
- package/src/components/indicators/indicator-status-tag.component.tsx +9 -0
- package/src/components/indicators/indicators-page.component.tsx +673 -0
- package/src/components/indicators/indicators-page.scss +121 -0
- package/src/components/indicators/indicators-table.component.tsx +188 -0
- package/src/components/indicators/preview-table.component.tsx +31 -0
- package/src/components/indicators/sections/composite-indicator-basics.section.tsx +36 -0
- package/src/components/indicators/sections/composite-indicator-picker.section.tsx +116 -0
- package/src/components/indicators/sections/composite-indicator-sql-preview.section.tsx +31 -0
- package/src/components/indicators/sections/custom-indicator-basics.section.tsx +65 -0
- package/src/components/indicators/sections/custom-indicator-disaggregation.section.tsx +93 -0
- package/src/components/indicators/sections/custom-indicator-filters.section.tsx +203 -0
- package/src/components/indicators/sections/custom-indicator-population.section.tsx +107 -0
- package/src/components/indicators/sections/custom-indicator-sql-preview.section.tsx +108 -0
- package/src/components/indicators/sections/final-indicator-basics.section.tsx +46 -0
- package/src/components/indicators/sections/final-indicator-disaggregation.section.tsx +47 -0
- package/src/components/indicators/sections/final-indicator-picker.section.tsx +60 -0
- package/src/components/indicators/sections/final-indicator-preview.section.tsx +20 -0
- package/src/components/indicators/sections/final-indicator-results-preview.section.tsx +65 -0
- package/src/components/indicators/sections/indicator-basics.section.tsx +40 -0
- package/src/components/indicators/sections/indicator-conditions.section.tsx +279 -0
- package/src/components/indicators/sections/indicator-sql-preview.section.tsx +63 -0
- package/src/components/indicators/sections/indicator-theme.section.tsx +48 -0
- package/src/components/indicators/sql-preview.component.tsx +19 -0
- package/src/components/indicators/tag-input.component.tsx +177 -0
- package/src/components/indicators/types/base-indicator-form.types.ts +17 -0
- package/src/components/indicators/types/base-indicator-theme.constants.ts +8 -0
- package/src/components/indicators/types/composite-indicator.types.ts +27 -0
- package/src/components/indicators/types/condition-ui.types.ts +11 -0
- package/src/components/indicators/types/custom-indicator.types.ts +161 -0
- package/src/components/indicators/types/data-theme-config.types.ts +88 -0
- package/src/components/indicators/types/indicator-types.ts +57 -0
- package/src/components/indicators/types/sql-builders.ts +43 -0
- package/src/components/indicators/utils/composite-indicator-sql.utils.test.ts +143 -0
- package/src/components/indicators/utils/composite-indicator-sql.utils.ts +426 -0
- package/src/components/indicators/utils/concept-preload.utils.ts +21 -0
- package/src/components/indicators/utils/custom-indicator-interpreter.test.ts +493 -0
- package/src/components/indicators/utils/custom-indicator-interpreter.ts +702 -0
- package/src/components/indicators/utils/final-indicator-sql.utils.ts +190 -0
- package/src/components/indicators/utils/indicator-conditions-hydration.utils.ts +254 -0
- package/src/components/indicators/utils/indicator-sql-resolution.utils.ts +204 -0
- package/src/components/indicators/utils/indicator-sql.utils.ts +721 -0
- package/src/components/indicators/utils/population-sql.compiler.test.ts +985 -0
- package/src/components/indicators/utils/population-sql.compiler.ts +858 -0
- package/src/components/landing/landing-action-item.component.tsx +50 -0
- package/src/components/landing/landing-action-list.component.tsx +12 -0
- package/src/components/landing/landing-activity-list.component.tsx +47 -0
- package/src/components/landing/landing-footer-grid.component.tsx +45 -0
- package/src/components/landing/landing-hero.component.tsx +18 -0
- package/src/components/landing/landing-section-card.component.tsx +33 -0
- package/src/components/landing/report-builder-landing-page.component.tsx +186 -0
- package/src/components/landing/report-builder-landing-page.scss +131 -0
- package/src/components/legacy-reports/legacy-report-detail-page.component.tsx +300 -0
- package/src/components/legacy-reports/legacy-report-editor-page.component.tsx +324 -0
- package/src/components/legacy-reports/legacy-report-upload-modal.component.tsx +307 -0
- package/src/components/legacy-reports/legacy-reports-page.component.tsx +206 -0
- package/src/components/legacy-reports/legacy-reports-table.component.tsx +154 -0
- package/src/components/legacy-reports/tabs/legacy-report-datasets-tab.component.tsx +344 -0
- package/src/components/legacy-reports/tabs/legacy-report-dimensions-tab.component.tsx +590 -0
- package/src/components/legacy-reports/tabs/legacy-report-indicators-tab.component.tsx +490 -0
- package/src/components/legacy-reports/tabs/legacy-report-json-preview-tab.component.tsx +272 -0
- package/src/components/legacy-reports/tabs/legacy-report-overview-tab.component.tsx +218 -0
- package/src/components/legacy-reports/tabs/legacy-report-parameters-tab.component.tsx +279 -0
- package/src/components/linelist/definition/indicator-to-sql.utils.ts +281 -0
- package/src/components/linelist/definition/linelist-definition-editor.component.tsx +1676 -0
- package/src/components/linelist/definition/linelist-definition-editor.scss +461 -0
- package/src/components/linelist/definition/linelist-definition.types.ts +108 -0
- package/src/components/linelist/definition/panels/column-properties-panel.component.tsx +328 -0
- package/src/components/linelist/definition/panels/column-selector-panel.component.tsx +1082 -0
- package/src/components/linelist/definition/panels/column-selector-panel.scss +100 -0
- package/src/components/linelist/definition/panels/custom-sql-column-modal.component.tsx +248 -0
- package/src/components/linelist/definition/panels/encounter-diagnosis-column-modal.component.tsx +300 -0
- package/src/components/linelist/definition/panels/encounter-diagnosis-column-modal.scss +21 -0
- package/src/components/linelist/definition/panels/multi-datasource-selector.component.tsx +332 -0
- package/src/components/linelist/definition/panels/multi-datasource-selector.scss +161 -0
- package/src/components/linelist/definition/panels/observation-column-modal.component.tsx +450 -0
- package/src/components/linelist/definition/panels/observation-column-modal.scss +29 -0
- package/src/components/linelist/definition/panels/parameter-panel.component.tsx +659 -0
- package/src/components/linelist/definition/panels/parameter-panel.scss +64 -0
- package/src/components/linelist/definition/panels/population-source-selector.component.tsx +407 -0
- package/src/components/linelist/definition/panels/population-source-selector.scss +187 -0
- package/src/components/linelist/design/panels/column-category-selector.component.tsx +433 -0
- package/src/components/linelist/design/panels/column-category-selector.scss +324 -0
- package/src/components/linelist/design/panels/column-debug-panel.component.tsx +197 -0
- package/src/components/linelist/design/panels/column-debug-panel.scss +141 -0
- package/src/components/linelist/design/panels/data-catalogue.component.tsx +1062 -0
- package/src/components/linelist/design/panels/data-catalogue.scss +263 -0
- package/src/components/linelist/design/panels/display-settings-panel.component.tsx +405 -0
- package/src/components/linelist/design/panels/display-settings-panel.scss +78 -0
- package/src/components/linelist/design/panels/filtermap-editor.component.tsx +434 -0
- package/src/components/linelist/design/panels/filtermap-editor.scss +176 -0
- package/src/components/linelist/design/panels/json-preview.component.tsx +114 -0
- package/src/components/linelist/design/panels/json-preview.scss +85 -0
- package/src/components/linelist/design/panels/query-config-panel.component.tsx +1137 -0
- package/src/components/linelist/design/panels/query-config-panel.scss +341 -0
- package/src/components/linelist/design/panels/sort-config-panel.component.tsx +330 -0
- package/src/components/linelist/design/panels/sort-config-panel.scss +77 -0
- package/src/components/linelist/design/panels/sql-builder-panel.component.tsx +475 -0
- package/src/components/linelist/design/panels/sql-builder-panel.scss +226 -0
- package/src/components/linelist/design/panels/transformation-panel.component.tsx +687 -0
- package/src/components/linelist/design/panels/transformation-panel.scss +81 -0
- package/src/components/linelist/design/panels/visual-filter-panel.component.tsx +595 -0
- package/src/components/linelist/design/panels/visual-filter-panel.scss +76 -0
- package/src/components/linelist/linelist-dashboard.page.component.tsx +756 -0
- package/src/components/linelist/linelist-dashboard.page.scss +240 -0
- package/src/components/linelist/linelist-editor.page.component.tsx +134 -0
- package/src/components/linelist/linelist-editor.page.scss +28 -0
- package/src/components/linelist/linelist-run-report.page.component.tsx +715 -0
- package/src/components/linelist/linelist-run-report.page.scss +136 -0
- package/src/components/linelist/modals/linelist-report-builder-modal.component.tsx +1454 -0
- package/src/components/linelist/modals/linelist-report-builder-modal.scss +164 -0
- package/src/components/linelist/modals/preview-parameter-modal.component.tsx +361 -0
- package/src/components/report/dashboard/reports-table.component.tsx +186 -0
- package/src/components/report/definition/panels/properties-panel.component.tsx +38 -0
- package/src/components/report/definition/panels/report-structure-panel.component.tsx +61 -0
- package/src/components/report/definition/panels/selection-panel.component.tsx +58 -0
- package/src/components/report/definition/report-definition-editor.component.tsx +99 -0
- package/src/components/report/definition/report-definition.types.ts +66 -0
- package/src/components/report/design/panels/IndicatorPropertiesPanel.scss +33 -0
- package/src/components/report/design/panels/IndicatorPropertiesPanel.tsx +389 -0
- package/src/components/report/design/panels/JsonPreviewPanel.scss +32 -0
- package/src/components/report/design/panels/JsonPreviewPanel.tsx +104 -0
- package/src/components/report/design/panels/mapping-preview-panel.component.tsx +82 -0
- package/src/components/report/design/panels/mapping-preview-panel.scss +55 -0
- package/src/components/report/design/panels/template-structure-panel.component.tsx +296 -0
- package/src/components/report/design/panels/template-structure-panel.scss +81 -0
- package/src/components/report/design/report-design-editor.component.tsx +1170 -0
- package/src/components/report/design/report-design.types.ts +48 -0
- package/src/components/report/design/report-design.utils.ts +86 -0
- package/src/components/report/panels/report-detail.component.tsx +71 -0
- package/src/components/report/panels/report-panel-shell.component.tsx +60 -0
- package/src/components/report/report-dashboard.page.component.tsx +554 -0
- package/src/components/report/report-editor.page.component.tsx +590 -0
- package/src/components/report/report.routes.tsx +32 -0
- package/src/components/report-sections/create-report-section-modal.component.tsx +388 -0
- package/src/components/report-sections/hooks/useAgeCategories.ts +25 -0
- package/src/components/report-sections/hooks/useSectionEditorState.ts +449 -0
- package/src/components/report-sections/panels/Dhis2MappingPanel.tsx +157 -0
- package/src/components/report-sections/panels/DisaggregationPanel.tsx +97 -0
- package/src/components/report-sections/panels/IndicatorPickerPanel.tsx +201 -0
- package/src/components/report-sections/panels/SectionBasicsPanel.tsx +27 -0
- package/src/components/report-sections/report-section-preview-modal.component.tsx +548 -0
- package/src/components/report-sections/report-sections-page.component.tsx +325 -0
- package/src/components/report-sections/section-disaggregation.utils.ts +637 -0
- package/src/components/report-sections/section-types.ts +55 -0
- package/src/components/report-sections/section-utils.ts +50 -0
- package/src/components/report-sections/sections-page.scss +79 -0
- package/src/components/run-reports/run-reports-page.component.tsx +8 -0
- package/src/components/security/access-denied-page.component.tsx +64 -0
- package/src/components/security/access-denied-page.scss +39 -0
- package/src/components/security/privilege-route.component.test.tsx +76 -0
- package/src/components/security/privilege-route.component.tsx +39 -0
- package/src/components/shared/compile-setup-modal.component.tsx +182 -0
- package/src/components/shared/concept-selector.component.tsx +245 -0
- package/src/components/shared/concept-selector.scss +121 -0
- package/src/components/shared/header/builder-header-actions.component.tsx +38 -0
- package/src/components/shared/header/header.component.tsx +85 -0
- package/src/components/shared/header/header.scss +151 -0
- package/src/components/shared/header/illustration.component.tsx +34 -0
- package/src/components/shared/indicator-properties-panel/IndicatorPropertiesPanel.scss +33 -0
- package/src/components/shared/indicator-properties-panel/IndicatorPropertiesPanel.tsx +389 -0
- package/src/components/shared/json-preview-panel/JsonPreviewPanel.scss +32 -0
- package/src/components/shared/json-preview-panel/JsonPreviewPanel.tsx +104 -0
- package/src/components/shared/mapping-preview-panel/mapping-preview-panel.component.tsx +82 -0
- package/src/components/shared/mapping-preview-panel/mapping-preview-panel.scss +55 -0
- package/src/components/shared/preview/query-results-preview.component.tsx +204 -0
- package/src/components/shared/template-structure-panel/template-structure-panel.component.tsx +296 -0
- package/src/components/shared/template-structure-panel/template-structure-panel.scss +81 -0
- package/src/config-schema.ts +43 -0
- package/src/constants/privileges.test.ts +54 -0
- package/src/constants/privileges.ts +118 -0
- package/src/features/dashboards/DashboardRendererPage.tsx +174 -0
- package/src/features/dashboards/DashboardsPage.tsx +164 -0
- package/src/features/dashboards/EtlDashboardPage.tsx +32 -0
- package/src/features/dashboards/components/DashboardEmptyState.tsx +41 -0
- package/src/features/dashboards/components/DashboardGrid.tsx +48 -0
- package/src/features/dashboards/components/DashboardHeader.tsx +58 -0
- package/src/features/dashboards/components/DashboardSection.tsx +46 -0
- package/src/features/dashboards/components/ReportLaunchCard.tsx +51 -0
- package/src/features/dashboards/components/WidgetSlotDispatcher.tsx +61 -0
- package/src/features/dashboards/components/WidgetUnavailableCard.tsx +36 -0
- package/src/features/dashboards/dashboards.scss +196 -0
- package/src/features/dashboards/hooks/useDashboard.ts +61 -0
- package/src/features/dashboards/hooks/useDashboardWidgets.ts +74 -0
- package/src/features/dashboards/hooks/useDashboards.ts +56 -0
- package/src/features/dashboards/hooks/useMonitorDataMap.ts +84 -0
- package/src/features/dashboards/index.ts +11 -0
- package/src/features/dashboards/utils/dashboard-config.util.test.ts +286 -0
- package/src/features/dashboards/utils/dashboard-config.util.ts +382 -0
- package/src/features/report-visualizer/ReportVisualizerPage.tsx +448 -0
- package/src/features/report-visualizer/components/Export/ExportMenu.tsx +141 -0
- package/src/features/report-visualizer/components/Export/index.ts +2 -0
- package/src/features/report-visualizer/components/ReportExplorer/QuickFilters.tsx +152 -0
- package/src/features/report-visualizer/components/ReportExplorer/ReportCategoryFilter.tsx +54 -0
- package/src/features/report-visualizer/components/ReportExplorer/ReportExplorerPanel.tsx +201 -0
- package/src/features/report-visualizer/components/ReportExplorer/ReportExplorerRail.tsx +202 -0
- package/src/features/report-visualizer/components/ReportExplorer/ReportList.tsx +287 -0
- package/src/features/report-visualizer/components/ReportExplorer/ReportSearch.tsx +151 -0
- package/src/features/report-visualizer/components/ReportExplorer/ReportTagFilter.tsx +100 -0
- package/src/features/report-visualizer/components/ReportExplorer/RunReportButton.tsx +42 -0
- package/src/features/report-visualizer/components/ReportExplorer/RuntimeParameterForm.tsx +259 -0
- package/src/features/report-visualizer/components/ReportExplorer/index.ts +8 -0
- package/src/features/report-visualizer/components/ReportWorkspace/ReportLayer.tsx +33 -0
- package/src/features/report-visualizer/components/ReportWorkspace/ReportSummary.tsx +88 -0
- package/src/features/report-visualizer/components/ReportWorkspace/ReportViewTabs.tsx +72 -0
- package/src/features/report-visualizer/components/ReportWorkspace/ReportWorkspaceHeader.tsx +92 -0
- package/src/features/report-visualizer/components/ReportWorkspace/ReportWorkspacePanel.tsx +242 -0
- package/src/features/report-visualizer/components/ReportWorkspace/index.ts +5 -0
- package/src/features/report-visualizer/components/TableView/ColumnVisibilityMenu.tsx +206 -0
- package/src/features/report-visualizer/components/TableView/ReportTable.tsx +253 -0
- package/src/features/report-visualizer/components/TableView/index.ts +2 -0
- package/src/features/report-visualizer/hooks/index.ts +4 -0
- package/src/features/report-visualizer/hooks/useExplorerPreferences.ts +103 -0
- package/src/features/report-visualizer/hooks/useReportCapabilities.ts +112 -0
- package/src/features/report-visualizer/hooks/useReportParameters.ts +152 -0
- package/src/features/report-visualizer/hooks/useReports.ts +135 -0
- package/src/features/report-visualizer/index.ts +6 -0
- package/src/features/report-visualizer/report-visualizer.scss +593 -0
- package/src/features/report-visualizer/types/index.ts +1 -0
- package/src/features/report-visualizer/types/report-visualizer.types.ts +104 -0
- package/src/features/report-visualizer/utils/status-colors.ts +117 -0
- package/src/globals.d.ts +9 -0
- package/src/hooks/address-template.ts +86 -0
- package/src/hooks/concept.ts +112 -0
- package/src/hooks/indicator/index.ts +1 -0
- package/src/hooks/indicator/useIndicatorsByTheme.ts +41 -0
- package/src/hooks/openmrs-reference-data.ts +432 -0
- package/src/hooks/theme/index.ts +4 -0
- package/src/hooks/theme/useDataTheme.ts +61 -0
- package/src/hooks/theme/useDataThemes.ts +28 -0
- package/src/hooks/theme/useMambaTableMeta.ts +34 -0
- package/src/hooks/theme/useMambaTables.ts +95 -0
- package/src/hooks/use-report-builder-privileges.test.tsx +92 -0
- package/src/hooks/use-report-builder-privileges.ts +58 -0
- package/src/index.ts +29 -0
- package/src/resources/address-template/address-template.api.ts +180 -0
- package/src/resources/agegroup/agegroups.api.ts +58 -0
- package/src/resources/concept/concept.api.ts +116 -0
- package/src/resources/concepts/concept-mapper.ts +21 -0
- package/src/resources/concepts/concept-types.ts +31 -0
- package/src/resources/concepts/concepts.resource.ts +44 -0
- package/src/resources/concepts/useConceptSearch.ts +41 -0
- package/src/resources/dashboard/dashboard.api.ts +107 -0
- package/src/resources/etl-monitor/etl-monitor-test.api.ts +409 -0
- package/src/resources/etl-monitor/etl-monitor.api.ts +381 -0
- package/src/resources/etl-source/etl-source.api.ts +65 -0
- package/src/resources/etl-task/etl-task.api.ts +96 -0
- package/src/resources/etl-task/etl-task.types.ts +31 -0
- package/src/resources/indicator/indicators.api.ts +125 -0
- package/src/resources/legacy-reports/legacy-reports.api.ts +144 -0
- package/src/resources/linelist/linelist-reports.api.ts +616 -0
- package/src/resources/location/location.api.ts +135 -0
- package/src/resources/openmrs-api.ts +40 -0
- package/src/resources/patient-identifier-type/patient-identifier-type.api.ts +65 -0
- package/src/resources/person-attribute-type/person-attribute-type.api.ts +71 -0
- package/src/resources/preview/sql-preview.api.ts +54 -0
- package/src/resources/report/reports.api.ts +140 -0
- package/src/resources/report-category/report-category.api.ts +41 -0
- package/src/resources/report-import-export/import-export-api.ts +164 -0
- package/src/resources/report-library/report-library.api.ts +63 -0
- package/src/resources/report-section/report-sections.api.ts +73 -0
- package/src/resources/report-section/section-preview.api.ts +25 -0
- package/src/resources/theme/data-theme.api.ts +88 -0
- package/src/resources/theme/etl-schema.api.ts +101 -0
- package/src/resources/theme/etl-table-meta.api.ts +45 -0
- package/src/root.component.tsx +20 -0
- package/src/routes/report-builder.routes.tsx +160 -0
- package/src/routes/report-builder.scss +56 -0
- package/src/routes.json +31 -0
- package/src/sample-template.ts +121 -0
- package/src/template-utils.ts +110 -0
- package/src/types/carbon-react-inert.d.ts +13 -0
- package/src/types/condition-operators.ts +63 -0
- package/src/types/dashboard/dashboard.types.ts +137 -0
- package/src/types/dashboard/index.ts +4 -0
- package/src/types/etl/etl-types.ts +238 -0
- package/src/types/etl-monitor/etl-monitor-builder.types.ts +555 -0
- package/src/types/etl-monitor/etl-monitor-v2.types.ts +397 -0
- package/src/types/etl-monitor/etl-monitor.types.ts +188 -0
- package/src/types/etl-monitor/index.ts +6 -0
- package/src/types/linelist/compile-config.ts +455 -0
- package/src/types/linelist-types.ts +2059 -0
- package/src/types/theme/data-theme.types.ts +88 -0
- package/src/utils/api-error.utils.test.ts +147 -0
- package/src/utils/api-error.utils.ts +131 -0
- package/src/utils/config-enhancer.ts +62 -0
- package/src/utils/etl-browser/etl-browser.util.test.ts +151 -0
- package/src/utils/etl-browser/export-csv.util.ts +43 -0
- package/src/utils/etl-browser/group-tables.util.ts +84 -0
- package/src/utils/etl-browser/index.ts +4 -0
- package/src/utils/etl-browser/summarize-columns.util.ts +27 -0
- package/src/utils/etl-browser/table-sql.util.ts +20 -0
- package/src/utils/etl-monitor/config-v2-adapter.util.ts +460 -0
- package/src/utils/etl-monitor/endpoint-config-normalizer.util.ts +383 -0
- package/src/utils/etl-monitor/index.ts +10 -0
- package/src/utils/etl-monitor/jsonpath-resolver.util.ts +118 -0
- package/src/utils/etl-monitor/normalization-examples.ts +0 -0
- package/src/utils/etl-monitor/schema-inspector.util.ts +76 -0
- package/src/utils/etl-monitor/semantic-type-detector.util.ts +76 -0
- package/src/utils/etl-monitor/status-mapper.util.ts +105 -0
- package/src/utils/etl-monitor/value-formatters.util.ts +167 -0
- package/src/utils/etl-task/etl-task-card.util.test.ts +240 -0
- package/src/utils/etl-task/etl-task-card.util.ts +276 -0
- package/src/utils/etl-task/index.ts +1 -0
- package/src/utils/html-entities.utils.ts +34 -0
- package/src/utils/parameter-resolution.ts +218 -0
- package/src/views/etl-monitor-builder/add-monitor-modal.component.scss +0 -0
- package/src/views/etl-monitor-builder/add-monitor-modal.component.tsx +210 -0
- package/src/views/etl-monitor-builder/etl-monitor-builder.component.scss +157 -0
- package/src/views/etl-monitor-builder/etl-monitor-builder.component.tsx +252 -0
- package/src/views/etl-monitor-builder/etl-monitor-builder.store.ts +126 -0
- package/tools/i18next-parser.config.js +0 -0
- package/tools/setup-tests.ts +1 -0
- package/tools/update-openmrs-deps.mjs +42 -0
- package/translations/am.json +65 -0
- package/translations/ar.json +65 -0
- package/translations/ar_SY.json +65 -0
- package/translations/bn.json +65 -0
- package/translations/cs.json +65 -0
- package/translations/de.json +65 -0
- package/translations/en.json +65 -0
- package/translations/en_US.json +65 -0
- package/translations/es.json +65 -0
- package/translations/es_MX.json +65 -0
- package/translations/fr.json +65 -0
- package/translations/he.json +65 -0
- package/translations/hi.json +65 -0
- package/translations/hi_IN.json +65 -0
- package/translations/id.json +65 -0
- package/translations/it.json +65 -0
- package/translations/ka.json +65 -0
- package/translations/km.json +65 -0
- package/translations/ku.json +65 -0
- package/translations/ky.json +65 -0
- package/translations/lg.json +65 -0
- package/translations/ne.json +65 -0
- package/translations/pl.json +65 -0
- package/translations/pt.json +65 -0
- package/translations/pt_BR.json +65 -0
- package/translations/qu.json +65 -0
- package/translations/ro_RO.json +65 -0
- package/translations/ru_RU.json +65 -0
- package/translations/si.json +65 -0
- package/translations/sq.json +65 -0
- package/translations/sw.json +65 -0
- package/translations/sw_KE.json +65 -0
- package/translations/tr.json +65 -0
- package/translations/tr_TR.json +65 -0
- package/translations/uk.json +65 -0
- package/translations/uz.json +65 -0
- package/translations/uz@Latn.json +65 -0
- package/translations/uz_UZ.json +65 -0
- package/translations/vi.json +65 -0
- package/translations/zh.json +65 -0
- package/translations/zh_CN.json +65 -0
- package/translations/zh_TW.json +65 -0
- package/tsconfig.json +24 -0
- package/vitest.config.mts +42 -0
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ETL Monitor Builder Context
|
|
3
|
+
* Provides state management for the monitor builder wizard
|
|
4
|
+
*/
|
|
5
|
+
import { getETLMonitor, createETLMonitor, updateETLMonitor } from '../../../resources/etl-monitor/etl-monitor.api';
|
|
6
|
+
|
|
7
|
+
import React, { createContext, useContext, useCallback, useReducer, ReactNode } from 'react';
|
|
8
|
+
import type {
|
|
9
|
+
MonitorBuilderState,
|
|
10
|
+
BuilderAction,
|
|
11
|
+
BuilderStep,
|
|
12
|
+
BuilderContextValue,
|
|
13
|
+
DisplayConfigV2,
|
|
14
|
+
} from '../../../types/etl-monitor';
|
|
15
|
+
import {
|
|
16
|
+
getDefaultBuilderState,
|
|
17
|
+
STEP_ORDER,
|
|
18
|
+
canAdvanceFromStep,
|
|
19
|
+
getNextStep,
|
|
20
|
+
getPreviousStep,
|
|
21
|
+
} from '../../../types/etl-monitor/etl-monitor-builder.types';
|
|
22
|
+
import {
|
|
23
|
+
generateConfigFromState as generateConfigFromStateMachine,
|
|
24
|
+
validateGeneralStep,
|
|
25
|
+
validateDataSourceStep,
|
|
26
|
+
validateDesignStep,
|
|
27
|
+
validateFieldsStep,
|
|
28
|
+
validatePreviewStep,
|
|
29
|
+
} from './builder-state-machine';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Builder context
|
|
33
|
+
*/
|
|
34
|
+
const BuilderContext = createContext<BuilderContextValue | null>(null);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* State reducer for builder actions
|
|
38
|
+
*/
|
|
39
|
+
function builderReducer(state: MonitorBuilderState, action: BuilderAction): MonitorBuilderState {
|
|
40
|
+
switch (action.type) {
|
|
41
|
+
case 'SET_GENERAL_CONFIG':
|
|
42
|
+
return {
|
|
43
|
+
...state,
|
|
44
|
+
general: { ...state.general, ...action.payload },
|
|
45
|
+
isDirty: true,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
case 'SET_ENDPOINT_CONFIG':
|
|
49
|
+
return {
|
|
50
|
+
...state,
|
|
51
|
+
endpoint: { ...state.endpoint, ...action.payload },
|
|
52
|
+
isDirty: true,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
case 'SET_TEST_RESULT':
|
|
56
|
+
return {
|
|
57
|
+
...state,
|
|
58
|
+
testResult: action.payload,
|
|
59
|
+
isDirty: true,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
case 'SET_DETECTED_SCHEMA':
|
|
63
|
+
return {
|
|
64
|
+
...state,
|
|
65
|
+
detectedSchema: action.payload,
|
|
66
|
+
isDirty: true,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
case 'SET_COMPONENT_TYPE':
|
|
70
|
+
return {
|
|
71
|
+
...state,
|
|
72
|
+
componentType: action.payload,
|
|
73
|
+
isDirty: true,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
case 'SET_FIELDS':
|
|
77
|
+
return {
|
|
78
|
+
...state,
|
|
79
|
+
fields: action.payload,
|
|
80
|
+
isDirty: true,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
case 'ADD_FIELD':
|
|
84
|
+
return {
|
|
85
|
+
...state,
|
|
86
|
+
fields: [...state.fields, action.payload],
|
|
87
|
+
isDirty: true,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
case 'UPDATE_FIELD':
|
|
91
|
+
return {
|
|
92
|
+
...state,
|
|
93
|
+
fields: state.fields.map(field =>
|
|
94
|
+
field.key === action.payload.key
|
|
95
|
+
? { ...field, ...action.payload.updates }
|
|
96
|
+
: field
|
|
97
|
+
),
|
|
98
|
+
isDirty: true,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
case 'REMOVE_FIELD':
|
|
102
|
+
return {
|
|
103
|
+
...state,
|
|
104
|
+
fields: state.fields.filter(field => field.key !== action.payload),
|
|
105
|
+
isDirty: true,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
case 'SET_COMPONENT_CONFIG':
|
|
109
|
+
return {
|
|
110
|
+
...state,
|
|
111
|
+
componentConfig: { ...state.componentConfig, ...action.payload },
|
|
112
|
+
isDirty: true,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
case 'SET_LAYOUT':
|
|
116
|
+
return {
|
|
117
|
+
...state,
|
|
118
|
+
layout: action.payload,
|
|
119
|
+
isDirty: true,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
case 'SET_DENSITY':
|
|
123
|
+
return {
|
|
124
|
+
...state,
|
|
125
|
+
density: action.payload,
|
|
126
|
+
isDirty: true,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
case 'SET_EMPTY_STATE':
|
|
130
|
+
return {
|
|
131
|
+
...state,
|
|
132
|
+
emptyState: action.payload,
|
|
133
|
+
isDirty: true,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
case 'SET_CURRENT_STEP':
|
|
137
|
+
return {
|
|
138
|
+
...state,
|
|
139
|
+
currentStep: action.payload,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
case 'VALIDATE_STEP':
|
|
143
|
+
return validateStepInState(state, action.payload);
|
|
144
|
+
|
|
145
|
+
case 'SET_SAVING':
|
|
146
|
+
return {
|
|
147
|
+
...state,
|
|
148
|
+
isSaving: action.payload,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
case 'RESET':
|
|
152
|
+
return getDefaultBuilderState(state.mode);
|
|
153
|
+
|
|
154
|
+
case 'LOAD_MONITOR':
|
|
155
|
+
return loadMonitorIntoState(action.payload);
|
|
156
|
+
|
|
157
|
+
default:
|
|
158
|
+
return state;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Validate a specific step in the state
|
|
164
|
+
*/
|
|
165
|
+
function validateStepInState(state: MonitorBuilderState, step: BuilderStep): MonitorBuilderState {
|
|
166
|
+
const validatedSteps = new Set(state.validation.validatedSteps);
|
|
167
|
+
validatedSteps.add(step);
|
|
168
|
+
|
|
169
|
+
const stepValidation = { ...state.stepValidation };
|
|
170
|
+
|
|
171
|
+
switch (step) {
|
|
172
|
+
case 'general': {
|
|
173
|
+
const result = validateGeneralStep(state.general);
|
|
174
|
+
stepValidation.general = {
|
|
175
|
+
nameValid: result.errors.filter(e => e.includes('Name')).length === 0,
|
|
176
|
+
codeValid: result.errors.filter(e => e.includes('Code')).length === 0,
|
|
177
|
+
codeUnique: true, // Would need server validation
|
|
178
|
+
categoryValid: true,
|
|
179
|
+
refreshIntervalValid: result.errors.filter(e => e.includes('Refresh')).length === 0,
|
|
180
|
+
timeoutValid: result.errors.filter(e => e.includes('Timeout')).length === 0,
|
|
181
|
+
};
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case 'data-source': {
|
|
185
|
+
const result = validateDataSourceStep(state.endpoint, state.testResult, state.mode === 'edit');
|
|
186
|
+
stepValidation['data-source'] = {
|
|
187
|
+
endpointTested: !!state.testResult,
|
|
188
|
+
endpointValid: result.valid,
|
|
189
|
+
urlValid: result.errors.filter(e => e.includes('URL')).length === 0,
|
|
190
|
+
authValid: true,
|
|
191
|
+
};
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case 'design': {
|
|
195
|
+
const result = validateDesignStep(state.componentType);
|
|
196
|
+
stepValidation.design = {
|
|
197
|
+
componentSelected: result.valid,
|
|
198
|
+
componentValid: result.valid,
|
|
199
|
+
};
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
case 'fields': {
|
|
203
|
+
const result = validateFieldsStep(
|
|
204
|
+
state.fields,
|
|
205
|
+
state.componentType,
|
|
206
|
+
state.testResult?.data,
|
|
207
|
+
state.detectedSchema?.arrayPath,
|
|
208
|
+
);
|
|
209
|
+
stepValidation.fields = {
|
|
210
|
+
requiredFieldsMapped: result.errors.filter(e => e.includes('required')).length === 0,
|
|
211
|
+
primaryFieldSet: state.fields.some(f => f.primary),
|
|
212
|
+
jsonPathsValid: result.errors.filter(e => e.includes('path')).length === 0,
|
|
213
|
+
};
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
case 'preview': {
|
|
217
|
+
const result = validatePreviewStep(state);
|
|
218
|
+
stepValidation.preview = {
|
|
219
|
+
configValid: result.valid,
|
|
220
|
+
previewRenderable: result.valid,
|
|
221
|
+
};
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
...state,
|
|
228
|
+
validation: {
|
|
229
|
+
...state.validation,
|
|
230
|
+
validatedSteps,
|
|
231
|
+
isValid: validatedSteps.size === 5, // All steps validated
|
|
232
|
+
},
|
|
233
|
+
stepValidation,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Convert V1 color to V2 tone
|
|
239
|
+
* Maps V1 color names to V2 tone values
|
|
240
|
+
*/
|
|
241
|
+
function convertV1ColorToTone(color: string): 'success' | 'critical' | 'warning' | 'info' | 'neutral' {
|
|
242
|
+
const colorToToneMap: Record<string, 'success' | 'critical' | 'warning' | 'info' | 'neutral'> = {
|
|
243
|
+
'green': 'success',
|
|
244
|
+
'red': 'critical',
|
|
245
|
+
'yellow': 'warning',
|
|
246
|
+
'blue': 'info',
|
|
247
|
+
'gray': 'neutral',
|
|
248
|
+
'grey': 'neutral',
|
|
249
|
+
'success': 'success',
|
|
250
|
+
'error': 'critical',
|
|
251
|
+
'warning': 'warning',
|
|
252
|
+
'info': 'info',
|
|
253
|
+
'neutral': 'neutral',
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const normalizedColor = color?.toLowerCase() || '';
|
|
257
|
+
return colorToToneMap[normalizedColor] || 'neutral';
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Convert V1 column to V2 field format
|
|
262
|
+
* Handles migration from old column-based format to new field-based format
|
|
263
|
+
*/
|
|
264
|
+
function convertV1ColumnToV2Field(column: any): any {
|
|
265
|
+
const field: any = {
|
|
266
|
+
key: column.key,
|
|
267
|
+
label: column.header || column.key,
|
|
268
|
+
path: column.jsonPath || `$.${column.key}`,
|
|
269
|
+
type: 'TEXT',
|
|
270
|
+
primary: false,
|
|
271
|
+
hidden: false,
|
|
272
|
+
order: 0,
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// Map V1 column types to V2 field types
|
|
276
|
+
switch (column.columnType) {
|
|
277
|
+
case 'STATUS_BADGE':
|
|
278
|
+
field.type = 'STATUS';
|
|
279
|
+
if (column.colorMap && typeof column.colorMap === 'object') {
|
|
280
|
+
field.statusMappings = Object.entries(column.colorMap).map(([rawValue, color]) => ({
|
|
281
|
+
rawValue,
|
|
282
|
+
label: rawValue, // Default label to the raw value
|
|
283
|
+
tone: convertV1ColorToTone(String(color)),
|
|
284
|
+
}));
|
|
285
|
+
}
|
|
286
|
+
break;
|
|
287
|
+
case 'TIMESTAMP':
|
|
288
|
+
field.type = 'TIMESTAMP';
|
|
289
|
+
break;
|
|
290
|
+
case 'NUMBER':
|
|
291
|
+
field.type = 'NUMBER';
|
|
292
|
+
break;
|
|
293
|
+
case 'PERCENTAGE':
|
|
294
|
+
field.type = 'PERCENTAGE';
|
|
295
|
+
break;
|
|
296
|
+
case 'DURATION':
|
|
297
|
+
field.type = 'DURATION';
|
|
298
|
+
break;
|
|
299
|
+
case 'BOOLEAN':
|
|
300
|
+
field.type = 'BOOLEAN';
|
|
301
|
+
break;
|
|
302
|
+
default:
|
|
303
|
+
field.type = 'TEXT';
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (column.defaultValue !== undefined) {
|
|
307
|
+
field.defaultValue = column.defaultValue;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return field;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Load an existing monitor into the builder state
|
|
315
|
+
*/
|
|
316
|
+
function loadMonitorIntoState(monitor: any): MonitorBuilderState {
|
|
317
|
+
const state = getDefaultBuilderState('edit');
|
|
318
|
+
state.initialMonitor = monitor;
|
|
319
|
+
|
|
320
|
+
// Parse configurations with better error handling
|
|
321
|
+
let config: any = {};
|
|
322
|
+
let displayConfig: any = {};
|
|
323
|
+
let parseError = false;
|
|
324
|
+
|
|
325
|
+
try {
|
|
326
|
+
if (monitor.configJson) {
|
|
327
|
+
config = JSON.parse(monitor.configJson);
|
|
328
|
+
}
|
|
329
|
+
} catch (e) {
|
|
330
|
+
console.error('Failed to parse monitor configJson:', e);
|
|
331
|
+
parseError = true;
|
|
332
|
+
// Set a flag or handle the error appropriately
|
|
333
|
+
state.parseError = 'configJson';
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
try {
|
|
337
|
+
if (monitor.displayConfigJson) {
|
|
338
|
+
displayConfig = JSON.parse(monitor.displayConfigJson);
|
|
339
|
+
}
|
|
340
|
+
} catch (e) {
|
|
341
|
+
console.error('Failed to parse monitor displayConfigJson:', e);
|
|
342
|
+
parseError = true;
|
|
343
|
+
state.parseError = state.parseError ? `${state.parseError}, displayConfigJson` : 'displayConfigJson';
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (parseError) {
|
|
347
|
+
console.warn('Monitor configuration parsing failed, builder may not function correctly:', monitor.code);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// Extract endpoint configuration - create new objects to avoid reference issues
|
|
351
|
+
const endpoint = config.apiEndpoint || {};
|
|
352
|
+
|
|
353
|
+
// Build auth configuration with proper defaults for all fields
|
|
354
|
+
let authConfig: any;
|
|
355
|
+
|
|
356
|
+
if (endpoint.auth && typeof endpoint.auth === 'object') {
|
|
357
|
+
// Use the auth object directly, ensuring all required fields exist
|
|
358
|
+
authConfig = {
|
|
359
|
+
type: endpoint.auth.type || endpoint.authType || 'NONE',
|
|
360
|
+
useSession: endpoint.auth.useSession || endpoint.useSession === true,
|
|
361
|
+
username: endpoint.auth.username || '',
|
|
362
|
+
password: endpoint.auth.password || '',
|
|
363
|
+
headerName: endpoint.auth.headerName || '',
|
|
364
|
+
apiKey: endpoint.auth.apiKey || '',
|
|
365
|
+
token: endpoint.auth.token || '',
|
|
366
|
+
};
|
|
367
|
+
} else {
|
|
368
|
+
// Fallback: build from V1 format or defaults
|
|
369
|
+
const authType = endpoint.authType || endpoint.auth?.type || 'NONE';
|
|
370
|
+
const authCfg = endpoint.authConfig || endpoint.authConfig || {};
|
|
371
|
+
|
|
372
|
+
authConfig = {
|
|
373
|
+
type: authType,
|
|
374
|
+
useSession: authType === 'OPENMRS' || authCfg.useSession === 'true' || authCfg.useSession === true,
|
|
375
|
+
username: authCfg.username || '',
|
|
376
|
+
password: authCfg.password || '',
|
|
377
|
+
headerName: authCfg.headerName || 'X-API-Key',
|
|
378
|
+
apiKey: authCfg.apiKey || '',
|
|
379
|
+
token: authCfg.token || '',
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
state.endpoint = {
|
|
384
|
+
url: endpoint.url || '',
|
|
385
|
+
method: endpoint.method || 'GET',
|
|
386
|
+
auth: authConfig,
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// Extract general configuration - create new object
|
|
390
|
+
state.general = {
|
|
391
|
+
name: monitor.name || '',
|
|
392
|
+
code: monitor.code || '',
|
|
393
|
+
description: monitor.description || '',
|
|
394
|
+
category: monitor.category || '',
|
|
395
|
+
refreshInterval: monitor.refreshInterval || 30,
|
|
396
|
+
timeout: monitor.timeout || 10,
|
|
397
|
+
active: monitor.active !== false,
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// Extract display configuration - handle both V1 and V2 formats
|
|
401
|
+
if (displayConfig.schemaVersion === 2) {
|
|
402
|
+
// V2 format - use directly
|
|
403
|
+
state.componentType = displayConfig.component;
|
|
404
|
+
// Use spread to create a NEW array, avoiding reference sharing
|
|
405
|
+
// Also convert statusMap to statusMappings for builder state
|
|
406
|
+
state.fields = displayConfig.fields ? displayConfig.fields.map((field: any) => ({
|
|
407
|
+
...field,
|
|
408
|
+
// Convert statusMap (Record<string, {label, tone}>) to statusMappings (Array<{rawValue, label, tone}>)
|
|
409
|
+
statusMappings: field.statusMap ? Object.entries(field.statusMap).map(([rawValue, mapping]: [string, any]) => ({
|
|
410
|
+
rawValue,
|
|
411
|
+
label: mapping.label,
|
|
412
|
+
tone: mapping.tone,
|
|
413
|
+
})) : field.statusMappings || [],
|
|
414
|
+
})) : [];
|
|
415
|
+
// Create copies of objects to prevent reference issues
|
|
416
|
+
state.componentConfig = displayConfig.componentConfig ? { ...displayConfig.componentConfig } : {};
|
|
417
|
+
state.layout = displayConfig.layout ? { ...displayConfig.layout } : undefined;
|
|
418
|
+
state.emptyState = displayConfig.emptyState ? { ...displayConfig.emptyState } : undefined;
|
|
419
|
+
state.density = displayConfig.presentation?.density || 'compact';
|
|
420
|
+
} else if (displayConfig.columns && Array.isArray(displayConfig.columns) && displayConfig.columns.length > 0) {
|
|
421
|
+
// V1 format - convert to V2
|
|
422
|
+
console.log('Converting V1 monitor format to V2 for editing:', monitor.code);
|
|
423
|
+
state.componentType = 'TABLE'; // V1 format is typically table-based
|
|
424
|
+
state.fields = displayConfig.columns.map(convertV1ColumnToV2Field);
|
|
425
|
+
// Set minimal component config for converted V1
|
|
426
|
+
state.componentConfig = {};
|
|
427
|
+
|
|
428
|
+
// Note: V1 had title/subtitle in displayConfig, but V2 uses layout/emptyState
|
|
429
|
+
// These can be manually reconfigured in the builder
|
|
430
|
+
} else {
|
|
431
|
+
// No valid display config found - set defaults
|
|
432
|
+
console.warn('No valid display configuration found for monitor:', monitor.code);
|
|
433
|
+
state.componentType = 'SUMMARY_CARD';
|
|
434
|
+
state.fields = [];
|
|
435
|
+
state.componentConfig = {};
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return state;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Provider props
|
|
443
|
+
*/
|
|
444
|
+
interface BuilderProviderProps {
|
|
445
|
+
children: ReactNode;
|
|
446
|
+
mode: 'create' | 'edit';
|
|
447
|
+
monitorId?: string;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Builder Provider Component
|
|
452
|
+
*/
|
|
453
|
+
export function BuilderProvider({ children, mode, monitorId }: BuilderProviderProps) {
|
|
454
|
+
const [state, dispatch] = useReducer(
|
|
455
|
+
builderReducer,
|
|
456
|
+
getDefaultBuilderState('create')
|
|
457
|
+
);
|
|
458
|
+
const [monitor, setMonitor] = React.useState<any | null>(null);
|
|
459
|
+
const [loadingMonitor, setLoadingMonitor] = React.useState(false);
|
|
460
|
+
|
|
461
|
+
// Load monitor data if in edit mode
|
|
462
|
+
React.useEffect(() => {
|
|
463
|
+
let isMounted = true;
|
|
464
|
+
const abortController = new AbortController();
|
|
465
|
+
|
|
466
|
+
if (mode === 'edit' && monitorId) {
|
|
467
|
+
setLoadingMonitor(true);
|
|
468
|
+
|
|
469
|
+
getETLMonitor(monitorId, abortController.signal)
|
|
470
|
+
.then(data => {
|
|
471
|
+
if (isMounted) {
|
|
472
|
+
// Update monitor state and dispatch in sequence
|
|
473
|
+
setMonitor(data);
|
|
474
|
+
dispatch({ type: 'LOAD_MONITOR', payload: data });
|
|
475
|
+
setLoadingMonitor(false);
|
|
476
|
+
}
|
|
477
|
+
})
|
|
478
|
+
.catch(error => {
|
|
479
|
+
if (isMounted && error.name !== 'AbortError') {
|
|
480
|
+
console.error('Failed to load monitor:', error);
|
|
481
|
+
setLoadingMonitor(false);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return () => {
|
|
487
|
+
isMounted = false;
|
|
488
|
+
abortController.abort();
|
|
489
|
+
};
|
|
490
|
+
}, [mode, monitorId]);
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Update state with partial updates
|
|
494
|
+
*/
|
|
495
|
+
const updateState = useCallback((updates: Partial<MonitorBuilderState>) => {
|
|
496
|
+
if (updates.general) {
|
|
497
|
+
dispatch({ type: 'SET_GENERAL_CONFIG', payload: updates.general });
|
|
498
|
+
}
|
|
499
|
+
if (updates.endpoint) {
|
|
500
|
+
dispatch({ type: 'SET_ENDPOINT_CONFIG', payload: updates.endpoint });
|
|
501
|
+
}
|
|
502
|
+
if (updates.testResult !== undefined) {
|
|
503
|
+
dispatch({ type: 'SET_TEST_RESULT', payload: updates.testResult });
|
|
504
|
+
}
|
|
505
|
+
if (updates.detectedSchema !== undefined) {
|
|
506
|
+
dispatch({ type: 'SET_DETECTED_SCHEMA', payload: updates.detectedSchema });
|
|
507
|
+
}
|
|
508
|
+
if (updates.componentType !== undefined) {
|
|
509
|
+
dispatch({ type: 'SET_COMPONENT_TYPE', payload: updates.componentType });
|
|
510
|
+
}
|
|
511
|
+
if (updates.fields !== undefined) {
|
|
512
|
+
dispatch({ type: 'SET_FIELDS', payload: updates.fields });
|
|
513
|
+
}
|
|
514
|
+
if (updates.componentConfig !== undefined) {
|
|
515
|
+
dispatch({ type: 'SET_COMPONENT_CONFIG', payload: updates.componentConfig });
|
|
516
|
+
}
|
|
517
|
+
if (updates.layout !== undefined) {
|
|
518
|
+
dispatch({ type: 'SET_LAYOUT', payload: updates.layout });
|
|
519
|
+
}
|
|
520
|
+
if (updates.density !== undefined) {
|
|
521
|
+
dispatch({ type: 'SET_DENSITY', payload: updates.density });
|
|
522
|
+
}
|
|
523
|
+
if (updates.emptyState !== undefined) {
|
|
524
|
+
dispatch({ type: 'SET_EMPTY_STATE', payload: updates.emptyState });
|
|
525
|
+
}
|
|
526
|
+
if (updates.currentStep !== undefined) {
|
|
527
|
+
dispatch({ type: 'SET_CURRENT_STEP', payload: updates.currentStep });
|
|
528
|
+
}
|
|
529
|
+
}, []);
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Validate a specific step
|
|
533
|
+
*/
|
|
534
|
+
const validateStep = useCallback((step: BuilderStep): boolean => {
|
|
535
|
+
return canAdvanceFromStep(step, state);
|
|
536
|
+
}, [state]);
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Check if can advance from a step
|
|
540
|
+
*/
|
|
541
|
+
const canAdvance = useCallback((fromStep: BuilderStep): boolean => {
|
|
542
|
+
return canAdvanceFromStep(fromStep, state);
|
|
543
|
+
}, [state]);
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Generate DisplayConfigV2 from current state
|
|
547
|
+
*/
|
|
548
|
+
const generateConfig = useCallback((): DisplayConfigV2 => {
|
|
549
|
+
return generateConfigFromStateMachine(state);
|
|
550
|
+
}, [state]);
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Save the monitor
|
|
554
|
+
*/
|
|
555
|
+
const saveMonitor = useCallback(async () => {
|
|
556
|
+
dispatch({ type: 'SET_SAVING', payload: true });
|
|
557
|
+
try {
|
|
558
|
+
// Import stateToSavePayload from builder-state-machine
|
|
559
|
+
const { stateToSavePayload } = await import('./builder-state-machine');
|
|
560
|
+
const payload = stateToSavePayload(state);
|
|
561
|
+
|
|
562
|
+
let result;
|
|
563
|
+
if (mode === 'edit' && monitor?.uuid) {
|
|
564
|
+
result = await updateETLMonitor(monitor.uuid, payload);
|
|
565
|
+
} else {
|
|
566
|
+
result = await createETLMonitor(payload);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
dispatch({ type: 'SET_SAVING', payload: false });
|
|
570
|
+
return result;
|
|
571
|
+
} catch (error) {
|
|
572
|
+
dispatch({ type: 'SET_SAVING', payload: false });
|
|
573
|
+
throw error;
|
|
574
|
+
}
|
|
575
|
+
}, [state, mode, monitor]);
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Cancel the builder
|
|
579
|
+
*/
|
|
580
|
+
const cancel = useCallback(() => {
|
|
581
|
+
dispatch({ type: 'RESET' });
|
|
582
|
+
}, []);
|
|
583
|
+
|
|
584
|
+
// Memoize context value to prevent unnecessary re-renders
|
|
585
|
+
// dispatch is stable from useReducer, so it doesn't need to be in deps
|
|
586
|
+
const contextValue: BuilderContextValue = React.useMemo(() => ({
|
|
587
|
+
state,
|
|
588
|
+
dispatch,
|
|
589
|
+
updateState,
|
|
590
|
+
validateStep,
|
|
591
|
+
canAdvance,
|
|
592
|
+
generateConfig,
|
|
593
|
+
saveMonitor,
|
|
594
|
+
cancel,
|
|
595
|
+
}), [state, updateState, validateStep, canAdvance, generateConfig, saveMonitor, cancel]);
|
|
596
|
+
|
|
597
|
+
// Show loading state while fetching monitor
|
|
598
|
+
if (loadingMonitor) {
|
|
599
|
+
return (
|
|
600
|
+
<BuilderContext.Provider value={contextValue}>
|
|
601
|
+
<div style={{ padding: '2rem', textAlign: 'center' }}>
|
|
602
|
+
<p>Loading monitor configuration...</p>
|
|
603
|
+
</div>
|
|
604
|
+
</BuilderContext.Provider>
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// Show warning if there was a parse error
|
|
609
|
+
if (state.parseError && mode === 'edit') {
|
|
610
|
+
console.warn('Monitor configuration had parsing errors:', state.parseError);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return (
|
|
614
|
+
<BuilderContext.Provider value={contextValue}>
|
|
615
|
+
{children}
|
|
616
|
+
</BuilderContext.Provider>
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Hook to use the builder context
|
|
622
|
+
*/
|
|
623
|
+
export function useBuilderContext(): BuilderContextValue {
|
|
624
|
+
const context = useContext(BuilderContext);
|
|
625
|
+
|
|
626
|
+
if (!context) {
|
|
627
|
+
throw new Error('useBuilderContext must be used within BuilderProvider');
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
return context;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Hook to get current builder state
|
|
635
|
+
*/
|
|
636
|
+
export function useBuilderState(): MonitorBuilderState {
|
|
637
|
+
const { state } = useBuilderContext();
|
|
638
|
+
return state;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Hook to update builder state
|
|
643
|
+
*/
|
|
644
|
+
export function useUpdateBuilderState() {
|
|
645
|
+
const { updateState } = useBuilderContext();
|
|
646
|
+
return updateState;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Hook to navigate between steps
|
|
651
|
+
*/
|
|
652
|
+
export function useStepNavigation() {
|
|
653
|
+
const { state, dispatch, canAdvance } = useBuilderContext();
|
|
654
|
+
|
|
655
|
+
const goToStep = useCallback((step: BuilderStep) => {
|
|
656
|
+
const currentIndex = STEP_ORDER.indexOf(state.currentStep);
|
|
657
|
+
const targetIndex = STEP_ORDER.indexOf(step);
|
|
658
|
+
|
|
659
|
+
// Can only move to adjacent steps or validate all intermediate steps
|
|
660
|
+
if (Math.abs(targetIndex - currentIndex) <= 1) {
|
|
661
|
+
dispatch({ type: 'SET_CURRENT_STEP', payload: step });
|
|
662
|
+
} else {
|
|
663
|
+
// Need to validate all intermediate steps
|
|
664
|
+
let canMove = true;
|
|
665
|
+
for (let i = Math.min(currentIndex, targetIndex); i < Math.max(currentIndex, targetIndex); i++) {
|
|
666
|
+
if (!canAdvance(STEP_ORDER[i])) {
|
|
667
|
+
canMove = false;
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (canMove) {
|
|
672
|
+
dispatch({ type: 'SET_CURRENT_STEP', payload: step });
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}, [state.currentStep, canAdvance, dispatch]);
|
|
676
|
+
|
|
677
|
+
const goToNextStep = useCallback(() => {
|
|
678
|
+
const next = getNextStep(state.currentStep);
|
|
679
|
+
if (next) {
|
|
680
|
+
goToStep(next);
|
|
681
|
+
}
|
|
682
|
+
}, [state.currentStep, goToStep]);
|
|
683
|
+
|
|
684
|
+
const goToPreviousStep = useCallback(() => {
|
|
685
|
+
const previous = getPreviousStep(state.currentStep);
|
|
686
|
+
if (previous) {
|
|
687
|
+
goToStep(previous);
|
|
688
|
+
}
|
|
689
|
+
}, [state.currentStep, goToStep]);
|
|
690
|
+
|
|
691
|
+
// Memoize return value to prevent unnecessary re-renders
|
|
692
|
+
return React.useMemo(() => ({
|
|
693
|
+
currentStep: state.currentStep,
|
|
694
|
+
goToStep,
|
|
695
|
+
goToNextStep,
|
|
696
|
+
goToPreviousStep,
|
|
697
|
+
canGoNext: !!getNextStep(state.currentStep),
|
|
698
|
+
canGoPrevious: !!getPreviousStep(state.currentStep),
|
|
699
|
+
}), [state.currentStep, goToStep, goToNextStep, goToPreviousStep]);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
export { BuilderContext };
|