@isoftdata/utility-dashboard-backend 1.4.7 → 1.5.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/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,6 +167,12 @@ 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) => {
160
177
  const queryParameterValues = parameterValues.reduce((acc, val) => {
161
178
  return val.queryValues ? {
@@ -179,9 +196,9 @@ const parameterizeQuery = (query, parameterValues) => {
179
196
  }
180
197
 
181
198
  module.exports = {
182
- formatReportMetadata: async(mysqlConnection, { report, chartsInReport }) => {
199
+ formatReportMetadata: async(mysqlConnection, { report, chartsInReport, session = {} }) => {
183
200
  try {
184
- const parameterValues = await loadOutputParameterValues(mysqlConnection, { definitionList: report.parameters, forClient: true })
201
+ const parameterValues = await loadOutputParameterValues(mysqlConnection, { definitionList: report.parameters, forClient: true, session })
185
202
 
186
203
  return {
187
204
  dashboardReportId: report.dashboardReportId,
@@ -197,9 +214,9 @@ module.exports = {
197
214
  throw err
198
215
  }
199
216
  },
200
- formatChartDataForReport: async(mysqlConnection, { reportParameters, chart, reportChart, parameterSelectionList }) => {
217
+ formatChartDataForReport: async(mysqlConnection, { reportParameters, chart, reportChart, parameterSelectionList, session = {} }) => {
201
218
  try {
202
- const parameterValues = await loadOutputParameterValues(mysqlConnection, { definitionList: reportParameters, selectionList: parameterSelectionList })
219
+ const parameterValues = await loadOutputParameterValues(mysqlConnection, { definitionList: reportParameters, selectionList: parameterSelectionList, session })
203
220
  if (reportChart?.jsonOverride?.chartWrapper?.dataTable) {
204
221
  const { dataTable, ...chartWrapper } = reportChart.jsonOverride.chartWrapper
205
222
  reportChart.jsonOverride.chartWrapper = chartWrapper
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isoftdata/utility-dashboard-backend",
3
- "version": "1.4.7",
3
+ "version": "1.5.0",
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 Properties
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 Properties
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 properties
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
  -- | ---- | ---- | ------- | -- | -- | --