Skip to content

Commit 6ecc7de

Browse files
committed
Rename routes
1 parent 74c69ff commit 6ecc7de

File tree

22 files changed

+216
-79
lines changed

22 files changed

+216
-79
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React, {
2+
useEffect,
3+
useState,
4+
lazy,
5+
useReducer,
6+
useRef,
7+
useMemo,
8+
} from "react";
9+
10+
interface Props {}
11+
12+
const TopPages: React.FC<Props> = () => {
13+
return <div>hello</div>;
14+
};
15+
16+
export default TopPages;

src/index.ts

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,30 @@
11
import type { Config as PayloadConfig } from "payload/config";
22
import type { DashboardAnalyticsConfig } from "./types";
3-
import type {
4-
PageInfoWidget,
5-
PageChartWidget,
6-
PageWidgets,
7-
NavigationWidgets,
8-
DashboardWidgets,
9-
} from "./types/widgets";
10-
import type { Field } from "payload/dist/fields/config/types";
3+
114
import { extendWebpackConfig } from "./extendWebpackConfig";
125
import getProvider from "./providers";
136

14-
import getGlobalAggregateData from "./routes/getGlobalAggregateData";
15-
import getGlobalChartData from "./routes/getGlobalChartData";
16-
import getPageChartData from "./routes/getPageChartData";
17-
import getPageAggregateData from "./routes/getPageAggregateData";
18-
import getLiveData from "./routes/getLiveData";
7+
import getGlobalAggregate from "./routes/getGlobalAggregate";
8+
import getGlobalChart from "./routes/getGlobalChart";
9+
import getPageChart from "./routes/getPageChart";
10+
import getPageAggregate from "./routes/getPageAggregate";
11+
import getLive from "./routes/getLive";
12+
import getReport from "./routes/getReport";
1913

2014
import type { CollectionConfig } from "payload/dist/collections/config/types";
2115
import type { GlobalConfig } from "payload/dist/globals/config/types";
22-
import { getPageViewsChart } from "./components/Charts/PageViewsChart";
23-
import { getAggregateDataWidget } from "./components/Aggregates/AggregateDataWidget";
24-
import LiveDataComponent from "./components/Live/LiveDataWidget";
25-
26-
const PageWidgetMap: Record<
27-
PageWidgets["type"],
28-
(config: any, index: number) => Field
29-
> = {
30-
chart: (config: PageChartWidget, index: number) => ({
31-
type: "ui",
32-
name: `chart_${index}_${config.timeframe ?? "30d"}`,
33-
admin: {
34-
position: "sidebar",
35-
components: {
36-
Field: (props: any) => getPageViewsChart(props, config),
37-
},
38-
},
39-
}),
40-
info: (config: PageInfoWidget) => ({
41-
type: "ui",
42-
name: "dashboardAnalyticsViewsChart",
43-
admin: {
44-
position: "sidebar",
45-
components: {
46-
Field: (props: any) => getAggregateDataWidget(props, config),
47-
},
48-
},
49-
}),
50-
};
5116

52-
const NavigationWidgetMap: Record<NavigationWidgets["type"], React.FC> = {
53-
live: LiveDataComponent.LiveDataWidget,
54-
};
17+
import {
18+
PageWidgetMap,
19+
NavigationWidgetMap,
20+
DashboardWidgetMap,
21+
} from "./utilities/widgetMaps";
5522

