@charlesgomes/leafcode-shared-lib-react 1.0.50 → 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 +608 -629
- package/dist/index.mjs +606 -627
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -129,7 +129,7 @@ function ModalBase({
|
|
|
129
129
|
import { useEffect as useEffect4, useState as useState3 } from "react";
|
|
130
130
|
|
|
131
131
|
// src/components/DataTableAdvancedFilter/DataTableAdvancedFilterWrapper.tsx
|
|
132
|
-
import { useEffect as useEffect3, useMemo,
|
|
132
|
+
import { useEffect as useEffect3, useMemo, useState as useState2 } from "react";
|
|
133
133
|
import { useQuery } from "@tanstack/react-query";
|
|
134
134
|
|
|
135
135
|
// src/primereact-compat.ts
|
|
@@ -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,68 +527,42 @@ function DataTableAdvancedFilterWrapper({
|
|
|
808
527
|
globalFilterFields
|
|
809
528
|
)
|
|
810
529
|
});
|
|
811
|
-
const didInitRef = useRef(false);
|
|
812
530
|
useEffect3(() => {
|
|
813
|
-
if (
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
);
|
|
820
|
-
}, []);
|
|
821
|
-
const updateUrlParams = (params, options = { replace: true }) => {
|
|
822
|
-
if (typeof window === "undefined" || !replaceUrl) return;
|
|
823
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
824
|
-
Object.entries(params).forEach(([key, value]) => {
|
|
825
|
-
if (value === void 0 || value === null || value === "") {
|
|
826
|
-
urlParams.delete(key);
|
|
827
|
-
} else {
|
|
828
|
-
urlParams.set(
|
|
829
|
-
key,
|
|
830
|
-
typeof value === "string" ? value : JSON.stringify(value)
|
|
831
|
-
);
|
|
832
|
-
}
|
|
833
|
-
});
|
|
834
|
-
const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
|
|
835
|
-
window.history.pushState(null, "", newUrl);
|
|
836
|
-
};
|
|
837
|
-
const hydrateFromUrl = () => {
|
|
838
|
-
const params = new URLSearchParams(window.location.search);
|
|
839
|
-
const pageParam = Number(params.get("page") ?? 1);
|
|
840
|
-
const rowsParam = Number(params.get("rows") ?? rows);
|
|
841
|
-
const sortFieldParam = params.get("sortField") ?? sortFieldInitial;
|
|
842
|
-
const sortOrderParam = Number(params.get("sortOrder") ?? sortOrderInitial);
|
|
843
|
-
const filterParam = params.get("filter") ?? "";
|
|
844
|
-
setPage(pageParam);
|
|
845
|
-
setRows(rowsParam);
|
|
846
|
-
setFirst((pageParam - 1) * rowsParam);
|
|
847
|
-
setSortField(sortFieldParam);
|
|
848
|
-
setSortOrder(sortOrderParam);
|
|
849
|
-
setSearchText(filterParam);
|
|
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 ?? "");
|
|
850
538
|
setFilters((prev) => ({
|
|
851
539
|
...prev,
|
|
852
540
|
global: {
|
|
853
541
|
...prev.global ?? { matchMode: "contains" },
|
|
854
|
-
value:
|
|
542
|
+
value: state.filter ?? ""
|
|
855
543
|
}
|
|
856
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
|
+
});
|
|
857
556
|
};
|
|
858
|
-
useEffect3(() => {
|
|
859
|
-
if (typeof window === "undefined") return;
|
|
860
|
-
const handlePopState = () => {
|
|
861
|
-
hydrateFromUrl();
|
|
862
|
-
};
|
|
863
|
-
window.addEventListener("popstate", handlePopState);
|
|
864
|
-
return () => {
|
|
865
|
-
window.removeEventListener("popstate", handlePopState);
|
|
866
|
-
};
|
|
867
|
-
}, []);
|
|
868
557
|
const onPage = (event) => {
|
|
558
|
+
const newPage = event.page + 1;
|
|
869
559
|
setFirst(event.first);
|
|
870
560
|
setRows(event.rows);
|
|
871
|
-
setPage(
|
|
872
|
-
|
|
561
|
+
setPage(newPage);
|
|
562
|
+
emitStateChange({
|
|
563
|
+
page: newPage,
|
|
564
|
+
rows: event.rows
|
|
565
|
+
});
|
|
873
566
|
};
|
|
874
567
|
const onGlobalFilterChange = (e) => {
|
|
875
568
|
const value = e.target.value;
|
|
@@ -885,10 +578,16 @@ function DataTableAdvancedFilterWrapper({
|
|
|
885
578
|
const onSort = (e) => {
|
|
886
579
|
setSortField(e.sortField);
|
|
887
580
|
setSortOrder(e.sortOrder);
|
|
888
|
-
|
|
581
|
+
emitStateChange({
|
|
582
|
+
sortField: e.sortField,
|
|
583
|
+
sortOrder: e.sortOrder
|
|
584
|
+
});
|
|
889
585
|
};
|
|
890
586
|
useEffect3(() => {
|
|
891
|
-
|
|
587
|
+
emitStateChange({
|
|
588
|
+
page: 1,
|
|
589
|
+
filter: debouncedSearch
|
|
590
|
+
});
|
|
892
591
|
}, [debouncedSearch]);
|
|
893
592
|
useEffect3(() => {
|
|
894
593
|
if (customers?.items && selectedRowsData.length > 0) {
|
|
@@ -1225,8 +924,7 @@ function DataTableAdvancedFilter({
|
|
|
1225
924
|
sortFieldInitial,
|
|
1226
925
|
sortOrderInitial = 1,
|
|
1227
926
|
isMultiSelectionMode = true,
|
|
1228
|
-
isLanguagePtBr = true
|
|
1229
|
-
replaceUrl = true
|
|
927
|
+
isLanguagePtBr = true
|
|
1230
928
|
}) {
|
|
1231
929
|
const [isClient, setIsClient] = useState3(false);
|
|
1232
930
|
useEffect4(() => {
|
|
@@ -1258,8 +956,7 @@ function DataTableAdvancedFilter({
|
|
|
1258
956
|
sortFieldInitial,
|
|
1259
957
|
sortOrderInitial,
|
|
1260
958
|
isMultiSelectionMode,
|
|
1261
|
-
isLanguagePtBr
|
|
1262
|
-
replaceUrl
|
|
959
|
+
isLanguagePtBr
|
|
1263
960
|
}
|
|
1264
961
|
)
|
|
1265
962
|
}
|
|
@@ -1276,303 +973,585 @@ var DateFilterTemplate = (options, mask) => {
|
|
|
1276
973
|
return /* @__PURE__ */ jsx11(
|
|
1277
974
|
Calendar,
|
|
1278
975
|
{
|
|
1279
|
-
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",
|
|
1280
1009
|
onChange: (e) => {
|
|
1281
|
-
|
|
1010
|
+
const selectedDate = e.value;
|
|
1011
|
+
if (!selectedDate) {
|
|
1282
1012
|
options.filterCallback(null, options.index);
|
|
1283
1013
|
return;
|
|
1284
1014
|
}
|
|
1285
|
-
const
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
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"
|
|
1291
1119
|
},
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
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";
|
|
1296
1340
|
}
|
|
1297
|
-
|
|
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
|
+
};
|
|
1298
1354
|
};
|
|
1299
|
-
var
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
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);
|
|
1316
1375
|
return;
|
|
1317
1376
|
}
|
|
1318
|
-
const
|
|
1319
|
-
|
|
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 });
|
|
1320
1388
|
}
|
|
1389
|
+
return;
|
|
1321
1390
|
}
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
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
|
+
});
|
|
1330
1403
|
return;
|
|
1331
1404
|
}
|
|
1332
|
-
const
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
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;
|
|
1344
1421
|
}
|
|
1345
|
-
|
|
1346
|
-
};
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
{
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
{
|
|
1357
|
-
options: selectOptions,
|
|
1358
|
-
value: currentValue,
|
|
1359
|
-
onChange: (selected) => options.filterCallback(selected?.value),
|
|
1360
|
-
placeholder: "Todos",
|
|
1361
|
-
isClearable: false,
|
|
1362
|
-
isSearchable: false,
|
|
1363
|
-
className: "custom-select-filtro",
|
|
1364
|
-
classNamePrefix: "custom-select-filtro",
|
|
1365
|
-
styles: {
|
|
1366
|
-
control: (baseStyles, state) => ({
|
|
1367
|
-
...baseStyles,
|
|
1368
|
-
"&:hover": {
|
|
1369
|
-
borderColor: state.isFocused ? "#094394" : ""
|
|
1370
|
-
},
|
|
1371
|
-
borderRadius: "6px"
|
|
1372
|
-
}),
|
|
1373
|
-
menuList: (base) => ({
|
|
1374
|
-
...base,
|
|
1375
|
-
"::-webkit-scrollbar": {
|
|
1376
|
-
width: "6px",
|
|
1377
|
-
height: "auto",
|
|
1378
|
-
overflowX: "hidden",
|
|
1379
|
-
overflowY: "hidden"
|
|
1380
|
-
},
|
|
1381
|
-
"::-webkit-scrollbar-track": {
|
|
1382
|
-
background: "#fff"
|
|
1383
|
-
},
|
|
1384
|
-
"::-webkit-scrollbar-thumb": {
|
|
1385
|
-
background: "#888",
|
|
1386
|
-
borderRadius: "2rem"
|
|
1387
|
-
},
|
|
1388
|
-
"::-webkit-scrollbar-thumb:hover": {
|
|
1389
|
-
background: "#555"
|
|
1390
|
-
}
|
|
1391
|
-
}),
|
|
1392
|
-
option: (provided, state) => ({
|
|
1393
|
-
...provided,
|
|
1394
|
-
backgroundColor: state.isFocused ? "#094394" : "#ffffff",
|
|
1395
|
-
color: state.isFocused ? "#ffffff" : "black",
|
|
1396
|
-
"&:hover": {
|
|
1397
|
-
backgroundColor: "#094394",
|
|
1398
|
-
// Cor de fundo quando em hover
|
|
1399
|
-
color: "#ffffff"
|
|
1400
|
-
// Cor da palavra quando em hover
|
|
1401
|
-
}
|
|
1402
|
-
})
|
|
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
|
+
]
|
|
1403
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);
|
|
1404
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 : ""
|
|
1405
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
|
+
};
|
|
1406
1497
|
};
|
|
1407
|
-
|
|
1408
|
-
const
|
|
1409
|
-
|
|
1410
|
-
const currentMatchMode = rawFilter.matchMode ?? "contains";
|
|
1411
|
-
const currentValue = typeof rawFilter.text === "string" ? rawFilter.text : "";
|
|
1412
|
-
const isSpecial = currentMatchMode === customMatchModes.empty || currentMatchMode === customMatchModes.notEmpty;
|
|
1413
|
-
return /* @__PURE__ */ jsxs6(
|
|
1414
|
-
"div",
|
|
1498
|
+
function buildSortingWithFilters(filters, sortField, order) {
|
|
1499
|
+
const direction = order === 1 ? "asc" : order === -1 ? "Des" : "Asc";
|
|
1500
|
+
let sorting = [
|
|
1415
1501
|
{
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
display: "flex",
|
|
1419
|
-
flexDirection: "column",
|
|
1420
|
-
gap: "8px",
|
|
1421
|
-
minWidth: "200px"
|
|
1422
|
-
},
|
|
1423
|
-
children: [
|
|
1424
|
-
/* @__PURE__ */ jsx11(
|
|
1425
|
-
Dropdown,
|
|
1426
|
-
{
|
|
1427
|
-
value: currentMatchMode,
|
|
1428
|
-
options: resolvedItems,
|
|
1429
|
-
optionLabel: "label",
|
|
1430
|
-
optionValue: "value",
|
|
1431
|
-
placeholder: "Tipo de filtro",
|
|
1432
|
-
style: { width: "100%" },
|
|
1433
|
-
onChange: (e) => {
|
|
1434
|
-
const newMatchMode = e.value;
|
|
1435
|
-
const isNewSpecial = newMatchMode === customMatchModes.empty || newMatchMode === customMatchModes.notEmpty;
|
|
1436
|
-
if (isNewSpecial) {
|
|
1437
|
-
options.filterCallback({
|
|
1438
|
-
text: null,
|
|
1439
|
-
matchMode: newMatchMode
|
|
1440
|
-
});
|
|
1441
|
-
return;
|
|
1442
|
-
}
|
|
1443
|
-
options.filterCallback({
|
|
1444
|
-
text: null,
|
|
1445
|
-
matchMode: newMatchMode
|
|
1446
|
-
});
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
),
|
|
1450
|
-
!isSpecial && /* @__PURE__ */ jsx11(
|
|
1451
|
-
InputText,
|
|
1452
|
-
{
|
|
1453
|
-
value: currentValue,
|
|
1454
|
-
placeholder: isLanguagePtBr ? "Pesquisar" : "Search",
|
|
1455
|
-
style: { width: "100%" },
|
|
1456
|
-
className: "p-column-filter",
|
|
1457
|
-
onChange: (e) => {
|
|
1458
|
-
const value = e.target.value;
|
|
1459
|
-
if (value.trim()) {
|
|
1460
|
-
options.filterCallback({
|
|
1461
|
-
text: value,
|
|
1462
|
-
matchMode: currentMatchMode
|
|
1463
|
-
});
|
|
1464
|
-
} else {
|
|
1465
|
-
options.filterCallback({
|
|
1466
|
-
text: null,
|
|
1467
|
-
matchMode: currentMatchMode
|
|
1468
|
-
});
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
)
|
|
1473
|
-
]
|
|
1502
|
+
field: sortField,
|
|
1503
|
+
direction
|
|
1474
1504
|
}
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
// src/components/DataTableAdvancedFilter/filterModes.ts
|
|
1479
|
-
import { FilterMatchMode as FilterMatchMode4 } from "primereact/api";
|
|
1480
|
-
var customMatchModes = {
|
|
1481
|
-
notStartsWith: "notStartsWith",
|
|
1482
|
-
notEndsWith: "notEndsWith",
|
|
1483
|
-
empty: "empty",
|
|
1484
|
-
notEmpty: "notEmpty"
|
|
1485
|
-
};
|
|
1486
|
-
var getDefaultFilterMatchOptionsString = (isLanguagePtBr = true) => [
|
|
1487
|
-
{
|
|
1488
|
-
label: isLanguagePtBr ? "Cont\xE9m" : "Contains",
|
|
1489
|
-
value: FilterMatchMode4.CONTAINS
|
|
1490
|
-
},
|
|
1491
|
-
{
|
|
1492
|
-
label: isLanguagePtBr ? "N\xE3o cont\xE9m" : "Does not contain",
|
|
1493
|
-
value: FilterMatchMode4.NOT_CONTAINS
|
|
1494
|
-
},
|
|
1495
|
-
{
|
|
1496
|
-
label: isLanguagePtBr ? "Igual" : "Equals",
|
|
1497
|
-
value: FilterMatchMode4.EQUALS
|
|
1498
|
-
},
|
|
1499
|
-
{
|
|
1500
|
-
label: isLanguagePtBr ? "Diferente" : "Not equals",
|
|
1501
|
-
value: FilterMatchMode4.NOT_EQUALS
|
|
1502
|
-
},
|
|
1503
|
-
{
|
|
1504
|
-
label: isLanguagePtBr ? "Come\xE7a com" : "Starts with",
|
|
1505
|
-
value: FilterMatchMode4.STARTS_WITH
|
|
1506
|
-
},
|
|
1507
|
-
{
|
|
1508
|
-
label: isLanguagePtBr ? "N\xE3o come\xE7a com" : "Does not start with",
|
|
1509
|
-
value: customMatchModes.notStartsWith
|
|
1510
|
-
},
|
|
1511
|
-
{
|
|
1512
|
-
label: isLanguagePtBr ? "Termina com" : "Ends with",
|
|
1513
|
-
value: FilterMatchMode4.ENDS_WITH
|
|
1514
|
-
},
|
|
1515
|
-
{
|
|
1516
|
-
label: isLanguagePtBr ? "N\xE3o termina com" : "Does not end with",
|
|
1517
|
-
value: customMatchModes.notEndsWith
|
|
1518
|
-
},
|
|
1519
|
-
{
|
|
1520
|
-
label: isLanguagePtBr ? "Vazio" : "Empty",
|
|
1521
|
-
value: customMatchModes.empty
|
|
1522
|
-
},
|
|
1523
|
-
{
|
|
1524
|
-
label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
|
|
1525
|
-
value: customMatchModes.notEmpty
|
|
1505
|
+
];
|
|
1506
|
+
if (!filters || !sortField) {
|
|
1507
|
+
return sorting;
|
|
1526
1508
|
}
|
|
1527
|
-
];
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
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
|
+
];
|
|
1536
1525
|
}
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
{
|
|
1544
|
-
label: isLanguagePtBr ? "Data depois de" : "Date after",
|
|
1545
|
-
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);
|
|
1546
1532
|
}
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
{
|
|
1550
|
-
label: isLanguagePtBr ? "Igual" : "Equals",
|
|
1551
|
-
value: FilterMatchMode4.EQUALS
|
|
1552
|
-
},
|
|
1553
|
-
{
|
|
1554
|
-
label: isLanguagePtBr ? "Diferente" : "Not equals",
|
|
1555
|
-
value: FilterMatchMode4.NOT_EQUALS
|
|
1556
|
-
},
|
|
1557
|
-
{
|
|
1558
|
-
label: isLanguagePtBr ? "Vazio" : "Empty",
|
|
1559
|
-
value: customMatchModes.empty
|
|
1560
|
-
},
|
|
1561
|
-
{
|
|
1562
|
-
label: isLanguagePtBr ? "N\xE3o Vazio" : "NotEmpty",
|
|
1563
|
-
value: customMatchModes.notEmpty
|
|
1533
|
+
if (typeof raw === "number") {
|
|
1534
|
+
return raw;
|
|
1564
1535
|
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
{
|
|
1568
|
-
label: isLanguagePtBr ? "Igual" : "Equals",
|
|
1569
|
-
value: FilterMatchMode4.EQUALS
|
|
1570
|
-
},
|
|
1571
|
-
{
|
|
1572
|
-
label: isLanguagePtBr ? "Diferente" : "Not equals",
|
|
1573
|
-
value: FilterMatchMode4.NOT_EQUALS
|
|
1536
|
+
if (typeof raw === "string") {
|
|
1537
|
+
return raw.trim() !== "" ? raw : null;
|
|
1574
1538
|
}
|
|
1575
|
-
|
|
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
|
+
}
|
|
1576
1555
|
|
|
1577
1556
|
// src/index.tsx
|
|
1578
1557
|
import { FilterMatchMode as FilterMatchMode5, FilterOperator as FilterOperator2 } from "primereact/api";
|