Skip to content

Commit 2a03202

Browse files
committed
Fix webpack compilation errors
1 parent b06fa13 commit 2a03202

File tree

5 files changed

+48
-46
lines changed

5 files changed

+48
-46
lines changed

demo/src/payload.config.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import Tags from "./collections/Tags";
66
import Users from "./collections/Users";
77
import Media from "./collections/Media";
88
import Homepage from "./globals/Homepage";
9-
import dashboardAnalytics from "../../src/index";
10-
import { PlausibleProvider, GoogleProvider } from "../../src/types/providers";
9+
import dashboardAnalytics from "../../dist/index";
1110

1211
const PLAUSIBLE_API_KEY = process.env.PLAUSIBLE_API_KEY;
1312
const PLAUSIBLE_HOST = process.env.PLAUSIBLE_HOST;
@@ -16,14 +15,14 @@ const PLAUSIBLE_SITE_ID = process.env.PLAUSIBLE_SITE_ID;
1615
const GOOGLE_PROPERTY_ID = process.env.GOOGLE_PROPERTY_ID;
1716
const GOOGLE_CREDENTIALS_FILE = process.env.GOOGLE_CREDENTIALS_FILE;
1817

19-
const plausibleProvider: PlausibleProvider = {
18+
const plausibleProvider = {
2019
source: "plausible",
2120
apiSecret: PLAUSIBLE_API_KEY,
2221
siteId: PLAUSIBLE_SITE_ID,
2322
host: PLAUSIBLE_HOST,
2423
};
2524

26-
const googleProvider: GoogleProvider = {
25+
const googleProvider = {
2726
source: "google",
2827
//credentials: GOOGLE_CREDENTIALS_FILE,
2928
propertyId: GOOGLE_PROPERTY_ID,
@@ -61,7 +60,7 @@ export default buildConfig({
6160
},
6261
plugins: [
6362
dashboardAnalytics({
64-
provider: googleProvider,
63+
provider: plausibleProvider,
6564
access: (user: any) => {
6665
return Boolean(user);
6766
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nouance/payload-dashboard-analytics",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"homepage:": "https://nouance.io",
55
"repository": "git@github.com:NouanceLabs/payload-dashboard-analytics.git",
66
"description": "Dashboard analytics integration plugin for Payload CMS",

src/components/Aggregates/AggregateDataWidget.tsx

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,30 @@ const AggregateDataWidget: React.FC<Props> = ({ options, metricsMap }) => {
9090
{isLoading ? (
9191
<>Loading...</>
9292
) : (
93-
<ul style={{ margin: "0", listStyle: "none", padding: "0" }}>
94-
{data.map((item, index) => {
95-
const value =
96-
typeof item.value === "string"
97-
? Math.floor(parseInt(item.value))
98-
: Math.floor(item.value);
99-
return (
100-
<li
101-
key={index}
102-
style={{ display: "flex", justifyContent: "space-between" }}
103-
>
104-
<div style={{ fontWeight: "700" }}>
105-
{metricsMap ? metricsMap[item.label].label : item.label}
106-
</div>
107-
<div>{value}</div>
108-
</li>
109-
);
110-
})}
111-
</ul>
93+
data.length > 0 && (
94+
<ul style={{ margin: "0", listStyle: "none", padding: "0" }}>
95+
{data.map((item, index) => {
96+
const value =
97+
typeof item.value === "string"
98+
? Math.floor(parseInt(item.value))
99+
: Math.floor(item.value);
100+
101+
const itemLabel = item.label;
102+
103+
const label = metricsMap?.[itemLabel] ?? itemLabel;
104+
105+
return (
106+
<li
107+
key={index}
108+
style={{ display: "flex", justifyContent: "space-between" }}
109+
>
110+
<div style={{ fontWeight: "700" }}>{label}</div>
111+
<div>{value}</div>
112+
</li>
113+
);
114+
})}
115+
</ul>
116+
)
112117
)}
113118
</div>
114119
</section>

src/extendWebpackConfig.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,22 @@ import type { Provider } from "./types";
66
const mockModulePath = path.resolve(__dirname, "mocks/serverModule.js");
77

88
/* Some providers may need their own list of mocked modules to avoid react errors and bundling of node modules */
9-
const aliasMap: Record<Provider["source"], any> = {
10-
google: {
11-
[path.resolve(__dirname, "./providers/google/client")]: mockModulePath,
12-
[path.resolve(__dirname, "./providers/google/getLiveData")]: mockModulePath,
13-
"@google-analytics/data": mockModulePath,
14-
url: mockModulePath,
15-
querystring: mockModulePath,
16-
fs: mockModulePath,
17-
os: mockModulePath,
18-
stream: mockModulePath,
19-
child_process: mockModulePath,
20-
util: mockModulePath,
21-
net: mockModulePath,
22-
tls: mockModulePath,
23-
assert: mockModulePath,
24-
request: mockModulePath,
25-
},
26-
plausible: {
27-
[path.resolve(__dirname, "./providers/plausible/client")]: mockModulePath,
28-
},
9+
const aliasMap /* : Record<Provider["source"], any> */ = {
10+
[path.resolve(__dirname, "./providers/google/client")]: mockModulePath,
11+
[path.resolve(__dirname, "./providers/google/getLiveData")]: mockModulePath,
12+
"@google-analytics/data": mockModulePath,
13+
url: mockModulePath,
14+
querystring: mockModulePath,
15+
fs: mockModulePath,
16+
os: mockModulePath,
17+
stream: mockModulePath,
18+
child_process: mockModulePath,
19+
util: mockModulePath,
20+
net: mockModulePath,
21+
tls: mockModulePath,
22+
assert: mockModulePath,
23+
request: mockModulePath,
24+
[path.resolve(__dirname, "./providers/plausible/client")]: mockModulePath,
2925
};
3026

3127
export const extendWebpackConfig =
@@ -48,7 +44,7 @@ export const extendWebpackConfig =
4844
? existingWebpackConfig.resolve.alias
4945
: {}),
5046
express: mockModulePath,
51-
...aliasMap[provider],
47+
...aliasMap,
5248
},
5349
},
5450
};

src/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ export type DashboardAnalyticsConfig = {
3939
afterDashboard?: DashboardWidgets[];
4040
};
4141
};
42+
43+
export { PlausibleProvider, GoogleProvider };

0 commit comments

Comments
 (0)