@bygd/nc-report-ui 0.1.9 → 0.1.11
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/dist/app/esm/index.js +103 -8
- package/dist/default/cjs/index.cjs +103 -8
- package/dist/default/esm/index.js +103 -8
- package/dist/default/iife/index.js +103 -8
- package/dist/default/iife/index.js.map +1 -0
- package/package.json +1 -1
package/dist/app/esm/index.js
CHANGED
|
@@ -11338,14 +11338,62 @@ const apiClient = axios.create({
|
|
|
11338
11338
|
'Content-Type': 'application/json'
|
|
11339
11339
|
}
|
|
11340
11340
|
});
|
|
11341
|
+
|
|
11342
|
+
// Cache for dashboard metadata
|
|
11343
|
+
const dashboardMetaCache = {};
|
|
11344
|
+
|
|
11345
|
+
/**
|
|
11346
|
+
* Helper function to get the first available dashboard ID from cache
|
|
11347
|
+
* @returns {string|null} First dashboard ID or null if cache is empty
|
|
11348
|
+
*/
|
|
11349
|
+
const getFirstCachedDashboardId = () => {
|
|
11350
|
+
const cachedIds = Object.keys(dashboardMetaCache);
|
|
11351
|
+
return cachedIds.length > 0 ? cachedIds[0] : null;
|
|
11352
|
+
};
|
|
11341
11353
|
const Api = {
|
|
11342
|
-
setAuth(
|
|
11343
|
-
|
|
11344
|
-
|
|
11354
|
+
setAuth(auth) {
|
|
11355
|
+
this.auth = auth;
|
|
11356
|
+
const token = auth?.token;
|
|
11357
|
+
const accessToken = token?.accessToken;
|
|
11358
|
+
if (!accessToken) return;
|
|
11359
|
+
apiClient.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`;
|
|
11360
|
+
},
|
|
11361
|
+
/**
|
|
11362
|
+
* Load and cache dashboard metadata
|
|
11363
|
+
* @param {Object} params - Parameters object
|
|
11364
|
+
* @param {string} params.dashboardId - Dashboard ID
|
|
11365
|
+
* @returns {Promise} Dashboard metadata object
|
|
11366
|
+
*/
|
|
11367
|
+
loadDashboardMeta: async ({
|
|
11368
|
+
dashboardId
|
|
11369
|
+
}) => {
|
|
11370
|
+
const {
|
|
11371
|
+
data
|
|
11372
|
+
} = await apiClient.get(`/dashboard-meta/${dashboardId}`);
|
|
11373
|
+
|
|
11374
|
+
// Cache the metadata
|
|
11375
|
+
dashboardMetaCache[dashboardId] = {
|
|
11376
|
+
dashboards: data.dashboards || {},
|
|
11377
|
+
charts: data.charts || {},
|
|
11378
|
+
reports: data.reports || {},
|
|
11379
|
+
reportMetadata: data.reportMetadata || {},
|
|
11380
|
+
dateRanges: data.dateRanges || []
|
|
11381
|
+
};
|
|
11382
|
+
return dashboardMetaCache[dashboardId];
|
|
11345
11383
|
},
|
|
11346
11384
|
getDashboard: async ({
|
|
11347
|
-
id
|
|
11385
|
+
id,
|
|
11386
|
+
dashboardId
|
|
11348
11387
|
}) => {
|
|
11388
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
11389
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
11390
|
+
|
|
11391
|
+
// Check cache first
|
|
11392
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.dashboards?.[id]) {
|
|
11393
|
+
return dashboardMetaCache[cacheKey].dashboards[id];
|
|
11394
|
+
}
|
|
11395
|
+
|
|
11396
|
+
// Fall back to HTTP request
|
|
11349
11397
|
const {
|
|
11350
11398
|
data
|
|
11351
11399
|
} = await apiClient.get(`/entity/dashboards/${id}`);
|
|
@@ -11355,11 +11403,22 @@ const Api = {
|
|
|
11355
11403
|
* Get chart by ID
|
|
11356
11404
|
* @param {Object} params - Parameters object
|
|
11357
11405
|
* @param {string} params.id - Chart ID
|
|
11406
|
+
* @param {string} [params.dashboardId] - Optional dashboard ID for cache lookup
|
|
11358
11407
|
* @returns {Promise} Axios response promise
|
|
11359
11408
|
*/
|
|
11360
11409
|
getChart: async ({
|
|
11361
|
-
id
|
|
11410
|
+
id,
|
|
11411
|
+
dashboardId
|
|
11362
11412
|
}) => {
|
|
11413
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
11414
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
11415
|
+
|
|
11416
|
+
// Check cache first
|
|
11417
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.charts?.[id]) {
|
|
11418
|
+
return dashboardMetaCache[cacheKey].charts[id];
|
|
11419
|
+
}
|
|
11420
|
+
|
|
11421
|
+
// Fall back to HTTP request
|
|
11363
11422
|
const {
|
|
11364
11423
|
data
|
|
11365
11424
|
} = await apiClient.get(`/entity/charts/${id}`);
|
|
@@ -11369,11 +11428,22 @@ const Api = {
|
|
|
11369
11428
|
* Get report by ID
|
|
11370
11429
|
* @param {Object} params - Parameters object
|
|
11371
11430
|
* @param {string} params.id - Report ID
|
|
11431
|
+
* @param {string} [params.dashboardId] - Optional dashboard ID for cache lookup
|
|
11372
11432
|
* @returns {Promise} Axios response promise
|
|
11373
11433
|
*/
|
|
11374
11434
|
getReport: async ({
|
|
11375
|
-
id
|
|
11435
|
+
id,
|
|
11436
|
+
dashboardId
|
|
11376
11437
|
}) => {
|
|
11438
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
11439
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
11440
|
+
|
|
11441
|
+
// Check cache first
|
|
11442
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.reports?.[id]) {
|
|
11443
|
+
return dashboardMetaCache[cacheKey].reports[id];
|
|
11444
|
+
}
|
|
11445
|
+
|
|
11446
|
+
// Fall back to HTTP request
|
|
11377
11447
|
const {
|
|
11378
11448
|
data
|
|
11379
11449
|
} = await apiClient.get(`/entity/reports/${id}`);
|
|
@@ -11383,12 +11453,23 @@ const Api = {
|
|
|
11383
11453
|
* Get report schema/metadata by ID
|
|
11384
11454
|
* @param {Object} params - Parameters object
|
|
11385
11455
|
* @param {string} params.id - Report ID
|
|
11456
|
+
* @param {string} [params.dashboardId] - Optional dashboard ID for cache lookup
|
|
11386
11457
|
* @returns {Promise} Axios response promise
|
|
11387
11458
|
*/
|
|
11388
11459
|
getReportSchema: async ({
|
|
11389
11460
|
id,
|
|
11461
|
+
dashboardId,
|
|
11390
11462
|
query = {}
|
|
11391
11463
|
}) => {
|
|
11464
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
11465
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
11466
|
+
|
|
11467
|
+
// Check cache first
|
|
11468
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.reportMetadata?.[id]) {
|
|
11469
|
+
return dashboardMetaCache[cacheKey].reportMetadata[id];
|
|
11470
|
+
}
|
|
11471
|
+
|
|
11472
|
+
// Fall back to HTTP request
|
|
11392
11473
|
// console.log({getReportSchema:{id,query}});
|
|
11393
11474
|
const {
|
|
11394
11475
|
data
|
|
@@ -11413,7 +11494,18 @@ const Api = {
|
|
|
11413
11494
|
} = await apiClient.post(`/reports/${id}/run`, query);
|
|
11414
11495
|
return data;
|
|
11415
11496
|
},
|
|
11416
|
-
getDateRanges: async (
|
|
11497
|
+
getDateRanges: async ({
|
|
11498
|
+
dashboardId
|
|
11499
|
+
} = {}) => {
|
|
11500
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
11501
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
11502
|
+
|
|
11503
|
+
// Check cache first
|
|
11504
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.dateRanges) {
|
|
11505
|
+
return dashboardMetaCache[cacheKey].dateRanges;
|
|
11506
|
+
}
|
|
11507
|
+
|
|
11508
|
+
// Fall back to HTTP request
|
|
11417
11509
|
const {
|
|
11418
11510
|
data
|
|
11419
11511
|
} = await apiClient.get(`/globals/date-ranges`);
|
|
@@ -45030,7 +45122,10 @@ function Dashboard({
|
|
|
45030
45122
|
const channel = useChannel();
|
|
45031
45123
|
useFilterManager(channel);
|
|
45032
45124
|
const init = async () => {
|
|
45033
|
-
Api.setAuth(auth
|
|
45125
|
+
Api.setAuth(auth);
|
|
45126
|
+
await Api.loadDashboardMeta({
|
|
45127
|
+
dashboardId: id
|
|
45128
|
+
});
|
|
45034
45129
|
|
|
45035
45130
|
// get dashboard entity
|
|
45036
45131
|
const dashboardTemp = await Api.getDashboard({
|
|
@@ -142,14 +142,62 @@ const apiClient = axios__default.default.create({
|
|
|
142
142
|
'Content-Type': 'application/json'
|
|
143
143
|
}
|
|
144
144
|
});
|
|
145
|
+
|
|
146
|
+
// Cache for dashboard metadata
|
|
147
|
+
const dashboardMetaCache = {};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Helper function to get the first available dashboard ID from cache
|
|
151
|
+
* @returns {string|null} First dashboard ID or null if cache is empty
|
|
152
|
+
*/
|
|
153
|
+
const getFirstCachedDashboardId = () => {
|
|
154
|
+
const cachedIds = Object.keys(dashboardMetaCache);
|
|
155
|
+
return cachedIds.length > 0 ? cachedIds[0] : null;
|
|
156
|
+
};
|
|
145
157
|
const Api = {
|
|
146
|
-
setAuth(
|
|
147
|
-
|
|
148
|
-
|
|
158
|
+
setAuth(auth) {
|
|
159
|
+
this.auth = auth;
|
|
160
|
+
const token = auth?.token;
|
|
161
|
+
const accessToken = token?.accessToken;
|
|
162
|
+
if (!accessToken) return;
|
|
163
|
+
apiClient.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`;
|
|
164
|
+
},
|
|
165
|
+
/**
|
|
166
|
+
* Load and cache dashboard metadata
|
|
167
|
+
* @param {Object} params - Parameters object
|
|
168
|
+
* @param {string} params.dashboardId - Dashboard ID
|
|
169
|
+
* @returns {Promise} Dashboard metadata object
|
|
170
|
+
*/
|
|
171
|
+
loadDashboardMeta: async ({
|
|
172
|
+
dashboardId
|
|
173
|
+
}) => {
|
|
174
|
+
const {
|
|
175
|
+
data
|
|
176
|
+
} = await apiClient.get(`/dashboard-meta/${dashboardId}`);
|
|
177
|
+
|
|
178
|
+
// Cache the metadata
|
|
179
|
+
dashboardMetaCache[dashboardId] = {
|
|
180
|
+
dashboards: data.dashboards || {},
|
|
181
|
+
charts: data.charts || {},
|
|
182
|
+
reports: data.reports || {},
|
|
183
|
+
reportMetadata: data.reportMetadata || {},
|
|
184
|
+
dateRanges: data.dateRanges || []
|
|
185
|
+
};
|
|
186
|
+
return dashboardMetaCache[dashboardId];
|
|
149
187
|
},
|
|
150
188
|
getDashboard: async ({
|
|
151
|
-
id
|
|
189
|
+
id,
|
|
190
|
+
dashboardId
|
|
152
191
|
}) => {
|
|
192
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
193
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
194
|
+
|
|
195
|
+
// Check cache first
|
|
196
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.dashboards?.[id]) {
|
|
197
|
+
return dashboardMetaCache[cacheKey].dashboards[id];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Fall back to HTTP request
|
|
153
201
|
const {
|
|
154
202
|
data
|
|
155
203
|
} = await apiClient.get(`/entity/dashboards/${id}`);
|
|
@@ -159,11 +207,22 @@ const Api = {
|
|
|
159
207
|
* Get chart by ID
|
|
160
208
|
* @param {Object} params - Parameters object
|
|
161
209
|
* @param {string} params.id - Chart ID
|
|
210
|
+
* @param {string} [params.dashboardId] - Optional dashboard ID for cache lookup
|
|
162
211
|
* @returns {Promise} Axios response promise
|
|
163
212
|
*/
|
|
164
213
|
getChart: async ({
|
|
165
|
-
id
|
|
214
|
+
id,
|
|
215
|
+
dashboardId
|
|
166
216
|
}) => {
|
|
217
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
218
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
219
|
+
|
|
220
|
+
// Check cache first
|
|
221
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.charts?.[id]) {
|
|
222
|
+
return dashboardMetaCache[cacheKey].charts[id];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Fall back to HTTP request
|
|
167
226
|
const {
|
|
168
227
|
data
|
|
169
228
|
} = await apiClient.get(`/entity/charts/${id}`);
|
|
@@ -173,11 +232,22 @@ const Api = {
|
|
|
173
232
|
* Get report by ID
|
|
174
233
|
* @param {Object} params - Parameters object
|
|
175
234
|
* @param {string} params.id - Report ID
|
|
235
|
+
* @param {string} [params.dashboardId] - Optional dashboard ID for cache lookup
|
|
176
236
|
* @returns {Promise} Axios response promise
|
|
177
237
|
*/
|
|
178
238
|
getReport: async ({
|
|
179
|
-
id
|
|
239
|
+
id,
|
|
240
|
+
dashboardId
|
|
180
241
|
}) => {
|
|
242
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
243
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
244
|
+
|
|
245
|
+
// Check cache first
|
|
246
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.reports?.[id]) {
|
|
247
|
+
return dashboardMetaCache[cacheKey].reports[id];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Fall back to HTTP request
|
|
181
251
|
const {
|
|
182
252
|
data
|
|
183
253
|
} = await apiClient.get(`/entity/reports/${id}`);
|
|
@@ -187,12 +257,23 @@ const Api = {
|
|
|
187
257
|
* Get report schema/metadata by ID
|
|
188
258
|
* @param {Object} params - Parameters object
|
|
189
259
|
* @param {string} params.id - Report ID
|
|
260
|
+
* @param {string} [params.dashboardId] - Optional dashboard ID for cache lookup
|
|
190
261
|
* @returns {Promise} Axios response promise
|
|
191
262
|
*/
|
|
192
263
|
getReportSchema: async ({
|
|
193
264
|
id,
|
|
265
|
+
dashboardId,
|
|
194
266
|
query = {}
|
|
195
267
|
}) => {
|
|
268
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
269
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
270
|
+
|
|
271
|
+
// Check cache first
|
|
272
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.reportMetadata?.[id]) {
|
|
273
|
+
return dashboardMetaCache[cacheKey].reportMetadata[id];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Fall back to HTTP request
|
|
196
277
|
// console.log({getReportSchema:{id,query}});
|
|
197
278
|
const {
|
|
198
279
|
data
|
|
@@ -217,7 +298,18 @@ const Api = {
|
|
|
217
298
|
} = await apiClient.post(`/reports/${id}/run`, query);
|
|
218
299
|
return data;
|
|
219
300
|
},
|
|
220
|
-
getDateRanges: async (
|
|
301
|
+
getDateRanges: async ({
|
|
302
|
+
dashboardId
|
|
303
|
+
} = {}) => {
|
|
304
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
305
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
306
|
+
|
|
307
|
+
// Check cache first
|
|
308
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.dateRanges) {
|
|
309
|
+
return dashboardMetaCache[cacheKey].dateRanges;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Fall back to HTTP request
|
|
221
313
|
const {
|
|
222
314
|
data
|
|
223
315
|
} = await apiClient.get(`/globals/date-ranges`);
|
|
@@ -993,7 +1085,10 @@ function Dashboard({
|
|
|
993
1085
|
const channel = useChannel();
|
|
994
1086
|
useFilterManager(channel);
|
|
995
1087
|
const init = async () => {
|
|
996
|
-
Api.setAuth(auth
|
|
1088
|
+
Api.setAuth(auth);
|
|
1089
|
+
await Api.loadDashboardMeta({
|
|
1090
|
+
dashboardId: id
|
|
1091
|
+
});
|
|
997
1092
|
|
|
998
1093
|
// get dashboard entity
|
|
999
1094
|
const dashboardTemp = await Api.getDashboard({
|
|
@@ -98,14 +98,62 @@ const apiClient = axios.create({
|
|
|
98
98
|
'Content-Type': 'application/json'
|
|
99
99
|
}
|
|
100
100
|
});
|
|
101
|
+
|
|
102
|
+
// Cache for dashboard metadata
|
|
103
|
+
const dashboardMetaCache = {};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Helper function to get the first available dashboard ID from cache
|
|
107
|
+
* @returns {string|null} First dashboard ID or null if cache is empty
|
|
108
|
+
*/
|
|
109
|
+
const getFirstCachedDashboardId = () => {
|
|
110
|
+
const cachedIds = Object.keys(dashboardMetaCache);
|
|
111
|
+
return cachedIds.length > 0 ? cachedIds[0] : null;
|
|
112
|
+
};
|
|
101
113
|
const Api = {
|
|
102
|
-
setAuth(
|
|
103
|
-
|
|
104
|
-
|
|
114
|
+
setAuth(auth) {
|
|
115
|
+
this.auth = auth;
|
|
116
|
+
const token = auth?.token;
|
|
117
|
+
const accessToken = token?.accessToken;
|
|
118
|
+
if (!accessToken) return;
|
|
119
|
+
apiClient.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`;
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* Load and cache dashboard metadata
|
|
123
|
+
* @param {Object} params - Parameters object
|
|
124
|
+
* @param {string} params.dashboardId - Dashboard ID
|
|
125
|
+
* @returns {Promise} Dashboard metadata object
|
|
126
|
+
*/
|
|
127
|
+
loadDashboardMeta: async ({
|
|
128
|
+
dashboardId
|
|
129
|
+
}) => {
|
|
130
|
+
const {
|
|
131
|
+
data
|
|
132
|
+
} = await apiClient.get(`/dashboard-meta/${dashboardId}`);
|
|
133
|
+
|
|
134
|
+
// Cache the metadata
|
|
135
|
+
dashboardMetaCache[dashboardId] = {
|
|
136
|
+
dashboards: data.dashboards || {},
|
|
137
|
+
charts: data.charts || {},
|
|
138
|
+
reports: data.reports || {},
|
|
139
|
+
reportMetadata: data.reportMetadata || {},
|
|
140
|
+
dateRanges: data.dateRanges || []
|
|
141
|
+
};
|
|
142
|
+
return dashboardMetaCache[dashboardId];
|
|
105
143
|
},
|
|
106
144
|
getDashboard: async ({
|
|
107
|
-
id
|
|
145
|
+
id,
|
|
146
|
+
dashboardId
|
|
108
147
|
}) => {
|
|
148
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
149
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
150
|
+
|
|
151
|
+
// Check cache first
|
|
152
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.dashboards?.[id]) {
|
|
153
|
+
return dashboardMetaCache[cacheKey].dashboards[id];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Fall back to HTTP request
|
|
109
157
|
const {
|
|
110
158
|
data
|
|
111
159
|
} = await apiClient.get(`/entity/dashboards/${id}`);
|
|
@@ -115,11 +163,22 @@ const Api = {
|
|
|
115
163
|
* Get chart by ID
|
|
116
164
|
* @param {Object} params - Parameters object
|
|
117
165
|
* @param {string} params.id - Chart ID
|
|
166
|
+
* @param {string} [params.dashboardId] - Optional dashboard ID for cache lookup
|
|
118
167
|
* @returns {Promise} Axios response promise
|
|
119
168
|
*/
|
|
120
169
|
getChart: async ({
|
|
121
|
-
id
|
|
170
|
+
id,
|
|
171
|
+
dashboardId
|
|
122
172
|
}) => {
|
|
173
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
174
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
175
|
+
|
|
176
|
+
// Check cache first
|
|
177
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.charts?.[id]) {
|
|
178
|
+
return dashboardMetaCache[cacheKey].charts[id];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Fall back to HTTP request
|
|
123
182
|
const {
|
|
124
183
|
data
|
|
125
184
|
} = await apiClient.get(`/entity/charts/${id}`);
|
|
@@ -129,11 +188,22 @@ const Api = {
|
|
|
129
188
|
* Get report by ID
|
|
130
189
|
* @param {Object} params - Parameters object
|
|
131
190
|
* @param {string} params.id - Report ID
|
|
191
|
+
* @param {string} [params.dashboardId] - Optional dashboard ID for cache lookup
|
|
132
192
|
* @returns {Promise} Axios response promise
|
|
133
193
|
*/
|
|
134
194
|
getReport: async ({
|
|
135
|
-
id
|
|
195
|
+
id,
|
|
196
|
+
dashboardId
|
|
136
197
|
}) => {
|
|
198
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
199
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
200
|
+
|
|
201
|
+
// Check cache first
|
|
202
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.reports?.[id]) {
|
|
203
|
+
return dashboardMetaCache[cacheKey].reports[id];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Fall back to HTTP request
|
|
137
207
|
const {
|
|
138
208
|
data
|
|
139
209
|
} = await apiClient.get(`/entity/reports/${id}`);
|
|
@@ -143,12 +213,23 @@ const Api = {
|
|
|
143
213
|
* Get report schema/metadata by ID
|
|
144
214
|
* @param {Object} params - Parameters object
|
|
145
215
|
* @param {string} params.id - Report ID
|
|
216
|
+
* @param {string} [params.dashboardId] - Optional dashboard ID for cache lookup
|
|
146
217
|
* @returns {Promise} Axios response promise
|
|
147
218
|
*/
|
|
148
219
|
getReportSchema: async ({
|
|
149
220
|
id,
|
|
221
|
+
dashboardId,
|
|
150
222
|
query = {}
|
|
151
223
|
}) => {
|
|
224
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
225
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
226
|
+
|
|
227
|
+
// Check cache first
|
|
228
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.reportMetadata?.[id]) {
|
|
229
|
+
return dashboardMetaCache[cacheKey].reportMetadata[id];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Fall back to HTTP request
|
|
152
233
|
// console.log({getReportSchema:{id,query}});
|
|
153
234
|
const {
|
|
154
235
|
data
|
|
@@ -173,7 +254,18 @@ const Api = {
|
|
|
173
254
|
} = await apiClient.post(`/reports/${id}/run`, query);
|
|
174
255
|
return data;
|
|
175
256
|
},
|
|
176
|
-
getDateRanges: async (
|
|
257
|
+
getDateRanges: async ({
|
|
258
|
+
dashboardId
|
|
259
|
+
} = {}) => {
|
|
260
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
261
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
262
|
+
|
|
263
|
+
// Check cache first
|
|
264
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.dateRanges) {
|
|
265
|
+
return dashboardMetaCache[cacheKey].dateRanges;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Fall back to HTTP request
|
|
177
269
|
const {
|
|
178
270
|
data
|
|
179
271
|
} = await apiClient.get(`/globals/date-ranges`);
|
|
@@ -949,7 +1041,10 @@ function Dashboard({
|
|
|
949
1041
|
const channel = useChannel();
|
|
950
1042
|
useFilterManager(channel);
|
|
951
1043
|
const init = async () => {
|
|
952
|
-
Api.setAuth(auth
|
|
1044
|
+
Api.setAuth(auth);
|
|
1045
|
+
await Api.loadDashboardMeta({
|
|
1046
|
+
dashboardId: id
|
|
1047
|
+
});
|
|
953
1048
|
|
|
954
1049
|
// get dashboard entity
|
|
955
1050
|
const dashboardTemp = await Api.getDashboard({
|
|
@@ -10913,14 +10913,62 @@ var _BYGD_NC_REPORT_UI = (function () {
|
|
|
10913
10913
|
'Content-Type': 'application/json'
|
|
10914
10914
|
}
|
|
10915
10915
|
});
|
|
10916
|
+
|
|
10917
|
+
// Cache for dashboard metadata
|
|
10918
|
+
const dashboardMetaCache = {};
|
|
10919
|
+
|
|
10920
|
+
/**
|
|
10921
|
+
* Helper function to get the first available dashboard ID from cache
|
|
10922
|
+
* @returns {string|null} First dashboard ID or null if cache is empty
|
|
10923
|
+
*/
|
|
10924
|
+
const getFirstCachedDashboardId = () => {
|
|
10925
|
+
const cachedIds = Object.keys(dashboardMetaCache);
|
|
10926
|
+
return cachedIds.length > 0 ? cachedIds[0] : null;
|
|
10927
|
+
};
|
|
10916
10928
|
const Api = {
|
|
10917
|
-
setAuth(
|
|
10918
|
-
|
|
10919
|
-
|
|
10929
|
+
setAuth(auth) {
|
|
10930
|
+
this.auth = auth;
|
|
10931
|
+
const token = auth?.token;
|
|
10932
|
+
const accessToken = token?.accessToken;
|
|
10933
|
+
if (!accessToken) return;
|
|
10934
|
+
apiClient.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`;
|
|
10935
|
+
},
|
|
10936
|
+
/**
|
|
10937
|
+
* Load and cache dashboard metadata
|
|
10938
|
+
* @param {Object} params - Parameters object
|
|
10939
|
+
* @param {string} params.dashboardId - Dashboard ID
|
|
10940
|
+
* @returns {Promise} Dashboard metadata object
|
|
10941
|
+
*/
|
|
10942
|
+
loadDashboardMeta: async ({
|
|
10943
|
+
dashboardId
|
|
10944
|
+
}) => {
|
|
10945
|
+
const {
|
|
10946
|
+
data
|
|
10947
|
+
} = await apiClient.get(`/dashboard-meta/${dashboardId}`);
|
|
10948
|
+
|
|
10949
|
+
// Cache the metadata
|
|
10950
|
+
dashboardMetaCache[dashboardId] = {
|
|
10951
|
+
dashboards: data.dashboards || {},
|
|
10952
|
+
charts: data.charts || {},
|
|
10953
|
+
reports: data.reports || {},
|
|
10954
|
+
reportMetadata: data.reportMetadata || {},
|
|
10955
|
+
dateRanges: data.dateRanges || []
|
|
10956
|
+
};
|
|
10957
|
+
return dashboardMetaCache[dashboardId];
|
|
10920
10958
|
},
|
|
10921
10959
|
getDashboard: async ({
|
|
10922
|
-
id
|
|
10960
|
+
id,
|
|
10961
|
+
dashboardId
|
|
10923
10962
|
}) => {
|
|
10963
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
10964
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
10965
|
+
|
|
10966
|
+
// Check cache first
|
|
10967
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.dashboards?.[id]) {
|
|
10968
|
+
return dashboardMetaCache[cacheKey].dashboards[id];
|
|
10969
|
+
}
|
|
10970
|
+
|
|
10971
|
+
// Fall back to HTTP request
|
|
10924
10972
|
const {
|
|
10925
10973
|
data
|
|
10926
10974
|
} = await apiClient.get(`/entity/dashboards/${id}`);
|
|
@@ -10930,11 +10978,22 @@ var _BYGD_NC_REPORT_UI = (function () {
|
|
|
10930
10978
|
* Get chart by ID
|
|
10931
10979
|
* @param {Object} params - Parameters object
|
|
10932
10980
|
* @param {string} params.id - Chart ID
|
|
10981
|
+
* @param {string} [params.dashboardId] - Optional dashboard ID for cache lookup
|
|
10933
10982
|
* @returns {Promise} Axios response promise
|
|
10934
10983
|
*/
|
|
10935
10984
|
getChart: async ({
|
|
10936
|
-
id
|
|
10985
|
+
id,
|
|
10986
|
+
dashboardId
|
|
10937
10987
|
}) => {
|
|
10988
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
10989
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
10990
|
+
|
|
10991
|
+
// Check cache first
|
|
10992
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.charts?.[id]) {
|
|
10993
|
+
return dashboardMetaCache[cacheKey].charts[id];
|
|
10994
|
+
}
|
|
10995
|
+
|
|
10996
|
+
// Fall back to HTTP request
|
|
10938
10997
|
const {
|
|
10939
10998
|
data
|
|
10940
10999
|
} = await apiClient.get(`/entity/charts/${id}`);
|
|
@@ -10944,11 +11003,22 @@ var _BYGD_NC_REPORT_UI = (function () {
|
|
|
10944
11003
|
* Get report by ID
|
|
10945
11004
|
* @param {Object} params - Parameters object
|
|
10946
11005
|
* @param {string} params.id - Report ID
|
|
11006
|
+
* @param {string} [params.dashboardId] - Optional dashboard ID for cache lookup
|
|
10947
11007
|
* @returns {Promise} Axios response promise
|
|
10948
11008
|
*/
|
|
10949
11009
|
getReport: async ({
|
|
10950
|
-
id
|
|
11010
|
+
id,
|
|
11011
|
+
dashboardId
|
|
10951
11012
|
}) => {
|
|
11013
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
11014
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
11015
|
+
|
|
11016
|
+
// Check cache first
|
|
11017
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.reports?.[id]) {
|
|
11018
|
+
return dashboardMetaCache[cacheKey].reports[id];
|
|
11019
|
+
}
|
|
11020
|
+
|
|
11021
|
+
// Fall back to HTTP request
|
|
10952
11022
|
const {
|
|
10953
11023
|
data
|
|
10954
11024
|
} = await apiClient.get(`/entity/reports/${id}`);
|
|
@@ -10958,12 +11028,23 @@ var _BYGD_NC_REPORT_UI = (function () {
|
|
|
10958
11028
|
* Get report schema/metadata by ID
|
|
10959
11029
|
* @param {Object} params - Parameters object
|
|
10960
11030
|
* @param {string} params.id - Report ID
|
|
11031
|
+
* @param {string} [params.dashboardId] - Optional dashboard ID for cache lookup
|
|
10961
11032
|
* @returns {Promise} Axios response promise
|
|
10962
11033
|
*/
|
|
10963
11034
|
getReportSchema: async ({
|
|
10964
11035
|
id,
|
|
11036
|
+
dashboardId,
|
|
10965
11037
|
query = {}
|
|
10966
11038
|
}) => {
|
|
11039
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
11040
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
11041
|
+
|
|
11042
|
+
// Check cache first
|
|
11043
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.reportMetadata?.[id]) {
|
|
11044
|
+
return dashboardMetaCache[cacheKey].reportMetadata[id];
|
|
11045
|
+
}
|
|
11046
|
+
|
|
11047
|
+
// Fall back to HTTP request
|
|
10967
11048
|
// console.log({getReportSchema:{id,query}});
|
|
10968
11049
|
const {
|
|
10969
11050
|
data
|
|
@@ -10988,7 +11069,18 @@ var _BYGD_NC_REPORT_UI = (function () {
|
|
|
10988
11069
|
} = await apiClient.post(`/reports/${id}/run`, query);
|
|
10989
11070
|
return data;
|
|
10990
11071
|
},
|
|
10991
|
-
getDateRanges: async (
|
|
11072
|
+
getDateRanges: async ({
|
|
11073
|
+
dashboardId
|
|
11074
|
+
} = {}) => {
|
|
11075
|
+
// Use provided dashboardId or fall back to first cached dashboard
|
|
11076
|
+
const cacheKey = dashboardId || getFirstCachedDashboardId();
|
|
11077
|
+
|
|
11078
|
+
// Check cache first
|
|
11079
|
+
if (cacheKey && dashboardMetaCache[cacheKey]?.dateRanges) {
|
|
11080
|
+
return dashboardMetaCache[cacheKey].dateRanges;
|
|
11081
|
+
}
|
|
11082
|
+
|
|
11083
|
+
// Fall back to HTTP request
|
|
10992
11084
|
const {
|
|
10993
11085
|
data
|
|
10994
11086
|
} = await apiClient.get(`/globals/date-ranges`);
|
|
@@ -45015,7 +45107,10 @@ export default theme;`;
|
|
|
45015
45107
|
const channel = useChannel();
|
|
45016
45108
|
useFilterManager(channel);
|
|
45017
45109
|
const init = async () => {
|
|
45018
|
-
Api.setAuth(auth
|
|
45110
|
+
Api.setAuth(auth);
|
|
45111
|
+
await Api.loadDashboardMeta({
|
|
45112
|
+
dashboardId: id
|
|
45113
|
+
});
|
|
45019
45114
|
|
|
45020
45115
|
// get dashboard entity
|
|
45021
45116
|
const dashboardTemp = await Api.getDashboard({
|