analytica-frontend-lib 1.3.68 → 1.3.69

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.
@@ -1455,6 +1455,89 @@ var Table_default = Table;
1455
1455
 
1456
1456
  // src/components/Filter/useTableFilter.ts
1457
1457
  var import_react5 = require("react");
1458
+
1459
+ // src/components/CheckBoxGroup/CheckBoxGroup.helpers.ts
1460
+ var areSelectedIdsEqual = (ids1, ids2) => {
1461
+ if (ids1 === ids2) return true;
1462
+ if (!ids1 || !ids2) return ids1 === ids2;
1463
+ if (ids1.length !== ids2.length) return false;
1464
+ for (let i = 0; i < ids1.length; i++) {
1465
+ if (ids1[i] !== ids2[i]) return false;
1466
+ }
1467
+ return true;
1468
+ };
1469
+ var isCategoryEnabled = (category, allCategories) => {
1470
+ if (!category.dependsOn || category.dependsOn.length === 0) {
1471
+ return true;
1472
+ }
1473
+ return category.dependsOn.every((depKey) => {
1474
+ const depCat = allCategories.find((c) => c.key === depKey);
1475
+ return depCat?.selectedIds && depCat.selectedIds.length > 0;
1476
+ });
1477
+ };
1478
+ var isItemMatchingFilter = (item, filter, allCategories) => {
1479
+ const parentCat = allCategories.find((c) => c.key === filter.key);
1480
+ const parentSelectedIds = parentCat?.selectedIds || [];
1481
+ const itemFieldValue = item[filter.internalField];
1482
+ return parentSelectedIds.includes(String(itemFieldValue));
1483
+ };
1484
+ var getBadgeText = (category, formattedItems) => {
1485
+ const visibleIds = formattedItems.flatMap((group) => group.itens || []).map((i) => i.id);
1486
+ const selectedVisibleCount = visibleIds.filter(
1487
+ (id) => category.selectedIds?.includes(id)
1488
+ ).length;
1489
+ const totalVisible = visibleIds.length;
1490
+ return `${selectedVisibleCount} de ${totalVisible} ${selectedVisibleCount === 1 ? "selecionado" : "selecionados"}`;
1491
+ };
1492
+ var handleAccordionValueChange = (value, categories, isCategoryEnabledFn) => {
1493
+ if (typeof value !== "string") {
1494
+ if (!value) {
1495
+ return "";
1496
+ }
1497
+ return null;
1498
+ }
1499
+ if (!value) {
1500
+ return "";
1501
+ }
1502
+ const category = categories.find((c) => c.key === value);
1503
+ if (!category) {
1504
+ return null;
1505
+ }
1506
+ const isEnabled = isCategoryEnabledFn(category);
1507
+ if (!isEnabled) {
1508
+ return null;
1509
+ }
1510
+ return value;
1511
+ };
1512
+ var calculateFormattedItemsForAutoSelection = (category, allCategories) => {
1513
+ if (!category?.dependsOn || category.dependsOn.length === 0) {
1514
+ return category?.itens || [];
1515
+ }
1516
+ const isEnabled = isCategoryEnabled(category, allCategories);
1517
+ if (!isEnabled) {
1518
+ return [];
1519
+ }
1520
+ const filters = category.filteredBy || [];
1521
+ if (filters.length === 0) {
1522
+ return category?.itens || [];
1523
+ }
1524
+ const selectedIdsArr = filters.map((f) => {
1525
+ const parentCat = allCategories.find((c) => c.key === f.key);
1526
+ if (!parentCat?.selectedIds?.length) {
1527
+ return [];
1528
+ }
1529
+ return parentCat.selectedIds;
1530
+ });
1531
+ if (selectedIdsArr.some((arr) => arr.length === 0)) {
1532
+ return [];
1533
+ }
1534
+ const filteredItems = (category.itens || []).filter(
1535
+ (item) => filters.every((filter) => isItemMatchingFilter(item, filter, allCategories))
1536
+ );
1537
+ return filteredItems;
1538
+ };
1539
+
1540
+ // src/components/Filter/useTableFilter.ts
1458
1541
  var mergeConfigsWithSelections = (newConfigs, prevConfigs) => {
1459
1542
  let changed = false;
1460
1543
  const result = newConfigs.map((newConfig, i) => ({
@@ -1514,6 +1597,22 @@ var useTableFilter = (initialConfigs, options = {}) => {
1514
1597
  return filters;
1515
1598
  }, [filterConfigs]);
1516
1599
  const hasActiveFilters = Object.keys(activeFilters).length > 0;
1600
+ const activeFiltersCount = (0, import_react5.useMemo)(() => {
1601
+ const allCategories = filterConfigs.flatMap((config) => config.categories);
1602
+ let count = 0;
1603
+ for (const category of allCategories) {
1604
+ if (!category.selectedIds || category.selectedIds.length === 0) continue;
1605
+ const availableItems = calculateFormattedItemsForAutoSelection(
1606
+ category,
1607
+ allCategories
1608
+ );
1609
+ const isAutoSelected = availableItems.length === 1 && category.selectedIds.length === 1 && category.selectedIds[0] === availableItems[0]?.id;
1610
+ if (!isAutoSelected) {
1611
+ count++;
1612
+ }
1613
+ }
1614
+ return count;
1615
+ }, [filterConfigs]);
1517
1616
  const updateFilters = (0, import_react5.useCallback)((configs) => {
1518
1617
  setFilterConfigs(configs);
1519
1618
  }, []);
@@ -1574,6 +1673,7 @@ var useTableFilter = (initialConfigs, options = {}) => {
1574
1673
  filterConfigs,
1575
1674
  activeFilters,
1576
1675
  hasActiveFilters,
1676
+ activeFiltersCount,
1577
1677
  updateFilters,
1578
1678
  applyFilters,
1579
1679
  clearFilters
@@ -3012,87 +3112,6 @@ var CheckBox = (0, import_react13.forwardRef)(
3012
3112
  CheckBox.displayName = "CheckBox";
3013
3113
  var CheckBox_default = CheckBox;
3014
3114
 
3015
- // src/components/CheckBoxGroup/CheckBoxGroup.helpers.ts
3016
- var areSelectedIdsEqual = (ids1, ids2) => {
3017
- if (ids1 === ids2) return true;
3018
- if (!ids1 || !ids2) return ids1 === ids2;
3019
- if (ids1.length !== ids2.length) return false;
3020
- for (let i = 0; i < ids1.length; i++) {
3021
- if (ids1[i] !== ids2[i]) return false;
3022
- }
3023
- return true;
3024
- };
3025
- var isCategoryEnabled = (category, allCategories) => {
3026
- if (!category.dependsOn || category.dependsOn.length === 0) {
3027
- return true;
3028
- }
3029
- return category.dependsOn.every((depKey) => {
3030
- const depCat = allCategories.find((c) => c.key === depKey);
3031
- return depCat?.selectedIds && depCat.selectedIds.length > 0;
3032
- });
3033
- };
3034
- var isItemMatchingFilter = (item, filter, allCategories) => {
3035
- const parentCat = allCategories.find((c) => c.key === filter.key);
3036
- const parentSelectedIds = parentCat?.selectedIds || [];
3037
- const itemFieldValue = item[filter.internalField];
3038
- return parentSelectedIds.includes(String(itemFieldValue));
3039
- };
3040
- var getBadgeText = (category, formattedItems) => {
3041
- const visibleIds = formattedItems.flatMap((group) => group.itens || []).map((i) => i.id);
3042
- const selectedVisibleCount = visibleIds.filter(
3043
- (id) => category.selectedIds?.includes(id)
3044
- ).length;
3045
- const totalVisible = visibleIds.length;
3046
- return `${selectedVisibleCount} de ${totalVisible} ${selectedVisibleCount === 1 ? "selecionado" : "selecionados"}`;
3047
- };
3048
- var handleAccordionValueChange = (value, categories, isCategoryEnabledFn) => {
3049
- if (typeof value !== "string") {
3050
- if (!value) {
3051
- return "";
3052
- }
3053
- return null;
3054
- }
3055
- if (!value) {
3056
- return "";
3057
- }
3058
- const category = categories.find((c) => c.key === value);
3059
- if (!category) {
3060
- return null;
3061
- }
3062
- const isEnabled = isCategoryEnabledFn(category);
3063
- if (!isEnabled) {
3064
- return null;
3065
- }
3066
- return value;
3067
- };
3068
- var calculateFormattedItemsForAutoSelection = (category, allCategories) => {
3069
- if (!category?.dependsOn || category.dependsOn.length === 0) {
3070
- return category?.itens || [];
3071
- }
3072
- const isEnabled = isCategoryEnabled(category, allCategories);
3073
- if (!isEnabled) {
3074
- return [];
3075
- }
3076
- const filters = category.filteredBy || [];
3077
- if (filters.length === 0) {
3078
- return category?.itens || [];
3079
- }
3080
- const selectedIdsArr = filters.map((f) => {
3081
- const parentCat = allCategories.find((c) => c.key === f.key);
3082
- if (!parentCat?.selectedIds?.length) {
3083
- return [];
3084
- }
3085
- return parentCat.selectedIds;
3086
- });
3087
- if (selectedIdsArr.some((arr) => arr.length === 0)) {
3088
- return [];
3089
- }
3090
- const filteredItems = (category.itens || []).filter(
3091
- (item) => filters.every((filter) => isItemMatchingFilter(item, filter, allCategories))
3092
- );
3093
- return filteredItems;
3094
- };
3095
-
3096
3115
  // src/components/Divider/Divider.tsx
3097
3116
  init_utils();
3098
3117
  var import_jsx_runtime17 = require("react/jsx-runtime");
@@ -6920,6 +6939,7 @@ function TableProvider({
6920
6939
  filterConfigs: [],
6921
6940
  activeFilters: {},
6922
6941
  hasActiveFilters: false,
6942
+ activeFiltersCount: 0,
6923
6943
  updateFilters: () => {
6924
6944
  },
6925
6945
  applyFilters: () => {
@@ -6933,7 +6953,7 @@ function TableProvider({
6933
6953
  const {
6934
6954
  filterConfigs,
6935
6955
  activeFilters,
6936
- hasActiveFilters,
6956
+ activeFiltersCount,
6937
6957
  updateFilters,
6938
6958
  applyFilters,
6939
6959
  clearFilters
@@ -7031,7 +7051,7 @@ function TableProvider({
7031
7051
  children: [
7032
7052
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_phosphor_react16.Funnel, { size: 20 }),
7033
7053
  "Filtros",
7034
- hasActiveFilters && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "ml-2 rounded-full bg-primary-500 px-2 py-0.5 text-xs text-white", children: Object.keys(activeFilters).length })
7054
+ activeFiltersCount > 0 && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "ml-2 rounded-full bg-primary-500 px-2 py-0.5 text-xs text-white", children: activeFiltersCount })
7035
7055
  ]
7036
7056
  }
7037
7057
  ),