@ministryofjustice/hmpps-digital-prison-reporting-frontend 3.5.1 → 3.5.2
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/dpr/all.scss +0 -0
- package/dpr/assets/css/all.css +0 -0
- package/dpr/components/filters/utils.js +40 -9
- package/dpr/components/filters/utils.ts +43 -9
- package/package.json +1 -1
- package/package.zip +0 -0
package/dpr/all.scss
CHANGED
|
File without changes
|
package/dpr/assets/css/all.css
CHANGED
|
File without changes
|
|
@@ -10,6 +10,31 @@ const filterHasValue = (value) => {
|
|
|
10
10
|
const getFilterValue = (filterValues, name) => {
|
|
11
11
|
return filterHasValue(filterValues[name]) ? filterValues[name] : null;
|
|
12
12
|
};
|
|
13
|
+
const setMinMax = (filter, startValue, endValue) => {
|
|
14
|
+
const { min, max } = filter;
|
|
15
|
+
let start;
|
|
16
|
+
if (min) {
|
|
17
|
+
const minDate = new Date(min);
|
|
18
|
+
const startDate = new Date(startValue);
|
|
19
|
+
start = startDate < minDate ? min : startValue;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
start = startValue;
|
|
23
|
+
}
|
|
24
|
+
let end;
|
|
25
|
+
if (max) {
|
|
26
|
+
const maxDate = new Date(max);
|
|
27
|
+
const endDate = new Date(endValue);
|
|
28
|
+
end = endDate > maxDate ? max : endValue;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
end = endValue;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
start,
|
|
35
|
+
end,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
13
38
|
exports.default = {
|
|
14
39
|
getFilters: (variantDefinition, filterValues, dynamicAutocompleteEndpoint = null) => variantDefinition.specification.fields
|
|
15
40
|
.filter((f) => f.filter)
|
|
@@ -28,12 +53,15 @@ exports.default = {
|
|
|
28
53
|
: dynamicAutocompleteEndpoint.replace('{fieldName}', f.name),
|
|
29
54
|
};
|
|
30
55
|
if (f.filter.type === enum_1.FilterType.dateRange.toLowerCase()) {
|
|
56
|
+
const startValue = getFilterValue(filterValues, `${f.name}.start`);
|
|
57
|
+
const endValue = getFilterValue(filterValues, `${f.name}.end`);
|
|
58
|
+
const { start, end } = setMinMax(f.filter, startValue, endValue);
|
|
31
59
|
filter = filter;
|
|
32
60
|
filter = {
|
|
33
61
|
...filter,
|
|
34
62
|
value: {
|
|
35
|
-
start
|
|
36
|
-
end
|
|
63
|
+
start,
|
|
64
|
+
end,
|
|
37
65
|
},
|
|
38
66
|
min: f.filter.min,
|
|
39
67
|
max: f.filter.max,
|
|
@@ -50,16 +78,19 @@ exports.default = {
|
|
|
50
78
|
.map((f) => {
|
|
51
79
|
let filterValueText = getFilterValue(reportQuery.filters, f.name);
|
|
52
80
|
if (f.filter.type === enum_1.FilterType.dateRange.toLowerCase()) {
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
81
|
+
const startValue = getFilterValue(reportQuery.filters, `${f.name}.start`);
|
|
82
|
+
const endValue = getFilterValue(reportQuery.filters, `${f.name}.end`);
|
|
83
|
+
const { start, end } = setMinMax(f.filter, startValue, endValue);
|
|
84
|
+
const localeStart = toLocaleDate(start);
|
|
85
|
+
const localeEnd = toLocaleDate(end);
|
|
86
|
+
if (localeStart && localeEnd) {
|
|
87
|
+
filterValueText = `${localeStart} - ${localeEnd}`;
|
|
57
88
|
}
|
|
58
|
-
else if (
|
|
59
|
-
filterValueText = `From ${
|
|
89
|
+
else if (localeStart) {
|
|
90
|
+
filterValueText = `From ${localeStart}`;
|
|
60
91
|
}
|
|
61
92
|
else {
|
|
62
|
-
filterValueText = `Until ${
|
|
93
|
+
filterValueText = `Until ${localeEnd}`;
|
|
63
94
|
}
|
|
64
95
|
}
|
|
65
96
|
else if (f.filter.staticOptions) {
|
|
@@ -17,6 +17,32 @@ const getFilterValue = (filterValues: Dict<string>, name: string) => {
|
|
|
17
17
|
return filterHasValue(filterValues[name]) ? filterValues[name] : null
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
const setMinMax = (filter: components['schemas']['FilterDefinition'], startValue: string, endValue: string) => {
|
|
21
|
+
const { min, max } = filter
|
|
22
|
+
let start
|
|
23
|
+
if (min) {
|
|
24
|
+
const minDate = new Date(min)
|
|
25
|
+
const startDate = new Date(startValue)
|
|
26
|
+
start = startDate < minDate ? min : startValue
|
|
27
|
+
} else {
|
|
28
|
+
start = startValue
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let end
|
|
32
|
+
if (max) {
|
|
33
|
+
const maxDate = new Date(max)
|
|
34
|
+
const endDate = new Date(endValue)
|
|
35
|
+
end = endDate > maxDate ? max : endValue
|
|
36
|
+
} else {
|
|
37
|
+
end = endValue
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
start,
|
|
42
|
+
end,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
20
46
|
export default {
|
|
21
47
|
getFilters: (
|
|
22
48
|
variantDefinition: components['schemas']['VariantDefinition'],
|
|
@@ -42,12 +68,16 @@ export default {
|
|
|
42
68
|
}
|
|
43
69
|
|
|
44
70
|
if (f.filter.type === FilterType.dateRange.toLowerCase()) {
|
|
71
|
+
const startValue = getFilterValue(filterValues, `${f.name}.start`)
|
|
72
|
+
const endValue = getFilterValue(filterValues, `${f.name}.end`)
|
|
73
|
+
const { start, end } = setMinMax(f.filter, startValue, endValue)
|
|
74
|
+
|
|
45
75
|
filter = filter as unknown as DateFilterValue
|
|
46
76
|
filter = {
|
|
47
77
|
...filter,
|
|
48
78
|
value: {
|
|
49
|
-
start
|
|
50
|
-
end
|
|
79
|
+
start,
|
|
80
|
+
end,
|
|
51
81
|
},
|
|
52
82
|
min: f.filter.min,
|
|
53
83
|
max: f.filter.max,
|
|
@@ -75,16 +105,20 @@ export default {
|
|
|
75
105
|
)
|
|
76
106
|
.map((f) => {
|
|
77
107
|
let filterValueText = getFilterValue(reportQuery.filters, f.name)
|
|
108
|
+
|
|
78
109
|
if (f.filter.type === FilterType.dateRange.toLowerCase()) {
|
|
79
|
-
const
|
|
80
|
-
const
|
|
110
|
+
const startValue = getFilterValue(reportQuery.filters, `${f.name}.start`)
|
|
111
|
+
const endValue = getFilterValue(reportQuery.filters, `${f.name}.end`)
|
|
112
|
+
const { start, end } = setMinMax(f.filter, startValue, endValue)
|
|
113
|
+
const localeStart = toLocaleDate(start)
|
|
114
|
+
const localeEnd = toLocaleDate(end)
|
|
81
115
|
|
|
82
|
-
if (
|
|
83
|
-
filterValueText = `${
|
|
84
|
-
} else if (
|
|
85
|
-
filterValueText = `From ${
|
|
116
|
+
if (localeStart && localeEnd) {
|
|
117
|
+
filterValueText = `${localeStart} - ${localeEnd}`
|
|
118
|
+
} else if (localeStart) {
|
|
119
|
+
filterValueText = `From ${localeStart}`
|
|
86
120
|
} else {
|
|
87
|
-
filterValueText = `Until ${
|
|
121
|
+
filterValueText = `Until ${localeEnd}`
|
|
88
122
|
}
|
|
89
123
|
} else if (f.filter.staticOptions) {
|
|
90
124
|
filterValueText = f.filter.staticOptions.find((o) => o.name === filterValueText).display
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ministryofjustice/hmpps-digital-prison-reporting-frontend",
|
|
3
3
|
"description": "The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.",
|
|
4
|
-
"version": "3.5.
|
|
4
|
+
"version": "3.5.2",
|
|
5
5
|
"main": "dpr/assets/js/all.mjs",
|
|
6
6
|
"sass": "dpr/all.scss",
|
|
7
7
|
"engines": {
|
package/package.zip
CHANGED
|
Binary file
|