@isoftdata/utility-dashboard-backend 1.4.7 → 1.5.1
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/chart-helper.js +1 -1
- package/index.js +29 -5
- package/package.json +3 -2
- package/schema.md +9 -4
package/chart-helper.js
CHANGED
|
@@ -233,7 +233,7 @@ module.exports = {
|
|
|
233
233
|
getRactiveTableDataFormat: (data, fields, formatting) => {
|
|
234
234
|
const columns = Object.keys(fields).map(field => {
|
|
235
235
|
// right align currency values
|
|
236
|
-
if (formatting[field]?.type === 'NumberFormat' && formatting?.[field].format.prefix === '$') {
|
|
236
|
+
if (formatting?.[field]?.type === 'NumberFormat' && formatting?.[field].format.prefix === '$') {
|
|
237
237
|
return {
|
|
238
238
|
property: field,
|
|
239
239
|
name: field,
|
package/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const {
|
|
|
10
10
|
getRactiveTableDataFormat: getRactiveTableDataFormat } = require('./chart-helper.js')
|
|
11
11
|
const { datesFromRange } = require('@isoftdata/utility-date-time')
|
|
12
12
|
const formatDate = require('date-fns/format')
|
|
13
|
+
const camelcase = require('camelcase')
|
|
13
14
|
|
|
14
15
|
const handleChartTypeSpecificQuirks = (chartType, resultSet) => {
|
|
15
16
|
if (resultSet.length) {
|
|
@@ -102,7 +103,7 @@ const loadOptionList = async(mysqlConnection, optionListQuery, optionList = [])
|
|
|
102
103
|
]
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
const loadOutputParameterValues = async(mysqlConnection, { definitionList = [], selectionList = [], forClient = false }) => {
|
|
106
|
+
const loadOutputParameterValues = async(mysqlConnection, { definitionList = [], selectionList = [], forClient = false, session = {} }) => {
|
|
106
107
|
let parameterValues = []
|
|
107
108
|
|
|
108
109
|
// If definitionList is not an Array, there are no parameters, so just return []
|
|
@@ -148,6 +149,16 @@ const loadOutputParameterValues = async(mysqlConnection, { definitionList = [],
|
|
|
148
149
|
[parameter.name]: parameter.value,
|
|
149
150
|
}
|
|
150
151
|
}
|
|
152
|
+
} else if (definition.type === 'session') {
|
|
153
|
+
// I think 'name' is the internal name of the parameter, and we should be able to expect that to be the name of the session variable
|
|
154
|
+
// Or we could have a separate value for the name of the session variable
|
|
155
|
+
// Might need to make this more complicated to handle nested variables
|
|
156
|
+
parameter.value = session[camelcase(definition.name)]
|
|
157
|
+
if (!forClient) {
|
|
158
|
+
parameter.queryValues = {
|
|
159
|
+
[parameter.name]: parameter.value,
|
|
160
|
+
}
|
|
161
|
+
}
|
|
151
162
|
}
|
|
152
163
|
|
|
153
164
|
parameterValues.push(parameter)
|
|
@@ -156,7 +167,20 @@ const loadOutputParameterValues = async(mysqlConnection, { definitionList = [],
|
|
|
156
167
|
return parameterValues
|
|
157
168
|
}
|
|
158
169
|
|
|
170
|
+
/**
|
|
171
|
+
*
|
|
172
|
+
* @param {string} query - unparameterized query, with ${placeholders} for parameters
|
|
173
|
+
* @param {Array<Object>} parameterValues - Parameter values to be plugged into the query
|
|
174
|
+
* @returns {{sql: string, values: Array}}
|
|
175
|
+
*/
|
|
159
176
|
const parameterizeQuery = (query, parameterValues) => {
|
|
177
|
+
// Don't parameterize a lack of a query
|
|
178
|
+
if (!query) {
|
|
179
|
+
return {
|
|
180
|
+
sql: '',
|
|
181
|
+
values: [],
|
|
182
|
+
}
|
|
183
|
+
}
|
|
160
184
|
const queryParameterValues = parameterValues.reduce((acc, val) => {
|
|
161
185
|
return val.queryValues ? {
|
|
162
186
|
...acc,
|
|
@@ -179,9 +203,9 @@ const parameterizeQuery = (query, parameterValues) => {
|
|
|
179
203
|
}
|
|
180
204
|
|
|
181
205
|
module.exports = {
|
|
182
|
-
formatReportMetadata: async(mysqlConnection, { report, chartsInReport }) => {
|
|
206
|
+
formatReportMetadata: async(mysqlConnection, { report, chartsInReport, session = {} }) => {
|
|
183
207
|
try {
|
|
184
|
-
const parameterValues = await loadOutputParameterValues(mysqlConnection, { definitionList: report.parameters, forClient: true })
|
|
208
|
+
const parameterValues = await loadOutputParameterValues(mysqlConnection, { definitionList: report.parameters, forClient: true, session })
|
|
185
209
|
|
|
186
210
|
return {
|
|
187
211
|
dashboardReportId: report.dashboardReportId,
|
|
@@ -197,9 +221,9 @@ module.exports = {
|
|
|
197
221
|
throw err
|
|
198
222
|
}
|
|
199
223
|
},
|
|
200
|
-
formatChartDataForReport: async(mysqlConnection, { reportParameters, chart, reportChart, parameterSelectionList }) => {
|
|
224
|
+
formatChartDataForReport: async(mysqlConnection, { reportParameters, chart, reportChart, parameterSelectionList, session = {} }) => {
|
|
201
225
|
try {
|
|
202
|
-
const parameterValues = await loadOutputParameterValues(mysqlConnection, { definitionList: reportParameters, selectionList: parameterSelectionList })
|
|
226
|
+
const parameterValues = await loadOutputParameterValues(mysqlConnection, { definitionList: reportParameters, selectionList: parameterSelectionList, session })
|
|
203
227
|
if (reportChart?.jsonOverride?.chartWrapper?.dataTable) {
|
|
204
228
|
const { dataTable, ...chartWrapper } = reportChart.jsonOverride.chartWrapper
|
|
205
229
|
reportChart.jsonOverride.chartWrapper = chartWrapper
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isoftdata/utility-dashboard-backend",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "A utility for formatting chart and report data to be usable by the frontend dashboard component.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"date-fns": "^2.23.0",
|
|
15
15
|
"klona": "^1.1.2",
|
|
16
16
|
"mysql": "^2.18.1",
|
|
17
|
-
"to-snake-case": "^1.0.0"
|
|
17
|
+
"to-snake-case": "^1.0.0",
|
|
18
|
+
"camelcase": "^5.3.1"
|
|
18
19
|
}
|
|
19
20
|
}
|
package/schema.md
CHANGED
|
@@ -15,28 +15,28 @@ share_type | `Enum` | Controls access to reports within the dashboard. Possible
|
|
|
15
15
|
share_id | `Unsigned integer` | Used in conjunction with `share_type` to control access to reports. When `share_type` is 'everyone', this field is null. Otherwise, it contains the id of the user, group, or store to share the report with. Defaults to `NULL`.
|
|
16
16
|
owner_id | `Unsigned integer` | The `user_account_id` of the user who created the report in the dashboard. This user will always have access to the given report, regardless of its sharing settings, and will be shown as the report owner on the configuration screen. Defaults to `NULL`, which designates it as a default report.
|
|
17
17
|
|
|
18
|
-
#### Parameter Object
|
|
18
|
+
#### Base Parameter Object
|
|
19
19
|
Property | Type | Description
|
|
20
20
|
---- | ---- | -----------
|
|
21
21
|
name | `String` | **Required** - a unique name for the parameter. This name is also used to reference param in a query.
|
|
22
22
|
title | `String` | This is used to label the parameter for the user.
|
|
23
23
|
type | `String` | Can be one of `dateRange`, `date`, or `selection`. See the tables below for parameter-type-specific properties
|
|
24
24
|
|
|
25
|
-
##### `dateRange` Type
|
|
25
|
+
##### `dateRange` Type Parameters
|
|
26
26
|
> In the UI, the user will see a dropdown with the possible date range values(see `default` description below).
|
|
27
27
|
|
|
28
28
|
Property | Type | Description
|
|
29
29
|
---- | ---- | -----------
|
|
30
30
|
default | `String` | One of the following values: `'Today'`, `'Yesterday'`, `'Last 7 Days'`, `'Last 30 Days'`, `'Last 90 Days'`, `'Last 365 Days'`, `'This Week'`, `'This Month'`, `'This Quarter'`, `'This Year'`, `'Previous Week'`, `'Previous Month'`, `'Previous Quarter'`, or `'Previous Year'`. If the `default` property is omitted or [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), `'Last 30 Days'` will be used.
|
|
31
31
|
|
|
32
|
-
##### `date` Type
|
|
32
|
+
##### `date` Type Parameters
|
|
33
33
|
> In the UI, the user will see a dropdown with a date picker.
|
|
34
34
|
|
|
35
35
|
Property | Type | Description
|
|
36
36
|
---- | ---- | -----------
|
|
37
37
|
default | `String` | Can be an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date string(eg. `'2021-01-13'`). If the `default` property is omitted or [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), the today's date will be used.
|
|
38
38
|
|
|
39
|
-
##### `selection` Type
|
|
39
|
+
##### `selection` Type Parameters
|
|
40
40
|
> In the UI, the user will see a dropdown with the `optionList` values(if any) and the values returned from the `optionListQuery`(if any).
|
|
41
41
|
|
|
42
42
|
Property | Type | Description
|
|
@@ -45,6 +45,11 @@ default | `String` | The `id` of the option you'd like to be selected by default
|
|
|
45
45
|
optionList | `Object` | Each object should have an `id`, and `name`. `id` is the value that will be given to you at query time and `name` is what will be displayed in the dropdown to the user.
|
|
46
46
|
optionListQuery | `String` | A query that selects 2 columns `id` and `name`. The results of this query will be merged with `optionList` and put in the dropdown for the user.
|
|
47
47
|
|
|
48
|
+
##### `session` Type Parameters
|
|
49
|
+
> These parameters are not shown in the UI since they do not require or allow user input.
|
|
50
|
+
|
|
51
|
+
The `name` property is camel cased and used to access the variable from the session object.
|
|
52
|
+
|
|
48
53
|
#### Example
|
|
49
54
|
'dashboard_report_id' | 'report_name' | 'report_title' | 'json' | 'share_type' | 'share_id' | 'owner_id'
|
|
50
55
|
-- | ---- | ---- | ------- | -- | -- | --
|