5623
const payloadDashboardAnalytics =
5724
(incomingConfig: DashboardAnalyticsConfig) =>
5825
(config: PayloadConfig): PayloadConfig => {
5926
const { admin, collections, globals } = config;
60-
const { provider, navigation } = incomingConfig;
27+
const { provider, navigation, dashboard } = incomingConfig;
6128
const endpoints = config.endpoints ?? [];
6229
const apiProvider = getProvider(provider);
6330

@@ -83,16 +50,33 @@ const payloadDashboardAnalytics =
8350
),
8451
],
8552
}),
53+
...(dashboard?.beforeDashboard && {
54+
beforeDashboard: [
55+
...(admin?.components?.beforeDashboard ?? []),
56+
...dashboard.beforeDashboard.map(
57+
(widget) => DashboardWidgetMap[widget]
58+
),
59+
],
60+
}),
61+
...(dashboard?.afterDashboard && {
62+
afterDashboard: [
63+
...(admin?.components?.afterDashboard ?? []),
64+
...dashboard.afterDashboard.map(
65+
(widget) => DashboardWidgetMap[widget]
66+
),
67+
],
68+
}),
8669
},
8770
webpack: extendWebpackConfig(config),
8871
},
8972
endpoints: [
9073
...endpoints,
91-
getGlobalAggregateData(apiProvider),
92-
getGlobalChartData(apiProvider),
93-
getPageChartData(apiProvider),
94-
getPageAggregateData(apiProvider),
95-
getLiveData(apiProvider),
74+
getGlobalAggregate(apiProvider),
75+
getGlobalChart(apiProvider),
76+
getPageChart(apiProvider),
77+
getPageAggregate(apiProvider),
78+
getLive(apiProvider),
79+
getReport(apiProvider),
9680
],
9781
...(collections && {
9882
collections: collections.map((collection) => {

src/providers/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import plausible from "./plausible";
22
import type { Provider } from "../types";
3-
import type { ChartWidget, InfoWidget } from "../types/widgets";
4-
import type { ChartData, AggregateData, LiveData } from "../types/data";
3+
import type { ChartWidget, InfoWidget, ReportWidget } from "../types/widgets";
4+
import type {
5+
ChartData,
6+
AggregateData,
7+
LiveData,
8+
ReportData,
9+
} from "../types/data";
510

611
type BaseOptions = {
712
timeframe?: string;
813
};
914

1015
export interface LiveDataOptions {}
1116

17+
export interface ReportDataOptions extends BaseOptions {
18+
metrics: ReportWidget["metrics"];
19+
property: ReportWidget["property"];
20+
}
21+
1222
export interface GlobalAggregateOptions extends BaseOptions {
1323
metrics: InfoWidget["metrics"];
1424
}
@@ -35,6 +45,7 @@ export type ApiProvider = {
3545
) => Promise<AggregateData>;
3646
getPageChartData: (options: PageChartOptions) => Promise<ChartData>;
3747
getLiveData: (options: LiveDataOptions) => Promise<LiveData>;
48+
getReportData: (options: ReportDataOptions) => Promise<ReportData>;
3849
};
3950

4051
const getProvider = (provider: Provider) => {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { PlausibleProvider } from "../../types/providers";
2+
import type { ReportDataOptions } from "..";
3+
import type { ReportData } from "../../types/data";
4+
import client from "./client";
5+
6+
async function getReportData(
7+
provider: PlausibleProvider,
8+
options: ReportDataOptions
9+
) {
10+
const plausibleClient = client(provider, {
11+
endpoint: "/stats/breakdown",
12+
});
13+
14+
const data = await plausibleClient.fetch().then((response) => {
15+
return response.json();
16+
});
17+
18+
const processedData: ReportData = data.results.map((item: any) => {
19+
return item;
20+
});
21+
22+
return processedData;
23+
}
24+
25+
export default getReportData;

src/providers/plausible/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import getGlobalChartData from "./getGlobalChartData";
44
import getPageAggregateData from "./getPageAggregateData";
55
import getPageChartData from "./getPageChartData";
66
import getLiveData from "./getLiveData";
7+
import getReportData from "./getReportData";
78
import type {
89
ApiProvider,
910
GlobalAggregateOptions,
1011
GlobalChartOptions,
1112
PageChartOptions,
1213
PageAggregateOptions,
1314
LiveDataOptions,
15+
ReportDataOptions,
1416
} from "..";
1517

1618
const plausible = (provider: PlausibleProvider): ApiProvider => {
@@ -25,6 +27,8 @@ const plausible = (provider: PlausibleProvider): ApiProvider => {
2527
await getPageAggregateData(provider, options),
2628
getLiveData: async (options: LiveDataOptions) =>
2729
await getLiveData(provider, options),
30+
getReportData: async (options: ReportDataOptions) =>
31+
await getReportData(provider, options),
2832
};
2933
};
3034

File renamed without changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Endpoint } from "payload/config";
22
import handler from "./handler";
33
import { ApiProvider } from "../../providers";
44

5-
const getGlobalChartData = (provider: ApiProvider): Endpoint => {
5+
const getGlobalAggregate = (provider: ApiProvider): Endpoint => {
66
return {
7-
path: "/analytics/globalChartData",
7+
path: "/analytics/globalAggregate",
88
method: "post",
99
handler: handler(provider),
1010
};
1111
};
1212

13-
export default getGlobalChartData;
13+
export default getGlobalAggregate;

src/routes/getGlobalAggregateData/index.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Endpoint } from "payload/config";
22
import handler from "./handler";
33
import { ApiProvider } from "../../providers";
44

5-
const getPageChartData = (provider: ApiProvider): Endpoint => {
5+
const getGlobalChart = (provider: ApiProvider): Endpoint => {
66
return {
7-
path: "/analytics/pageChartData",
7+
path: "/analytics/globalChart",
88
method: "post",
99
handler: handler(provider),
1010
};
1111
};
1212

13-
export default getPageChartData;
13+
export default getGlobalChart;

0 commit comments

Comments
 (0)