tienjs-chartbrew-plugin-strapi 0.1.3 → 0.1.5

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.
@@ -1,11 +1,11 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
- import { useState, useEffect } from "react";
2
+ import { useRef, useState, useEffect } from "react";
3
3
  import { Link, Routes, Route } from "react-router-dom";
4
4
  import { Layouts, Page } from "@strapi/strapi/admin";
5
5
  import { LinkButton, Loader, Box, Flex, Typography, SingleSelect, SingleSelectOption, EmptyStateLayout, Alert, Link as Link$1, Checkbox, Grid, Button, Divider, Combobox, ComboboxOption } from "@strapi/design-system";
6
6
  import { ChartCircle, Plus, ExternalLink, ArrowLeft } from "@strapi/icons";
7
- import { P as PLUGIN_ID } from "./index-BAu-oge7.mjs";
8
- import { g as getSettings, s as setSettings, i as instance } from "./store-CG_sYhrl.mjs";
7
+ import { P as PLUGIN_ID } from "./index-BDl1QGlA.mjs";
8
+ import { g as getSettings, s as setSettings, i as instance } from "./store-CoX04Dgx.mjs";
9
9
  import "js-cookie";
10
10
  async function login() {
11
11
  const { host, token } = await getSettings();
@@ -146,6 +146,7 @@ function Illo() {
146
146
  ] });
147
147
  }
