-
Notifications
You must be signed in to change notification settings - Fork 0
Announcements #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Announcements #26
Changes from 6 commits
f83ece5
19b8738
8216763
c80678e
c4141fd
f4604c2
fb24cb7
46e2d7f
82bcfc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"authority": "http://172.17.0.1:9090/", | ||
"client_id": "my-client-2", | ||
"redirect_uri": "http://localhost:3000/sign-in-callback", | ||
"post_logout_redirect_uri": "http://localhost:3000/logout-callback", | ||
"silent_redirect_uri": "http://localhost:3000/silent-renew-callback", | ||
"client_id": "gridadmin-local", | ||
"redirect_uri": "http://localhost:3002/sign-in-callback", | ||
"post_logout_redirect_uri": "http://localhost:3002/logout-callback", | ||
"silent_redirect_uri": "http://localhost:3002/silent-renew-callback", | ||
"scope": "openid" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { FunctionComponent, useState } from 'react'; | ||
import { useIntl } from 'react-intl'; | ||
import { AppBar, Button, Grid, List, Toolbar } from '@mui/material'; | ||
import { AddCircleOutline } from '@mui/icons-material'; | ||
import { CreateAnnouncementDialog } from './CreateAnnouncementDialog'; | ||
import { useAnnouncements } from './useAnnouncements'; | ||
import { ListItemAnnouncement } from './ListItemAnnouncement'; | ||
|
||
const Announcements: FunctionComponent = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can separate in different components the top bar from the announcements list There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm extracting the Topbar/Toolbar combo, you think about something else ? |
||
const intl = useIntl(); | ||
const [openDialog, setOpenDialog] = useState(false); | ||
const announcements = useAnnouncements(); | ||
|
||
return ( | ||
<Grid item container spacing={2} direction="column"> | ||
<Grid item> | ||
<AppBar position="static" color="default"> | ||
<Toolbar variant="dense"> | ||
<Button | ||
onClick={() => setOpenDialog(true)} | ||
variant="outlined" | ||
startIcon={<AddCircleOutline />} | ||
size="small" | ||
> | ||
{intl.formatMessage({ id: 'announcements.add' })} | ||
</Button> | ||
</Toolbar> | ||
</AppBar> | ||
</Grid> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you extract that in common component with Users ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The layout part There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok doing it |
||
<CreateAnnouncementDialog | ||
open={openDialog} | ||
onClose={() => setOpenDialog(false)} | ||
/> | ||
<Grid item> | ||
<List sx={{ maxWidth: 1400 }}> | ||
{announcements.map((announcement) => ( | ||
<ListItemAnnouncement {...announcement} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AnnouncementItem ? And I think I prefer when the arguments are an object. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer like this, for me this way is clearer. |
||
))} | ||
</List> | ||
</Grid> | ||
</Grid> | ||
); | ||
}; | ||
export default Announcements; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { FunctionComponent, useCallback } from 'react'; | ||
import { | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogTitle, | ||
Grid, | ||
} from '@mui/material'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
import { yupResolver } from '@hookform/resolvers/yup'; | ||
import { DurationInput } from './DurationInput'; | ||
import { SubmitButton, TextInput } from '@gridsuite/commons-ui'; | ||
import { | ||
AnnouncementFormData, | ||
emptyFormData, | ||
formSchema, | ||
fromFrontToBack, | ||
MESSAGE, | ||
} from './utils'; | ||
import { UserAdminSrv } from '../../services'; | ||
|
||
interface CreateAnnouncementDialogProps { | ||
open: boolean; | ||
onClose: () => void; | ||
} | ||
|
||
export const CreateAnnouncementDialog: FunctionComponent< | ||
CreateAnnouncementDialogProps | ||
> = (props) => { | ||
const formMethods = useForm<AnnouncementFormData>({ | ||
defaultValues: emptyFormData, | ||
//@ts-ignore because yup TS is broken | ||
resolver: yupResolver(formSchema), | ||
}); | ||
|
||
const { handleSubmit, reset } = formMethods; | ||
|
||
const onSubmit = useCallback( | ||
(formData: AnnouncementFormData) => { | ||
UserAdminSrv.createAnnouncement(fromFrontToBack(formData)); | ||
reset(); | ||
props.onClose(); | ||
}, | ||
[props, reset] | ||
); | ||
|
||
return ( | ||
//@ts-ignore because RHF TS is broken | ||
<FormProvider validationSchema={formSchema} {...formMethods}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure ? It's not just that we shouldn't define this property ? Schema is in the yup resolver already, no ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's something we already talked about on Slack. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I'm wondering if we don't do it wrong since the start haha |
||
<Dialog open={props.open} onClose={props.onClose}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can unwrap {open, onClose} in the method argument directly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer like this then we know it comes from the props. Maybe something to define in the team I agree. |
||
<DialogTitle> | ||
<FormattedMessage id="announcements.dialog.title" /> | ||
</DialogTitle> | ||
<DialogContent> | ||
<Grid container spacing={2} direction="column"> | ||
<Grid item> | ||
<TextInput | ||
name={MESSAGE} | ||
label={'announcements.dialog.input'} | ||
formProps={{ | ||
multiline: true, | ||
variant: 'filled', | ||
minRows: 3, | ||
}} | ||
/> | ||
</Grid> | ||
<DurationInput /> | ||
</Grid> | ||
</DialogContent> | ||
<DialogActions> | ||
<SubmitButton | ||
onClick={handleSubmit(onSubmit)} | ||
variant="outlined" | ||
/> | ||
</DialogActions> | ||
</Dialog> | ||
</FormProvider> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { Grid, Typography } from '@mui/material'; | ||
import { DAYS, DURATION, HOURS, MINUTES } from './utils'; | ||
import { IntegerInput } from '@gridsuite/commons-ui'; | ||
import { useIntl } from 'react-intl'; | ||
|
||
const centerStyle = { | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}; | ||
|
||
const DaysAdornment = { | ||
position: 'end', | ||
text: 'd', | ||
}; | ||
const HoursAdornment = { | ||
position: 'end', | ||
text: 'h', | ||
}; | ||
const MinutesAdornment = { | ||
position: 'end', | ||
text: 'm', | ||
}; | ||
|
||
export const DurationInput = () => { | ||
const intl = useIntl(); | ||
|
||
return ( | ||
<Grid item container columns={30} justifyContent="center"> | ||
<Grid item xs={6} sx={centerStyle}> | ||
<Typography variant="body1"> | ||
{intl.formatMessage({ | ||
id: 'announcements.dialog.duration', | ||
})} | ||
</Typography> | ||
</Grid> | ||
<Grid item xs={4}> | ||
<IntegerInput | ||
name={`${DURATION}.${DAYS}`} | ||
label={'duration.days'} | ||
adornment={DaysAdornment} | ||
/> | ||
</Grid> | ||
<Grid item xs={1} sx={centerStyle}> | ||
<Typography variant="h6">:</Typography> | ||
</Grid> | ||
<Grid item xs={4}> | ||
<IntegerInput | ||
name={`${DURATION}.${HOURS}`} | ||
label={'duration.hours'} | ||
adornment={HoursAdornment} | ||
/> | ||
</Grid> | ||
<Grid item xs={1} sx={centerStyle}> | ||
<Typography variant="h6">:</Typography> | ||
</Grid> | ||
<Grid item xs={4}> | ||
<IntegerInput | ||
name={`${DURATION}.${MINUTES}`} | ||
label={'duration.minutes'} | ||
adornment={MinutesAdornment} | ||
/> | ||
</Grid> | ||
</Grid> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid storing ReactElement in a variable ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just use the existing pattern, if you think we should refactor this, we need to do an other PR.
How bad is it ?