tienjs-chartbrew-plugin-strapi 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +187 -0
- package/dist/_chunks/App-Be1FtvNK.mjs +618 -0
- package/dist/_chunks/App-ngsyON1R.js +618 -0
- package/dist/_chunks/Setup-CL3F4zOi.js +304 -0
- package/dist/_chunks/Setup-C_xPro4U.mjs +304 -0
- package/dist/_chunks/en-B4KWt_jN.js +4 -0
- package/dist/_chunks/en-Byx4XI2L.mjs +4 -0
- package/dist/_chunks/fr-C8Qw4iPZ.js +4 -0
- package/dist/_chunks/fr-hkSxFuzl.mjs +4 -0
- package/dist/_chunks/index-Bk9ujIXz.js +96 -0
- package/dist/_chunks/index-CXvgiYYO.mjs +97 -0
- package/dist/_chunks/store-B-zkLoDr.js +2505 -0
- package/dist/_chunks/store-CES_iNgI.mjs +2506 -0
- package/dist/admin/index.js +3 -0
- package/dist/admin/index.mjs +4 -0
- package/dist/server/index.js +252 -0
- package/dist/server/index.mjs +251 -0
- package/package.json +75 -0
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
import { Link, Routes, Route } from "react-router-dom";
|
|
4
|
+
import { Layouts, Page } from "@strapi/strapi/admin";
|
|
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
|
+
import { ChartCircle, Plus, ExternalLink, ArrowLeft } from "@strapi/icons";
|
|
7
|
+
import { P as PLUGIN_ID } from "./index-CXvgiYYO.mjs";
|
|
8
|
+
import { g as getSettings, s as setSettings, i as instance } from "./store-CES_iNgI.mjs";
|
|
9
|
+
async function login() {
|
|
10
|
+
const { host, token } = await getSettings();
|
|
11
|
+
return fetch(`${host}/user/relog`, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
headers: new Headers({
|
|
14
|
+
accept: "application/json",
|
|
15
|
+
authorization: `Bearer ${token}`
|
|
16
|
+
})
|
|
17
|
+
}).then((response) => {
|
|
18
|
+
if (!response.ok) throw new Error("Cannot authenticate");
|
|
19
|
+
return response.json();
|
|
20
|
+
}).then((user) => {
|
|
21
|
+
return user;
|
|
22
|
+
}).catch((err) => {
|
|
23
|
+
return Promise.reject(err);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async function getUserTeam() {
|
|
27
|
+
const { host, token } = await getSettings();
|
|
28
|
+
return fetch(`${host}/team`, {
|
|
29
|
+
method: "GET",
|
|
30
|
+
headers: new Headers({
|
|
31
|
+
accept: "application/json",
|
|
32
|
+
authorization: `Bearer ${token}`
|
|
33
|
+
})
|
|
34
|
+
}).then((response) => {
|
|
35
|
+
if (!response.ok) throw new Error("Cannot fetch the template configuration");
|
|
36
|
+
return response.json();
|
|
37
|
+
}).then((teams) => {
|
|
38
|
+
return teams;
|
|
39
|
+
}).catch((err) => {
|
|
40
|
+
return Promise.reject(err);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async function getStrapiTemplate(teamId) {
|
|
44
|
+
const { host, token } = await getSettings();
|
|
45
|
+
return fetch(`${host}/team/${teamId}/template/community/strapi`, {
|
|
46
|
+
method: "GET",
|
|
47
|
+
headers: new Headers({
|
|
48
|
+
accept: "application/json",
|
|
49
|
+
authorization: `Bearer ${token}`
|
|
50
|
+
})
|
|
51
|
+
}).then((response) => {
|
|
52
|
+
if (!response.ok) throw new Error("Cannot fetch the template configuration");
|
|
53
|
+
return response.json();
|
|
54
|
+
}).then((template) => {
|
|
55
|
+
return template;
|
|
56
|
+
}).catch((err) => {
|
|
57
|
+
return Promise.reject(err);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async function getTeamConnections(teamId) {
|
|
61
|
+
const { host, token } = await getSettings();
|
|
62
|
+
return fetch(`${host}/team/${teamId}/connections`, {
|
|
63
|
+
method: "GET",
|
|
64
|
+
headers: new Headers({
|
|
65
|
+
accept: "application/json",
|
|
66
|
+
authorization: `Bearer ${token}`
|
|
67
|
+
})
|
|
68
|
+
}).then((response) => {
|
|
69
|
+
if (!response.ok) throw new Error("Cannot fetch the template configuration");
|
|
70
|
+
return response.json();
|
|
71
|
+
}).then((connections) => {
|
|
72
|
+
return connections;
|
|
73
|
+
}).catch((err) => {
|
|
74
|
+
return Promise.reject(err);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function Illo() {
|
|
78
|
+
return /* @__PURE__ */ jsxs("svg", { width: "159", height: "88", viewBox: "0 0 159 88", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
|
|
79
|
+
/* @__PURE__ */ jsx(
|
|
80
|
+
"path",
|
|
81
|
+
{
|
|
82
|
+
fillRule: "evenodd",
|
|
83
|
+
clipRule: "evenodd",
|
|
84
|
+
d: "M134.933 17.417C137.768 17.417 140.067 19.7153 140.067 22.5503C140.067 25.3854 137.768 27.6837 134.933 27.6837H105.6C108.435 27.6837 110.733 29.9819 110.733 32.817C110.733 35.6521 108.435 37.9503 105.6 37.9503H121.733C124.568 37.9503 126.867 40.2486 126.867 43.0837C126.867 45.9187 124.568 48.217 121.733 48.217H114.272C110.698 48.217 107.8 50.5153 107.8 53.3503C107.8 55.2404 109.267 56.9515 112.2 58.4837C115.035 58.4837 117.333 60.7819 117.333 63.617C117.333 66.4521 115.035 68.7503 112.2 68.7503H51.3333C48.4982 68.7503 46.2 66.4521 46.2 63.617C46.2 60.7819 48.4982 58.4837 51.3333 58.4837H22.7333C19.8982 58.4837 17.6 56.1854 17.6 53.3503C17.6 50.5153 19.8982 48.217 22.7333 48.217H52.0666C54.9017 48.217 57.2 45.9187 57.2 43.0837C57.2 40.2486 54.9017 37.9503 52.0666 37.9503H33.7333C30.8982 37.9503 28.6 35.6521 28.6 32.817C28.6 29.9819 30.8982 27.6837 33.7333 27.6837H63.0666C60.2316 27.6837 57.9333 25.3854 57.9333 22.5503C57.9333 19.7153 60.2316 17.417 63.0666 17.417H134.933ZM134.933 37.9503C137.768 37.9503 140.067 40.2486 140.067 43.0837C140.067 45.9187 137.768 48.217 134.933 48.217C132.098 48.217 129.8 45.9187 129.8 43.0837C129.8 40.2486 132.098 37.9503 134.933 37.9503Z",
|
|
85
|
+
fill: "#DBDBFA"
|
|
86
|
+
}
|
|
87
|
+
),
|
|
88
|
+
/* @__PURE__ */ jsx(
|
|
89
|
+
"path",
|
|
90
|
+
{
|
|
91
|
+
fillRule: "evenodd",
|
|
92
|
+
clipRule: "evenodd",
|
|
93
|
+
d: "M95.826 16.6834L102.647 66.4348L103.26 71.4261C103.458 73.034 102.314 74.4976 100.706 74.695L57.7621 79.9679C56.1542 80.1653 54.6906 79.0219 54.4932 77.4139L47.8816 23.5671C47.7829 22.7631 48.3546 22.0313 49.1586 21.9326C49.1637 21.932 49.1688 21.9313 49.1739 21.9307L52.7367 21.5311L95.826 16.6834ZM55.6176 21.208L58.9814 20.8306Z",
|
|
94
|
+
fill: "white"
|
|
95
|
+
}
|
|
96
|
+
),
|
|
97
|
+
/* @__PURE__ */ jsx(
|
|
98
|
+
"path",
|
|
99
|
+
{
|
|
100
|
+
d: "M55.6176 21.208L58.9814 20.8306M95.826 16.6834L102.647 66.4348L103.26 71.4261C103.458 73.034 102.314 74.4976 100.706 74.695L57.7621 79.9679C56.1542 80.1653 54.6906 79.0219 54.4932 77.4139L47.8816 23.5671C47.7829 22.7631 48.3546 22.0313 49.1586 21.9326C49.1637 21.932 49.1688 21.9313 49.1739 21.9307L52.7367 21.5311L95.826 16.6834Z",
|
|
101
|
+
stroke: "#7E7BF6",
|
|
102
|
+
strokeWidth: "2.5"
|
|
103
|
+
}
|
|
104
|
+
),
|
|
105
|
+
/* @__PURE__ */ jsx(
|
|
106
|
+
"path",
|
|
107
|
+
{
|
|
108
|
+
fillRule: "evenodd",
|
|
109
|
+
clipRule: "evenodd",
|
|
110
|
+
d: "M93.9695 19.8144L100.144 64.9025L100.699 69.4258C100.878 70.8831 99.8559 72.2077 98.416 72.3845L59.9585 77.1065C58.5185 77.2833 57.2062 76.2453 57.0272 74.7881L51.0506 26.112C50.9519 25.308 51.5236 24.5762 52.3276 24.4775L57.0851 23.8934",
|
|
111
|
+
fill: "#F0F0FF"
|
|
112
|
+
}
|
|
113
|
+
),
|
|
114
|
+
/* @__PURE__ */ jsx(
|
|
115
|
+
"path",
|
|
116
|
+
{
|
|
117
|
+
fillRule: "evenodd",
|
|
118
|
+
clipRule: "evenodd",
|
|
119
|
+
d: "M97.701 7.33301H64.2927C63.7358 7.33301 63.2316 7.55873 62.8667 7.92368C62.5017 8.28862 62.276 8.79279 62.276 9.34967V65.083C62.276 65.6399 62.5017 66.1441 62.8667 66.509C63.2316 66.874 63.7358 67.0997 64.2927 67.0997H107.559C108.116 67.0997 108.62 66.874 108.985 66.509C109.35 66.1441 109.576 65.6399 109.576 65.083V19.202C109.576 18.6669 109.363 18.1537 108.985 17.7755L99.1265 7.92324C98.7484 7.54531 98.2356 7.33301 97.701 7.33301Z",
|
|
120
|
+
fill: "white",
|
|
121
|
+
stroke: "#7F7CFA",
|
|
122
|
+
strokeWidth: "2.5"
|
|
123
|
+
}
|
|
124
|
+
),
|
|
125
|
+
/* @__PURE__ */ jsx(
|
|
126
|
+
"path",
|
|
127
|
+
{
|
|
128
|
+
d: "M98.026 8.17871V16.6833C98.026 17.8983 99.011 18.8833 100.226 18.8833H106.044",
|
|
129
|
+
stroke: "#807EFA",
|
|
130
|
+
strokeWidth: "2.5",
|
|
131
|
+
strokeLinecap: "round",
|
|
132
|
+
strokeLinejoin: "round"
|
|
133
|
+
}
|
|
134
|
+
),
|
|
135
|
+
/* @__PURE__ */ jsx(
|
|
136
|
+
"path",
|
|
137
|
+
{
|
|
138
|
+
d: "M70.1594 56.2838H89.2261M70.1594 18.8838H89.2261H70.1594ZM70.1594 27.6838H101.693H70.1594ZM70.1594 37.2171H101.693H70.1594ZM70.1594 46.7505H101.693H70.1594Z",
|
|
139
|
+
stroke: "#817FFA",
|
|
140
|
+
strokeWidth: "2.5",
|
|
141
|
+
strokeLinecap: "round",
|
|
142
|
+
strokeLinejoin: "round"
|
|
143
|
+
}
|
|
144
|
+
)
|
|
145
|
+
] });
|
|
146
|
+
}
|
|
147
|
+
function Dashboard() {
|
|
148
|
+
const [store, setStore] = useState({});
|
|
149
|
+
const [user, setUser] = useState({});
|
|
150
|
+
const [projects, setProjects] = useState([]);
|
|
151
|
+
const [pageLoading, setPageLoading] = useState(true);
|
|
152
|
+
const [dropdownProject, setDropdownProject] = useState("");
|
|
153
|
+
const [authError, setAuthError] = useState(false);
|
|
154
|
+
const [team, setTeam] = useState({});
|
|
155
|
+
const [teams, setTeams] = useState([]);
|
|
156
|
+
const [dropdownTeam, setDropdownTeam] = useState("");
|
|
157
|
+
const [selectedProject, setSelectedProject] = useState({});
|
|
158
|
+
const [removeHeader, setRemoveHeader] = useState(false);
|
|
159
|
+
const [removeStyling, setRemoveStyling] = useState(false);
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
getSettings().then((data) => setStore(data));
|
|
162
|
+
_init();
|
|
163
|
+
}, []);
|
|
164
|
+
useEffect(() => {
|
|
165
|
+
if (store.defaultTeam && teams.length > 0 && !dropdownTeam) {
|
|
166
|
+
const selectedTeam = teams.find((t) => t.id === store.defaultTeam);
|
|
167
|
+
if (selectedTeam) {
|
|
168
|
+
setDropdownTeam(`${selectedTeam.name}-${selectedTeam.id}`);
|
|
169
|
+
setProjects(selectedTeam.Projects);
|
|
170
|
+
if (store.defaultProject) {
|
|
171
|
+
const selectedProject2 = selectedTeam.Projects.find((p) => p.id === store.defaultProject);
|
|
172
|
+
if (selectedProject2) {
|
|
173
|
+
setDropdownProject(`${selectedProject2.name}-${selectedProject2.id}`);
|
|
174
|
+
setSelectedProject(selectedProject2);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}, [teams, store, dropdownTeam]);
|
|
180
|
+
const _init = () => {
|
|
181
|
+
login().then(async (data) => {
|
|
182
|
+
setUser(data);
|
|
183
|
+
const teamData = await getUserTeam();
|
|
184
|
+
setTeams(teamData);
|
|
185
|
+
setTeam(teamData[0]);
|
|
186
|
+
setProjects(teamData[0]?.Projects || []);
|
|
187
|
+
setPageLoading(false);
|
|
188
|
+
}).catch(() => {
|
|
189
|
+
setPageLoading(false);
|
|
190
|
+
setAuthError(true);
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
const _onSelectProject = async (projectValue) => {
|
|
194
|
+
if (!projectValue) return;
|
|
195
|
+
const project = projects.filter((p) => `${p.name}-${p.id}` === projectValue)[0];
|
|
196
|
+
setSelectedProject(project);
|
|
197
|
+
setDropdownProject(`${project.name}-${project.id}`);
|
|
198
|
+
setSettings({ defaultProject: project.id }).then(() => {
|
|
199
|
+
return getSettings();
|
|
200
|
+
}).then((data) => setStore(data));
|
|
201
|
+
};
|
|
202
|
+
const _onSelectTeam = (teamValue) => {
|
|
203
|
+
if (!teamValue) return;
|
|
204
|
+
const selectedTeam = teams.filter((t) => `${t.name}-${t.id}` === teamValue)[0];
|
|
205
|
+
setTeam(selectedTeam);
|
|
206
|
+
setDropdownTeam(`${selectedTeam.name}-${selectedTeam.id}`);
|
|
207
|
+
setDropdownProject("");
|
|
208
|
+
setProjects(selectedTeam.Projects);
|
|
209
|
+
setSettings({ defaultTeam: selectedTeam.id }).then(() => {
|
|
210
|
+
return getSettings();
|
|
211
|
+
}).then((data) => setStore(data));
|
|
212
|
+
};
|
|
213
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
214
|
+
/* @__PURE__ */ jsx(
|
|
215
|
+
Layouts.Header,
|
|
216
|
+
{
|
|
217
|
+
title: "Dashboard",
|
|
218
|
+
subtitle: "Visualize your Strapi data",
|
|
219
|
+
primaryAction: /* @__PURE__ */ jsx(LinkButton, { tag: Link, startIcon: /* @__PURE__ */ jsx(ChartCircle, {}), to: `/plugins/${PLUGIN_ID}/create`, disabled: !user.id, children: "Create new visualizations" })
|
|
220
|
+
}
|
|
221
|
+
),
|
|
222
|
+
/* @__PURE__ */ jsxs(Layouts.Content, { children: [
|
|
223
|
+
pageLoading && /* @__PURE__ */ jsx(Loader, { children: "Loading your dashboard..." }),
|
|
224
|
+
!pageLoading && !store.defaultTeam && user.id && teams && /* @__PURE__ */ jsxs(Box, { padding: 4, shadow: "filterShadow", background: "neutral0", children: [
|
|
225
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 1, children: [
|
|
226
|
+
/* @__PURE__ */ jsx(Typography, { variant: "beta", children: "Let's set up your first dashboard " }),
|
|
227
|
+
/* @__PURE__ */ jsx(Typography, { variant: "epsilon", children: "Select a Chartbrew dashboard to load it in Strapi " })
|
|
228
|
+
] }),
|
|
229
|
+
/* @__PURE__ */ jsxs(Flex, { paddingTop: 4, gap: 2, children: [
|
|
230
|
+
/* @__PURE__ */ jsx(
|
|
231
|
+
SingleSelect,
|
|
232
|
+
{
|
|
233
|
+
label: "Select a Chartbrew team",
|
|
234
|
+
value: dropdownTeam,
|
|
235
|
+
onChange: _onSelectTeam,
|
|
236
|
+
children: teams.map((t) => {
|
|
237
|
+
return /* @__PURE__ */ jsx(SingleSelectOption, { value: `${t.name}-${t.id}`, children: t.name }, t.id);
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
),
|
|
241
|
+
/* @__PURE__ */ jsx(
|
|
242
|
+
SingleSelect,
|
|
243
|
+
{
|
|
244
|
+
label: "Select a Chartbrew dashboard",
|
|
245
|
+
value: dropdownProject,
|
|
246
|
+
onChange: _onSelectProject,
|
|
247
|
+
children: projects.map((p) => {
|
|
248
|
+
return /* @__PURE__ */ jsx(SingleSelectOption, { value: `${p.name}-${p.id}`, children: p.name }, p.id);
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
)
|
|
252
|
+
] })
|
|
253
|
+
] }),
|
|
254
|
+
!pageLoading && !authError && user.id && team && projects.length === 0 && /* @__PURE__ */ jsx(Box, { padding: 4, children: /* @__PURE__ */ jsx(
|
|
255
|
+
EmptyStateLayout,
|
|
256
|
+
{
|
|
257
|
+
icon: /* @__PURE__ */ jsx(Illo, {}),
|
|
258
|
+
content: "It looks like you don't have a dashboard yet",
|
|
259
|
+
action: /* @__PURE__ */ jsx(LinkButton, { variant: "secondary", startIcon: /* @__PURE__ */ jsx(Plus, {}), to: `/plugins/${PLUGIN_ID}/create`, children: "Create your first dashboard" })
|
|
260
|
+
}
|
|
261
|
+
) }),
|
|
262
|
+
!pageLoading && authError && /* @__PURE__ */ jsx(Box, { padding: 4, shadow: "filterShadow", background: "neutral0", children: /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(
|
|
263
|
+
Alert,
|
|
264
|
+
{
|
|
265
|
+
closeLabel: "Close message",
|
|
266
|
+
title: "Cannot authenticate to Chartbrew",
|
|
267
|
+
action: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Link$1, { to: `/settings/${PLUGIN_ID}`, children: "Click here to configure your Chartbrew connection" }) }),
|
|
268
|
+
children: "In order to access your Chartbrew dashboards, you must first set up the credentials in the settings menu. Click the link below to get started. "
|
|
269
|
+
}
|
|
270
|
+
) }) }),
|
|
271
|
+
!pageLoading && store.defaultTeam && user.id && projects.length > 0 && /* @__PURE__ */ jsxs(Box, { children: [
|
|
272
|
+
/* @__PURE__ */ jsxs(Flex, { wrap: "wrap", gap: 2, children: [
|
|
273
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
274
|
+
SingleSelect,
|
|
275
|
+
{
|
|
276
|
+
label: "Select a Chartbrew team",
|
|
277
|
+
value: dropdownTeam,
|
|
278
|
+
onChange: _onSelectTeam,
|
|
279
|
+
children: teams.map((t) => {
|
|
280
|
+
return /* @__PURE__ */ jsx(SingleSelectOption, { value: `${t.name}-${t.id}`, children: t.name }, t.id);
|
|
281
|
+
})
|
|
282
|
+
}
|
|
283
|
+
) }),
|
|
284
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
285
|
+
SingleSelect,
|
|
286
|
+
{
|
|
287
|
+
label: "Select a Chartbrew dashboard",
|
|
288
|
+
placeholder: "Select a dashboard",
|
|
289
|
+
value: dropdownProject,
|
|
290
|
+
onChange: _onSelectProject,
|
|
291
|
+
children: projects.map((p) => {
|
|
292
|
+
return /* @__PURE__ */ jsx(SingleSelectOption, { value: `${p.name}-${p.id}`, children: p.name }, p.id);
|
|
293
|
+
})
|
|
294
|
+
}
|
|
295
|
+
) }),
|
|
296
|
+
selectedProject && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
297
|
+
/* @__PURE__ */ jsx(Checkbox, { paddingLeft: 4, onCheckedChange: () => setRemoveHeader(!removeHeader), children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Remove header" }) }),
|
|
298
|
+
/* @__PURE__ */ jsx(Checkbox, { paddingLeft: 4, onCheckedChange: () => setRemoveStyling(!removeStyling), children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Remove styling" }) })
|
|
299
|
+
] }),
|
|
300
|
+
team && /* @__PURE__ */ jsx(
|
|
301
|
+
LinkButton,
|
|
302
|
+
{
|
|
303
|
+
href: `${store.clientHost}/${team.id}/${store.defaultProject}/dashboard`,
|
|
304
|
+
variant: "tertiary",
|
|
305
|
+
target: "_blank",
|
|
306
|
+
rel: "noopener",
|
|
307
|
+
endIcon: /* @__PURE__ */ jsx(ExternalLink, {}),
|
|
308
|
+
children: "Edit dashboard in Chartbrew"
|
|
309
|
+
}
|
|
310
|
+
)
|
|
311
|
+
] }),
|
|
312
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 4, height: "100vh", children: /* @__PURE__ */ jsx(
|
|
313
|
+
"iframe",
|
|
314
|
+
{
|
|
315
|
+
src: `${store.clientHost}/report/${selectedProject.brewName}?removeHeader=${removeHeader}&removeStyling=${removeStyling}`,
|
|
316
|
+
width: "100%",
|
|
317
|
+
height: "100%",
|
|
318
|
+
style: { border: "none", borderRadius: "10px" }
|
|
319
|
+
},
|
|
320
|
+
`${removeHeader}-${removeStyling}`
|
|
321
|
+
) })
|
|
322
|
+
] })
|
|
323
|
+
] })
|
|
324
|
+
] });
|
|
325
|
+
}
|
|
326
|
+
async function getModels() {
|
|
327
|
+
const models = await instance.get("/chartbrew/models");
|
|
328
|
+
return models.data;
|
|
329
|
+
}
|
|
330
|
+
async function generateTemplate(data) {
|
|
331
|
+
return instance.post(`/${PLUGIN_ID}/generate`, data).then((project) => {
|
|
332
|
+
return project.data;
|
|
333
|
+
}).catch((err) => {
|
|
334
|
+
return Promise.reject(err);
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
function Create() {
|
|
338
|
+
const [collection, setCollection] = useState({});
|
|
339
|
+
const [models, setModels] = useState([]);
|
|
340
|
+
const [createdAt, setCreatedAt] = useState("");
|
|
341
|
+
const [updatedAt, setUpdatedAt] = useState("");
|
|
342
|
+
const [settingsLoading, setSettingsLoading] = useState(true);
|
|
343
|
+
const [hasToken, setHasToken] = useState(false);
|
|
344
|
+
const [projects, setProjects] = useState([]);
|
|
345
|
+
const [templateCharts, setTemplateCharts] = useState([]);
|
|
346
|
+
const [selectedCharts, setSelectedCharts] = useState([]);
|
|
347
|
+
const [selectedProject, setSelectedProject] = useState({});
|
|
348
|
+
const [dropdownProject, setDropdownProject] = useState("");
|
|
349
|
+
const [generating, setGenerating] = useState(false);
|
|
350
|
+
const [userTeam, setUserTeam] = useState({});
|
|
351
|
+
const [planLimits, setPlanLimits] = useState(false);
|
|
352
|
+
const [store, setStore] = useState({});
|
|
353
|
+
const [generationError, setGenerationError] = useState(false);
|
|
354
|
+
const [teams, setTeams] = useState([]);
|
|
355
|
+
const [dropdownTeam, setDropdownTeam] = useState("");
|
|
356
|
+
useEffect(async () => {
|
|
357
|
+
getSettings().then((data) => {
|
|
358
|
+
setSettingsLoading(false);
|
|
359
|
+
setHasToken(data.hasToken);
|
|
360
|
+
setStore(data);
|
|
361
|
+
}).catch(() => setSettingsLoading(false));
|
|
362
|
+
getModels().then((data) => {
|
|
363
|
+
setModels(data);
|
|
364
|
+
});
|
|
365
|
+
const user = await login();
|
|
366
|
+
const teamData = await getUserTeam(user.id);
|
|
367
|
+
setTeams(teamData);
|
|
368
|
+
const template = await getStrapiTemplate(teamData[0].id);
|
|
369
|
+
const charts = template.Charts.map((c) => ({
|
|
370
|
+
tid: c.tid,
|
|
371
|
+
name: c.name
|
|
372
|
+
}));
|
|
373
|
+
setTemplateCharts(charts);
|
|
374
|
+
setSelectedCharts(charts.map((c) => c.tid));
|
|
375
|
+
}, []);
|
|
376
|
+
const _onSelectCollection = (model) => {
|
|
377
|
+
setCollection(model);
|
|
378
|
+
if (model.attributes.createdAt) setCreatedAt("createdAt");
|
|
379
|
+
else if (model.attributes.created_at) setCreatedAt("created_at");
|
|
380
|
+
if (model.attributes.updatedAt) setUpdatedAt("updatedAt");
|
|
381
|
+
else if (model.attributes.updated_at) setUpdatedAt("updated_at");
|
|
382
|
+
};
|
|
383
|
+
const _onToggleChart = (chart) => {
|
|
384
|
+
let foundIndex;
|
|
385
|
+
selectedCharts.forEach((c, index) => {
|
|
386
|
+
if (c === chart.tid) foundIndex = index;
|
|
387
|
+
});
|
|
388
|
+
let newSelectedCharts = [...selectedCharts];
|
|
389
|
+
if (foundIndex || foundIndex === 0) newSelectedCharts.splice(foundIndex, 1);
|
|
390
|
+
else newSelectedCharts.push(chart.tid);
|
|
391
|
+
setSelectedCharts(newSelectedCharts);
|
|
392
|
+
};
|
|
393
|
+
const _onSelectProject = (projectValue) => {
|
|
394
|
+
if (!projectValue) return;
|
|
395
|
+
const project = projects.filter((p) => `${p.name}-${p.id}` === projectValue)[0];
|
|
396
|
+
setDropdownProject(`${project.name}-${project.id}`);
|
|
397
|
+
setSelectedProject(project);
|
|
398
|
+
};
|
|
399
|
+
const _onGenerateCharts = async () => {
|
|
400
|
+
const data = {
|
|
401
|
+
createdField: createdAt,
|
|
402
|
+
updatedField: updatedAt,
|
|
403
|
+
collection: collection.pluralName,
|
|
404
|
+
projectId: selectedProject.id,
|
|
405
|
+
charts: selectedCharts,
|
|
406
|
+
teamId: userTeam.id
|
|
407
|
+
};
|
|
408
|
+
if (selectedProject && selectedProject.id) {
|
|
409
|
+
const connections = await getTeamConnections(userTeam.id);
|
|
410
|
+
const strapiConnection = connections.filter((c) => {
|
|
411
|
+
return c.host && c.host.indexOf(store.strapiHost) > -1;
|
|
412
|
+
})[0];
|
|
413
|
+
if (strapiConnection && strapiConnection.id) {
|
|
414
|
+
data.connections_id = strapiConnection.id;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
setGenerating(true);
|
|
418
|
+
generateTemplate(data).then((project) => {
|
|
419
|
+
return setSettings({ defaultProject: project.id });
|
|
420
|
+
}).then(() => {
|
|
421
|
+
setTimeout(() => {
|
|
422
|
+
location.pathname = `/admin/plugins/${PLUGIN_ID}`;
|
|
423
|
+
setGenerating(false);
|
|
424
|
+
}, 1e3);
|
|
425
|
+
}).catch((err) => {
|
|
426
|
+
if (err && err.message && err.message.indexOf("406") > -1) {
|
|
427
|
+
setPlanLimits(true);
|
|
428
|
+
} else {
|
|
429
|
+
setGenerationError(true);
|
|
430
|
+
}
|
|
431
|
+
setGenerating(false);
|
|
432
|
+
});
|
|
433
|
+
};
|
|
434
|
+
const _isLocalConnectingToManaged = () => {
|
|
435
|
+
if (store.strapiHost && store.strapiHost.indexOf("http://localhost") > -1 && store.host.indexOf("https://api.chartbrew.com") > -1) {
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
return false;
|
|
439
|
+
};
|
|
440
|
+
const _onSelectTeam = (teamValue) => {
|
|
441
|
+
if (!teamValue) return;
|
|
442
|
+
const team = teams.find((t) => `${t.name}-${t.id}` === teamValue);
|
|
443
|
+
setDropdownTeam(`${team.name}-${team.id}`);
|
|
444
|
+
setUserTeam(team);
|
|
445
|
+
setProjects(team.Projects);
|
|
446
|
+
};
|
|
447
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
448
|
+
/* @__PURE__ */ jsx(
|
|
449
|
+
Layouts.Header,
|
|
450
|
+
{
|
|
451
|
+
title: "Create",
|
|
452
|
+
subtitle: "Add new visualizations to your Chartbrew dashboards",
|
|
453
|
+
navigationAction: /* @__PURE__ */ jsx(Link$1, { startIcon: /* @__PURE__ */ jsx(ArrowLeft, {}), to: `/plugins/${PLUGIN_ID}`, children: "Back to the dashboard" })
|
|
454
|
+
}
|
|
455
|
+
),
|
|
456
|
+
/* @__PURE__ */ jsx(Layouts.Content, { children: /* @__PURE__ */ jsxs(Box, { padding: 6, shadow: "filterShadow", background: "neutral0", children: [
|
|
457
|
+
!settingsLoading && store.strapiHost && _isLocalConnectingToManaged() && /* @__PURE__ */ jsx(Box, { paddingBottom: 4, children: /* @__PURE__ */ jsx(
|
|
458
|
+
Alert,
|
|
459
|
+
{
|
|
460
|
+
closeLabel: "Close alert",
|
|
461
|
+
title: "Chartbrew might not be able to create charts",
|
|
462
|
+
variant: "danger",
|
|
463
|
+
action: /* @__PURE__ */ jsx(Link$1, { tag: Link, to: `/settings/${PLUGIN_ID}`, children: "Click here to go to settings" }),
|
|
464
|
+
onClose: () => {
|
|
465
|
+
},
|
|
466
|
+
children: "It looks like your Strapi Backend URL is on localhost. Chartbrew's server will not be able to access your localhost environment. Please update your Strapi Backend URL to something like https://my-strapi-backend.com or self-host Chartbrew on the same server as your Strapi Backend."
|
|
467
|
+
}
|
|
468
|
+
) }),
|
|
469
|
+
!settingsLoading && !hasToken && /* @__PURE__ */ jsx(Box, { paddingBottom: 4, children: /* @__PURE__ */ jsx(
|
|
470
|
+
Alert,
|
|
471
|
+
{
|
|
472
|
+
closeLabel: "Close alert",
|
|
473
|
+
title: "Chartbrew cannot create charts from your Strapi data",
|
|
474
|
+
variant: "danger",
|
|
475
|
+
action: /* @__PURE__ */ jsx(Link$1, { tag: Link, to: `/settings/${PLUGIN_ID}`, children: "Click here to go to settings" }),
|
|
476
|
+
onClose: () => {
|
|
477
|
+
},
|
|
478
|
+
children: "In order to allow Chartbrew to create visualizations for you, please add a Strapi API token in the settings. "
|
|
479
|
+
}
|
|
480
|
+
) }),
|
|
481
|
+
!settingsLoading && !store.strapiHost && /* @__PURE__ */ jsx(Box, { paddingBottom: 4, children: /* @__PURE__ */ jsx(
|
|
482
|
+
Alert,
|
|
483
|
+
{
|
|
484
|
+
closeLabel: "Close alert",
|
|
485
|
+
title: "Chartbrew cannot create charts from your Strapi data",
|
|
486
|
+
variant: "danger",
|
|
487
|
+
action: /* @__PURE__ */ jsx(Link$1, { tag: Link, to: `/settings/${PLUGIN_ID}`, children: "Click here to go to settings" }),
|
|
488
|
+
onClose: () => {
|
|
489
|
+
},
|
|
490
|
+
children: "Your Strapi backend URL is missing from the Chartbrew settings. Set it up by going to the settings page. "
|
|
491
|
+
}
|
|
492
|
+
) }),
|
|
493
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Select your Chartbrew team" }) }),
|
|
494
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 2, children: /* @__PURE__ */ jsx(
|
|
495
|
+
SingleSelect,
|
|
496
|
+
{
|
|
497
|
+
value: dropdownTeam,
|
|
498
|
+
onChange: _onSelectTeam,
|
|
499
|
+
children: teams.map((t) => {
|
|
500
|
+
return /* @__PURE__ */ jsx(SingleSelectOption, { value: `${t.name}-${t.id}`, children: t.name }, t.id);
|
|
501
|
+
})
|
|
502
|
+
}
|
|
503
|
+
) }),
|
|
504
|
+
dropdownTeam && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
505
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Select one of your collection types below " }) }),
|
|
506
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(Grid.Root, { gap: 3, children: models.map((model) => /* @__PURE__ */ jsx(Grid.Item, { col: 2, s: 4, xs: 6, children: /* @__PURE__ */ jsx(
|
|
507
|
+
Button,
|
|
508
|
+
{
|
|
509
|
+
variant: model.uid === collection.uid ? "default" : "secondary",
|
|
510
|
+
onClick: () => _onSelectCollection(model),
|
|
511
|
+
fullWidth: true,
|
|
512
|
+
children: model.displayName
|
|
513
|
+
}
|
|
514
|
+
) }, model.uid)) }) })
|
|
515
|
+
] }),
|
|
516
|
+
collection.uid && /* @__PURE__ */ jsxs(Box, { children: [
|
|
517
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 6, paddingBottom: 6, children: /* @__PURE__ */ jsx(Divider, {}) }),
|
|
518
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Timestamp settings " }) }),
|
|
519
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 2, children: /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
|
520
|
+
/* @__PURE__ */ jsx(
|
|
521
|
+
Combobox,
|
|
522
|
+
{
|
|
523
|
+
label: "Select your 'created at' field",
|
|
524
|
+
value: createdAt,
|
|
525
|
+
onChange: (value) => setCreatedAt(value),
|
|
526
|
+
children: Object.keys(collection.attributes)?.map((attribute) => {
|
|
527
|
+
return /* @__PURE__ */ jsx(ComboboxOption, { value: attribute, children: attribute }, attribute);
|
|
528
|
+
})
|
|
529
|
+
}
|
|
530
|
+
),
|
|
531
|
+
/* @__PURE__ */ jsx(
|
|
532
|
+
Combobox,
|
|
533
|
+
{
|
|
534
|
+
label: "Select your 'updated at' field",
|
|
535
|
+
value: updatedAt,
|
|
536
|
+
onChange: (value) => setUpdatedAt(value),
|
|
537
|
+
children: Object.keys(collection.attributes)?.map((attribute) => {
|
|
538
|
+
return /* @__PURE__ */ jsx(ComboboxOption, { value: attribute, children: attribute }, attribute);
|
|
539
|
+
})
|
|
540
|
+
}
|
|
541
|
+
)
|
|
542
|
+
] }) }),
|
|
543
|
+
/* @__PURE__ */ jsxs(Box, { paddingTop: 6, children: [
|
|
544
|
+
/* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Select the charts you want to create " }),
|
|
545
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: "(More will be added later) " }) })
|
|
546
|
+
] }),
|
|
547
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(Grid.Root, { gap: 3, children: templateCharts.map((chart) => /* @__PURE__ */ jsx(Grid.Item, { col: 3, s: 4, xs: 6, children: /* @__PURE__ */ jsx(
|
|
548
|
+
Checkbox,
|
|
549
|
+
{
|
|
550
|
+
checked: selectedCharts.indexOf(chart.tid) > -1,
|
|
551
|
+
onClick: () => _onToggleChart(chart),
|
|
552
|
+
children: chart.name && chart.name.replace("undefined", collection.pluralName)
|
|
553
|
+
}
|
|
554
|
+
) }, chart.tid)) }) }),
|
|
555
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 6, paddingBottom: 6, children: /* @__PURE__ */ jsx(Divider, {}) }),
|
|
556
|
+
/* @__PURE__ */ jsxs(Box, { children: [
|
|
557
|
+
/* @__PURE__ */ jsx(Typography, { variant: "delta", children: "Choose a dashboard where to place the charts " }),
|
|
558
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: "Or leave empty to create a new dashboard " }) })
|
|
559
|
+
] }),
|
|
560
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 2, children: /* @__PURE__ */ jsx(
|
|
561
|
+
Combobox,
|
|
562
|
+
{
|
|
563
|
+
"aria-label": "Select a Chartbrew dashboard",
|
|
564
|
+
placeholder: "Select a dashboard or leave empty",
|
|
565
|
+
value: dropdownProject,
|
|
566
|
+
onChange: _onSelectProject,
|
|
567
|
+
children: projects.filter((p) => p).map((p) => {
|
|
568
|
+
return /* @__PURE__ */ jsx(ComboboxOption, { value: `${p.name}-${p.id}`, children: p.name }, p.id);
|
|
569
|
+
})
|
|
570
|
+
}
|
|
571
|
+
) }),
|
|
572
|
+
/* @__PURE__ */ jsx(Box, { paddingTop: 6, children: /* @__PURE__ */ jsx(
|
|
573
|
+
Button,
|
|
574
|
+
{
|
|
575
|
+
onClick: () => _onGenerateCharts(),
|
|
576
|
+
size: "L",
|
|
577
|
+
loading: generating,
|
|
578
|
+
disabled: selectedCharts.length < 1 || !dropdownTeam,
|
|
579
|
+
variant: planLimits ? "danger" : "default",
|
|
580
|
+
children: "Create the charts"
|
|
581
|
+
}
|
|
582
|
+
) }),
|
|
583
|
+
generationError && /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(
|
|
584
|
+
Alert,
|
|
585
|
+
{
|
|
586
|
+
closeLabel: "Close alert",
|
|
587
|
+
title: "The charts could not be created",
|
|
588
|
+
variant: "danger",
|
|
589
|
+
action: /* @__PURE__ */ jsx(Link$1, { tag: Link, to: `/settings/${PLUGIN_ID}`, children: "Click here to go to settings" }),
|
|
590
|
+
onClose: () => setGenerationError(false),
|
|
591
|
+
children: "There was an error generating your charts. Please make sure all your settings are correct and try again."
|
|
592
|
+
}
|
|
593
|
+
) }),
|
|
594
|
+
planLimits && /* @__PURE__ */ jsx(Box, { paddingTop: 4, children: /* @__PURE__ */ jsx(
|
|
595
|
+
Alert,
|
|
596
|
+
{
|
|
597
|
+
closeLabel: "Close alert",
|
|
598
|
+
title: "You reached the limits of your Chartbrew plan",
|
|
599
|
+
variant: "danger",
|
|
600
|
+
action: /* @__PURE__ */ jsx(Link$1, { href: `${store.clientHost}/manage/${userTeam.id}/plans`, children: "Click here to go to your Chartbrew accounts settings" }),
|
|
601
|
+
onClose: () => setPlanLimits(false),
|
|
602
|
+
children: "Your plan does not allow to create more charts in this project, or to create new projects. Please update your Chartbrew subscription to add more charts. "
|
|
603
|
+
}
|
|
604
|
+
) })
|
|
605
|
+
] })
|
|
606
|
+
] }) })
|
|
607
|
+
] });
|
|
608
|
+
}
|
|
609
|
+
function App() {
|
|
610
|
+
return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(Routes, { children: [
|
|
611
|
+
/* @__PURE__ */ jsx(Route, { index: true, element: /* @__PURE__ */ jsx(Dashboard, {}) }),
|
|
612
|
+
/* @__PURE__ */ jsx(Route, { path: `create`, element: /* @__PURE__ */ jsx(Create, {}) }),
|
|
613
|
+
/* @__PURE__ */ jsx(Route, { path: "*", element: /* @__PURE__ */ jsx(Page.Error, {}) })
|
|
614
|
+
] }) });
|
|
615
|
+
}
|
|
616
|
+
export {
|
|
617
|
+
App
|
|
618
|
+
};
|