@charlesgomes/leafcode-shared-lib-react 1.0.51 → 1.0.52
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.d.mts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +607 -632
- package/dist/index.mjs +604 -629
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -461,288 +461,6 @@ var useDebounce = (value, delay) => {
|
|
|
461
461
|
return debouncedValue;
|
|
462
462
|
};
|
|
463
463
|
|
|
464
|
-
// src/components/DataTableAdvancedFilter/utils/DataTableUtils.tsx
|
|
465
|
-
import { FilterMatchMode as FilterMatchMode3, FilterOperator } from "primereact/api";
|
|
466
|
-
var mapMatchMode = (mode) => {
|
|
467
|
-
switch (mode) {
|
|
468
|
-
case "startsWith":
|
|
469
|
-
return "StartsWith";
|
|
470
|
-
case "contains":
|
|
471
|
-
return "Contains";
|
|
472
|
-
case "equals":
|
|
473
|
-
return "Equals";
|
|
474
|
-
case "notEquals":
|
|
475
|
-
return "notEquals";
|
|
476
|
-
case "endsWith":
|
|
477
|
-
return "EndsWith";
|
|
478
|
-
case "lt":
|
|
479
|
-
case "dateBefore":
|
|
480
|
-
return "LessThan";
|
|
481
|
-
case "lte":
|
|
482
|
-
return "LessThanOrEqualTo";
|
|
483
|
-
case "gt":
|
|
484
|
-
case "dateAfter":
|
|
485
|
-
return "GreaterThan";
|
|
486
|
-
case "gte":
|
|
487
|
-
return "GreaterThanOrEqualTo";
|
|
488
|
-
case "notContains":
|
|
489
|
-
return "NotContains";
|
|
490
|
-
case "empty":
|
|
491
|
-
return "Empty";
|
|
492
|
-
default:
|
|
493
|
-
return "Equals";
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
var buildFilterPayload = (fieldName, matchMode, rawValue) => {
|
|
497
|
-
const normalized = normalizeFilterValue(rawValue);
|
|
498
|
-
if (matchMode === "empty") {
|
|
499
|
-
return {
|
|
500
|
-
field: fieldName,
|
|
501
|
-
operator: "Empty"
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
if (matchMode === "notEmpty") {
|
|
505
|
-
return {
|
|
506
|
-
not: {
|
|
507
|
-
field: fieldName,
|
|
508
|
-
operator: "Empty"
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
if (normalized === null) return null;
|
|
513
|
-
if (matchMode === "notStartsWith" || matchMode === "notEndsWith" || matchMode === "notEquals" || // <- notEquals
|
|
514
|
-
matchMode === "dateIsNot" || matchMode === "notContains") {
|
|
515
|
-
let operator;
|
|
516
|
-
switch (matchMode) {
|
|
517
|
-
case "notStartsWith":
|
|
518
|
-
operator = "StartsWith";
|
|
519
|
-
break;
|
|
520
|
-
case "notEndsWith":
|
|
521
|
-
operator = "EndsWith";
|
|
522
|
-
break;
|
|
523
|
-
case "notContains":
|
|
524
|
-
operator = "Contains";
|
|
525
|
-
break;
|
|
526
|
-
case "notEquals":
|
|
527
|
-
case "dateIsNot":
|
|
528
|
-
default:
|
|
529
|
-
operator = "Equals";
|
|
530
|
-
}
|
|
531
|
-
return {
|
|
532
|
-
not: {
|
|
533
|
-
field: fieldName,
|
|
534
|
-
operator,
|
|
535
|
-
value: normalized
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
return {
|
|
540
|
-
field: fieldName,
|
|
541
|
-
operator: mapMatchMode(matchMode),
|
|
542
|
-
value: normalized
|
|
543
|
-
};
|
|
544
|
-
};
|
|
545
|
-
var mapPrimeToBackendFilters = (filters, globalFilterFields) => {
|
|
546
|
-
const finalAnd = [];
|
|
547
|
-
const globalOr = [];
|
|
548
|
-
const camposMap = {};
|
|
549
|
-
Object.entries(filters).forEach(([field, config]) => {
|
|
550
|
-
if (!config) return;
|
|
551
|
-
const value = config?.value?.text ?? config?.value;
|
|
552
|
-
if (field === "global" && typeof config.value === "string" && config.value.trim() !== "") {
|
|
553
|
-
const globalOrNodes = [];
|
|
554
|
-
globalFilterFields.forEach((globalField) => {
|
|
555
|
-
const fieldConfig = filters[globalField];
|
|
556
|
-
if (!fieldConfig) return;
|
|
557
|
-
const payload = buildFilterPayload(
|
|
558
|
-
fieldConfig.filterFieldCollection ?? globalField,
|
|
559
|
-
resolveMatchMode(config.matchMode, config.value),
|
|
560
|
-
config.value
|
|
561
|
-
);
|
|
562
|
-
if (!payload) return;
|
|
563
|
-
if (!fieldConfig.collection) {
|
|
564
|
-
globalOrNodes.push(payload);
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
const rootCollections = [];
|
|
568
|
-
pushIntoCollectionTree(
|
|
569
|
-
rootCollections,
|
|
570
|
-
fieldConfig.collection,
|
|
571
|
-
payload.field ?? payload.not?.field,
|
|
572
|
-
payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
|
|
573
|
-
);
|
|
574
|
-
globalOrNodes.push(...rootCollections);
|
|
575
|
-
});
|
|
576
|
-
if (globalOrNodes.length) {
|
|
577
|
-
finalAnd.push({ or: globalOrNodes });
|
|
578
|
-
}
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
const constraints = Array.isArray(config.constraints) ? config.constraints.filter((c) => normalizeFilterValue(c.value) !== null || normalizeFilterValue(c.value) === "__NULL__") : [];
|
|
582
|
-
if (!constraints.length) return;
|
|
583
|
-
const colOperator = config.operator === "or" ? "or" : "and";
|
|
584
|
-
if (config.collection === "campos" && config.fieldId) {
|
|
585
|
-
if (!camposMap[config.fieldId]) {
|
|
586
|
-
camposMap[config.fieldId] = { operator: colOperator, values: [] };
|
|
587
|
-
}
|
|
588
|
-
constraints.forEach((c) => {
|
|
589
|
-
const effectiveMatchMode = resolveMatchMode(c.matchMode, c.value);
|
|
590
|
-
const payload = buildFilterPayload(config.filterFieldCollection ?? "valor", effectiveMatchMode, c.value);
|
|
591
|
-
if (payload) camposMap[config.fieldId].values.push(payload);
|
|
592
|
-
});
|
|
593
|
-
return;
|
|
594
|
-
}
|
|
595
|
-
const columnPayloads = constraints.map(
|
|
596
|
-
(c) => buildFilterPayload(config.filterFieldCollection ?? field, resolveMatchMode(c.matchMode, c.value), c.value)
|
|
597
|
-
).filter(Boolean);
|
|
598
|
-
if (!columnPayloads.length) return;
|
|
599
|
-
if (config.collection) {
|
|
600
|
-
const rootCollections = [];
|
|
601
|
-
columnPayloads.forEach((payload) => {
|
|
602
|
-
pushIntoCollectionTree(
|
|
603
|
-
rootCollections,
|
|
604
|
-
config.collection,
|
|
605
|
-
payload.field ?? payload.not?.field,
|
|
606
|
-
payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
|
|
607
|
-
);
|
|
608
|
-
});
|
|
609
|
-
rootCollections.forEach((c) => finalAnd.push(c));
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
finalAnd.push({ [colOperator]: columnPayloads });
|
|
613
|
-
});
|
|
614
|
-
Object.entries(camposMap).forEach(([fieldId, config]) => {
|
|
615
|
-
if (!config.values.length) return;
|
|
616
|
-
finalAnd.push({
|
|
617
|
-
collection: "campos",
|
|
618
|
-
any: {
|
|
619
|
-
and: [
|
|
620
|
-
{ field: "tipocampo.id", operator: "Equals", value: fieldId },
|
|
621
|
-
{ [config.operator]: config.values }
|
|
622
|
-
]
|
|
623
|
-
}
|
|
624
|
-
});
|
|
625
|
-
});
|
|
626
|
-
return finalAnd.length ? { and: finalAnd } : void 0;
|
|
627
|
-
};
|
|
628
|
-
function pushIntoCollectionTree(root, collectionPath, fieldName, payloadBase) {
|
|
629
|
-
const collections = collectionPath.split(".");
|
|
630
|
-
let current = root;
|
|
631
|
-
collections.forEach((collection) => {
|
|
632
|
-
let node = current.find(
|
|
633
|
-
(n) => n.collection === collection && n.any
|
|
634
|
-
);
|
|
635
|
-
if (!node) {
|
|
636
|
-
node = {
|
|
637
|
-
collection,
|
|
638
|
-
any: { or: [] }
|
|
639
|
-
};
|
|
640
|
-
current.push(node);
|
|
641
|
-
}
|
|
642
|
-
current = node.any.or;
|
|
643
|
-
});
|
|
644
|
-
current.push({
|
|
645
|
-
...payloadBase,
|
|
646
|
-
field: fieldName
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
|
-
function getMatchModeByTipo(tipo) {
|
|
650
|
-
switch (tipo) {
|
|
651
|
-
case "NumeroInteiro":
|
|
652
|
-
case "NumeroDecimal":
|
|
653
|
-
return FilterMatchMode3.EQUALS;
|
|
654
|
-
default:
|
|
655
|
-
return FilterMatchMode3.CONTAINS;
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
function buildDynamicCampoFilters(campos) {
|
|
659
|
-
return campos?.reduce((acc, campo) => {
|
|
660
|
-
acc[`${campo.id}`] = {
|
|
661
|
-
operator: FilterOperator.AND,
|
|
662
|
-
constraints: [
|
|
663
|
-
{
|
|
664
|
-
value: null,
|
|
665
|
-
matchMode: getMatchModeByTipo(campo.tipoDado)
|
|
666
|
-
}
|
|
667
|
-
],
|
|
668
|
-
collection: "campos",
|
|
669
|
-
filterFieldCollection: "valor",
|
|
670
|
-
fieldId: campo.id
|
|
671
|
-
// opcional (útil pro backend)
|
|
672
|
-
};
|
|
673
|
-
return acc;
|
|
674
|
-
}, {});
|
|
675
|
-
}
|
|
676
|
-
var getUrlParams = (sortFieldInitial, sortOrderInitial) => {
|
|
677
|
-
const params = new URLSearchParams(
|
|
678
|
-
typeof window !== "undefined" ? window.location.search : ""
|
|
679
|
-
);
|
|
680
|
-
return {
|
|
681
|
-
page: Number(params.get("page") ?? 1),
|
|
682
|
-
rows: Number(params.get("rows") ?? 10),
|
|
683
|
-
sortField: params.get("sortField") || sortFieldInitial || "",
|
|
684
|
-
sortOrder: Number(params.get("sortOrder") ?? sortOrderInitial),
|
|
685
|
-
filter: params.get("filter") ?? ""
|
|
686
|
-
};
|
|
687
|
-
};
|
|
688
|
-
function buildSortingWithFilters(filters, sortField, order) {
|
|
689
|
-
const direction = order === 1 ? "asc" : order === -1 ? "Des" : "Asc";
|
|
690
|
-
let sorting = [
|
|
691
|
-
{
|
|
692
|
-
field: sortField,
|
|
693
|
-
direction
|
|
694
|
-
}
|
|
695
|
-
];
|
|
696
|
-
if (!filters || !sortField) {
|
|
697
|
-
return sorting;
|
|
698
|
-
}
|
|
699
|
-
const sortFilter = Object.prototype.hasOwnProperty.call(filters, sortField) ? filters[sortField] : null;
|
|
700
|
-
if (sortFilter?.fieldId) {
|
|
701
|
-
sorting = [
|
|
702
|
-
{
|
|
703
|
-
collection: "campos",
|
|
704
|
-
filter: {
|
|
705
|
-
field: "tipocampo.id",
|
|
706
|
-
operator: "equals",
|
|
707
|
-
value: sortFilter.fieldId
|
|
708
|
-
},
|
|
709
|
-
first: {
|
|
710
|
-
field: "valor",
|
|
711
|
-
direction
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
];
|
|
715
|
-
}
|
|
716
|
-
return sorting;
|
|
717
|
-
}
|
|
718
|
-
function normalizeFilterValue(raw) {
|
|
719
|
-
if (raw === null || raw === void 0) return null;
|
|
720
|
-
if (typeof raw === "boolean") {
|
|
721
|
-
return String(raw);
|
|
722
|
-
}
|
|
723
|
-
if (typeof raw === "number") {
|
|
724
|
-
return raw;
|
|
725
|
-
}
|
|
726
|
-
if (typeof raw === "string") {
|
|
727
|
-
return raw.trim() !== "" ? raw : null;
|
|
728
|
-
}
|
|
729
|
-
if (typeof raw === "object") {
|
|
730
|
-
if ("text" in raw && raw.text === null) {
|
|
731
|
-
return "__NULL__";
|
|
732
|
-
}
|
|
733
|
-
if (typeof raw.text === "string") {
|
|
734
|
-
return raw.text.trim() !== "" ? raw.text : null;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
return null;
|
|
738
|
-
}
|
|
739
|
-
function resolveMatchMode(constraintMatchMode, rawValue) {
|
|
740
|
-
if (rawValue && typeof rawValue === "object" && typeof rawValue.matchMode === "string") {
|
|
741
|
-
return rawValue.matchMode;
|
|
742
|
-
}
|
|
743
|
-
return constraintMatchMode;
|
|
744
|
-
}
|
|
745
|
-
|
|
746
464
|
// src/components/DataTableAdvancedFilter/DataTableAdvancedFilterWrapper.tsx
|
|
747
465
|
import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
748
466
|
function DataTableAdvancedFilterWrapper({
|
|
@@ -760,28 +478,29 @@ function DataTableAdvancedFilterWrapper({
|
|
|
760
478
|
sortOrderInitial = 1,
|
|
761
479
|
isMultiSelectionMode = true,
|
|
762
480
|
isLanguagePtBr = true,
|
|
763
|
-
|
|
481
|
+
state,
|
|
482
|
+
onStateChange
|
|
764
483
|
}) {
|
|
765
484
|
const [isClient, setIsClient] = useState2(false);
|
|
766
485
|
useEffect3(() => {
|
|
767
486
|
setIsClient(true);
|
|
768
487
|
}, []);
|
|
769
|
-
const {
|
|
770
|
-
page:
|
|
771
|
-
rows:
|
|
772
|
-
sortField:
|
|
773
|
-
sortOrder:
|
|
774
|
-
filter:
|
|
775
|
-
}
|
|
776
|
-
const [page, setPage] = useState2(
|
|
777
|
-
const [rows, setRows] = useState2(
|
|
778
|
-
const [first, setFirst] = useState2((
|
|
779
|
-
const [sortField, setSortField] = useState2(
|
|
780
|
-
const [sortOrder, setSortOrder] = useState2(
|
|
781
|
-
const [searchText, setSearchText] = useState2(
|
|
488
|
+
const initialState = state ?? {
|
|
489
|
+
page: 1,
|
|
490
|
+
rows: 10,
|
|
491
|
+
sortField: sortFieldInitial,
|
|
492
|
+
sortOrder: sortOrderInitial,
|
|
493
|
+
filter: ""
|
|
494
|
+
};
|
|
495
|
+
const [page, setPage] = useState2(initialState.page);
|
|
496
|
+
const [rows, setRows] = useState2(initialState.rows);
|
|
497
|
+
const [first, setFirst] = useState2((initialState.page - 1) * initialState.rows);
|
|
498
|
+
const [sortField, setSortField] = useState2(initialState.sortField);
|
|
499
|
+
const [sortOrder, setSortOrder] = useState2(initialState.sortOrder ?? 1);
|
|
500
|
+
const [searchText, setSearchText] = useState2(initialState.filter ?? "");
|
|
782
501
|
const [filters, setFilters] = useState2({
|
|
783
502
|
...initFilters,
|
|
784
|
-
global: { value:
|
|
503
|
+
global: { value: initialState.filter, matchMode: "contains" }
|
|
785
504
|
});
|
|
786
505
|
const [selectedRowsData, setSelectedRowsData] = useState2([]);
|
|
787
506
|
const debouncedSearch = useDebounce(searchText, 500);
|
|
@@ -808,66 +527,42 @@ function DataTableAdvancedFilterWrapper({
|
|
|
808
527
|
globalFilterFields
|
|
809
528
|
)
|
|
810
529
|
});
|
|
811
|
-
|
|
812
|
-
if (
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
key,
|
|
820
|
-
typeof value === "string" ? value : JSON.stringify(value)
|
|
821
|
-
);
|
|
822
|
-
}
|
|
823
|
-
});
|
|
824
|
-
const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
|
|
825
|
-
if (mode === "replace") {
|
|
826
|
-
window.history.replaceState(null, "", newUrl);
|
|
827
|
-
} else {
|
|
828
|
-
window.history.pushState(null, "", newUrl);
|
|
829
|
-
}
|
|
830
|
-
};
|
|
831
|
-
const hydrateFromUrl = () => {
|
|
832
|
-
const params = new URLSearchParams(window.location.search);
|
|
833
|
-
const pageParam = Number(params.get("page") ?? 1);
|
|
834
|
-
const rowsParam = Number(params.get("rows") ?? rows);
|
|
835
|
-
const sortFieldParam = params.get("sortField") ?? sortFieldInitial;
|
|
836
|
-
const sortOrderParam = Number(params.get("sortOrder") ?? sortOrderInitial);
|
|
837
|
-
const filterParam = params.get("filter") ?? "";
|
|
838
|
-
setPage(pageParam);
|
|
839
|
-
setRows(rowsParam);
|
|
840
|
-
setFirst((pageParam - 1) * rowsParam);
|
|
841
|
-
setSortField(sortFieldParam);
|
|
842
|
-
setSortOrder(sortOrderParam);
|
|
843
|
-
setSearchText(filterParam);
|
|
530
|
+
useEffect3(() => {
|
|
531
|
+
if (!state) return;
|
|
532
|
+
setPage(state.page);
|
|
533
|
+
setRows(state.rows);
|
|
534
|
+
setFirst((state.page - 1) * state.rows);
|
|
535
|
+
setSortField(state.sortField);
|
|
536
|
+
setSortOrder(state.sortOrder ?? 1);
|
|
537
|
+
setSearchText(state.filter ?? "");
|
|
844
538
|
setFilters((prev) => ({
|
|
845
539
|
...prev,
|
|
846
540
|
global: {
|
|
847
541
|
...prev.global ?? { matchMode: "contains" },
|
|
848
|
-
value:
|
|
542
|
+
value: state.filter ?? ""
|
|
849
543
|
}
|
|
850
544
|
}));
|
|
545
|
+
}, [state]);
|
|
546
|
+
const emitStateChange = (partial) => {
|
|
547
|
+
if (!onStateChange) return;
|
|
548
|
+
onStateChange({
|
|
549
|
+
page,
|
|
550
|
+
rows,
|
|
551
|
+
sortField,
|
|
552
|
+
sortOrder,
|
|
553
|
+
filter: searchText,
|
|
554
|
+
...partial
|
|
555
|
+
});
|
|
851
556
|
};
|
|
852
|
-
useEffect3(() => {
|
|
853
|
-
if (typeof window === "undefined") return;
|
|
854
|
-
const handlePopState = () => {
|
|
855
|
-
hydrateFromUrl();
|
|
856
|
-
};
|
|
857
|
-
window.addEventListener("popstate", handlePopState);
|
|
858
|
-
return () => {
|
|
859
|
-
window.removeEventListener("popstate", handlePopState);
|
|
860
|
-
};
|
|
861
|
-
}, []);
|
|
862
557
|
const onPage = (event) => {
|
|
863
558
|
const newPage = event.page + 1;
|
|
864
559
|
setFirst(event.first);
|
|
865
560
|
setRows(event.rows);
|
|
866
561
|
setPage(newPage);
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
);
|
|
562
|
+
emitStateChange({
|
|
563
|
+
page: newPage,
|
|
564
|
+
rows: event.rows
|
|
565
|
+
});
|
|
871
566
|
};
|
|
872
567
|
const onGlobalFilterChange = (e) => {
|
|
873
568
|
const value = e.target.value;
|
|
@@ -883,16 +578,16 @@ function DataTableAdvancedFilterWrapper({
|
|
|
883
578
|
const onSort = (e) => {
|
|
884
579
|
setSortField(e.sortField);
|
|
885
580
|
setSortOrder(e.sortOrder);
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
);
|
|
581
|
+
emitStateChange({
|
|
582
|
+
sortField: e.sortField,
|
|
583
|
+
sortOrder: e.sortOrder
|
|
584
|
+
});
|
|
890
585
|
};
|
|
891
586
|
useEffect3(() => {
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
);
|
|
587
|
+
emitStateChange({
|
|
588
|
+
page: 1,
|
|
589
|
+
filter: debouncedSearch
|
|
590
|
+
});
|
|
896
591
|
}, [debouncedSearch]);
|
|
897
592
|
useEffect3(() => {
|
|
898
593
|
if (customers?.items && selectedRowsData.length > 0) {
|
|
@@ -1229,8 +924,7 @@ function DataTableAdvancedFilter({
|
|
|
1229
924
|
sortFieldInitial,
|
|
1230
925
|
sortOrderInitial = 1,
|
|
1231
926
|
isMultiSelectionMode = true,
|
|
1232
|
-
isLanguagePtBr = true
|
|
1233
|
-
replaceUrl = true
|
|
927
|
+
isLanguagePtBr = true
|
|
1234
928
|
}) {
|
|
1235
929
|
const [isClient, setIsClient] = useState3(false);
|
|
1236
930
|
useEffect4(() => {
|
|
@@ -1262,8 +956,7 @@ function DataTableAdvancedFilter({
|
|
|
1262
956
|
sortFieldInitial,
|
|
1263
957
|
sortOrderInitial,
|
|
1264
958
|
isMultiSelectionMode,
|
|
1265
|
-
isLanguagePtBr
|
|
1266
|
-
replaceUrl
|
|
959
|
+
isLanguagePtBr
|
|
1267
960
|
}
|
|
1268
961
|
)
|
|
1269
962
|
}
|
|
@@ -1280,303 +973,585 @@ var DateFilterTemplate = (options, mask) => {
|
|
|
1280
973
|
return /* @__PURE__ */ jsx11(
|
|
1281
974
|
Calendar,
|
|
1282
975
|
{
|
|
1283
|
-
value: parsedValue,
|
|
976
|
+
value: parsedValue,
|
|
977
|
+
onChange: (e) => {
|
|
978
|
+
if (!e.value) {
|
|
979
|
+
options.filterCallback(null, options.index);
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
const date = e.value;
|
|
983
|
+
const valueToFilter = mask ? mask(date) : `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
|
|
984
|
+
2,
|
|
985
|
+
"0"
|
|
986
|
+
)}-${String(date.getDate()).padStart(2, "0")}`;
|
|
987
|
+
options.filterCallback(valueToFilter, options.index);
|
|
988
|
+
},
|
|
989
|
+
dateFormat: "dd/mm/yy",
|
|
990
|
+
placeholder: "dd/mm/yyyy",
|
|
991
|
+
mask: "99/99/9999",
|
|
992
|
+
inputClassName: "p-column-filter"
|
|
993
|
+
}
|
|
994
|
+
);
|
|
995
|
+
};
|
|
996
|
+
var DateTimeFilterTemplate = (options, mask) => {
|
|
997
|
+
const value = typeof options.value === "string" ? moment2(options.value).toDate() : options.value ?? null;
|
|
998
|
+
return /* @__PURE__ */ jsx11(
|
|
999
|
+
Calendar,
|
|
1000
|
+
{
|
|
1001
|
+
value,
|
|
1002
|
+
showTime: true,
|
|
1003
|
+
showSeconds: true,
|
|
1004
|
+
hourFormat: "24",
|
|
1005
|
+
dateFormat: "dd/mm/yy",
|
|
1006
|
+
placeholder: "dd/mm/yyyy 00:00:00",
|
|
1007
|
+
readOnlyInput: true,
|
|
1008
|
+
inputClassName: "p-column-filter",
|
|
1284
1009
|
onChange: (e) => {
|
|
1285
|
-
|
|
1010
|
+
const selectedDate = e.value;
|
|
1011
|
+
if (!selectedDate) {
|
|
1286
1012
|
options.filterCallback(null, options.index);
|
|
1287
1013
|
return;
|
|
1288
1014
|
}
|
|
1289
|
-
const
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1015
|
+
const formatted = mask ? mask(selectedDate) : moment2(selectedDate).utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
|
|
1016
|
+
options.filterCallback(formatted, options.index);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
);
|
|
1020
|
+
};
|
|
1021
|
+
var ValueFilterTemplate = (options, mask) => {
|
|
1022
|
+
const parsedValue = options.value !== null && options.value !== void 0 ? centsToReal(options.value) : null;
|
|
1023
|
+
const handleChange = (e) => {
|
|
1024
|
+
const rawValue = e.value;
|
|
1025
|
+
if (rawValue === null || rawValue === void 0) {
|
|
1026
|
+
options.filterCallback(null, options.index);
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
const valueToFilter = mask ? mask(rawValue) : rawValue;
|
|
1030
|
+
options.filterCallback(valueToFilter, options.index);
|
|
1031
|
+
};
|
|
1032
|
+
return /* @__PURE__ */ jsx11(
|
|
1033
|
+
InputNumber,
|
|
1034
|
+
{
|
|
1035
|
+
value: parsedValue,
|
|
1036
|
+
onValueChange: handleChange,
|
|
1037
|
+
mode: "currency",
|
|
1038
|
+
currency: "BRL",
|
|
1039
|
+
locale: "pt-BR",
|
|
1040
|
+
inputClassName: "custom-input"
|
|
1041
|
+
}
|
|
1042
|
+
);
|
|
1043
|
+
};
|
|
1044
|
+
var SelectFilterTemplate = (options, isLanguagePtBr = true, items = []) => {
|
|
1045
|
+
const selectOptions = items.length > 0 ? items : [
|
|
1046
|
+
{ label: isLanguagePtBr ? "Todos" : "All", value: null },
|
|
1047
|
+
{ label: isLanguagePtBr ? "Sim" : "Yes", value: true },
|
|
1048
|
+
{ label: isLanguagePtBr ? "N\xE3o" : "No", value: false }
|
|
1049
|
+
];
|
|
1050
|
+
const currentValue = selectOptions.find((opt) => opt.value === options.value) || null;
|
|
1051
|
+
return /* @__PURE__ */ jsx11(
|
|
1052
|
+
Select,
|
|
1053
|
+
{
|
|
1054
|
+
options: selectOptions,
|
|
1055
|
+
value: currentValue,
|
|
1056
|
+
onChange: (selected) => options.filterCallback(selected?.value),
|
|
1057
|
+
placeholder: "Todos",
|
|
1058
|
+
isClearable: false,
|
|
1059
|
+
isSearchable: false,
|
|
1060
|
+
className: "custom-select-filtro",
|
|
1061
|
+
classNamePrefix: "custom-select-filtro",
|
|
1062
|
+
styles: {
|
|
1063
|
+
control: (baseStyles, state) => ({
|
|
1064
|
+
...baseStyles,
|
|
1065
|
+
"&:hover": {
|
|
1066
|
+
borderColor: state.isFocused ? "#094394" : ""
|
|
1067
|
+
},
|
|
1068
|
+
borderRadius: "6px"
|
|
1069
|
+
}),
|
|
1070
|
+
menuList: (base) => ({
|
|
1071
|
+
...base,
|
|
1072
|
+
"::-webkit-scrollbar": {
|
|
1073
|
+
width: "6px",
|
|
1074
|
+
height: "auto",
|
|
1075
|
+
overflowX: "hidden",
|
|
1076
|
+
overflowY: "hidden"
|
|
1077
|
+
},
|
|
1078
|
+
"::-webkit-scrollbar-track": {
|
|
1079
|
+
background: "#fff"
|
|
1080
|
+
},
|
|
1081
|
+
"::-webkit-scrollbar-thumb": {
|
|
1082
|
+
background: "#888",
|
|
1083
|
+
borderRadius: "2rem"
|
|
1084
|
+
},
|
|
1085
|
+
"::-webkit-scrollbar-thumb:hover": {
|
|
1086
|
+
background: "#555"
|
|
1087
|
+
}
|
|
1088
|
+
}),
|
|
1089
|
+
option: (provided, state) => ({
|
|
1090
|
+
...provided,
|
|
1091
|
+
backgroundColor: state.isFocused ? "#094394" : "#ffffff",
|
|
1092
|
+
color: state.isFocused ? "#ffffff" : "black",
|
|
1093
|
+
"&:hover": {
|
|
1094
|
+
backgroundColor: "#094394",
|
|
1095
|
+
// Cor de fundo quando em hover
|
|
1096
|
+
color: "#ffffff"
|
|
1097
|
+
// Cor da palavra quando em hover
|
|
1098
|
+
}
|
|
1099
|
+
})
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
);
|
|
1103
|
+
};
|
|
1104
|
+
var CustomFilterElement = (options, isLanguagePtBr = true, items) => {
|
|
1105
|
+
const resolvedItems = items ?? getDefaultFilterMatchOptionsString(isLanguagePtBr);
|
|
1106
|
+
const rawFilter = options.value ?? {};
|
|
1107
|
+
const currentMatchMode = rawFilter.matchMode ?? "contains";
|
|
1108
|
+
const currentValue = typeof rawFilter.text === "string" ? rawFilter.text : "";
|
|
1109
|
+
const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
|
|
1110
|
+
return /* @__PURE__ */ jsxs6(
|
|
1111
|
+
"div",
|
|
1112
|
+
{
|
|
1113
|
+
className: "filter-wrapper",
|
|
1114
|
+
style: {
|
|
1115
|
+
display: "flex",
|
|
1116
|
+
flexDirection: "column",
|
|
1117
|
+
gap: "8px",
|
|
1118
|
+
minWidth: "200px"
|
|
1295
1119
|
},
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1120
|
+
children: [
|
|
1121
|
+
/* @__PURE__ */ jsx11(
|
|
1122
|
+
Dropdown,
|
|
1123
|
+
{
|
|
1124
|
+
value: currentMatchMode,
|
|
1125
|
+
options: resolvedItems,
|
|
1126
|
+
optionLabel: "label",
|
|
1127
|
+
optionValue: "value",
|
|
1128
|
+
placeholder: "Tipo de filtro",
|
|
1129
|
+
style: { width: "100%" },
|
|
1130
|
+
onChange: (e) => {
|
|
1131
|
+
const newMatchMode = e.value;
|
|
1132
|
+
const isNewSpecial = newMatchMode === customMatchModes.empty || newMatchMode === customMatchModes.notEmpty;
|
|
1133
|
+
if (isNewSpecial) {
|
|
1134
|
+
options.filterCallback({
|
|
1135
|
+
text: null,
|
|
1136
|
+
matchMode: newMatchMode
|
|
1137
|
+
});
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
options.filterCallback({
|
|
1141
|
+
text: null,
|
|
1142
|
+
matchMode: newMatchMode
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
),
|
|
1147
|
+
!isSpecial && /* @__PURE__ */ jsx11(
|
|
1148
|
+
InputText,
|
|
1149
|
+
{
|
|
1150
|
+
value: currentValue,
|
|
1151
|
+
placeholder: isLanguagePtBr ? "Pesquisar" : "Search",
|
|
1152
|
+
style: { width: "100%" },
|
|
1153
|
+
className: "p-column-filter",
|
|
1154
|
+
onChange: (e) => {
|
|
1155
|
+
const value = e.target.value;
|
|
1156
|
+
if (value.trim()) {
|
|
1157
|
+
options.filterCallback({
|
|
1158
|
+
text: value,
|
|
1159
|
+
matchMode: currentMatchMode
|
|
1160
|
+
});
|
|
1161
|
+
} else {
|
|
1162
|
+
options.filterCallback({
|
|
1163
|
+
text: null,
|
|
1164
|
+
matchMode: currentMatchMode
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
)
|
|
1170
|
+
]
|
|
1171
|
+
}
|
|
1172
|
+
);
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
// src/components/DataTableAdvancedFilter/filterModes.ts
|
|
1176
|
+
import { FilterMatchMode as FilterMatchMode3 } from "primereact/api";
|
|
1177
|
+
var customMatchModes = {
|
|
1178
|
+
notStartsWith: "notStartsWith",
|
|
1179
|
+
notEndsWith: "notEndsWith",
|
|
1180
|
+
empty: "empty",
|
|
1181
|
+
notEmpty: "notEmpty"
|
|
1182
|
+
};
|
|
1183
|
+
var getDefaultFilterMatchOptionsString = (isLanguagePtBr = true) => [
|
|
1184
|
+
{
|
|
1185
|
+
label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
|
|
1186
|
+
value: FilterMatchMode3.CONTAINS
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
|
|
1190
|
+
value: FilterMatchMode3.NOT_CONTAINS
|
|
1191
|
+
},
|
|
1192
|
+
{
|
|
1193
|
+
label: isLanguagePtBr ? "Igual" : "Equals",
|
|
1194
|
+
value: FilterMatchMode3.EQUALS
|
|
1195
|
+
},
|
|
1196
|
+
{
|
|
1197
|
+
label: isLanguagePtBr ? "Diferente" : "Not equals",
|
|
1198
|
+
value: FilterMatchMode3.NOT_EQUALS
|
|
1199
|
+
},
|
|
1200
|
+
{
|
|
1201
|
+
label: isLanguagePtBr ? "Come\xE7a com" : "Starts with",
|
|
1202
|
+
value: FilterMatchMode3.STARTS_WITH
|
|
1203
|
+
},
|
|
1204
|
+
{
|
|
1205
|
+
label: isLanguagePtBr ? "N\xE3o come\xE7a com" : "Does not start with",
|
|
1206
|
+
value: customMatchModes.notStartsWith
|
|
1207
|
+
},
|
|
1208
|
+
{
|
|
1209
|
+
label: isLanguagePtBr ? "Termina com" : "Ends with",
|
|
1210
|
+
value: FilterMatchMode3.ENDS_WITH
|
|
1211
|
+
},
|
|
1212
|
+
{
|
|
1213
|
+
label: isLanguagePtBr ? "N\xE3o termina com" : "Does not end with",
|
|
1214
|
+
value: customMatchModes.notEndsWith
|
|
1215
|
+
},
|
|
1216
|
+
{
|
|
1217
|
+
label: isLanguagePtBr ? "Vazio" : "Empty",
|
|
1218
|
+
value: customMatchModes.empty
|
|
1219
|
+
},
|
|
1220
|
+
{
|
|
1221
|
+
label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
|
|
1222
|
+
value: customMatchModes.notEmpty
|
|
1223
|
+
}
|
|
1224
|
+
];
|
|
1225
|
+
var getDefaultFilterMatchOptionsStringArray = (isLanguagePtBr = true) => [
|
|
1226
|
+
{
|
|
1227
|
+
label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
|
|
1228
|
+
value: FilterMatchMode3.CONTAINS
|
|
1229
|
+
},
|
|
1230
|
+
{
|
|
1231
|
+
label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
|
|
1232
|
+
value: FilterMatchMode3.NOT_CONTAINS
|
|
1233
|
+
}
|
|
1234
|
+
];
|
|
1235
|
+
var getDefaultFilterMatchOptionsDate = (isLanguagePtBr) => [
|
|
1236
|
+
{
|
|
1237
|
+
label: isLanguagePtBr ? "Data antes de" : "Date before",
|
|
1238
|
+
value: FilterMatchMode3.DATE_BEFORE
|
|
1239
|
+
},
|
|
1240
|
+
{
|
|
1241
|
+
label: isLanguagePtBr ? "Data depois de" : "Date after",
|
|
1242
|
+
value: FilterMatchMode3.DATE_AFTER
|
|
1243
|
+
}
|
|
1244
|
+
];
|
|
1245
|
+
var getDefaultFilterMatchOptionsEnum = (isLanguagePtBr) => [
|
|
1246
|
+
{
|
|
1247
|
+
label: isLanguagePtBr ? "Igual" : "Equals",
|
|
1248
|
+
value: FilterMatchMode3.EQUALS
|
|
1249
|
+
},
|
|
1250
|
+
{
|
|
1251
|
+
label: isLanguagePtBr ? "Diferente" : "Not equals",
|
|
1252
|
+
value: FilterMatchMode3.NOT_EQUALS
|
|
1253
|
+
},
|
|
1254
|
+
{
|
|
1255
|
+
label: isLanguagePtBr ? "Vazio" : "Empty",
|
|
1256
|
+
value: customMatchModes.empty
|
|
1257
|
+
},
|
|
1258
|
+
{
|
|
1259
|
+
label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
|
|
1260
|
+
value: customMatchModes.notEmpty
|
|
1261
|
+
}
|
|
1262
|
+
];
|
|
1263
|
+
var getDefaultFilterMatchOptionsEnumNotNullable = (isLanguagePtBr) => [
|
|
1264
|
+
{
|
|
1265
|
+
label: isLanguagePtBr ? "Igual" : "Equals",
|
|
1266
|
+
value: FilterMatchMode3.EQUALS
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
label: isLanguagePtBr ? "Diferente" : "Not equals",
|
|
1270
|
+
value: FilterMatchMode3.NOT_EQUALS
|
|
1271
|
+
}
|
|
1272
|
+
];
|
|
1273
|
+
|
|
1274
|
+
// src/components/DataTableAdvancedFilter/utils/DataTableUtils.tsx
|
|
1275
|
+
import { FilterMatchMode as FilterMatchMode4, FilterOperator } from "primereact/api";
|
|
1276
|
+
var mapMatchMode = (mode) => {
|
|
1277
|
+
switch (mode) {
|
|
1278
|
+
case "startsWith":
|
|
1279
|
+
return "StartsWith";
|
|
1280
|
+
case "contains":
|
|
1281
|
+
return "Contains";
|
|
1282
|
+
case "equals":
|
|
1283
|
+
return "Equals";
|
|
1284
|
+
case "notEquals":
|
|
1285
|
+
return "notEquals";
|
|
1286
|
+
case "endsWith":
|
|
1287
|
+
return "EndsWith";
|
|
1288
|
+
case "lt":
|
|
1289
|
+
case "dateBefore":
|
|
1290
|
+
return "LessThan";
|
|
1291
|
+
case "lte":
|
|
1292
|
+
return "LessThanOrEqualTo";
|
|
1293
|
+
case "gt":
|
|
1294
|
+
case "dateAfter":
|
|
1295
|
+
return "GreaterThan";
|
|
1296
|
+
case "gte":
|
|
1297
|
+
return "GreaterThanOrEqualTo";
|
|
1298
|
+
case "notContains":
|
|
1299
|
+
return "NotContains";
|
|
1300
|
+
case "empty":
|
|
1301
|
+
return "Empty";
|
|
1302
|
+
default:
|
|
1303
|
+
return "Equals";
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
var buildFilterPayload = (fieldName, matchMode, rawValue) => {
|
|
1307
|
+
const normalized = normalizeFilterValue(rawValue);
|
|
1308
|
+
if (matchMode === "empty") {
|
|
1309
|
+
return {
|
|
1310
|
+
field: fieldName,
|
|
1311
|
+
operator: "Empty"
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
if (matchMode === "notEmpty") {
|
|
1315
|
+
return {
|
|
1316
|
+
not: {
|
|
1317
|
+
field: fieldName,
|
|
1318
|
+
operator: "Empty"
|
|
1319
|
+
}
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
if (normalized === null) return null;
|
|
1323
|
+
if (matchMode === "notStartsWith" || matchMode === "notEndsWith" || matchMode === "notEquals" || // <- notEquals
|
|
1324
|
+
matchMode === "dateIsNot" || matchMode === "notContains") {
|
|
1325
|
+
let operator;
|
|
1326
|
+
switch (matchMode) {
|
|
1327
|
+
case "notStartsWith":
|
|
1328
|
+
operator = "StartsWith";
|
|
1329
|
+
break;
|
|
1330
|
+
case "notEndsWith":
|
|
1331
|
+
operator = "EndsWith";
|
|
1332
|
+
break;
|
|
1333
|
+
case "notContains":
|
|
1334
|
+
operator = "Contains";
|
|
1335
|
+
break;
|
|
1336
|
+
case "notEquals":
|
|
1337
|
+
case "dateIsNot":
|
|
1338
|
+
default:
|
|
1339
|
+
operator = "Equals";
|
|
1300
1340
|
}
|
|
1301
|
-
|
|
1341
|
+
return {
|
|
1342
|
+
not: {
|
|
1343
|
+
field: fieldName,
|
|
1344
|
+
operator,
|
|
1345
|
+
value: normalized
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
return {
|
|
1350
|
+
field: fieldName,
|
|
1351
|
+
operator: mapMatchMode(matchMode),
|
|
1352
|
+
value: normalized
|
|
1353
|
+
};
|
|
1302
1354
|
};
|
|
1303
|
-
var
|
|
1304
|
-
const
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1355
|
+
var mapPrimeToBackendFilters = (filters, globalFilterFields) => {
|
|
1356
|
+
const finalAnd = [];
|
|
1357
|
+
const globalOr = [];
|
|
1358
|
+
const camposMap = {};
|
|
1359
|
+
Object.entries(filters).forEach(([field, config]) => {
|
|
1360
|
+
if (!config) return;
|
|
1361
|
+
const value = config?.value?.text ?? config?.value;
|
|
1362
|
+
if (field === "global" && typeof config.value === "string" && config.value.trim() !== "") {
|
|
1363
|
+
const globalOrNodes = [];
|
|
1364
|
+
globalFilterFields.forEach((globalField) => {
|
|
1365
|
+
const fieldConfig = filters[globalField];
|
|
1366
|
+
if (!fieldConfig) return;
|
|
1367
|
+
const payload = buildFilterPayload(
|
|
1368
|
+
fieldConfig.filterFieldCollection ?? globalField,
|
|
1369
|
+
resolveMatchMode(config.matchMode, config.value),
|
|
1370
|
+
config.value
|
|
1371
|
+
);
|
|
1372
|
+
if (!payload) return;
|
|
1373
|
+
if (!fieldConfig.collection) {
|
|
1374
|
+
globalOrNodes.push(payload);
|
|
1320
1375
|
return;
|
|
1321
1376
|
}
|
|
1322
|
-
const
|
|
1323
|
-
|
|
1377
|
+
const rootCollections = [];
|
|
1378
|
+
pushIntoCollectionTree(
|
|
1379
|
+
rootCollections,
|
|
1380
|
+
fieldConfig.collection,
|
|
1381
|
+
payload.field ?? payload.not?.field,
|
|
1382
|
+
payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
|
|
1383
|
+
);
|
|
1384
|
+
globalOrNodes.push(...rootCollections);
|
|
1385
|
+
});
|
|
1386
|
+
if (globalOrNodes.length) {
|
|
1387
|
+
finalAnd.push({ or: globalOrNodes });
|
|
1324
1388
|
}
|
|
1389
|
+
return;
|
|
1325
1390
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1391
|
+
const constraints = Array.isArray(config.constraints) ? config.constraints.filter((c) => normalizeFilterValue(c.value) !== null || normalizeFilterValue(c.value) === "__NULL__") : [];
|
|
1392
|
+
if (!constraints.length) return;
|
|
1393
|
+
const colOperator = config.operator === "or" ? "or" : "and";
|
|
1394
|
+
if (config.collection === "campos" && config.fieldId) {
|
|
1395
|
+
if (!camposMap[config.fieldId]) {
|
|
1396
|
+
camposMap[config.fieldId] = { operator: colOperator, values: [] };
|
|
1397
|
+
}
|
|
1398
|
+
constraints.forEach((c) => {
|
|
1399
|
+
const effectiveMatchMode = resolveMatchMode(c.matchMode, c.value);
|
|
1400
|
+
const payload = buildFilterPayload(config.filterFieldCollection ?? "valor", effectiveMatchMode, c.value);
|
|
1401
|
+
if (payload) camposMap[config.fieldId].values.push(payload);
|
|
1402
|
+
});
|
|
1334
1403
|
return;
|
|
1335
1404
|
}
|
|
1336
|
-
const
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1405
|
+
const columnPayloads = constraints.map(
|
|
1406
|
+
(c) => buildFilterPayload(config.filterFieldCollection ?? field, resolveMatchMode(c.matchMode, c.value), c.value)
|
|
1407
|
+
).filter(Boolean);
|
|
1408
|
+
if (!columnPayloads.length) return;
|
|
1409
|
+
if (config.collection) {
|
|
1410
|
+
const rootCollections = [];
|
|
1411
|
+
columnPayloads.forEach((payload) => {
|
|
1412
|
+
pushIntoCollectionTree(
|
|
1413
|
+
rootCollections,
|
|
1414
|
+
config.collection,
|
|
1415
|
+
payload.field ?? payload.not?.field,
|
|
1416
|
+
payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
|
|
1417
|
+
);
|
|
1418
|
+
});
|
|
1419
|
+
rootCollections.forEach((c) => finalAnd.push(c));
|
|
1420
|
+
return;
|
|
1348
1421
|
}
|
|
1349
|
-
|
|
1350
|
-
};
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
{
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
{
|
|
1361
|
-
options: selectOptions,
|
|
1362
|
-
value: currentValue,
|
|
1363
|
-
onChange: (selected) => options.filterCallback(selected?.value),
|
|
1364
|
-
placeholder: "Todos",
|
|
1365
|
-
isClearable: false,
|
|
1366
|
-
isSearchable: false,
|
|
1367
|
-
className: "custom-select-filtro",
|
|
1368
|
-
classNamePrefix: "custom-select-filtro",
|
|
1369
|
-
styles: {
|
|
1370
|
-
control: (baseStyles, state) => ({
|
|
1371
|
-
...baseStyles,
|
|
1372
|
-
"&:hover": {
|
|
1373
|
-
borderColor: state.isFocused ? "#094394" : ""
|
|
1374
|
-
},
|
|
1375
|
-
borderRadius: "6px"
|
|
1376
|
-
}),
|
|
1377
|
-
menuList: (base) => ({
|
|
1378
|
-
...base,
|
|
1379
|
-
"::-webkit-scrollbar": {
|
|
1380
|
-
width: "6px",
|
|
1381
|
-
height: "auto",
|
|
1382
|
-
overflowX: "hidden",
|
|
1383
|
-
overflowY: "hidden"
|
|
1384
|
-
},
|
|
1385
|
-
"::-webkit-scrollbar-track": {
|
|
1386
|
-
background: "#fff"
|
|
1387
|
-
},
|
|
1388
|
-
"::-webkit-scrollbar-thumb": {
|
|
1389
|
-
background: "#888",
|
|
1390
|
-
borderRadius: "2rem"
|
|
1391
|
-
},
|
|
1392
|
-
"::-webkit-scrollbar-thumb:hover": {
|
|
1393
|
-
background: "#555"
|
|
1394
|
-
}
|
|
1395
|
-
}),
|
|
1396
|
-
option: (provided, state) => ({
|
|
1397
|
-
...provided,
|
|
1398
|
-
backgroundColor: state.isFocused ? "#094394" : "#ffffff",
|
|
1399
|
-
color: state.isFocused ? "#ffffff" : "black",
|
|
1400
|
-
"&:hover": {
|
|
1401
|
-
backgroundColor: "#094394",
|
|
1402
|
-
// Cor de fundo quando em hover
|
|
1403
|
-
color: "#ffffff"
|
|
1404
|
-
// Cor da palavra quando em hover
|
|
1405
|
-
}
|
|
1406
|
-
})
|
|
1422
|
+
finalAnd.push({ [colOperator]: columnPayloads });
|
|
1423
|
+
});
|
|
1424
|
+
Object.entries(camposMap).forEach(([fieldId, config]) => {
|
|
1425
|
+
if (!config.values.length) return;
|
|
1426
|
+
finalAnd.push({
|
|
1427
|
+
collection: "campos",
|
|
1428
|
+
any: {
|
|
1429
|
+
and: [
|
|
1430
|
+
{ field: "tipocampo.id", operator: "Equals", value: fieldId },
|
|
1431
|
+
{ [config.operator]: config.values }
|
|
1432
|
+
]
|
|
1407
1433
|
}
|
|
1434
|
+
});
|
|
1435
|
+
});
|
|
1436
|
+
return finalAnd.length ? { and: finalAnd } : void 0;
|
|
1437
|
+
};
|
|
1438
|
+
function pushIntoCollectionTree(root, collectionPath, fieldName, payloadBase) {
|
|
1439
|
+
const collections = collectionPath.split(".");
|
|
1440
|
+
let current = root;
|
|
1441
|
+
collections.forEach((collection) => {
|
|
1442
|
+
let node = current.find(
|
|
1443
|
+
(n) => n.collection === collection && n.any
|
|
1444
|
+
);
|
|
1445
|
+
if (!node) {
|
|
1446
|
+
node = {
|
|
1447
|
+
collection,
|
|
1448
|
+
any: { or: [] }
|
|
1449
|
+
};
|
|
1450
|
+
current.push(node);
|
|
1408
1451
|
}
|
|
1452
|
+
current = node.any.or;
|
|
1453
|
+
});
|
|
1454
|
+
current.push({
|
|
1455
|
+
...payloadBase,
|
|
1456
|
+
field: fieldName
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
function getMatchModeByTipo(tipo) {
|
|
1460
|
+
switch (tipo) {
|
|
1461
|
+
case "NumeroInteiro":
|
|
1462
|
+
case "NumeroDecimal":
|
|
1463
|
+
return FilterMatchMode4.EQUALS;
|
|
1464
|
+
default:
|
|
1465
|
+
return FilterMatchMode4.CONTAINS;
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
function buildDynamicCampoFilters(campos) {
|
|
1469
|
+
return campos?.reduce((acc, campo) => {
|
|
1470
|
+
acc[`${campo.id}`] = {
|
|
1471
|
+
operator: FilterOperator.AND,
|
|
1472
|
+
constraints: [
|
|
1473
|
+
{
|
|
1474
|
+
value: null,
|
|
1475
|
+
matchMode: getMatchModeByTipo(campo.tipoDado)
|
|
1476
|
+
}
|
|
1477
|
+
],
|
|
1478
|
+
collection: "campos",
|
|
1479
|
+
filterFieldCollection: "valor",
|
|
1480
|
+
fieldId: campo.id
|
|
1481
|
+
// opcional (útil pro backend)
|
|
1482
|
+
};
|
|
1483
|
+
return acc;
|
|
1484
|
+
}, {});
|
|
1485
|
+
}
|
|
1486
|
+
var getUrlParams = (sortFieldInitial, sortOrderInitial) => {
|
|
1487
|
+
const params = new URLSearchParams(
|
|
1488
|
+
typeof window !== "undefined" ? window.location.search : ""
|
|
1409
1489
|
);
|
|
1490
|
+
return {
|
|
1491
|
+
page: Number(params.get("page") ?? 1),
|
|
1492
|
+
rows: Number(params.get("rows") ?? 10),
|
|
1493
|
+
sortField: params.get("sortField") || sortFieldInitial || "",
|
|
1494
|
+
sortOrder: Number(params.get("sortOrder") ?? sortOrderInitial),
|
|
1495
|
+
filter: params.get("filter") ?? ""
|
|
1496
|
+
};
|
|
1410
1497
|
};
|
|
1411
|
-
|
|
1412
|
-
const
|
|
1413
|
-
|
|
1414
|
-
const currentMatchMode = rawFilter.matchMode ?? "contains";
|
|
1415
|
-
const currentValue = typeof rawFilter.text === "string" ? rawFilter.text : "";
|
|
1416
|
-
const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
|
|
1417
|
-
return /* @__PURE__ */ jsxs6(
|
|
1418
|
-
"div",
|
|
1498
|
+
function buildSortingWithFilters(filters, sortField, order) {
|
|
1499
|
+
const direction = order === 1 ? "asc" : order === -1 ? "Des" : "Asc";
|
|
1500
|
+
let sorting = [
|
|
1419
1501
|
{
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
display: "flex",
|
|
1423
|
-
flexDirection: "column",
|
|
1424
|
-
gap: "8px",
|
|
1425
|
-
minWidth: "200px"
|
|
1426
|
-
},
|
|
1427
|
-
children: [
|
|
1428
|
-
/* @__PURE__ */ jsx11(
|
|
1429
|
-
Dropdown,
|
|
1430
|
-
{
|
|
1431
|
-
value: currentMatchMode,
|
|
1432
|
-
options: resolvedItems,
|
|
1433
|
-
optionLabel: "label",
|
|
1434
|
-
optionValue: "value",
|
|
1435
|
-
placeholder: "Tipo de filtro",
|
|
1436
|
-
style: { width: "100%" },
|
|
1437
|
-
onChange: (e) => {
|
|
1438
|
-
const newMatchMode = e.value;
|
|
1439
|
-
const isNewSpecial = newMatchMode === customMatchModes.empty || newMatchMode === customMatchModes.notEmpty;
|
|
1440
|
-
if (isNewSpecial) {
|
|
1441
|
-
options.filterCallback({
|
|
1442
|
-
text: null,
|
|
1443
|
-
matchMode: newMatchMode
|
|
1444
|
-
});
|
|
1445
|
-
return;
|
|
1446
|
-
}
|
|
1447
|
-
options.filterCallback({
|
|
1448
|
-
text: null,
|
|
1449
|
-
matchMode: newMatchMode
|
|
1450
|
-
});
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
),
|
|
1454
|
-
!isSpecial && /* @__PURE__ */ jsx11(
|
|
1455
|
-
InputText,
|
|
1456
|
-
{
|
|
1457
|
-
value: currentValue,
|
|
1458
|
-
placeholder: isLanguagePtBr ? "Pesquisar" : "Search",
|
|
1459
|
-
style: { width: "100%" },
|
|
1460
|
-
className: "p-column-filter",
|
|
1461
|
-
onChange: (e) => {
|
|
1462
|
-
const value = e.target.value;
|
|
1463
|
-
if (value.trim()) {
|
|
1464
|
-
options.filterCallback({
|
|
1465
|
-
text: value,
|
|
1466
|
-
matchMode: currentMatchMode
|
|
1467
|
-
});
|
|
1468
|
-
} else {
|
|
1469
|
-
options.filterCallback({
|
|
1470
|
-
text: null,
|
|
1471
|
-
matchMode: currentMatchMode
|
|
1472
|
-
});
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
)
|
|
1477
|
-
]
|
|
1502
|
+
field: sortField,
|
|
1503
|
+
direction
|
|
1478
1504
|
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
// src/components/DataTableAdvancedFilter/filterModes.ts
|
|
1483
|
-
import { FilterMatchMode as FilterMatchMode4 } from "primereact/api";
|
|
1484
|
-
var customMatchModes = {
|
|
1485
|
-
notStartsWith: "notStartsWith",
|
|
1486
|
-
notEndsWith: "notEndsWith",
|
|
1487
|
-
empty: "empty",
|
|
1488
|
-
notEmpty: "notEmpty"
|
|
1489
|
-
};
|
|
1490
|
-
var getDefaultFilterMatchOptionsString = (isLanguagePtBr = true) => [
|
|
1491
|
-
{
|
|
1492
|
-
label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
|
|
1493
|
-
value: FilterMatchMode4.CONTAINS
|
|
1494
|
-
},
|
|
1495
|
-
{
|
|
1496
|
-
label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
|
|
1497
|
-
value: FilterMatchMode4.NOT_CONTAINS
|
|
1498
|
-
},
|
|
1499
|
-
{
|
|
1500
|
-
label: isLanguagePtBr ? "Igual" : "Equals",
|
|
1501
|
-
value: FilterMatchMode4.EQUALS
|
|
1502
|
-
},
|
|
1503
|
-
{
|
|
1504
|
-
label: isLanguagePtBr ? "Diferente" : "Not equals",
|
|
1505
|
-
value: FilterMatchMode4.NOT_EQUALS
|
|
1506
|
-
},
|
|
1507
|
-
{
|
|
1508
|
-
label: isLanguagePtBr ? "Come\xE7a com" : "Starts with",
|
|
1509
|
-
value: FilterMatchMode4.STARTS_WITH
|
|
1510
|
-
},
|
|
1511
|
-
{
|
|
1512
|
-
label: isLanguagePtBr ? "N\xE3o come\xE7a com" : "Does not start with",
|
|
1513
|
-
value: customMatchModes.notStartsWith
|
|
1514
|
-
},
|
|
1515
|
-
{
|
|
1516
|
-
label: isLanguagePtBr ? "Termina com" : "Ends with",
|
|
1517
|
-
value: FilterMatchMode4.ENDS_WITH
|
|
1518
|
-
},
|
|
1519
|
-
{
|
|
1520
|
-
label: isLanguagePtBr ? "N\xE3o termina com" : "Does not end with",
|
|
1521
|
-
value: customMatchModes.notEndsWith
|
|
1522
|
-
},
|
|
1523
|
-
{
|
|
1524
|
-
label: isLanguagePtBr ? "Vazio" : "Empty",
|
|
1525
|
-
value: customMatchModes.empty
|
|
1526
|
-
},
|
|
1527
|
-
{
|
|
1528
|
-
label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
|
|
1529
|
-
value: customMatchModes.notEmpty
|
|
1505
|
+
];
|
|
1506
|
+
if (!filters || !sortField) {
|
|
1507
|
+
return sorting;
|
|
1530
1508
|
}
|
|
1531
|
-
];
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1509
|
+
const sortFilter = Object.prototype.hasOwnProperty.call(filters, sortField) ? filters[sortField] : null;
|
|
1510
|
+
if (sortFilter?.fieldId) {
|
|
1511
|
+
sorting = [
|
|
1512
|
+
{
|
|
1513
|
+
collection: "campos",
|
|
1514
|
+
filter: {
|
|
1515
|
+
field: "tipocampo.id",
|
|
1516
|
+
operator: "equals",
|
|
1517
|
+
value: sortFilter.fieldId
|
|
1518
|
+
},
|
|
1519
|
+
first: {
|
|
1520
|
+
field: "valor",
|
|
1521
|
+
direction
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
];
|
|
1540
1525
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
{
|
|
1548
|
-
label: isLanguagePtBr ? "Data depois de" : "Date after",
|
|
1549
|
-
value: FilterMatchMode4.DATE_AFTER
|
|
1526
|
+
return sorting;
|
|
1527
|
+
}
|
|
1528
|
+
function normalizeFilterValue(raw) {
|
|
1529
|
+
if (raw === null || raw === void 0) return null;
|
|
1530
|
+
if (typeof raw === "boolean") {
|
|
1531
|
+
return String(raw);
|
|
1550
1532
|
}
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
{
|
|
1554
|
-
label: isLanguagePtBr ? "Igual" : "Equals",
|
|
1555
|
-
value: FilterMatchMode4.EQUALS
|
|
1556
|
-
},
|
|
1557
|
-
{
|
|
1558
|
-
label: isLanguagePtBr ? "Diferente" : "Not equals",
|
|
1559
|
-
value: FilterMatchMode4.NOT_EQUALS
|
|
1560
|
-
},
|
|
1561
|
-
{
|
|
1562
|
-
label: isLanguagePtBr ? "Vazio" : "Empty",
|
|
1563
|
-
value: customMatchModes.empty
|
|
1564
|
-
},
|
|
1565
|
-
{
|
|
1566
|
-
label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
|
|
1567
|
-
value: customMatchModes.notEmpty
|
|
1533
|
+
if (typeof raw === "number") {
|
|
1534
|
+
return raw;
|
|
1568
1535
|
}
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
{
|
|
1572
|
-
label: isLanguagePtBr ? "Igual" : "Equals",
|
|
1573
|
-
value: FilterMatchMode4.EQUALS
|
|
1574
|
-
},
|
|
1575
|
-
{
|
|
1576
|
-
label: isLanguagePtBr ? "Diferente" : "Not equals",
|
|
1577
|
-
value: FilterMatchMode4.NOT_EQUALS
|
|
1536
|
+
if (typeof raw === "string") {
|
|
1537
|
+
return raw.trim() !== "" ? raw : null;
|
|
1578
1538
|
}
|
|
1579
|
-
|
|
1539
|
+
if (typeof raw === "object") {
|
|
1540
|
+
if ("text" in raw && raw.text === null) {
|
|
1541
|
+
return "__NULL__";
|
|
1542
|
+
}
|
|
1543
|
+
if (typeof raw.text === "string") {
|
|
1544
|
+
return raw.text.trim() !== "" ? raw.text : null;
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
return null;
|
|
1548
|
+
}
|
|
1549
|
+
function resolveMatchMode(constraintMatchMode, rawValue) {
|
|
1550
|
+
if (rawValue && typeof rawValue === "object" && typeof rawValue.matchMode === "string") {
|
|
1551
|
+
return rawValue.matchMode;
|
|
1552
|
+
}
|
|
1553
|
+
return constraintMatchMode;
|
|
1554
|
+
}
|
|
1580
1555
|
|
|
1581
1556
|
// src/index.tsx
|
|
1582
1557
|
import { FilterMatchMode as FilterMatchMode5, FilterOperator as FilterOperator2 } from "primereact/api";
|