@postrun/react 2.18.0 → 2.20.0
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.cjs +72 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -3
- package/dist/index.d.ts +35 -3
- package/dist/index.js +75 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -92,6 +92,7 @@ __export(index_exports, {
|
|
|
92
92
|
profileKeys: () => profileKeys,
|
|
93
93
|
resolveVariantMedia: () => resolveVariantMedia,
|
|
94
94
|
tiktokKeys: () => tiktokKeys,
|
|
95
|
+
useAdTree: () => useAdTree,
|
|
95
96
|
useCalendar: () => useCalendar,
|
|
96
97
|
useConnect: () => useConnect,
|
|
97
98
|
useConnection: () => useConnection,
|
|
@@ -1030,6 +1031,76 @@ function useTikTokCreatorInfo(connectionId) {
|
|
|
1030
1031
|
queryClient
|
|
1031
1032
|
);
|
|
1032
1033
|
}
|
|
1034
|
+
function useAdTree(params) {
|
|
1035
|
+
const { connectionId, since, until, metrics, expanded = [] } = params;
|
|
1036
|
+
const { client, queryClient } = usePostrun();
|
|
1037
|
+
const enabled = Boolean(connectionId && since && until);
|
|
1038
|
+
const path = { connection_id: connectionId };
|
|
1039
|
+
const baseQuery = { since, until, metrics };
|
|
1040
|
+
const campaign = reactQuery.useQuery(
|
|
1041
|
+
{
|
|
1042
|
+
...query_star.googleGetAdTreeOptions({ client, path, query: baseQuery }),
|
|
1043
|
+
enabled
|
|
1044
|
+
},
|
|
1045
|
+
queryClient
|
|
1046
|
+
);
|
|
1047
|
+
const combine = react.useCallback(
|
|
1048
|
+
(results) => {
|
|
1049
|
+
const nodes = results.flatMap((q) => q.data?.data ?? []);
|
|
1050
|
+
const loadingById2 = new Map(
|
|
1051
|
+
expanded.map((id, i) => [id, results[i]?.isLoading ?? false])
|
|
1052
|
+
);
|
|
1053
|
+
return { nodes, loadingById: loadingById2 };
|
|
1054
|
+
},
|
|
1055
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- expanded is an array; join gives a stable string dep
|
|
1056
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: intentional string-join dep for array stability
|
|
1057
|
+
[expanded.join(",")]
|
|
1058
|
+
);
|
|
1059
|
+
const { nodes: subtreeNodes, loadingById } = reactQuery.useQueries(
|
|
1060
|
+
{
|
|
1061
|
+
queries: expanded.map((campaignId) => ({
|
|
1062
|
+
...query_star.googleGetAdTreeOptions({
|
|
1063
|
+
client,
|
|
1064
|
+
path,
|
|
1065
|
+
query: { ...baseQuery, campaign_id: campaignId }
|
|
1066
|
+
}),
|
|
1067
|
+
enabled
|
|
1068
|
+
})),
|
|
1069
|
+
combine
|
|
1070
|
+
},
|
|
1071
|
+
queryClient
|
|
1072
|
+
);
|
|
1073
|
+
const tree = react.useMemo(
|
|
1074
|
+
() => js.groupAdTree([...campaign.data?.data ?? [], ...subtreeNodes]),
|
|
1075
|
+
[campaign.data, subtreeNodes]
|
|
1076
|
+
);
|
|
1077
|
+
const isExpanding = react.useCallback(
|
|
1078
|
+
(campaignId) => loadingById.get(campaignId) ?? false,
|
|
1079
|
+
[loadingById]
|
|
1080
|
+
);
|
|
1081
|
+
const refetch = react.useCallback(
|
|
1082
|
+
(...args) => campaign.refetch(...args),
|
|
1083
|
+
[campaign.refetch]
|
|
1084
|
+
);
|
|
1085
|
+
return react.useMemo(
|
|
1086
|
+
() => ({
|
|
1087
|
+
tree,
|
|
1088
|
+
isLoading: campaign.isLoading,
|
|
1089
|
+
isError: campaign.isError,
|
|
1090
|
+
error: campaign.error,
|
|
1091
|
+
isExpanding,
|
|
1092
|
+
refetch
|
|
1093
|
+
}),
|
|
1094
|
+
[
|
|
1095
|
+
tree,
|
|
1096
|
+
campaign.isLoading,
|
|
1097
|
+
campaign.isError,
|
|
1098
|
+
campaign.error,
|
|
1099
|
+
isExpanding,
|
|
1100
|
+
refetch
|
|
1101
|
+
]
|
|
1102
|
+
);
|
|
1103
|
+
}
|
|
1033
1104
|
|
|
1034
1105
|
// src/query.ts
|
|
1035
1106
|
var query_exports = {};
|
|
@@ -3516,6 +3587,7 @@ exports.postKeys = postKeys;
|
|
|
3516
3587
|
exports.profileKeys = profileKeys;
|
|
3517
3588
|
exports.resolveVariantMedia = resolveVariantMedia;
|
|
3518
3589
|
exports.tiktokKeys = tiktokKeys;
|
|
3590
|
+
exports.useAdTree = useAdTree;
|
|
3519
3591
|
exports.useCalendar = useCalendar;
|
|
3520
3592
|
exports.useConnect = useConnect;
|
|
3521
3593
|
exports.useConnection = useConnection;
|