tienjs-chartbrew-plugin-strapi 0.1.3 → 0.1.4

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.
@@ -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-BU939xMZ.js");
10
+ const store = require("./store-D2CP2hEa.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,15 +172,30 @@ 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);
181
+ _sendAuthToken(store$1.token);
178
182
  }
179
183
  }
180
184
  }
181
185
  }
182
186
  }, [teams, store$1, dropdownTeam]);
187
+ const _sendAuthToken = (token) => {
188
+ if (iframeRef.current && iframeRef.current.contentWindow) {
189
+ const targetOrigin = store$1.clientHost;
190
+ iframeRef.current.contentWindow.postMessage(
191
+ {
192
+ type: "AUTH_TOKEN",
193
+ token
194
+ },
195
+ targetOrigin
196
+ );
197
+ }
198
+ };
183
199
  const _init = () => {
184
200
  login().then(async (data) => {
185
201
  setUser(data);
@@ -195,7 +211,9 @@ function Dashboard() {
195
211
  };
196
212
  const _onSelectProject = async (projectValue) => {
197
213
  if (!projectValue) return;
198
- const project = projects.filter((p) => `${p.name}-${p.id}` === projectValue)[0];
214
+ const project = projects.filter(
215
+ (p) => `${p.name}-${p.id}` === projectValue
216
+ )[0];
199
217
  setSelectedProject(project);
200
218
  setDropdownProject(`${project.name}-${project.id}`);
201
219
  store.setSettings({ defaultProject: project.id }).then(() => {
@@ -204,7 +222,9 @@ function Dashboard() {
204
222
  };
205
223
  const _onSelectTeam = (teamValue) => {
206
224
  if (!teamValue) return;
207
- const selectedTeam = teams.filter((t) => `${t.name}-${t.id}` === teamValue)[0];
225
+ const selectedTeam = teams.filter(
226
+ (t) => `${t.name}-${t.id}` === teamValue
227
+ )[0];
208
228
  setTeam(selectedTeam);
209
229
  setDropdownTeam(`${selectedTeam.name}-${selectedTeam.id}`);
210
230
  setDropdownProject("");
@@ -219,7 +239,16 @@ function Dashboard() {
219
239
  {
220
240
  title: "Dashboard",
221
241
  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" })
242
+ primaryAction: /* @__PURE__ */ jsxRuntime.jsx(
243
+ designSystem.LinkButton,
244
+ {
245
+ tag: reactRouterDom.Link,
246
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ChartCircle, {}),
247
+ to: `/plugins/${index.PLUGIN_ID}/create`,
248
+ disabled: !user.id,
249
+ children: "Create new visualizations"
250
+ }
251
+ )
223
252
  }
224
253
  ),
225
254
  /* @__PURE__ */ jsxRuntime.jsxs(admin.Layouts.Content, { children: [
@@ -259,7 +288,15 @@ function Dashboard() {
259
288
  {
260
289
  icon: /* @__PURE__ */ jsxRuntime.jsx(Illo, {}),
261
290
  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" })
291
+ action: /* @__PURE__ */ jsxRuntime.jsx(
292
+ designSystem.LinkButton,
293
+ {
294
+ variant: "secondary",
295
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
296
+ to: `/plugins/${index.PLUGIN_ID}/create`,
297
+ children: "Create your first dashboard"
298
+ }
299
+ )
263
300
  }
264
301
  ) }),
265
302
  !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 +317,14 @@ function Dashboard() {
280
317
  value: dropdownTeam,
281
318
  onChange: _onSelectTeam,
282
319
  children: teams.map((t) => {
283
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: `${t.name}-${t.id}`, children: t.name }, t.id);
320
+ return /* @__PURE__ */ jsxRuntime.jsx(
321
+ designSystem.SingleSelectOption,
322
+ {
323
+ value: `${t.name}-${t.id}`,
324
+ children: t.name
325
+ },
326
+ t.id
327
+ );
284
328
  })
285
329
  }
286
330
  ) }),
@@ -292,13 +336,34 @@ function Dashboard() {
292
336
  value: dropdownProject,
293
337
  onChange: _onSelectProject,
294
338
  children: projects.map((p) => {
295
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: `${p.name}-${p.id}`, children: p.name }, p.id);
339
+ return /* @__PURE__ */ jsxRuntime.jsx(
340
+ designSystem.SingleSelectOption,
341
+ {
342
+ value: `${p.name}-${p.id}`,
343
+ children: p.name
344
+ },
345
+ p.id
346
+ );
296
347
  })
297
348
  }
