@nnkogift/dhis2-form-utils-devtools 0.1.0-alpha.2 → 0.1.0-alpha.4

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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { IconInfo16, IconLink16, IconMail16, IconMessages16, IconErrorFilled16, IconWarningFilled16, IconStarFilled16, IconEdit16, IconView16, IconViewOff16, IconFullscreen16, Button, NoticeBox, Card, IconChevronDown16, IconChevronRight16, Tag, Divider, Chip, Modal, ModalTitle, ModalContent } from '@dhis2/ui';
1
+ import { IconInfo16, IconLink16, IconMail16, IconMessages16, IconErrorFilled16, IconWarningFilled16, IconStarFilled16, IconEdit16, IconView16, IconViewOff16, IconFullscreen16, SegmentedControl, Button, NoticeBox, Card, IconChevronDown16, IconChevronRight16, Tag, Divider, Chip, Modal, ModalTitle, ModalContent } from '@dhis2/ui';
2
2
  import { useFormStore, useFormStateContext } from '@nnkogift/dhis2-form-utils-hooks';
3
3
  import { createContext, memo, useState, useMemo, useEffect, useSyncExternalStore, useCallback, useContext } from 'react';
4
4
  import { selectProgramStage } from '@nnkogift/dhis2-form-utils-metadata';
@@ -1350,6 +1350,10 @@ function countObservedRules(entries) {
1350
1350
  return ruleIds.size;
1351
1351
  }
1352
1352
  var PANEL_TAB_KEYS = ["rules", "trace", "graph"];
1353
+ var SCOPE_FILTER_OPTIONS = [
1354
+ { label: translate("In scope"), value: "scoped" },
1355
+ { label: translate("All"), value: "all" }
1356
+ ];
1353
1357
  function resolveTabLabel(key) {
1354
1358
  switch (key) {
1355
1359
  case "rules":
@@ -1368,6 +1372,7 @@ function RulesPanel({ metadata, showConditions = true }) {
1368
1372
  const [selectedEntryId, setSelectedEntryId] = useState(null);
1369
1373
  const [highlightRuleId, setHighlightRuleId] = useState(null);
1370
1374
  const [graphModalOpen, setGraphModalOpen] = useState(false);
1375
+ const [scopeFilter, setScopeFilter] = useState("scoped");
1371
1376
  const labelLookup = useMemo(() => createLabelLookup(metadata), [metadata]);
1372
1377
  const catalog = useMemo(() => resolveProgramRulesList(metadata), [metadata]);
1373
1378
  const scopeStageId = useMemo(() => resolveScopeStageId(metadata), [metadata]);
@@ -1460,10 +1465,22 @@ function RulesPanel({ metadata, showConditions = true }) {
1460
1465
  ),
1461
1466
  /* @__PURE__ */ jsx("h2", { className: "m-0 text-base font-bold leading-[1.35] text-dhis2-grey-900", children: translate("Rules") })
1462
1467
  ] }),
1463
- /* @__PURE__ */ jsx("span", { className: "shrink-0 text-xs text-dhis2-grey-600", children: translate("{{scoped}} in scope \xB7 {{firing}} firing", {
1464
- scoped: scopedRules.length,
1465
- firing: firingCount
1466
- }) })
1468
+ /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-dp8", children: [
1469
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-dhis2-grey-600", children: translate("{{scoped}} in scope \xB7 {{firing}} firing", {
1470
+ scoped: scopedRules.length,
1471
+ firing: firingCount
1472
+ }) }),
1473
+ /* @__PURE__ */ jsx(
1474
+ SegmentedControl,
1475
+ {
1476
+ options: SCOPE_FILTER_OPTIONS,
1477
+ selected: scopeFilter,
1478
+ onChange: ({ value }) => {
1479
+ setScopeFilter(value);
1480
+ }
1481
+ }
1482
+ )
1483
+ ] })
1467
1484
  ] }),
1468
1485
  /* @__PURE__ */ jsx("div", { className: "flex", children: PANEL_TAB_KEYS.map((key) => /* @__PURE__ */ jsx(
1469
1486
  "button",
@@ -1503,6 +1520,7 @@ function RulesPanel({ metadata, showConditions = true }) {
1503
1520
  {
1504
1521
  catalog,
1505
1522
  scopeStageId,
1523
+ scopeFilter,
1506
1524
  activeRuleIds,
1507
1525
  selectedRuleId: highlightRuleId,
1508
1526
  showConditions,
@@ -1559,6 +1577,7 @@ function RulesPanel({ metadata, showConditions = true }) {
1559
1577
  function RulesTab({
1560
1578
  catalog,
1561
1579
  scopeStageId,
1580
+ scopeFilter,
1562
1581
  activeRuleIds,
1563
1582
  selectedRuleId,
1564
1583
  showConditions,
@@ -1568,7 +1587,11 @@ function RulesTab({
1568
1587
  if (!catalog.length) {
1569
1588
  return /* @__PURE__ */ jsx("p", { className: "m-0 text-sm leading-normal text-dhis2-grey-600", children: translate("This program has no rules.") });
1570
1589
  }
1571
- return /* @__PURE__ */ jsx("ul", { className: "m-0 flex list-none flex-col gap-[10px] p-0", children: catalog.map((rule) => {
1590
+ const visibleRules = scopeFilter === "all" ? catalog : catalog.filter((rule) => isRuleInScope(rule, scopeStageId));
1591
+ if (!visibleRules.length) {
1592
+ return /* @__PURE__ */ jsx("p", { className: "m-0 text-sm leading-normal text-dhis2-grey-600", children: translate("No rules are in scope for this stage.") });
1593
+ }
1594
+ return /* @__PURE__ */ jsx("ul", { className: "m-0 flex list-none flex-col gap-[10px] p-0", children: visibleRules.map((rule) => {
1572
1595
  const inScope = isRuleInScope(rule, scopeStageId);
1573
1596
  const firing = activeRuleIds.has(rule.id);
1574
1597
  const isSelected = selectedRuleId === rule.id;