5
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- import { FunctionComponent , useCallback , useMemo , useRef , useState } from 'react' ;
8
+ import type { UUID } from 'crypto' ;
9
+ import { useCallback , useMemo , useRef , useState } from 'react' ;
9
10
import { FormattedMessage , useIntl } from 'react-intl' ;
10
- import { Grid } from '@mui/material' ;
11
- import { GridTableRef } from '../../components/Grid' ;
11
+ import { Grid , type SxProps , type Theme } from '@mui/material' ;
12
+ import { useSnackMessage } from '@gridsuite/commons-ui' ;
13
+ import type { ColDef , GetRowIdParams , ValueGetterParams } from 'ag-grid-community' ;
14
+ import { type GridTableRef } from '../../components/Grid' ;
12
15
import { Announcement , UserAdminSrv } from '../../services' ;
13
- import { ColDef , GetRowIdParams , ValueGetterParams } from 'ag-grid-community' ;
14
16
import AddAnnouncementForm from './add-announcement-form' ;
15
17
import { DateCellRenderer } from './date-cell-renderer' ;
16
18
import AgGrid from '../../components/Grid/AgGrid' ;
17
- import { useSnackMessage } from '@gridsuite/commons-ui' ;
18
19
import { CancelButtonCellRenderer } from './cancel-button-cell-renderer' ;
19
- import { UUID } from 'crypto' ;
20
20
21
21
const stylesLayout = {
22
+ root : { display : 'flex' } ,
22
23
columnContainer : {
23
24
maxHeight : '60px' ,
24
25
paddingLeft : '15px' ,
25
26
} ,
26
- } ;
27
+ } as const satisfies Record < string , SxProps < Theme > > ;
27
28
28
29
const defaultColDef : ColDef < Announcement > = {
29
30
editable : false ,
@@ -34,11 +35,11 @@ const defaultColDef: ColDef<Announcement> = {
34
35
sortable : true ,
35
36
} ;
36
37
37
- function getRowId ( params : GetRowIdParams < Announcement > ) : string {
38
+ function getRowId ( params : GetRowIdParams < Announcement > ) {
38
39
return params . data . id ;
39
40
}
40
41
41
- const AnnouncementsPage : FunctionComponent = ( ) => {
42
+ export default function AnnouncementsPage ( ) {
42
43
const intl = useIntl ( ) ;
43
44
const gridRef = useRef < GridTableRef < Announcement > > ( null ) ;
44
45
@@ -61,9 +62,9 @@ const AnnouncementsPage: FunctionComponent = () => {
61
62
const convertSeverity = useCallback (
62
63
( severity : string ) => {
63
64
if ( severity === UserAdminSrv . AnnouncementSeverity . INFO ) {
64
- return intl . formatMessage ( { id : 'banners.table.info ' } ) ;
65
+ return intl . formatMessage ( { id : 'announcements.severity.INFO ' } ) ;
65
66
} else if ( severity === UserAdminSrv . AnnouncementSeverity . WARN ) {
66
- return intl . formatMessage ( { id : 'banners.table.warn ' } ) ;
67
+ return intl . formatMessage ( { id : 'announcements.severity.WARN ' } ) ;
67
68
} else {
68
69
return '' ;
69
70
}
@@ -72,14 +73,12 @@ const AnnouncementsPage: FunctionComponent = () => {
72
73
) ;
73
74
74
75
const refreshGrid = useCallback ( ( ) => {
75
- gridRef . current ?. context ?. refresh ( ) ;
76
+ gridRef . current ?. context ?. refresh ?. ( ) ;
76
77
} , [ ] ) ;
77
78
78
79
const handleDeleteAnnouncement = useCallback (
79
80
( announcementId : UUID ) => {
80
- UserAdminSrv . deleteAnnouncement ( announcementId ) . then ( ( ) => {
81
- refreshGrid ( ) ;
82
- } ) ;
81
+ UserAdminSrv . deleteAnnouncement ( announcementId ) . then ( refreshGrid ) ;
83
82
} ,
84
83
[ refreshGrid ]
85
84
) ;
@@ -91,28 +90,28 @@ const AnnouncementsPage: FunctionComponent = () => {
91
90
cellDataType : 'text' ,
92
91
flex : 3 ,
93
92
lockVisible : true ,
94
- headerName : intl . formatMessage ( { id : 'banners .table.message' } ) ,
93
+ headerName : intl . formatMessage ( { id : 'announcements .table.message' } ) ,
95
94
} ,
96
95
{
97
96
field : 'startDate' ,
98
97
cellRenderer : DateCellRenderer ,
99
98
flex : 3 ,
100
99
lockVisible : true ,
101
- headerName : intl . formatMessage ( { id : 'banners .table.startDate' } ) ,
100
+ headerName : intl . formatMessage ( { id : 'announcements .table.startDate' } ) ,
102
101
} ,
103
102
{
104
103
field : 'endDate' ,
105
104
cellRenderer : DateCellRenderer ,
106
105
flex : 3 ,
107
106
lockVisible : true ,
108
- headerName : intl . formatMessage ( { id : 'banners .table.endDate' } ) ,
107
+ headerName : intl . formatMessage ( { id : 'announcements .table.endDate' } ) ,
109
108
} ,
110
109
{
111
110
field : 'severity' ,
112
111
cellDataType : 'text' ,
113
112
flex : 2 ,
114
113
lockVisible : true ,
115
- headerName : intl . formatMessage ( { id : 'banners.table .severity' } ) ,
114
+ headerName : intl . formatMessage ( { id : 'announcements .severity' } ) ,
116
115
valueGetter : ( value : ValueGetterParams ) => convertSeverity ( value . data . severity ) ,
117
116
} ,
118
117
{
@@ -123,55 +122,47 @@ const AnnouncementsPage: FunctionComponent = () => {
123
122
} ,
124
123
flex : 2 ,
125
124
lockVisible : true ,
126
- headerName : intl . formatMessage ( { id : 'banners .table.cancel' } ) ,
125
+ headerName : intl . formatMessage ( { id : 'announcements .table.cancel' } ) ,
127
126
} ,
128
127
] ,
129
128
[ intl , convertSeverity , handleDeleteAnnouncement ]
130
129
) ;
131
130
132
131
return (
133
- < >
134
- < Grid container direction = "column" sx = { { display : 'flex' } } >
135
- < Grid container item xs = { 3 } direction = "column" >
136
- < Grid item xs sx = { stylesLayout . columnContainer } >
137
- < h3 >
138
- < FormattedMessage id = "banners.programNewMessage" > </ FormattedMessage >
139
- </ h3 >
140
- </ Grid >
141
- < Grid item xs paddingX = { '15px' } >
142
- < AddAnnouncementForm onAnnouncementCreated = { refreshGrid } />
143
- </ Grid >
132
+ < Grid container direction = "column" sx = { stylesLayout . root } >
133
+ < Grid container item xs = { 3 } direction = "column" >
134
+ < Grid item xs sx = { stylesLayout . columnContainer } >
135
+ < h3 >
136
+ < FormattedMessage id = "announcements.programNewMessage" > </ FormattedMessage >
137
+ </ h3 >
144
138
</ Grid >
139
+ < Grid item xs paddingX = "15px" >
140
+ < AddAnnouncementForm onAnnouncementCreated = { refreshGrid } />
141
+ </ Grid >
142
+ </ Grid >
145
143
146
- < Grid container item xs direction = "column" marginBottom = { '15px' } >
147
- < Grid item sx = { stylesLayout . columnContainer } >
148
- < h3 >
149
- < FormattedMessage id = "banners.programmedMessage" > </ FormattedMessage >
150
- </ h3 >
151
- </ Grid >
152
- < Grid container item xs paddingX = { '15px' } >
153
- < Grid item xs >
154
- < AgGrid < Announcement , { } >
155
- ref = { gridRef }
156
- rowData = { data }
157
- alwaysShowVerticalScroll = { true }
158
- onGridReady = { loadDataAndSave }
159
- columnDefs = { columns }
160
- defaultColDef = { defaultColDef }
161
- gridId = "table-banners"
162
- getRowId = { getRowId }
163
- context = { useMemo (
164
- ( ) => ( {
165
- refresh : loadDataAndSave ,
166
- } ) ,
167
- [ loadDataAndSave ]
168
- ) }
169
- />
170
- </ Grid >
144
+ < Grid container item xs direction = "column" marginBottom = "15px" >
145
+ < Grid item sx = { stylesLayout . columnContainer } >
146
+ < h3 >
147
+ < FormattedMessage id = "announcements.programmedMessage" />
148
+ </ h3 >
149
+ </ Grid >
150
+ < Grid container item xs paddingX = "15px" >
151
+ < Grid item xs >
152
+ < AgGrid < Announcement >
153
+ ref = { gridRef }
154
+ rowData = { data }
155
+ alwaysShowVerticalScroll
156
+ onGridReady = { loadDataAndSave }
157
+ columnDefs = { columns }
158
+ defaultColDef = { defaultColDef }
159
+ gridId = "table-banners"
160
+ getRowId = { getRowId }
161
+ context = { useMemo ( ( ) => ( { refresh : loadDataAndSave } ) , [ loadDataAndSave ] ) }
162
+ />
171
163
</ Grid >
172
164
</ Grid >
173
165
</ Grid >
174
- </ >
166
+ </ Grid >
175
167
) ;
176
- } ;
177
- export default AnnouncementsPage ;
168
+ }
0 commit comments