298
349
  ) }),
299
350
  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" }) })
351
+ /* @__PURE__ */ jsxRuntime.jsx(
352
+ designSystem.Checkbox,
353
+ {
354
+ paddingLeft: 4,
355
+ onCheckedChange: () => setRemoveHeader(!removeHeader),
356
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", children: "Remove header" })
357
+ }
358
+ ),
359
+ /* @__PURE__ */ jsxRuntime.jsx(
360
+ designSystem.Checkbox,
361
+ {
362
+ paddingLeft: 4,
363
+ onCheckedChange: () => setRemoveStyling(!removeStyling),
364
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", children: "Remove styling" })
365
+ }
366
+ )
302
367
  ] }),
303
368
  team && /* @__PURE__ */ jsxRuntime.jsx(
304
369
  designSystem.LinkButton,
@@ -315,6 +380,7 @@ function Dashboard() {
315
380
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, height: "100vh", children: /* @__PURE__ */ jsxRuntime.jsx(
316
381
  "iframe",
317
382
  {
383
+ ref: iframeRef,
318
384
  src: `${store$1.clientHost}/report/${selectedProject.brewName}?removeHeader=${removeHeader}&removeStyling=${removeStyling}`,
319
385
  width: "100%",
320
386
  height: "100%",
@@ -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-Ob7hTXVE.mjs";
8
+ import { g as getSettings, s as setSettings, i as instance } from "./store-BD7p4pKs.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,15 +170,30 @@ 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);
179
+ _sendAuthToken(store.token);
176
180
  }
177
181
  }
178
182
  }
179
183
  }
180
184
  }, [teams, store, dropdownTeam]);
