@charlesgomes/leafcode-shared-lib-react 1.0.51 → 1.0.53
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 +611 -633
- package/dist/index.mjs +608 -630
- 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,39 @@ 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 = (nextState) => {
|
|
547
|
+
if (!onStateChange) return;
|
|
548
|
+
onStateChange(nextState);
|
|
851
549
|
};
|
|
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
550
|
const onPage = (event) => {
|
|
863
551
|
const newPage = event.page + 1;
|
|
552
|
+
const newRows = event.rows;
|
|
864
553
|
setFirst(event.first);
|
|
865
|
-
setRows(
|
|
554
|
+
setRows(newRows);
|
|
866
555
|
setPage(newPage);
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
556
|
+
emitStateChange({
|
|
557
|
+
page: newPage,
|
|
558
|
+
rows: newRows,
|
|
559
|
+
sortField,
|
|
560
|
+
sortOrder,
|
|
561
|
+
filter: searchText
|
|
562
|
+
});
|
|
871
563
|
};
|
|
872
564
|
const onGlobalFilterChange = (e) => {
|
|
873
565
|
const value = e.target.value;
|
|
@@ -883,16 +575,22 @@ function DataTableAdvancedFilterWrapper({
|
|
|
883
575
|
const onSort = (e) => {
|
|
884
576
|
setSortField(e.sortField);
|
|
885
577
|
setSortOrder(e.sortOrder);
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
578
|
+
emitStateChange({
|
|
579
|
+
page,
|
|
580
|
+
rows,
|
|
581
|
+
sortField: e.sortField,
|
|
582
|
+
sortOrder: e.sortOrder,
|
|
583
|
+
filter: searchText
|
|
584
|
+
});
|
|
890
585
|
};
|
|
891
586
|
useEffect3(() => {
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
587
|
+
emitStateChange({
|
|
588
|
+
page: 1,
|
|
589
|
+
rows,
|
|
590
|
+
sortField,
|
|
591
|
+
sortOrder,
|
|
592
|
+
filter: debouncedSearch
|
|
593
|
+
});
|
|
896
594
|
}, [debouncedSearch]);
|
|
897
595
|
useEffect3(() => {
|
|
898
596
|
if (customers?.items && selectedRowsData.length > 0) {
|
|
@@ -1229,8 +927,7 @@ function DataTableAdvancedFilter({
|
|
|
1229
927
|
sortFieldInitial,
|
|
1230
928
|
sortOrderInitial = 1,
|
|
1231
929
|
isMultiSelectionMode = true,
|
|
1232
|
-
isLanguagePtBr = true
|
|
1233
|
-
replaceUrl = true
|
|
930
|
+
isLanguagePtBr = true
|
|
1234
931
|
}) {
|
|
1235
932
|
const [isClient, setIsClient] = useState3(false);
|
|
1236
933
|
useEffect4(() => {
|
|
@@ -1262,8 +959,7 @@ function DataTableAdvancedFilter({
|
|
|
1262
959
|
sortFieldInitial,
|
|
1263
960
|
sortOrderInitial,
|
|
1264
961
|
isMultiSelectionMode,
|
|
1265
|
-
isLanguagePtBr
|
|
1266
|
-
replaceUrl
|
|
962
|
+
isLanguagePtBr
|
|
1267
963
|
}
|
|
1268
964
|
)
|
|
1269
965
|
}
|
|
@@ -1280,303 +976,585 @@ var DateFilterTemplate = (options, mask) => {
|
|
|
1280
976
|
return /* @__PURE__ */ jsx11(
|
|
1281
977
|
Calendar,
|
|
1282
978
|
{
|
|
1283
|
-
value: parsedValue,
|
|
979
|
+
value: parsedValue,
|
|
980
|
+
onChange: (e) => {
|
|
981
|
+
if (!e.value) {
|
|
982
|
+
options.filterCallback(null, options.index);
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
const date = e.value;
|
|
986
|
+
const valueToFilter = mask ? mask(date) : `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
|
|
987
|
+
2,
|
|
988
|
+
"0"
|
|
989
|
+
)}-${String(date.getDate()).padStart(2, "0")}`;
|
|
990
|
+
options.filterCallback(valueToFilter, options.index);
|
|
991
|
+
},
|
|
992
|
+
dateFormat: "dd/mm/yy",
|
|
993
|
+
placeholder: "dd/mm/yyyy",
|
|
994
|
+
mask: "99/99/9999",
|
|
995
|
+
inputClassName: "p-column-filter"
|
|
996
|
+
}
|
|
997
|
+
);
|
|
998
|
+
};
|
|
999
|
+
var DateTimeFilterTemplate = (options, mask) => {
|
|
1000
|
+
const value = typeof options.value === "string" ? moment2(options.value).toDate() : options.value ?? null;
|
|
1001
|
+
return /* @__PURE__ */ jsx11(
|
|
1002
|
+
Calendar,
|
|
1003
|
+
{
|
|
1004
|
+
value,
|
|
1005
|
+
showTime: true,
|
|
1006
|
+
showSeconds: true,
|
|
1007
|
+
hourFormat: "24",
|
|
1008
|
+
dateFormat: "dd/mm/yy",
|
|
1009
|
+
placeholder: "dd/mm/yyyy 00:00:00",
|
|
1010
|
+
readOnlyInput: true,
|
|
1011
|
+
inputClassName: "p-column-filter",
|
|
1284
1012
|
onChange: (e) => {
|
|
1285
|
-
|
|
1013
|
+
const selectedDate = e.value;
|
|
1014
|
+
if (!selectedDate) {
|
|
1286
1015
|
options.filterCallback(null, options.index);
|
|
1287
1016
|
return;
|
|
1288
1017
|
}
|
|
1289
|
-
const
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1018
|
+
const formatted = mask ? mask(selectedDate) : moment2(selectedDate).utc().format("YYYY-MM-DDTHH:mm:ss.SSS[Z]");
|
|
1019
|
+
options.filterCallback(formatted, options.index);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
);
|
|
1023
|
+
};
|
|
1024
|
+
var ValueFilterTemplate = (options, mask) => {
|
|
1025
|
+
const parsedValue = options.value !== null && options.value !== void 0 ? centsToReal(options.value) : null;
|
|
1026
|
+
const handleChange = (e) => {
|
|
1027
|
+
const rawValue = e.value;
|
|
1028
|
+
if (rawValue === null || rawValue === void 0) {
|
|
1029
|
+
options.filterCallback(null, options.index);
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
const valueToFilter = mask ? mask(rawValue) : rawValue;
|
|
1033
|
+
options.filterCallback(valueToFilter, options.index);
|
|
1034
|
+
};
|
|
1035
|
+
return /* @__PURE__ */ jsx11(
|
|
1036
|
+
InputNumber,
|
|
1037
|
+
{
|
|
1038
|
+
value: parsedValue,
|
|
1039
|
+
onValueChange: handleChange,
|
|
1040
|
+
mode: "currency",
|
|
1041
|
+
currency: "BRL",
|
|
1042
|
+
locale: "pt-BR",
|
|
1043
|
+
inputClassName: "custom-input"
|
|
1044
|
+
}
|
|
1045
|
+
);
|
|
1046
|
+
};
|
|
1047
|
+
var SelectFilterTemplate = (options, isLanguagePtBr = true, items = []) => {
|
|
1048
|
+
const selectOptions = items.length > 0 ? items : [
|
|
1049
|
+
{ label: isLanguagePtBr ? "Todos" : "All", value: null },
|
|
1050
|
+
{ label: isLanguagePtBr ? "Sim" : "Yes", value: true },
|
|
1051
|
+
{ label: isLanguagePtBr ? "N\xE3o" : "No", value: false }
|
|
1052
|
+
];
|
|
1053
|
+
const currentValue = selectOptions.find((opt) => opt.value === options.value) || null;
|
|
1054
|
+
return /* @__PURE__ */ jsx11(
|
|
1055
|
+
Select,
|
|
1056
|
+
{
|
|
1057
|
+
options: selectOptions,
|
|
1058
|
+
value: currentValue,
|
|
1059
|
+
onChange: (selected) => options.filterCallback(selected?.value),
|
|
1060
|
+
placeholder: "Todos",
|
|
1061
|
+
isClearable: false,
|
|
1062
|
+
isSearchable: false,
|
|
1063
|
+
className: "custom-select-filtro",
|
|
1064
|
+
classNamePrefix: "custom-select-filtro",
|
|
1065
|
+
styles: {
|
|
1066
|
+
control: (baseStyles, state) => ({
|
|
1067
|
+
...baseStyles,
|
|
1068
|
+
"&:hover": {
|
|
1069
|
+
borderColor: state.isFocused ? "#094394" : ""
|
|
1070
|
+
},
|
|
1071
|
+
borderRadius: "6px"
|
|
1072
|
+
}),
|
|
1073
|
+
menuList: (base) => ({
|
|
1074
|
+
...base,
|
|
1075
|
+
"::-webkit-scrollbar": {
|
|
1076
|
+
width: "6px",
|
|
1077
|
+
height: "auto",
|
|
1078
|
+
overflowX: "hidden",
|
|
1079
|
+
overflowY: "hidden"
|
|
1080
|
+
},
|
|
1081
|
+
"::-webkit-scrollbar-track": {
|
|
1082
|
+
background: "#fff"
|
|
1083
|
+
},
|
|
1084
|
+
"::-webkit-scrollbar-thumb": {
|
|
1085
|
+
background: "#888",
|
|
1086
|
+
borderRadius: "2rem"
|
|
1087
|
+
},
|
|
1088
|
+
"::-webkit-scrollbar-thumb:hover": {
|
|
1089
|
+
background: "#555"
|
|
1090
|
+
}
|
|
1091
|
+
}),
|
|
1092
|
+
option: (provided, state) => ({
|
|
1093
|
+
...provided,
|
|
1094
|
+
backgroundColor: state.isFocused ? "#094394" : "#ffffff",
|
|
1095
|
+
color: state.isFocused ? "#ffffff" : "black",
|
|
1096
|
+
"&:hover": {
|
|
1097
|
+
backgroundColor: "#094394",
|
|
1098
|
+
// Cor de fundo quando em hover
|
|
1099
|
+
color: "#ffffff"
|
|
1100
|
+
// Cor da palavra quando em hover
|
|
1101
|
+
}
|
|
1102
|
+
})
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
);
|
|
1106
|
+
};
|
|
1107
|
+
var CustomFilterElement = (options, isLanguagePtBr = true, items) => {
|
|
1108
|
+
const resolvedItems = items ?? getDefaultFilterMatchOptionsString(isLanguagePtBr);
|
|
1109
|
+
const rawFilter = options.value ?? {};
|
|
1110
|
+
const currentMatchMode = rawFilter.matchMode ?? "contains";
|
|
1111
|
+
const currentValue = typeof rawFilter.text === "string" ? rawFilter.text : "";
|
|
1112
|
+
const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
|
|
1113
|
+
return /* @__PURE__ */ jsxs6(
|
|
1114
|
+
"div",
|
|
1115
|
+
{
|
|
1116
|
+
className: "filter-wrapper",
|
|
1117
|
+
style: {
|
|
1118
|
+
display: "flex",
|
|
1119
|
+
flexDirection: "column",
|
|
1120
|
+
gap: "8px",
|
|
1121
|
+
minWidth: "200px"
|
|
1295
1122
|
},
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1123
|
+
children: [
|
|
1124
|
+
/* @__PURE__ */ jsx11(
|
|
1125
|
+
Dropdown,
|
|
1126
|
+
{
|
|
1127
|
+
value: currentMatchMode,
|
|
1128
|
+
options: resolvedItems,
|
|
1129
|
+
optionLabel: "label",
|
|
1130
|
+
optionValue: "value",
|
|
1131
|
+
placeholder: "Tipo de filtro",
|
|
1132
|
+
style: { width: "100%" },
|
|
1133
|
+
onChange: (e) => {
|
|
1134
|
+
const newMatchMode = e.value;
|
|
1135
|
+
const isNewSpecial = newMatchMode === customMatchModes.empty || newMatchMode === customMatchModes.notEmpty;
|
|
1136
|
+
if (isNewSpecial) {
|
|
1137
|
+
options.filterCallback({
|
|
1138
|
+
text: null,
|
|
1139
|
+
matchMode: newMatchMode
|
|
1140
|
+
});
|
|
1141
|
+
return;
|
|
1142
|
+
}
|
|
1143
|
+
options.filterCallback({
|
|
1144
|
+
text: null,
|
|
1145
|
+
matchMode: newMatchMode
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
),
|
|
1150
|
+
!isSpecial && /* @__PURE__ */ jsx11(
|
|
1151
|
+
InputText,
|
|
1152
|
+
{
|
|
1153
|
+
value: currentValue,
|
|
1154
|
+
placeholder: isLanguagePtBr ? "Pesquisar" : "Search",
|
|
1155
|
+
style: { width: "100%" },
|
|
1156
|
+
className: "p-column-filter",
|
|
1157
|
+
onChange: (e) => {
|
|
1158
|
+
const value = e.target.value;
|
|
1159
|
+
if (value.trim()) {
|
|
1160
|
+
options.filterCallback({
|
|
1161
|
+
text: value,
|
|
1162
|
+
matchMode: currentMatchMode
|
|
1163
|
+
});
|
|
1164
|
+
} else {
|
|
1165
|
+
options.filterCallback({
|
|
1166
|
+
text: null,
|
|
1167
|
+
matchMode: currentMatchMode
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
)
|
|
1173
|
+
]
|
|
1174
|
+
}
|
|
1175
|
+
);
|
|
1176
|
+
};
|
|
1177
|
+
|
|
1178
|
+
// src/components/DataTableAdvancedFilter/filterModes.ts
|
|
1179
|
+
import { FilterMatchMode as FilterMatchMode3 } from "primereact/api";
|
|
1180
|
+
var customMatchModes = {
|
|
1181
|
+
notStartsWith: "notStartsWith",
|
|
1182
|
+
notEndsWith: "notEndsWith",
|
|
1183
|
+
empty: "empty",
|
|
1184
|
+
notEmpty: "notEmpty"
|
|
1185
|
+
};
|
|
1186
|
+
var getDefaultFilterMatchOptionsString = (isLanguagePtBr = true) => [
|
|
1187
|
+
{
|
|
1188
|
+
label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
|
|
1189
|
+
value: FilterMatchMode3.CONTAINS
|
|
1190
|
+
},
|
|
1191
|
+
{
|
|
1192
|
+
label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
|
|
1193
|
+
value: FilterMatchMode3.NOT_CONTAINS
|
|
1194
|
+
},
|
|
1195
|
+
{
|
|
1196
|
+
label: isLanguagePtBr ? "Igual" : "Equals",
|
|
1197
|
+
value: FilterMatchMode3.EQUALS
|
|
1198
|
+
},
|
|
1199
|
+
{
|
|
1200
|
+
label: isLanguagePtBr ? "Diferente" : "Not equals",
|
|
1201
|
+
value: FilterMatchMode3.NOT_EQUALS
|
|
1202
|
+
},
|
|
1203
|
+
{
|
|
1204
|
+
label: isLanguagePtBr ? "Come\xE7a com" : "Starts with",
|
|
1205
|
+
value: FilterMatchMode3.STARTS_WITH
|
|
1206
|
+
},
|
|
1207
|
+
{
|
|
1208
|
+
label: isLanguagePtBr ? "N\xE3o come\xE7a com" : "Does not start with",
|
|
1209
|
+
value: customMatchModes.notStartsWith
|
|
1210
|
+
},
|
|
1211
|
+
{
|
|
1212
|
+
label: isLanguagePtBr ? "Termina com" : "Ends with",
|
|
1213
|
+
value: FilterMatchMode3.ENDS_WITH
|
|
1214
|
+
},
|
|
1215
|
+
{
|
|
1216
|
+
label: isLanguagePtBr ? "N\xE3o termina com" : "Does not end with",
|
|
1217
|
+
value: customMatchModes.notEndsWith
|
|
1218
|
+
},
|
|
1219
|
+
{
|
|
1220
|
+
label: isLanguagePtBr ? "Vazio" : "Empty",
|
|
1221
|
+
value: customMatchModes.empty
|
|
1222
|
+
},
|
|
1223
|
+
{
|
|
1224
|
+
label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
|
|
1225
|
+
value: customMatchModes.notEmpty
|
|
1226
|
+
}
|
|
1227
|
+
];
|
|
1228
|
+
var getDefaultFilterMatchOptionsStringArray = (isLanguagePtBr = true) => [
|
|
1229
|
+
{
|
|
1230
|
+
label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
|
|
1231
|
+
value: FilterMatchMode3.CONTAINS
|
|
1232
|
+
},
|
|
1233
|
+
{
|
|
1234
|
+
label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
|
|
1235
|
+
value: FilterMatchMode3.NOT_CONTAINS
|
|
1236
|
+
}
|
|
1237
|
+
];
|
|
1238
|
+
var getDefaultFilterMatchOptionsDate = (isLanguagePtBr) => [
|
|
1239
|
+
{
|
|
1240
|
+
label: isLanguagePtBr ? "Data antes de" : "Date before",
|
|
1241
|
+
value: FilterMatchMode3.DATE_BEFORE
|
|
1242
|
+
},
|
|
1243
|
+
{
|
|
1244
|
+
label: isLanguagePtBr ? "Data depois de" : "Date after",
|
|
1245
|
+
value: FilterMatchMode3.DATE_AFTER
|
|
1246
|
+
}
|
|
1247
|
+
];
|
|
1248
|
+
var getDefaultFilterMatchOptionsEnum = (isLanguagePtBr) => [
|
|
1249
|
+
{
|
|
1250
|
+
label: isLanguagePtBr ? "Igual" : "Equals",
|
|
1251
|
+
value: FilterMatchMode3.EQUALS
|
|
1252
|
+
},
|
|
1253
|
+
{
|
|
1254
|
+
label: isLanguagePtBr ? "Diferente" : "Not equals",
|
|
1255
|
+
value: FilterMatchMode3.NOT_EQUALS
|
|
1256
|
+
},
|
|
1257
|
+
{
|
|
1258
|
+
label: isLanguagePtBr ? "Vazio" : "Empty",
|
|
1259
|
+
value: customMatchModes.empty
|
|
1260
|
+
},
|
|
1261
|
+
{
|
|
1262
|
+
label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
|
|
1263
|
+
value: customMatchModes.notEmpty
|
|
1264
|
+
}
|
|
1265
|
+
];
|
|
1266
|
+
var getDefaultFilterMatchOptionsEnumNotNullable = (isLanguagePtBr) => [
|
|
1267
|
+
{
|
|
1268
|
+
label: isLanguagePtBr ? "Igual" : "Equals",
|
|
1269
|
+
value: FilterMatchMode3.EQUALS
|
|
1270
|
+
},
|
|
1271
|
+
{
|
|
1272
|
+
label: isLanguagePtBr ? "Diferente" : "Not equals",
|
|
1273
|
+
value: FilterMatchMode3.NOT_EQUALS
|
|
1274
|
+
}
|
|
1275
|
+
];
|
|
1276
|
+
|
|
1277
|
+
// src/components/DataTableAdvancedFilter/utils/DataTableUtils.tsx
|
|
1278
|
+
import { FilterMatchMode as FilterMatchMode4, FilterOperator } from "primereact/api";
|
|
1279
|
+
var mapMatchMode = (mode) => {
|
|
1280
|
+
switch (mode) {
|
|
1281
|
+
case "startsWith":
|
|
1282
|
+
return "StartsWith";
|
|
1283
|
+
case "contains":
|
|
1284
|
+
return "Contains";
|
|
1285
|
+
case "equals":
|
|
1286
|
+
return "Equals";
|
|
1287
|
+
case "notEquals":
|
|
1288
|
+
return "notEquals";
|
|
1289
|
+
case "endsWith":
|
|
1290
|
+
return "EndsWith";
|
|
1291
|
+
case "lt":
|
|
1292
|
+
case "dateBefore":
|
|
1293
|
+
return "LessThan";
|
|
1294
|
+
case "lte":
|
|
1295
|
+
return "LessThanOrEqualTo";
|
|
1296
|
+
case "gt":
|
|
1297
|
+
case "dateAfter":
|
|
1298
|
+
return "GreaterThan";
|
|
1299
|
+
case "gte":
|
|
1300
|
+
return "GreaterThanOrEqualTo";
|
|
1301
|
+
case "notContains":
|
|
1302
|
+
return "NotContains";
|
|
1303
|
+
case "empty":
|
|
1304
|
+
return "Empty";
|
|
1305
|
+
default:
|
|
1306
|
+
return "Equals";
|
|
1307
|
+
}
|
|
1308
|
+
};
|
|
1309
|
+
var buildFilterPayload = (fieldName, matchMode, rawValue) => {
|
|
1310
|
+
const normalized = normalizeFilterValue(rawValue);
|
|
1311
|
+
if (matchMode === "empty") {
|
|
1312
|
+
return {
|
|
1313
|
+
field: fieldName,
|
|
1314
|
+
operator: "Empty"
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
if (matchMode === "notEmpty") {
|
|
1318
|
+
return {
|
|
1319
|
+
not: {
|
|
1320
|
+
field: fieldName,
|
|
1321
|
+
operator: "Empty"
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
if (normalized === null) return null;
|
|
1326
|
+
if (matchMode === "notStartsWith" || matchMode === "notEndsWith" || matchMode === "notEquals" || // <- notEquals
|
|
1327
|
+
matchMode === "dateIsNot" || matchMode === "notContains") {
|
|
1328
|
+
let operator;
|
|
1329
|
+
switch (matchMode) {
|
|
1330
|
+
case "notStartsWith":
|
|
1331
|
+
operator = "StartsWith";
|
|
1332
|
+
break;
|
|
1333
|
+
case "notEndsWith":
|
|
1334
|
+
operator = "EndsWith";
|
|
1335
|
+
break;
|
|
1336
|
+
case "notContains":
|
|
1337
|
+
operator = "Contains";
|
|
1338
|
+
break;
|
|
1339
|
+
case "notEquals":
|
|
1340
|
+
case "dateIsNot":
|
|
1341
|
+
default:
|
|
1342
|
+
operator = "Equals";
|
|
1300
1343
|
}
|
|
1301
|
-
|
|
1344
|
+
return {
|
|
1345
|
+
not: {
|
|
1346
|
+
field: fieldName,
|
|
1347
|
+
operator,
|
|
1348
|
+
value: normalized
|
|
1349
|
+
}
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
return {
|
|
1353
|
+
field: fieldName,
|
|
1354
|
+
operator: mapMatchMode(matchMode),
|
|
1355
|
+
value: normalized
|
|
1356
|
+
};
|
|
1302
1357
|
};
|
|
1303
|
-
var
|
|
1304
|
-
const
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1358
|
+
var mapPrimeToBackendFilters = (filters, globalFilterFields) => {
|
|
1359
|
+
const finalAnd = [];
|
|
1360
|
+
const globalOr = [];
|
|
1361
|
+
const camposMap = {};
|
|
1362
|
+
Object.entries(filters).forEach(([field, config]) => {
|
|
1363
|
+
if (!config) return;
|
|
1364
|
+
const value = config?.value?.text ?? config?.value;
|
|
1365
|
+
if (field === "global" && typeof config.value === "string" && config.value.trim() !== "") {
|
|
1366
|
+
const globalOrNodes = [];
|
|
1367
|
+
globalFilterFields.forEach((globalField) => {
|
|
1368
|
+
const fieldConfig = filters[globalField];
|
|
1369
|
+
if (!fieldConfig) return;
|
|
1370
|
+
const payload = buildFilterPayload(
|
|
1371
|
+
fieldConfig.filterFieldCollection ?? globalField,
|
|
1372
|
+
resolveMatchMode(config.matchMode, config.value),
|
|
1373
|
+
config.value
|
|
1374
|
+
);
|
|
1375
|
+
if (!payload) return;
|
|
1376
|
+
if (!fieldConfig.collection) {
|
|
1377
|
+
globalOrNodes.push(payload);
|
|
1320
1378
|
return;
|
|
1321
1379
|
}
|
|
1322
|
-
const
|
|
1323
|
-
|
|
1380
|
+
const rootCollections = [];
|
|
1381
|
+
pushIntoCollectionTree(
|
|
1382
|
+
rootCollections,
|
|
1383
|
+
fieldConfig.collection,
|
|
1384
|
+
payload.field ?? payload.not?.field,
|
|
1385
|
+
payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
|
|
1386
|
+
);
|
|
1387
|
+
globalOrNodes.push(...rootCollections);
|
|
1388
|
+
});
|
|
1389
|
+
if (globalOrNodes.length) {
|
|
1390
|
+
finalAnd.push({ or: globalOrNodes });
|
|
1324
1391
|
}
|
|
1392
|
+
return;
|
|
1325
1393
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1394
|
+
const constraints = Array.isArray(config.constraints) ? config.constraints.filter((c) => normalizeFilterValue(c.value) !== null || normalizeFilterValue(c.value) === "__NULL__") : [];
|
|
1395
|
+
if (!constraints.length) return;
|
|
1396
|
+
const colOperator = config.operator === "or" ? "or" : "and";
|
|
1397
|
+
if (config.collection === "campos" && config.fieldId) {
|
|
1398
|
+
if (!camposMap[config.fieldId]) {
|
|
1399
|
+
camposMap[config.fieldId] = { operator: colOperator, values: [] };
|
|
1400
|
+
}
|
|
1401
|
+
constraints.forEach((c) => {
|
|
1402
|
+
const effectiveMatchMode = resolveMatchMode(c.matchMode, c.value);
|
|
1403
|
+
const payload = buildFilterPayload(config.filterFieldCollection ?? "valor", effectiveMatchMode, c.value);
|
|
1404
|
+
if (payload) camposMap[config.fieldId].values.push(payload);
|
|
1405
|
+
});
|
|
1334
1406
|
return;
|
|
1335
1407
|
}
|
|
1336
|
-
const
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1408
|
+
const columnPayloads = constraints.map(
|
|
1409
|
+
(c) => buildFilterPayload(config.filterFieldCollection ?? field, resolveMatchMode(c.matchMode, c.value), c.value)
|
|
1410
|
+
).filter(Boolean);
|
|
1411
|
+
if (!columnPayloads.length) return;
|
|
1412
|
+
if (config.collection) {
|
|
1413
|
+
const rootCollections = [];
|
|
1414
|
+
columnPayloads.forEach((payload) => {
|
|
1415
|
+
pushIntoCollectionTree(
|
|
1416
|
+
rootCollections,
|
|
1417
|
+
config.collection,
|
|
1418
|
+
payload.field ?? payload.not?.field,
|
|
1419
|
+
payload.not ? { not: payload.not } : { operator: payload.operator, value: payload.value }
|
|
1420
|
+
);
|
|
1421
|
+
});
|
|
1422
|
+
rootCollections.forEach((c) => finalAnd.push(c));
|
|
1423
|
+
return;
|
|
1348
1424
|
}
|
|
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
|
-
})
|
|
1425
|
+
finalAnd.push({ [colOperator]: columnPayloads });
|
|
1426
|
+
});
|
|
1427
|
+
Object.entries(camposMap).forEach(([fieldId, config]) => {
|
|
1428
|
+
if (!config.values.length) return;
|
|
1429
|
+
finalAnd.push({
|
|
1430
|
+
collection: "campos",
|
|
1431
|
+
any: {
|
|
1432
|
+
and: [
|
|
1433
|
+
{ field: "tipocampo.id", operator: "Equals", value: fieldId },
|
|
1434
|
+
{ [config.operator]: config.values }
|
|
1435
|
+
]
|
|
1407
1436
|
}
|
|
1437
|
+
});
|
|
1438
|
+
});
|
|
1439
|
+
return finalAnd.length ? { and: finalAnd } : void 0;
|
|
1440
|
+
};
|
|
1441
|
+
function pushIntoCollectionTree(root, collectionPath, fieldName, payloadBase) {
|
|
1442
|
+
const collections = collectionPath.split(".");
|
|
1443
|
+
let current = root;
|
|
1444
|
+
collections.forEach((collection) => {
|
|
1445
|
+
let node = current.find(
|
|
1446
|
+
(n) => n.collection === collection && n.any
|
|
1447
|
+
);
|
|
1448
|
+
if (!node) {
|
|
1449
|
+
node = {
|
|
1450
|
+
collection,
|
|
1451
|
+
any: { or: [] }
|
|
1452
|
+
};
|
|
1453
|
+
current.push(node);
|
|
1408
1454
|
}
|
|
1455
|
+
current = node.any.or;
|
|
1456
|
+
});
|
|
1457
|
+
current.push({
|
|
1458
|
+
...payloadBase,
|
|
1459
|
+
field: fieldName
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
function getMatchModeByTipo(tipo) {
|
|
1463
|
+
switch (tipo) {
|
|
1464
|
+
case "NumeroInteiro":
|
|
1465
|
+
case "NumeroDecimal":
|
|
1466
|
+
return FilterMatchMode4.EQUALS;
|
|
1467
|
+
default:
|
|
1468
|
+
return FilterMatchMode4.CONTAINS;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
function buildDynamicCampoFilters(campos) {
|
|
1472
|
+
return campos?.reduce((acc, campo) => {
|
|
1473
|
+
acc[`${campo.id}`] = {
|
|
1474
|
+
operator: FilterOperator.AND,
|
|
1475
|
+
constraints: [
|
|
1476
|
+
{
|
|
1477
|
+
value: null,
|
|
1478
|
+
matchMode: getMatchModeByTipo(campo.tipoDado)
|
|
1479
|
+
}
|
|
1480
|
+
],
|
|
1481
|
+
collection: "campos",
|
|
1482
|
+
filterFieldCollection: "valor",
|
|
1483
|
+
fieldId: campo.id
|
|
1484
|
+
// opcional (útil pro backend)
|
|
1485
|
+
};
|
|
1486
|
+
return acc;
|
|
1487
|
+
}, {});
|
|
1488
|
+
}
|
|
1489
|
+
var getUrlParams = (sortFieldInitial, sortOrderInitial) => {
|
|
1490
|
+
const params = new URLSearchParams(
|
|
1491
|
+
typeof window !== "undefined" ? window.location.search : ""
|
|
1409
1492
|
);
|
|
1493
|
+
return {
|
|
1494
|
+
page: Number(params.get("page") ?? 1),
|
|
1495
|
+
rows: Number(params.get("rows") ?? 10),
|
|
1496
|
+
sortField: params.get("sortField") || sortFieldInitial || "",
|
|
1497
|
+
sortOrder: Number(params.get("sortOrder") ?? sortOrderInitial),
|
|
1498
|
+
filter: params.get("filter") ?? ""
|
|
1499
|
+
};
|
|
1410
1500
|
};
|
|
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",
|
|
1501
|
+
function buildSortingWithFilters(filters, sortField, order) {
|
|
1502
|
+
const direction = order === 1 ? "asc" : order === -1 ? "Des" : "Asc";
|
|
1503
|
+
let sorting = [
|
|
1419
1504
|
{
|
|
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
|
-
]
|
|
1505
|
+
field: sortField,
|
|
1506
|
+
direction
|
|
1478
1507
|
}
|
|
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
|
|
1508
|
+
];
|
|
1509
|
+
if (!filters || !sortField) {
|
|
1510
|
+
return sorting;
|
|
1530
1511
|
}
|
|
1531
|
-
];
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1512
|
+
const sortFilter = Object.prototype.hasOwnProperty.call(filters, sortField) ? filters[sortField] : null;
|
|
1513
|
+
if (sortFilter?.fieldId) {
|
|
1514
|
+
sorting = [
|
|
1515
|
+
{
|
|
1516
|
+
collection: "campos",
|
|
1517
|
+
filter: {
|
|
1518
|
+
field: "tipocampo.id",
|
|
1519
|
+
operator: "equals",
|
|
1520
|
+
value: sortFilter.fieldId
|
|
1521
|
+
},
|
|
1522
|
+
first: {
|
|
1523
|
+
field: "valor",
|
|
1524
|
+
direction
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
];
|
|
1540
1528
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
{
|
|
1548
|
-
label: isLanguagePtBr ? "Data depois de" : "Date after",
|
|
1549
|
-
value: FilterMatchMode4.DATE_AFTER
|
|
1529
|
+
return sorting;
|
|
1530
|
+
}
|
|
1531
|
+
function normalizeFilterValue(raw) {
|
|
1532
|
+
if (raw === null || raw === void 0) return null;
|
|
1533
|
+
if (typeof raw === "boolean") {
|
|
1534
|
+
return String(raw);
|
|
1550
1535
|
}
|
|
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
|
|
1536
|
+
if (typeof raw === "number") {
|
|
1537
|
+
return raw;
|
|
1568
1538
|
}
|
|
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
|
|
1539
|
+
if (typeof raw === "string") {
|
|
1540
|
+
return raw.trim() !== "" ? raw : null;
|
|
1578
1541
|
}
|
|
1579
|
-
|
|
1542
|
+
if (typeof raw === "object") {
|
|
1543
|
+
if ("text" in raw && raw.text === null) {
|
|
1544
|
+
return "__NULL__";
|
|
1545
|
+
}
|
|
1546
|
+
if (typeof raw.text === "string") {
|
|
1547
|
+
return raw.text.trim() !== "" ? raw.text : null;
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
function resolveMatchMode(constraintMatchMode, rawValue) {
|
|
1553
|
+
if (rawValue && typeof rawValue === "object" && typeof rawValue.matchMode === "string") {
|
|
1554
|
+
return rawValue.matchMode;
|
|
1555
|
+
}
|
|
1556
|
+
return constraintMatchMode;
|
|
1557
|
+
}
|
|
1580
1558
|
|
|
1581
1559
|
// src/index.tsx
|
|
1582
1560
|
import { FilterMatchMode as FilterMatchMode5, FilterOperator as FilterOperator2 } from "primereact/api";
|