@qrvey/utils 1.3.0-15 → 1.3.0-18

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/.eslintrc.json CHANGED
@@ -20,7 +20,9 @@
20
20
  "comma-spacing": "off",
21
21
  "semi": "off",
22
22
  "no-unused-vars": "off",
23
+ "no-shadow": "off",
23
24
 
25
+ "@typescript-eslint/no-shadow": ["error"],
24
26
  "@typescript-eslint/no-inferrable-types": "warn",
25
27
  "@typescript-eslint/object-curly-spacing": ["warn", "always"],
26
28
  "@typescript-eslint/no-extra-semi": ["warn"],
@@ -13,7 +13,7 @@ const getDatasetColumn_1 = require("./getDatasetColumn");
13
13
  function getDatasetColumnByDatasets(column, datasets) {
14
14
  if ((0, isEmpty_1.isEmpty)(column) || (0, isEmpty_1.isEmpty)(datasets))
15
15
  return;
16
- const dataset = datasets.find(dataset => dataset.qrveyid === column.qrveyid);
16
+ const dataset = datasets.find(_dataset => _dataset.qrveyid === column.qrveyid);
17
17
  return (0, getDatasetColumn_1.getDatasetColumn)(column, dataset);
18
18
  }
19
19
  exports.getDatasetColumnByDatasets = getDatasetColumnByDatasets;
@@ -29,8 +29,9 @@ exports.FDToLogic = FDToLogic;
29
29
  * @returns a filter logic array
30
30
  */