185
+ const _sendAuthToken = (token) => {
186
+ if (iframeRef.current && iframeRef.current.contentWindow) {
187
+ const targetOrigin = store.clientHost;
188
+ iframeRef.current.contentWindow.postMessage(
189
+ {
190
+ type: "AUTH_TOKEN",
191
+ token
192
+ },
193
+ targetOrigin
194
+ );
195
+ }
196
+ };
181
197
  const _init = () => {
182
198
  login().then(async (data) => {
183
199
  setUser(data);
@@ -193,7 +209,9 @@ function Dashboard() {
193
209
  };
194
210
  const _onSelectProject = async (projectValue) => {
195
211
  if (!projectValue) return;
196
- const project = projects.filter((p) => `${p.name}-${p.id}` === projectValue)[0];
212
+ const project = projects.filter(
213
+ (p) => `${p.name}-${p.id}` === projectValue
214
+ )[0];
197
215
  setSelectedProject(project);
198
216
  setDropdownProject(`${project.name}-${project.id}`);
199
217
  setSettings({ defaultProject: project.id }).then(() => {
@@ -202,7 +220,9 @@ function Dashboard() {
202
220
  };
203
221
  const _onSelectTeam = (teamValue) => {
204
222
  if (!teamValue) return;
205
- const selectedTeam = teams.filter((t) => `${t.name}-${t.id}` === teamValue)[0];
223
+ const selectedTeam = teams.filter(
224
+ (t) => `${t.name}-${t.id}` === teamValue
225
+ )[0];
206
226
  setTeam(selectedTeam);
207
227
  setDropdownTeam(`${selectedTeam.name}-${selectedTeam.id}`);
208
228
  setDropdownProject("");
@@ -217,7 +237,16 @@ function Dashboard() {
217
237
  {
218
238
  title: "Dashboard",
219
239
  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" })
240
+ primaryAction: /* @__PURE__ */ jsx(
241
+ LinkButton,
242
+ {
243
+ tag: Link,
244
+ startIcon: /* @__PURE__ */ jsx(ChartCircle, {}),
245
+ to: `/plugins/${PLUGIN_ID}/create`,
246
+ disabled: !user.id,
247
+ children: "Create new visualizations"
248
+ }
249
+ )
221
250
  }
222
251
  ),
223
252
  /* @__PURE__ */ jsxs(Layouts.Content, { children: [
@@ -257,7 +286,15 @@ function Dashboard() {
257
286
  {
258
287
  icon: /* @__PURE__ */ jsx(Illo, {}),
259
288
  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" })
289
+ action: /* @__PURE__ */ jsx(
290
+ LinkButton,
291
+ {
292
+ variant: "secondary",
293
+ startIcon: /* @__PURE__ */ jsx(Plus, {}),
294
+ to: `/plugins/${PLUGIN_ID}/create`,
295
+ children: "Create your first dashboard"
296
+ }
297
+ )
261
298
  }
262
299
  ) }),
263
300
  !pageLoading && authError && /* @__PURE__ */ jsx(Box, { padding: 4, shadow: "filterShadow", background: "neutral0", children: /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(
@@ -278,7 +315,14 @@ function Dashboard() {
278
315
  value: dropdownTeam,
279
316
  onChange: _onSelectTeam,
280
317
  children: teams.map((t) => {
281
- return /* @__PURE__ */ jsx(SingleSelectOption, { value: `${t.name}-${t.id}`, children: t.name }, t.id);
318
+ return /* @__PURE__ */ jsx(
319
+ SingleSelectOption,
320
+ {
321
+ value: `${t.name}-${t.id}`,
322
+ children: t.name
323
+ },
324
+ t.id
325
+ );
282
326
  })
283
327
  }
284
328
  ) }),
@@ -290,13 +334,34 @@ function Dashboard() {
290
334
  value: dropdownProject,
291
335
  onChange: _onSelectProject,
292
336
  children: projects.map((p) => {
293
- return /* @__PURE__ */ jsx(SingleSelectOption, { value: `${p.name}-${p.id}`, children: p.name }, p.id);
337
+ return /* @__PURE__ */ jsx(
338
+ SingleSelectOption,
339
+ {
340
+ value: `${p.name}-${p.id}`,
341
+ children: p.name
342
+ },
343
+ p.id
344
+ );
294
345
  })
295
346
  }
296
347
  ) }),
297
348
  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" }) })
349
+ /* @__PURE__ */ jsx(
350
+ Checkbox,
351
+ {
352
+ paddingLeft: 4,
353
+ onCheckedChange: () => setRemoveHeader(!removeHeader),
354
+ children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Remove header" })
355
+ }
356
+ ),
357
+ /* @__PURE__ */ jsx(
358
+ Checkbox,
359
+ {
360
+ paddingLeft: 4,
361
+ onCheckedChange: () => setRemoveStyling(!removeStyling),
362
+ children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Remove styling" })
363
+ }
364
+ )
300
365
  ] }),
301
366
  team && /* @__PURE__ */ jsx(
302
367
  LinkButton,
@@ -313,6 +378,7 @@ function Dashboard() {
313
378
  /* @__PURE__ */ jsx(Box, { paddingTop: 4, height: "100vh", children: /* @__PURE__ */ jsx(
314
379
  "iframe",
315
380
  {
381
+ ref: iframeRef,
316
382
  src: `${store.clientHost}/report/${selectedProject.brewName}?removeHeader=${removeHeader}&removeStyling=${removeStyling}`,
317
383
  width: "100%",
318
384
  height: "100%",
@@ -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-Ob7hTXVE.mjs";
8
+ import { g as getSettings, s as setSettings } from "./store-BD7p4pKs.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-BU939xMZ.js");
10
+ const store = require("./store-D2CP2hEa.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;
@@ -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-DYsrUWaq.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-BCxwweFO.js"));
63
63
  return Setup;
64
64
  }
65
65
  }
@@ -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-MJAOBwBX.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-BBCrCEZR.mjs");
62
62
  return Setup;
63
63
  }
64
64
  }
@@ -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-Ob7hTXVE.mjs";
3
3
  function bind(fn, thisArg) {
4
4
  return function wrap() {
5
5
  return fn.apply(thisArg, arguments);
@@ -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-BU939xMZ.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,3 +1,3 @@
1
1
  "use strict";
2
- const index = require("../_chunks/index-99tSyF1-.js");
2
+ const index = require("../_chunks/index-BU939xMZ.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-Ob7hTXVE.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.4",
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",