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