Compare commits
1 Commits
openapi-si
...
cccb4604fd
| Author | SHA1 | Date | |
|---|---|---|---|
| cccb4604fd |
@@ -30,13 +30,13 @@ export function useResource<T = any>(config: ResourceConfig | undefined) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// --- READ ONE ---
|
// --- READ ONE ---
|
||||||
const useRead = (id: string | null) =>
|
const useRead = (id: string, params?: any | null) =>
|
||||||
useQuery({
|
useQuery({
|
||||||
queryKey: [name, "detail", id],
|
queryKey: [name, "detail", id, params],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
if (!id || !endpoint) return null;
|
if (!id || !endpoint) return null;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const res = await api.get<T>(`${endpoint}/${id}`);
|
const res = await api.get<T>(`${endpoint}/${id}`, params ? { params } : undefined);
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
enabled: !!id && !!endpoint,
|
enabled: !!id && !!endpoint,
|
||||||
|
|||||||
@@ -50,10 +50,10 @@ export default function Dashboard() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (report.data?.data) {
|
if (report.data) {
|
||||||
setLoadedPayees(prev => {
|
setLoadedPayees(prev => {
|
||||||
const pSet = new Set<string>(prev);
|
const pSet = new Set<string>(prev);
|
||||||
report.data.data.buckets.forEach((b: any) => {
|
report.data.buckets.forEach((b: any) => {
|
||||||
Object.values(b.periods).forEach((periodArray: any) => {
|
Object.values(b.periods).forEach((periodArray: any) => {
|
||||||
periodArray?.forEach((p: any) => {
|
periodArray?.forEach((p: any) => {
|
||||||
p.metric?.transactions?.forEach((t: any) => {
|
p.metric?.transactions?.forEach((t: any) => {
|
||||||
@@ -67,7 +67,7 @@ export default function Dashboard() {
|
|||||||
|
|
||||||
setLoadedTags(prev => {
|
setLoadedTags(prev => {
|
||||||
const tSet = new Set<string>(prev);
|
const tSet = new Set<string>(prev);
|
||||||
report.data.data.buckets.forEach((b: any) => {
|
report.data.buckets.forEach((b: any) => {
|
||||||
Object.values(b.periods).forEach((periodArray: any) => {
|
Object.values(b.periods).forEach((periodArray: any) => {
|
||||||
periodArray?.forEach((p: any) => {
|
periodArray?.forEach((p: any) => {
|
||||||
p.metric?.transactions?.forEach((t: any) => {
|
p.metric?.transactions?.forEach((t: any) => {
|
||||||
@@ -79,7 +79,7 @@ export default function Dashboard() {
|
|||||||
return Array.from(tSet).sort();
|
return Array.from(tSet).sort();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [report.data?.data]);
|
}, [report.data]);
|
||||||
|
|
||||||
const toggleFlow =
|
const toggleFlow =
|
||||||
React.useCallback(() => {
|
React.useCallback(() => {
|
||||||
@@ -219,7 +219,7 @@ export default function Dashboard() {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = prepareReport(report.data.data);
|
const data = prepareReport(report.data);
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Container>
|
<Container>
|
||||||
|
|||||||
@@ -9,10 +9,13 @@ export interface ReportParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useReport(params: ReportParams) {
|
export function useReport(params: ReportParams) {
|
||||||
const { useList } = useResourceByName("reports");
|
const { useRead } = useResourceByName("reports");
|
||||||
|
|
||||||
return useList({
|
return useRead(
|
||||||
...params,
|
params.snapshot_id ? params.snapshot_id : "latest",
|
||||||
periods: params.periods,
|
{
|
||||||
});
|
...params,
|
||||||
|
periods: params.periods,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user