31
31
  function getLogicBodyFromFD21(filterData) {
32
- let logics = [];
33
- logics = filterData.scopes.reduce((logics, scope) => {
32
+ if ((0, isEmpty_1.isEmpty)(filterData))
33
+ return [];
34
+ return filterData.scopes.reduce((logics, scope) => {
34
35
  const logic = buildLogic(scope);
35
36
  let filters = [];
36
37
  if (scope.datasets.length > 0) {
@@ -42,7 +43,6 @@ function getLogicBodyFromFD21(filterData) {
42
43
  logics.push(Object.assign(Object.assign({}, logic), { filters }));
43
44
  return logics;
44
45
  }, []);
45
- return logics;
46
46
  }
47
47
  function buildLogic(scopeSection) {
48
48
  return {
@@ -14,8 +14,8 @@ function getFiltersByDatasetsColumns(data, datasets = []) {
14
14
  return;
15
15
  if ((0, isEmpty_1.isEmpty)(datasets))
16
16
  return data;
17
- return Object.assign(Object.assign({}, data), { scopes: data.scopes.map(scope => (Object.assign(Object.assign({}, scope), { datasets: scope.datasets.map(filterDataset => {
18
- const dataset = datasets.find(data => data.qrveyid === filterDataset.qrveyid);
17
+ const newData = Object.assign(Object.assign({}, data), { scopes: data.scopes.map(scope => (Object.assign(Object.assign({}, scope), { datasets: scope.datasets.map(filterDataset => {
18
+ const dataset = datasets.find(_data => _data.qrveyid === filterDataset.qrveyid);
19
19
  if (!(0, isEmpty_1.isEmpty)(dataset)) {
20
20
  return Object.assign(Object.assign({}, filterDataset), { filters: filterDataset.filters.map(filter => {
21
21
  const column = (dataset.options || []).find(cInfo => cInfo.id === filter.column.id && cInfo.qrveyid === filter.column.qrveyid);
@@ -25,5 +25,8 @@ function getFiltersByDatasetsColumns(data, datasets = []) {
25
25
  }).filter(Boolean) });
26
26
  }
27
27
  }).filter(dataset => !(0, isEmpty_1.isEmpty)(dataset) && dataset.filters.length > 0) }))).filter(scope => !(0, isEmpty_1.isEmpty)(scope) && scope.datasets.length > 0) });
28
+ if (!(0, isEmpty_1.isEmpty)(newData) && newData.scopes.length > 0) {
29
+ return newData;
30
+ }
28
31
  }
29
32
  exports.getFiltersByDatasetsColumns = getFiltersByDatasetsColumns;
@@ -100,7 +100,8 @@ class FiltersApi {
100
100
  var _a;
101
101
  const scopes = this.getAvailableScopeIds(config);
102
102
  let filterData = (0, getFiltersByVisibility_1.getFiltersByVisibility)(config.filterData, scopes);
103
- filterData = (0, getFiltersByDatasetsColumns_1.getFiltersByDatasetsColumns)(filterData, config.datasets);
103
+ const dataset = config.datasets.find(d => { var _a; return d.qrveyid === ((_a = config.filter) === null || _a === void 0 ? void 0 : _a.column.qrveyid); });
104
+ filterData = (0, getFiltersByDatasetsColumns_1.getFiltersByDatasetsColumns)(filterData, (0, isEmpty_1.isEmpty)(dataset) ? [] : [dataset]);
104
105
  filterData = (0, excludeFiltersByAggregateColumn_1.excludeFiltersByAggregateColumn)(filterData);
105
106
  const logics = (0, FDToLogic_1.FDToLogic)(filterData);
106
107
  const hierarchyLogic = (0, getLogicByScopesHierarchy_1.getLogicByScopesHierarchy)(logics, scopes, (_a = config.filter) === null || _a === void 0 ? void 0 : _a.extras.scope);
@@ -29,7 +29,7 @@ function getI18nMonthLabel(label, translate) {
29
29
  }
30
30
  function getI18nYearMonthLabel(label, translate) {
31
31
  if (!(0, isTokenLabel_1.isTokenLabel)(label) && !(0, isEmpty_1.isEmpty)(translate)) {
32
- const month = getI18nMonthPropertyByIndex(DATE_YEAR_MONTHS_1.DATE_YEAR_MONTHS.findIndex(month => month === label));
32
+ const month = getI18nMonthPropertyByIndex(DATE_YEAR_MONTHS_1.DATE_YEAR_MONTHS.findIndex(_month => _month === label));
33
33
  if (!(0, isEmpty_1.isEmpty)(month))
34
34
  label = translate('common.date_grouping.' + month + '_mmm');
35
35
  }
@@ -11,9 +11,9 @@ const BColumnsToUIColumns_adapter_1 = require("./BColumnsToUIColumns.adapter");
11
11
  function BBranchesMapToUIBranchesMap(branchesMap) {
12
12
  if ((0, isEmpty_1.isEmpty)(branchesMap))
13
13
  return [];
14
- return branchesMap.map(branchesMap => ({
15
- questionid: branchesMap.questionid,
16
- branches: branchesMap.branches.map(branch => ({
14
+ return branchesMap.map(branchMap => ({
15
+ questionid: branchMap.questionid,
16
+ branches: branchMap.branches.map(branch => ({
17
17
  columns: (0, BColumnsToUIColumns_adapter_1.BColumnsToUIColumns)(branch.questions.data)
18
18
  }))
19
19
  }));
@@ -10,6 +10,6 @@ import { getDatasetColumn } from "./getDatasetColumn";
10
10
  export function getDatasetColumnByDatasets(column, datasets) {
11
11
  if (isEmpty(column) || isEmpty(datasets))
12
12
  return;
13
- const dataset = datasets.find(dataset => dataset.qrveyid === column.qrveyid);
13
+ const dataset = datasets.find(_dataset => _dataset.qrveyid === column.qrveyid);
14
14
  return getDatasetColumn(column, dataset);
15
15
  }
@@ -25,8 +25,9 @@ export function FDToLogic(filterData) {
25
25
  * @returns a filter logic array
26
26
  */
27
27
  function getLogicBodyFromFD21(filterData) {
28
- let logics = [];
29
- logics = filterData.scopes.reduce((logics, scope) => {
28
+ if (isEmpty(filterData))
29
+ return [];
30
+ return filterData.scopes.reduce((logics, scope) => {
30
31
  const logic = buildLogic(scope);
31
32
  let filters = [];
32
33
  if (scope.datasets.length > 0) {
@@ -38,7 +39,6 @@ function getLogicBodyFromFD21(filterData) {
38
39
  logics.push(Object.assign(Object.assign({}, logic), { filters }));
39
40
  return logics;
40
41
  }, []);
41
- return logics;
42
42
  }
43
43
  function buildLogic(scopeSection) {
44
44
  return {
@@ -11,8 +11,8 @@ export function getFiltersByDatasetsColumns(data, datasets = []) {
11
11
  return;
12
12
  if (isEmpty(datasets))
13
13
  return data;
14
- return Object.assign(Object.assign({}, data), { scopes: data.scopes.map(scope => (Object.assign(Object.assign({}, scope), { datasets: scope.datasets.map(filterDataset => {
15
- const dataset = datasets.find(data => data.qrveyid === filterDataset.qrveyid);
14
+ const newData = Object.assign(Object.assign({}, data), { scopes: data.scopes.map(scope => (Object.assign(Object.assign({}, scope), { datasets: scope.datasets.map(filterDataset => {
15
+ const dataset = datasets.find(_data => _data.qrveyid === filterDataset.qrveyid);
16
16
  if (!isEmpty(dataset)) {
17
17
  return Object.assign(Object.assign({}, filterDataset), { filters: filterDataset.filters.map(filter => {
18
18
  const column = (dataset.options || []).find(cInfo => cInfo.id === filter.column.id && cInfo.qrveyid === filter.column.qrveyid);
@@ -22,4 +22,7 @@ export function getFiltersByDatasetsColumns(data, datasets = []) {
22
22
  }).filter(Boolean) });
23
23
  }
24
24
  }).filter(dataset => !isEmpty(dataset) && dataset.filters.length > 0) }))).filter(scope => !isEmpty(scope) && scope.datasets.length > 0) });
25
+ if (!isEmpty(newData) && newData.scopes.length > 0) {
26
+ return newData;
27
+ }
25
28
  }
@@ -94,7 +94,8 @@ export class FiltersApi {
94
94
  var _a;
95
95
  const scopes = this.getAvailableScopeIds(config);
96
96
  let filterData = getFiltersByVisibility(config.filterData, scopes);
97
- filterData = getFiltersByDatasetsColumns(filterData, config.datasets);
97
+ const dataset = config.datasets.find(d => { var _a; return d.qrveyid === ((_a = config.filter) === null || _a === void 0 ? void 0 : _a.column.qrveyid); });
98
+ filterData = getFiltersByDatasetsColumns(filterData, isEmpty(dataset) ? [] : [dataset]);
98
99
  filterData = excludeFiltersByAggregateColumn(filterData);
99
100
  const logics = FDToLogic(filterData);
100
101
  const hierarchyLogic = getLogicByScopesHierarchy(logics, scopes, (_a = config.filter) === null || _a === void 0 ? void 0 : _a.extras.scope);
@@ -25,7 +25,7 @@ function getI18nMonthLabel(label, translate) {
25
25
  }
26
26
  function getI18nYearMonthLabel(label, translate) {
27
27
  if (!isTokenLabel(label) && !isEmpty(translate)) {
28
- const month = getI18nMonthPropertyByIndex(DATE_YEAR_MONTHS.findIndex(month => month === label));
28
+ const month = getI18nMonthPropertyByIndex(DATE_YEAR_MONTHS.findIndex(_month => _month === label));
29
29
  if (!isEmpty(month))
30
30
  label = translate('common.date_grouping.' + month + '_mmm');
31
31
  }
@@ -8,9 +8,9 @@ import { BColumnsToUIColumns } from "./BColumnsToUIColumns.adapter";
8
8
  export function BBranchesMapToUIBranchesMap(branchesMap) {
9
9
  if (isEmpty(branchesMap))
10
10
  return [];
11
- return branchesMap.map(branchesMap => ({
12
- questionid: branchesMap.questionid,
13
- branches: branchesMap.branches.map(branch => ({
11
+ return branchesMap.map(branchMap => ({
12
+ questionid: branchMap.questionid,
13
+ branches: branchMap.branches.map(branch => ({
14
14
  columns: BColumnsToUIColumns(branch.questions.data)
15
15
  }))
16
16
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.3.0-15",
3
+ "version": "1.3.0-18",
4
4
  "description": "Helper, Utils for all Qrvey Projects",
5
5
  "homepage": "https://bitbucket.org/qrvey/qrvey_utils/wiki/Home",
6
6
  "main": "dist/index.js",
@@ -14,6 +14,6 @@ import { getDatasetColumn } from "./getDatasetColumn";
14
14
  export function getDatasetColumnByDatasets(column: Partial<IColumn>, datasets: IDataset[]): IColumn {
15
15
  if (isEmpty(column) || isEmpty(datasets)) return;
16
16
 
17
- const dataset = datasets.find(dataset => dataset.qrveyid === column.qrveyid);
17
+ const dataset = datasets.find(_dataset => _dataset.qrveyid === column.qrveyid);
18
18
  return getDatasetColumn(column, dataset);
19
19
  }
@@ -33,8 +33,9 @@ export function FDToLogic(filterData: IFSData): IFBLogic[] {
33
33
  * @returns a filter logic array
34
34
  */
35
35
  function getLogicBodyFromFD21(filterData: IFSData): IFBLogic[] {
36
- let logics = [];
37
- logics = filterData.scopes.reduce((logics: IFBLogic[], scope: IFSScope) => {
36
+ if (isEmpty(filterData)) return [];
37
+
38
+ return filterData.scopes.reduce((logics: IFBLogic[], scope: IFSScope) => {
38
39
  const logic: IFBLogic = buildLogic(scope);
39
40
  let filters: IFBFilter[] = [];
40
41
  if (scope.datasets.length > 0) {
@@ -45,9 +46,8 @@ function getLogicBodyFromFD21(filterData: IFSData): IFBLogic[] {
45
46
  }
46
47
  logics.push({ ...logic, filters });
47
48
  return logics;
48
- }, [] as IFBLogic[]);
49
- return logics;
50
- }
49
+ }, [] as IFBLogic[]);
50
+ }
51
51
 
52
52
  function buildLogic(scopeSection: IFSScope): IFBLogic {
53
53
  return {
@@ -13,12 +13,12 @@ export function getFiltersByDatasetsColumns(data: IFUData, datasets: IDataset[]
13
13
  if (isEmpty(data) || isEmpty(data.scopes)) return;
14
14
  if (isEmpty(datasets)) return data;
15
15
 
16
- return {
16
+ const newData = {
17
17
  ...data,
18
18
  scopes: data.scopes.map(scope => ({
19
19
  ...scope,
20
20
  datasets: scope.datasets.map(filterDataset => {
21
- const dataset = datasets.find(data => data.qrveyid === filterDataset.qrveyid);
21
+ const dataset = datasets.find(_data => _data.qrveyid === filterDataset.qrveyid);
22
22
  if (!isEmpty(dataset)) {
23
23
  return {
24
24
  ...filterDataset,
@@ -33,4 +33,8 @@ export function getFiltersByDatasetsColumns(data: IFUData, datasets: IDataset[]
33
33
  }).filter(dataset => !isEmpty(dataset) && dataset.filters.length > 0)
34
34
  })).filter(scope => !isEmpty(scope) && scope.datasets.length > 0)
35
35
  };
36
+
37
+ if (!isEmpty(newData) && newData.scopes.length > 0) {
38
+ return newData;
39
+ }
36
40
  }
@@ -109,7 +109,8 @@ export class FiltersApi {
109
109
  private getLogic(config: IFSGetDataValues) {
110
110
  const scopes = this.getAvailableScopeIds(config);
111
111
  let filterData = getFiltersByVisibility(config.filterData, scopes);
112
- filterData = getFiltersByDatasetsColumns(filterData as IFUData, config.datasets);
112
+ const dataset = config.datasets.find(d => d.qrveyid === config.filter?.column.qrveyid);
113
+ filterData = getFiltersByDatasetsColumns(filterData as IFUData, isEmpty(dataset) ? [] : [dataset]);
113
114
  filterData = excludeFiltersByAggregateColumn(filterData);
114
115
  const logics = FDToLogic(filterData);
115
116
  const hierarchyLogic = getLogicByScopesHierarchy(logics, scopes, config.filter?.extras.scope);
@@ -30,7 +30,7 @@ function getI18nMonthLabel(label: string, translate?: II18nServiceTranslate): st
30
30
 
31
31
  function getI18nYearMonthLabel(label: string, translate?: II18nServiceTranslate): string {
32
32
  if (!isTokenLabel(label) && !isEmpty(translate)) {
33
- const month = getI18nMonthPropertyByIndex(DATE_YEAR_MONTHS.findIndex(month => month === label));
33
+ const month = getI18nMonthPropertyByIndex(DATE_YEAR_MONTHS.findIndex(_month => _month === label));
34
34
  if (!isEmpty(month)) label = translate('common.date_grouping.' + month + '_mmm');
35
35
  }
36
36
  return label;
@@ -11,9 +11,9 @@ import { BColumnsToUIColumns } from "./BColumnsToUIColumns.adapter";
11
11
  export function BBranchesMapToUIBranchesMap(branchesMap: IBModelBranchesMap[]): IModelBranchesMap[] {
12
12
  if (isEmpty(branchesMap)) return [];
13
13
 
14
- return branchesMap.map(branchesMap => ({
15
- questionid: branchesMap.questionid,
16
- branches: branchesMap.branches.map(branch => ({
14
+ return branchesMap.map(branchMap => ({
15
+ questionid: branchMap.questionid,
16
+ branches: branchMap.branches.map(branch => ({
17
17
  columns: BColumnsToUIColumns(branch.questions.data)
18
18
  }))
19
19
  }));