148
148
  function Dashboard() {
149
+ const iframeRef = useRef(null);
149
150
  const [store, setStore] = useState({});
150
151
  const [user, setUser] = useState({});
151
152
  const [projects, setProjects] = useState([]);
@@ -169,7 +170,9 @@ function Dashboard() {
169
170
  setDropdownTeam(`${selectedTeam.name}-${selectedTeam.id}`);
170
171
  setProjects(selectedTeam.Projects);
171
172
  if (store.defaultProject) {
172
- const selectedProject2 = selectedTeam.Projects.find((p) => p.id === store.defaultProject);
173
+ const selectedProject2 = selectedTeam.Projects.find(
174
+ (p) => p.id === store.defaultProject
175
+ );
173
176
  if (selectedProject2) {
174
177
  setDropdownProject(`${selectedProject2.name}-${selectedProject2.id}`);
175
178
  setSelectedProject(selectedProject2);
@@ -178,6 +181,18 @@ function Dashboard() {
178
181
  }
179
182
  }
180
183
  }, [teams, store, dropdownTeam]);
184
+ const _sendAuthToken = (token) => {
185
+ if (iframeRef.current && iframeRef.current.contentWindow) {
186
+ const targetOrigin = store.clientHost;
187
+ iframeRef.current.contentWindow.postMessage(
188
+ {
189
+ type: "AUTH_TOKEN",
190
+ token
191
+ },
192
+ targetOrigin
193
+ );
194
+ }
195
+ };
181
196
  const _init = () => {
182
197
  login().then(async (data) => {
183
198
  setUser(data);
@@ -193,7 +208,9 @@ function Dashboard() {
193
208
  };
194
209
  const _onSelectProject = async (projectValue) => {
195
210
  if (!projectValue) return;
196
- const project = projects.filter((p) => `${p.name}-${p.id}` === projectValue)[0];
211
+ const project = projects.filter(
212
+ (p) => `${p.name}-${p.id}` === projectValue
213
+ )[0];
197
214
  setSelectedProject(project);
198
215
  setDropdownProject(`${project.name}-${project.id}`);
199
216
  setSettings({ defaultProject: project.id }).then(() => {
@@ -202,7 +219,9 @@ function Dashboard() {
202
219
  };
203
220
  const _onSelectTeam = (teamValue) => {
204
221
  if (!teamValue) return;
205
- const selectedTeam = teams.filter((t) => `${t.name}-${t.id}` === teamValue)[0];
222
+ const selectedTeam = teams.filter(
223
+ (t) => `${t.name}-${t.id}` === teamValue
224
+ )[0];
206
225
  setTeam(selectedTeam);
207
226
  setDropdownTeam(`${selectedTeam.name}-${selectedTeam.id}`);
208
227
  setDropdownProject("");
@@ -217,7 +236,16 @@ function Dashboard() {
217
236
  {
218
237
  title: "Dashboard",
219
238
  subtitle: "Visualize your Strapi data",
220
- primaryAction: /* @__PURE__ */ jsx(LinkButton, { tag: Link, startIcon: /* @__PURE__ */ jsx(ChartCircle, {}), to: `/plugins/${PLUGIN_ID}/create`, disabled: !user.id, children: "Create new visualizations" })
239
+ primaryAction: /* @__PURE__ */ jsx(
240
+ LinkButton,
241
+ {
242
+ tag: Link,
243
+ startIcon: /* @__PURE__ */ jsx(ChartCircle, {}),
244
+ to: `/plugins/${PLUGIN_ID}/create`,
245
+ disabled: !user.id,
246
+ children: "Create new visualizations"
247
+ }
248
+ )
221
249
  }
222
250
  ),
223
251
  /* @__PURE__ */ jsxs(Layouts.Content, { children: [
@@ -257,7 +285,15 @@ function Dashboard() {
257
285
  {
258
286
  icon: /* @__PURE__ */ jsx(Illo, {}),
259
287
  content: "It looks like you don't have a dashboard yet",
260
- action: /* @__PURE__ */ jsx(LinkButton, { variant: "secondary", startIcon: /* @__PURE__ */ jsx(Plus, {}), to: `/plugins/${PLUGIN_ID}/create`, children: "Create your first dashboard" })
288
+ action: /* @__PURE__ */ jsx(
289
+ LinkButton,
290
+ {
291
+ variant: "secondary",
292
+ startIcon: /* @__PURE__ */ jsx(Plus, {}),
293
+ to: `/plugins/${PLUGIN_ID}/create`,
294
+ children: "Create your first dashboard"
295
+ }
296
+ )
261
297
  }
262
298
  ) }),
263
299
  !pageLoading && authError && /* @__PURE__ */ jsx(Box, { padding: 4, shadow: "filterShadow", background: "neutral0", children: /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(
@@ -278,7 +314,14 @@ function Dashboard() {
278
314
  value: dropdownTeam,
279
315
  onChange: _onSelectTeam,
280
316
  children: teams.map((t) => {
281
- return /* @__PURE__ */ jsx(SingleSelectOption, { value: `${t.name}-${t.id}`, children: t.name }, t.id);
317
+ return /* @__PURE__ */ jsx(
318
+ SingleSelectOption,
319
+ {
320
+ value: `${t.name}-${t.id}`,
321
+ children: t.name
322
+ },
323
+ t.id
324
+ );
282
325
  })
283
326
  }
284
327
  ) }),
@@ -290,13 +333,34 @@ function Dashboard() {
290
333
  value: dropdownProject,
291
334
  onChange: _onSelectProject,
292
335
  children: projects.map((p) => {
293
- return /* @__PURE__ */ jsx(SingleSelectOption, { value: `${p.name}-${p.id}`, children: p.name }, p.id);
336
+ return /* @__PURE__ */ jsx(
337
+ SingleSelectOption,
338
+ {
339
+ value: `${p.name}-${p.id}`,
340
+ children: p.name
341
+ },
342
+ p.id
343
+ );
294
344
  })
295
345
  }
296
346
  ) }),
297
347
  selectedProject && /* @__PURE__ */ jsxs(Fragment, { children: [
298
- /* @__PURE__ */ jsx(Checkbox, { paddingLeft: 4, onCheckedChange: () => setRemoveHeader(!removeHeader), children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Remove header" }) }),
299
- /* @__PURE__ */ jsx(Checkbox, { paddingLeft: 4, onCheckedChange: () => setRemoveStyling(!removeStyling), children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Remove styling" }) })
348
+ /* @__PURE__ */ jsx(
349
+ Checkbox,
350
+ {
351
+ paddingLeft: 4,
352
+ onCheckedChange: () => setRemoveHeader(!removeHeader),
353
+ children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Remove header" })
354
+ }
355
+ ),
356
+ /* @__PURE__ */ jsx(
357
+ Checkbox,
358
+ {
359
+ paddingLeft: 4,
360
+ onCheckedChange: () => setRemoveStyling(!removeStyling),
361
+ children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Remove styling" })
362
+ }
363
+ )
300
364
  ] }),
301
365
  team && /* @__PURE__ */ jsx(
302
366
  LinkButton,
@@ -313,7 +377,13 @@ function Dashboard() {
313
377
  /* @__PURE__ */ jsx(Box, { paddingTop: 4, height: "100vh", children: /* @__PURE__ */ jsx(
314
378
  "iframe",
315
379
  {
380
+ ref: iframeRef,
316
381
  src: `${store.clientHost}/report/${selectedProject.brewName}?removeHeader=${removeHeader}&removeStyling=${removeStyling}`,
382
+ onLoad: () => {
383
+ if (store?.token) {
384
+ _sendAuthToken(store?.token);
385
+ }
386
+ },
317
387
  width: "100%",
318
388
  height: "100%",
319
389
  style: { border: "none", borderRadius: "10px" }
@@ -6,8 +6,8 @@ const reactRouterDom = require("react-router-dom");
6
6
  const admin = require("@strapi/strapi/admin");
7
7
  const designSystem = require("@strapi/design-system");
8
8
  const icons = require("@strapi/icons");
9
- const index = require("./index-99tSyF1-.js");
10
- const store = require("./store-CRky1w-V.js");
9
+ const index = require("./index-DLMKLG2u.js");
10
+ const store = require("./store-CcXWjkY_.js");
11
11
  require("js-cookie");
12
12
  async function login() {
13
13
  const { host, token } = await store.getSettings();
@@ -148,6 +148,7 @@ function Illo() {
148
148
  ] });
149
149
  }
150
150
  function Dashboard() {
151
+ const iframeRef = react.useRef(null);
151
152
  const [store$1, setStore] = react.useState({});
152
153
  const [user, setUser] = react.useState({});
153
154
  const [projects, setProjects] = react.useState([]);
@@ -171,7 +172,9 @@ function Dashboard() {
171
172
  setDropdownTeam(`${selectedTeam.name}-${selectedTeam.id}`);
172
173
  setProjects(selectedTeam.Projects);
173
174
  if (store$1.defaultProject) {
174
- const selectedProject2 = selectedTeam.Projects.find((p) => p.id === store$1.defaultProject);
175
+ const selectedProject2 = selectedTeam.Projects.find(
176
+ (p) => p.id === store$1.defaultProject
177
+ );
175
178
  if (selectedProject2) {
176
179
  setDropdownProject(`${selectedProject2.name}-${selectedProject2.id}`);
177
180
  setSelectedProject(selectedProject2);
@@ -180,6 +183,18 @@ function Dashboard() {
180
183
  }
181
184
  }
182
185
  }, [teams, store$1, dropdownTeam]);
186
+ const _sendAuthToken = (token) => {
187
+ if (iframeRef.current && iframeRef.current.contentWindow) {
188
+ const targetOrigin = store$1.clientHost;
189
+ iframeRef.current.contentWindow.postMessage(
190
+ {
191
+ type: "AUTH_TOKEN",
192
+ token
193
+ },
194
+ targetOrigin
195
+ );
196
+ }
197
+ };
183
198
  const _init = () => {
184
199
  login().then(async (data) => {
185
200
  setUser(data);
@@ -195,7 +210,9 @@ function Dashboard() {
195
210
  };
196
211
  const _onSelectProject = async (projectValue) => {
197
212
  if (!projectValue) return;
198
- const project = projects.filter((p) => `${p.name}-${p.id}` === projectValue)[0];
213
+ const project = projects.filter(
214
+ (p) => `${p.name}-${p.id}` === projectValue
215
+ )[0];
199
216
  setSelectedProject(project);
200
217
  setDropdownProject(`${project.name}-${project.id}`);
201
218
  store.setSettings({ defaultProject: project.id }).then(() => {
@@ -204,7 +221,9 @@ function Dashboard() {
204
221
  };
205
222
  const _onSelectTeam = (teamValue) => {
206
223
  if (!teamValue) return;
207
- const selectedTeam = teams.filter((t) => `${t.name}-${t.id}` === teamValue)[0];
224
+ const selectedTeam = teams.filter(
225
+ (t) => `${t.name}-${t.id}` === teamValue
226
+ )[0];
208
227
  setTeam(selectedTeam);
209
228
  setDropdownTeam(`${selectedTeam.name}-${selectedTeam.id}`);
210
229
  setDropdownProject("");
@@ -219,7 +238,16 @@ function Dashboard() {
219
238
  {
220
239
  title: "Dashboard",
221
240
  subtitle: "Visualize your Strapi data",
222
- primaryAction: /* @__PURE__ */ jsxRuntime.jsx(designSystem.LinkButton, { tag: reactRouterDom.Link, startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ChartCircle, {}), to: `/plugins/${index.PLUGIN_ID}/create`, disabled: !user.id, children: "Create new visualizations" })
241
+ primaryAction: /* @__PURE__ */ jsxRuntime.jsx(
242
+ designSystem.LinkButton,
243
+ {
244
+ tag: reactRouterDom.Link,
245
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ChartCircle, {}),
246
+ to: `/plugins/${index.PLUGIN_ID}/create`,
247
+ disabled: !user.id,
248
+ children: "Create new visualizations"
249
+ }
250
+ )
223
251
  }
224
252
  ),
225
253
  /* @__PURE__ */ jsxRuntime.jsxs(admin.Layouts.Content, { children: [
@@ -259,7 +287,15 @@ function Dashboard() {
259
287
  {
260
288
  icon: /* @__PURE__ */ jsxRuntime.jsx(Illo, {}),
261
289
  content: "It looks like you don't have a dashboard yet",
262
- action: /* @__PURE__ */ jsxRuntime.jsx(designSystem.LinkButton, { variant: "secondary", startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}), to: `/plugins/${index.PLUGIN_ID}/create`, children: "Create your first dashboard" })
290
+ action: /* @__PURE__ */ jsxRuntime.jsx(
291
+ designSystem.LinkButton,
292
+ {
293
+ variant: "secondary",
294
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
295
+ to: `/plugins/${index.PLUGIN_ID}/create`,
296
+ children: "Create your first dashboard"
297
+ }
298
+ )
263
299
  }
264
300
  ) }),
265
301
  !pageLoading && authError && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 4, shadow: "filterShadow", background: "neutral0", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -280,7 +316,14 @@ function Dashboard() {
280
316
  value: dropdownTeam,
281
317
  onChange: _onSelectTeam,
282
318
  children: teams.map((t) => {
283
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: `${t.name}-${t.id}`, children: t.name }, t.id);
319
+ return /* @__PURE__ */ jsxRuntime.jsx(
320
+ designSystem.SingleSelectOption,
321
+ {
322
+ value: `${t.name}-${t.id}`,
323
+ children: t.name
324
+ },
325
+ t.id
326
+ );
284
327
  })
285
328
  }
286
329
  ) }),
@@ -292,13 +335,34 @@ function Dashboard() {
292
335
  value: dropdownProject,
293
336
  onChange: _onSelectProject,
294
337
  children: projects.map((p) => {
295
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: `${p.name}-${p.id}`, children: p.name }, p.id);
338
+ return /* @__PURE__ */ jsxRuntime.jsx(
339
+ designSystem.SingleSelectOption,
340
+ {
341
+ value: `${p.name}-${p.id}`,
342
+ children: p.name
343
+ },
344
+ p.id
345
+ );
296
346
  })
297
347
  }
298
348
  ) }),
299
349
  selectedProject && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
300
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Checkbox, { paddingLeft: 4, onCheckedChange: () => setRemoveHeader(!removeHeader), children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", children: "Remove header" }) }),
301
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Checkbox, { paddingLeft: 4, onCheckedChange: () => setRemoveStyling(!removeStyling), children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", children: "Remove styling" }) })
350
+ /* @__PURE__ */ jsxRuntime.jsx(
351
+ designSystem.Checkbox,
352
+ {
353
+ paddingLeft: 4,
354
+ onCheckedChange: () => setRemoveHeader(!removeHeader),
355
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", children: "Remove header" })
356
+ }
357
+ ),
358
+ /* @__PURE__ */ jsxRuntime.jsx(
359
+ designSystem.Checkbox,
360
+ {
361
+ paddingLeft: 4,
362
+ onCheckedChange: () => setRemoveStyling(!removeStyling),
363
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", children: "Remove styling" })
364
+ }
365
+ )
302
366
  ] }),
303
367
  team && /* @__PURE__ */ jsxRuntime.jsx(
304
368
  designSystem.LinkButton,
@@ -315,7 +379,13 @@ function Dashboard() {
315
379
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, height: "100vh", children: /* @__PURE__ */ jsxRuntime.jsx(
316
380
  "iframe",
317
381
  {
382
+ ref: iframeRef,
318
383
  src: `${store$1.clientHost}/report/${selectedProject.brewName}?removeHeader=${removeHeader}&removeStyling=${removeStyling}`,
384
+ onLoad: () => {
385
+ if (store$1?.token) {
386
+ _sendAuthToken(store$1?.token);
387
+ }
388
+ },
319
389
  width: "100%",
320
390
  height: "100%",
321
391
  style: { border: "none", borderRadius: "10px" }
@@ -4,8 +4,8 @@ import { LinkButton, Box, Typography, Tabs, Field, Button, Link, Flex, Alert } f
4
4
  import { useNotification, Layouts } from "@strapi/strapi/admin";
5
5
  import { ExternalLink, Magic, Check, Cross, ChevronRight } from "@strapi/icons";
6
6
  import { Link as Link$1 } from "react-router-dom";
7
- import { P as PLUGIN_ID } from "./index-BAu-oge7.mjs";
8
- import { g as getSettings, s as setSettings } from "./store-CG_sYhrl.mjs";
7
+ import { P as PLUGIN_ID } from "./index-BDl1QGlA.mjs";
8
+ import { g as getSettings, s as setSettings } from "./store-CoX04Dgx.mjs";
9
9
  const defaultHost = "https://api.chartbrew.com";
10
10
  const defaultClientHost = "https://app.chartbrew.com";
11
11
  const strapiHostEnv = process.env.STRAPI_ADMIN_BACKEND_URL;
@@ -6,8 +6,8 @@ const designSystem = require("@strapi/design-system");
6
6
  const admin = require("@strapi/strapi/admin");
7
7
  const icons = require("@strapi/icons");
8
8
  const reactRouterDom = require("react-router-dom");
9
- const index = require("./index-99tSyF1-.js");
10
- const store = require("./store-CRky1w-V.js");
9
+ const index = require("./index-DLMKLG2u.js");
10
+ const store = require("./store-CcXWjkY_.js");
11
11
  const defaultHost = "https://api.chartbrew.com";
12
12
  const defaultClientHost = "https://app.chartbrew.com";
13
13
  const strapiHostEnv = process.env.STRAPI_ADMIN_BACKEND_URL;
@@ -37,7 +37,7 @@ const index = {
37
37
  defaultMessage: "Chartbrew"
38
38
  },
39
39
  Component: async () => {
40
- const { App } = await import("./App-CZYH4Lv3.mjs");
40
+ const { App } = await import("./App-CZqPHB0f.mjs");
41
41
  return App;
42
42
  }
43
43
  });
@@ -58,7 +58,7 @@ const index = {
58
58
  id: "settings",
59
59
  to: `/settings/${PLUGIN_ID}`,
60
60
  Component: async () => {
61
- const { Setup } = await import("./Setup-BDc8qCYW.mjs");
61
+ const { Setup } = await import("./Setup-C8OVk4-q.mjs");
62
62
  return Setup;
63
63
  }
64
64
  }
@@ -38,7 +38,7 @@ const index = {
38
38
  defaultMessage: "Chartbrew"
39
39
  },
40
40
  Component: async () => {
41
- const { App } = await Promise.resolve().then(() => require("./App-m-xvbLqv.js"));
41
+ const { App } = await Promise.resolve().then(() => require("./App-DSC2kgiX.js"));
42
42
  return App;
43
43
  }
44
44
  });
@@ -59,7 +59,7 @@ const index = {
59
59
  id: "settings",
60
60
  to: `/settings/${PLUGIN_ID}`,
61
61
  Component: async () => {
62
- const { Setup } = await Promise.resolve().then(() => require("./Setup-B-KYP8ql.js"));
62
+ const { Setup } = await Promise.resolve().then(() => require("./Setup-D8qqF_69.js"));
63
63
  return Setup;
64
64
  }
65
65
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  const Cookies = require("js-cookie");
3
- const index = require("./index-99tSyF1-.js");
3
+ const index = require("./index-DLMKLG2u.js");
4
4
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
5
5
  const Cookies__default = /* @__PURE__ */ _interopDefault(Cookies);
6
6
  function bind(fn, thisArg) {
@@ -1,5 +1,5 @@
1
1
  import Cookies from "js-cookie";
2
- import { P as PLUGIN_ID } from "./index-BAu-oge7.mjs";
2
+ import { P as PLUGIN_ID } from "./index-BDl1QGlA.mjs";
3
3
  function bind(fn, thisArg) {
4
4
  return function wrap() {
5
5
  return fn.apply(thisArg, arguments);
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
- const index = require("../_chunks/index-99tSyF1-.js");
2
+ const index = require("../_chunks/index-DLMKLG2u.js");
3
3
  module.exports = index.index;
@@ -1,4 +1,4 @@
1
- import { i } from "../_chunks/index-BAu-oge7.mjs";
1
+ import { i } from "../_chunks/index-BDl1QGlA.mjs";
2
2
  export {
3
3
  i as default
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tienjs-chartbrew-plugin-strapi",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Chartbrew brings data visualization to your Strapi dashboard",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/chartbrew/strapi-plugin-chartbrew#readme",