ehr-alerts-ui 0.0.26 → 0.0.28
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/.husky/pre-commit +4 -0
- package/.prettierrc +13 -0
- package/lib/index.cjs.js +1 -1
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +20 -9
- package/src/App.tsx +21 -23
- package/src/Reducer.ts +1 -0
- package/src/index.tsx +1 -2
- package/src/library/actions/AlertActions.ts +91 -66
- package/src/library/actions/TableActions.ts +55 -54
- package/src/library/components/AlertModal/AlertModal.tsx +251 -152
- package/src/library/components/AlertModal/AlertModalContainer.tsx +16 -14
- package/src/library/components/AlertModal/index.ts +1 -1
- package/src/library/components/AlertsTable/AlertsTable.tsx +144 -66
- package/src/library/components/AlertsTable/AlertsTableContainer.tsx +37 -24
- package/src/library/components/AlertsTable/SortableRow/SortableRow.tsx +53 -33
- package/src/library/components/AlertsTable/SortableRow/index.ts +1 -1
- package/src/library/components/AlertsTable/index.ts +1 -1
- package/src/library/components/Header/Header.tsx +11 -12
- package/src/library/components/Header/HeaderContainer.tsx +13 -11
- package/src/library/components/Header/index.ts +1 -1
- package/src/library/components/MainPage/MainPage.tsx +59 -24
- package/src/library/components/MainPage/index.ts +2 -2
- package/src/library/configureStore.ts +12 -14
- package/src/library/helpers/appendZero.ts +1 -1
- package/src/library/helpers/printDate.ts +1 -1
- package/src/library/index.ts +1 -1
- package/src/library/reducers/alertReducer.ts +19 -20
- package/src/library/reducers/index.ts +16 -6
- package/src/library/reducers/tableReducer.ts +32 -33
- package/src/react-app-env.d.ts +1 -1
- package/src/setupProxy.js +9 -7
- package/src/translations/elements_et.json +231 -244
- package/tsconfig.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {Action} from
|
|
2
|
-
import {Alert, Audience} from
|
|
3
|
-
import {ThunkAction} from
|
|
4
|
-
import {AlertsUiState} from
|
|
5
|
-
import Axios from
|
|
6
|
-
import {clearTable, loadAlerts, TableActions} from
|
|
7
|
-
import {AlertModalError} from
|
|
8
|
-
import appendZero from
|
|
1
|
+
import { Action } from 'redux';
|
|
2
|
+
import { Alert, Audience } from '../reducers/tableReducer';
|
|
3
|
+
import { ThunkAction } from 'redux-thunk';
|
|
4
|
+
import { AlertsUiState } from '../reducers';
|
|
5
|
+
import Axios from 'axios';
|
|
6
|
+
import { clearTable, loadAlerts, TableActions } from './TableActions';
|
|
7
|
+
import { AlertModalError } from '../reducers/alertReducer';
|
|
8
|
+
import appendZero from '../helpers/appendZero';
|
|
9
9
|
|
|
10
10
|
export enum AlertActionsType {
|
|
11
11
|
CREATE_ALERT = 'CREATE_ALERT',
|
|
@@ -16,31 +16,32 @@ export enum AlertActionsType {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
interface AlertSimpleAction extends Action {
|
|
19
|
-
type:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
type:
|
|
20
|
+
| AlertActionsType.CREATE_ALERT
|
|
21
|
+
| AlertActionsType.CLEAR_ALERT
|
|
22
|
+
| AlertActionsType.CLEAR_ALERT_MODAL_ERRORS;
|
|
23
|
+
payload: {};
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export function createAlert(): AlertSimpleAction {
|
|
26
27
|
return {
|
|
27
28
|
type: AlertActionsType.CREATE_ALERT,
|
|
28
29
|
payload: {},
|
|
29
|
-
}
|
|
30
|
+
};
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export function clearAlert(): AlertSimpleAction {
|
|
33
34
|
return {
|
|
34
35
|
type: AlertActionsType.CLEAR_ALERT,
|
|
35
36
|
payload: {},
|
|
36
|
-
}
|
|
37
|
+
};
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
interface AlertEdit extends Action {
|
|
40
|
-
type: AlertActionsType.EDIT_ALERT
|
|
41
|
+
type: AlertActionsType.EDIT_ALERT;
|
|
41
42
|
payload: {
|
|
42
|
-
alert: Alert
|
|
43
|
-
}
|
|
43
|
+
alert: Alert;
|
|
44
|
+
};
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
export function editAlert(alert: Alert): AlertEdit {
|
|
@@ -48,15 +49,15 @@ export function editAlert(alert: Alert): AlertEdit {
|
|
|
48
49
|
type: AlertActionsType.EDIT_ALERT,
|
|
49
50
|
payload: {
|
|
50
51
|
alert,
|
|
51
|
-
}
|
|
52
|
-
}
|
|
52
|
+
},
|
|
53
|
+
};
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
interface AddAlertModalError {
|
|
56
|
-
type: AlertActionsType.ADD_ALERT_MODAL_ERROR
|
|
57
|
+
type: AlertActionsType.ADD_ALERT_MODAL_ERROR;
|
|
57
58
|
payload: {
|
|
58
|
-
error: AlertModalError
|
|
59
|
-
}
|
|
59
|
+
error: AlertModalError;
|
|
60
|
+
};
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
export function addAlertModalError(error: AlertModalError): AddAlertModalError {
|
|
@@ -64,43 +65,53 @@ export function addAlertModalError(error: AlertModalError): AddAlertModalError {
|
|
|
64
65
|
type: AlertActionsType.ADD_ALERT_MODAL_ERROR,
|
|
65
66
|
payload: {
|
|
66
67
|
error,
|
|
67
|
-
}
|
|
68
|
-
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
export function clearAlertModalErrors(): AlertSimpleAction {
|
|
72
73
|
return {
|
|
73
74
|
type: AlertActionsType.CLEAR_ALERT_MODAL_ERRORS,
|
|
74
|
-
payload: {
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
}
|
|
75
|
+
payload: {},
|
|
76
|
+
};
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
export type AlertActions = AlertSimpleAction | AlertEdit | AddAlertModalError;
|
|
81
80
|
|
|
82
|
-
export function updateAlert(): ThunkAction<
|
|
81
|
+
export function updateAlert(): ThunkAction<
|
|
82
|
+
void,
|
|
83
|
+
AlertsUiState,
|
|
84
|
+
unknown,
|
|
85
|
+
AlertActions | TableActions
|
|
86
|
+
> {
|
|
83
87
|
return (dispatch, getState) => {
|
|
84
88
|
const alert = getState().alert.alert;
|
|
85
89
|
if (!alert || alert.id === 0) {
|
|
86
90
|
return;
|
|
87
91
|
}
|
|
88
92
|
|
|
89
|
-
const begin = applyHour(
|
|
90
|
-
|
|
93
|
+
const begin = applyHour(
|
|
94
|
+
alert.beginHour,
|
|
95
|
+
applyMinutes(alert.beginMinute, alert.begin),
|
|
96
|
+
);
|
|
97
|
+
const end = applyHour(
|
|
98
|
+
alert.endHour,
|
|
99
|
+
applyMinutes(alert.endMinute, alert.end),
|
|
100
|
+
);
|
|
91
101
|
|
|
92
102
|
// Lazy convert to local time
|
|
93
103
|
const beginDate = toLocalString(begin);
|
|
94
104
|
console.log(beginDate);
|
|
95
105
|
const endDate = toLocalString(end);
|
|
96
106
|
|
|
97
|
-
|
|
98
107
|
Axios({
|
|
99
|
-
method:
|
|
100
|
-
url:
|
|
108
|
+
method: 'put',
|
|
109
|
+
url:
|
|
110
|
+
(window as any).APP_URL_APP +
|
|
111
|
+
`/api/yld-teated/v1/api/message/${alert.id}`,
|
|
101
112
|
data: JSON.stringify({
|
|
102
113
|
id: 0,
|
|
103
|
-
code:
|
|
114
|
+
code: '',
|
|
104
115
|
title: alert.title,
|
|
105
116
|
body: alert.content,
|
|
106
117
|
open: alert.audience === Audience.NOT_AUTHENTICATED,
|
|
@@ -110,52 +121,62 @@ export function updateAlert(): ThunkAction<void, AlertsUiState, unknown, AlertAc
|
|
|
110
121
|
}),
|
|
111
122
|
headers: {
|
|
112
123
|
'Content-Type': 'Application/JSON',
|
|
113
|
-
}
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
124
|
+
},
|
|
125
|
+
}).then(() => {
|
|
126
|
+
dispatch(clearAlert());
|
|
127
|
+
dispatch(clearTable());
|
|
128
|
+
dispatch(loadAlerts());
|
|
129
|
+
});
|
|
130
|
+
};
|
|
121
131
|
}
|
|
122
132
|
|
|
123
|
-
export function postAlert(): ThunkAction<
|
|
133
|
+
export function postAlert(): ThunkAction<
|
|
134
|
+
void,
|
|
135
|
+
AlertsUiState,
|
|
136
|
+
unknown,
|
|
137
|
+
AlertActions | TableActions
|
|
138
|
+
> {
|
|
124
139
|
return (dispatch, getState) => {
|
|
125
140
|
const alert = getState().alert.alert;
|
|
126
141
|
if (!alert) {
|
|
127
142
|
return;
|
|
128
143
|
}
|
|
129
144
|
|
|
130
|
-
const begin = toLocalString(
|
|
131
|
-
|
|
145
|
+
const begin = toLocalString(
|
|
146
|
+
applyHour(alert.beginHour, applyMinutes(alert.beginMinute, alert.begin)),
|
|
147
|
+
);
|
|
148
|
+
const end = toLocalString(
|
|
149
|
+
applyHour(alert.endHour, applyMinutes(alert.endMinute, alert.end)),
|
|
150
|
+
);
|
|
132
151
|
|
|
133
152
|
Axios({
|
|
134
|
-
method:
|
|
153
|
+
method: 'post',
|
|
135
154
|
url: (window as any).APP_URL_APP + '/api/yld-teated/v1/api/message',
|
|
136
155
|
data: JSON.stringify({
|
|
137
156
|
id: 0,
|
|
138
|
-
code:
|
|
157
|
+
code: '',
|
|
139
158
|
title: alert.title,
|
|
140
159
|
body: alert.content,
|
|
141
160
|
open: alert.audience === Audience.NOT_AUTHENTICATED,
|
|
142
161
|
level: alert.level,
|
|
143
162
|
begin: begin,
|
|
144
|
-
end: end
|
|
163
|
+
end: end,
|
|
145
164
|
}),
|
|
146
165
|
headers: {
|
|
147
166
|
'Content-Type': 'Application/JSON',
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
167
|
+
},
|
|
168
|
+
}).then(() => {
|
|
169
|
+
dispatch(clearAlert());
|
|
170
|
+
dispatch(clearTable());
|
|
171
|
+
dispatch(loadAlerts());
|
|
172
|
+
});
|
|
173
|
+
};
|
|
156
174
|
}
|
|
157
175
|
|
|
158
|
-
function applyHour(
|
|
176
|
+
function applyHour(
|
|
177
|
+
value: number | undefined,
|
|
178
|
+
oldDate: Date | string | undefined,
|
|
179
|
+
): Date {
|
|
159
180
|
let hour = value || 0;
|
|
160
181
|
if (hour < 0 || hour > 23) {
|
|
161
182
|
hour = 23;
|
|
@@ -166,11 +187,13 @@ function applyHour(value: number | undefined, oldDate: Date | string | undefined
|
|
|
166
187
|
return newDate;
|
|
167
188
|
}
|
|
168
189
|
|
|
169
|
-
function applyMinutes(
|
|
170
|
-
|
|
190
|
+
function applyMinutes(
|
|
191
|
+
value: number | undefined,
|
|
192
|
+
oldDate: Date | string | undefined,
|
|
193
|
+
): Date {
|
|
171
194
|
let minutes = value || 0;
|
|
172
195
|
if (minutes < 0 || minutes > 59) {
|
|
173
|
-
minutes = 59
|
|
196
|
+
minutes = 59;
|
|
174
197
|
}
|
|
175
198
|
|
|
176
199
|
const newDate = new Date(oldDate || '');
|
|
@@ -180,8 +203,10 @@ function applyMinutes(value: number | undefined, oldDate: Date | string | undefi
|
|
|
180
203
|
}
|
|
181
204
|
|
|
182
205
|
function toLocalString(date: Date): string {
|
|
183
|
-
return
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
206
|
+
return (
|
|
207
|
+
`${date.getUTCFullYear()}-` +
|
|
208
|
+
`${appendZero((date.getUTCMonth() + 1).toString())}-` +
|
|
209
|
+
`${appendZero(date.getDate().toString())}` +
|
|
210
|
+
`T${date.toLocaleTimeString()}`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {Alert, Audience} from
|
|
2
|
-
import {ThunkAction} from
|
|
1
|
+
import { Alert, Audience } from '../reducers/tableReducer';
|
|
2
|
+
import { ThunkAction } from 'redux-thunk';
|
|
3
3
|
import Axios from 'axios';
|
|
4
|
-
import {AlertsUiState} from
|
|
5
|
-
import printDate from
|
|
4
|
+
import { AlertsUiState } from '../reducers';
|
|
5
|
+
import printDate from '../helpers/printDate';
|
|
6
6
|
|
|
7
7
|
export enum TableActionsType {
|
|
8
8
|
ADD_ALERT = 'ADD_ALERT',
|
|
@@ -12,10 +12,10 @@ export enum TableActionsType {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
interface AddAlert {
|
|
15
|
-
type: TableActionsType.ADD_ALERT
|
|
15
|
+
type: TableActionsType.ADD_ALERT;
|
|
16
16
|
payload: {
|
|
17
|
-
alert: Alert
|
|
18
|
-
}
|
|
17
|
+
alert: Alert;
|
|
18
|
+
};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function addAlert(alert: Alert): AddAlert {
|
|
@@ -24,30 +24,26 @@ export function addAlert(alert: Alert): AddAlert {
|
|
|
24
24
|
payload: {
|
|
25
25
|
alert,
|
|
26
26
|
},
|
|
27
|
-
}
|
|
27
|
+
};
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
interface ClearTable {
|
|
31
|
-
type: TableActionsType.CLEAR_TABLE | TableActionsType.CLEAR_DELETES
|
|
32
|
-
payload: {
|
|
33
|
-
|
|
34
|
-
},
|
|
31
|
+
type: TableActionsType.CLEAR_TABLE | TableActionsType.CLEAR_DELETES;
|
|
32
|
+
payload: {};
|
|
35
33
|
}
|
|
36
34
|
|
|
37
35
|
export function clearTable(): ClearTable {
|
|
38
36
|
return {
|
|
39
37
|
type: TableActionsType.CLEAR_TABLE,
|
|
40
|
-
payload: {
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
}
|
|
38
|
+
payload: {},
|
|
39
|
+
};
|
|
44
40
|
}
|
|
45
41
|
|
|
46
42
|
interface SetDeleteOpen {
|
|
47
|
-
type: TableActionsType.SET_DELETE_OPEN
|
|
43
|
+
type: TableActionsType.SET_DELETE_OPEN;
|
|
48
44
|
payload: {
|
|
49
|
-
id: number
|
|
50
|
-
}
|
|
45
|
+
id: number;
|
|
46
|
+
};
|
|
51
47
|
}
|
|
52
48
|
|
|
53
49
|
export function setDeleteOpen(id: number): SetDeleteOpen {
|
|
@@ -55,41 +51,46 @@ export function setDeleteOpen(id: number): SetDeleteOpen {
|
|
|
55
51
|
type: TableActionsType.SET_DELETE_OPEN,
|
|
56
52
|
payload: {
|
|
57
53
|
id,
|
|
58
|
-
}
|
|
59
|
-
}
|
|
54
|
+
},
|
|
55
|
+
};
|
|
60
56
|
}
|
|
61
57
|
|
|
62
58
|
export function clearDeletes(): ClearTable {
|
|
63
59
|
return {
|
|
64
60
|
type: TableActionsType.CLEAR_DELETES,
|
|
65
|
-
payload: {
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
}
|
|
61
|
+
payload: {},
|
|
62
|
+
};
|
|
69
63
|
}
|
|
70
64
|
|
|
71
65
|
export type TableActions = AddAlert | ClearTable | SetDeleteOpen;
|
|
72
66
|
|
|
73
|
-
export function loadAlerts(): ThunkAction<
|
|
67
|
+
export function loadAlerts(): ThunkAction<
|
|
68
|
+
void,
|
|
69
|
+
AlertsUiState,
|
|
70
|
+
unknown,
|
|
71
|
+
TableActions
|
|
72
|
+
> {
|
|
74
73
|
return (dispatch) => {
|
|
75
74
|
Axios({
|
|
76
|
-
method:
|
|
77
|
-
url: (window as any).APP_URL_APP + '/api/yld-teated/v1/api/messages'
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
75
|
+
method: 'get',
|
|
76
|
+
url: (window as any).APP_URL_APP + '/api/yld-teated/v1/api/messages',
|
|
77
|
+
}).then((res) => {
|
|
78
|
+
const alerts: any[] = res.data;
|
|
79
|
+
|
|
80
|
+
// Populate table
|
|
81
|
+
for (const alert of alerts) {
|
|
82
|
+
const begin = new Date(alert.begin);
|
|
83
|
+
const end = new Date(alert.end);
|
|
84
|
+
|
|
85
|
+
dispatch(
|
|
86
|
+
addAlert({
|
|
88
87
|
id: alert.id,
|
|
89
88
|
title: alert.title,
|
|
90
89
|
content: alert.body,
|
|
91
90
|
level: alert.level,
|
|
92
|
-
audience:
|
|
91
|
+
audience: alert.open
|
|
92
|
+
? Audience.NOT_AUTHENTICATED
|
|
93
|
+
: Audience.AUTHENTICATED,
|
|
93
94
|
begin: printDate(begin, true),
|
|
94
95
|
beginHour: begin.getHours(),
|
|
95
96
|
beginMinute: begin.getMinutes(),
|
|
@@ -97,23 +98,23 @@ export function loadAlerts(): ThunkAction<void, AlertsUiState, unknown, TableAct
|
|
|
97
98
|
endHour: end.getHours(),
|
|
98
99
|
endMinute: end.getMinutes(),
|
|
99
100
|
deleted: alert.deleted,
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
};
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
export function deleteAlert(
|
|
109
|
+
id: number,
|
|
110
|
+
): ThunkAction<void, AlertsUiState, unknown, TableActions> {
|
|
108
111
|
return (dispatch) => {
|
|
109
112
|
Axios({
|
|
110
|
-
method:
|
|
111
|
-
url: (window as any).APP_URL_APP + `/api/yld-teated/v1/api/message/${id}
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
113
|
+
method: 'delete',
|
|
114
|
+
url: (window as any).APP_URL_APP + `/api/yld-teated/v1/api/message/${id}`,
|
|
115
|
+
}).then((res) => {
|
|
116
|
+
dispatch(clearTable());
|
|
117
|
+
dispatch(loadAlerts());
|
|
118
|
+
});
|
|
119
|
+
};
|
|
118
120
|
}
|
|
119
|
-
|