-
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
Conversation
Signed-off-by: Florent MILLOT <[email protected]>
Signed-off-by: Florent MILLOT <[email protected]>
Signed-off-by: Florent MILLOT <[email protected]>
Signed-off-by: Florent MILLOT <[email protected]>
Signed-off-by: Florent MILLOT <[email protected]>
Signed-off-by: Florent MILLOT <[email protected]>
src/components/App/app-top-bar.tsx
Outdated
[ | ||
MainPaths.announcements, | ||
<TabNavLink | ||
icon={<Announcement />} | ||
label={<FormattedMessage id="appBar.tabs.announcement" />} | ||
href={`/${MainPaths.announcements}`} | ||
value={MainPaths.announcements} | ||
key={`tab-${MainPaths.announcements}`} | ||
/>, | ||
], |
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 ?
<Grid item> | ||
<List sx={{ maxWidth: 1400 }}> | ||
{announcements.map((announcement) => ( | ||
<ListItemAnnouncement {...announcement} /> |
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.
AnnouncementItem ? And I think I prefer when the arguments are an object.
<AnnouncementItem item={announcement} />
? I think it makes it more readable
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 prefer like this, for me this way is clearer.
export const ListItemAnnouncement: FunctionComponent<Announcement> = (
No need to define a new ListItemAnnouncementProps with just one item which is an Announcement...
It's already an item itself, so why giving an inner item prop ?
It follow the pattern ListItemText.
But if it's rly a bad way and if the second reviewer agree with you, I'll change it.
<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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Ok doing it
|
||
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
It's something we already talked about on Slack.
We found some way to avoid the issue, ie
https://github.com/gridsuite/gridstudy-app/blob/760264391c6b49a26e60edb94973b5752dbf9d67/src/components/dialogs/dynamicsimulation/event/dynamic-simulation-event-dialog.tsx#L228-L233
But not working here
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.
Actually I'm wondering if we don't do it wrong since the start haha
import { useAnnouncements } from './useAnnouncements'; | ||
import { ListItemAnnouncement } from './ListItemAnnouncement'; | ||
|
||
const Announcements: FunctionComponent = () => { |
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.
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 comment
The 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 formSchema: ObjectSchema<FormData> = yup |
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.
To be removed ?
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.
Yeah I've let it for the reviewers to discuss about this issue because I don't really like all this, with the tsignore also...
[HOURS, MINUTES], | ||
[DAYS, MINUTES], | ||
[DAYS, HOURS], |
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.
How does that work ?
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.
Internally I don't really know, it's not even in the doc, but like this we remove all cyclic dep combo
}; | ||
|
||
// const formSchema: ObjectSchema<FormData> = yup | ||
export const formSchema = yup |
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 separate the formSchema from type definitions ?
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.
What do you mean ?
@@ -95,3 +100,44 @@ export function addUser(sub: string): Promise<void> { | |||
throw reason; | |||
}); | |||
} | |||
|
|||
export function getAnnouncements(): Promise<AnnouncementServerData[]> { |
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 catch errors and display snackBar ?
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.
Yes I forgot you're right
src/pages/announcements/utils.ts
Outdated
{ | ||
[DAYS]: getDurationUnitSchema(HOURS, MINUTES), | ||
[HOURS]: getDurationUnitSchema(DAYS, MINUTES), | ||
[MINUTES]: getDurationUnitSchema(DAYS, HOURS), | ||
}, | ||
// to avoid cyclic dependencies | ||
[ | ||
[HOURS, MINUTES], | ||
[DAYS, MINUTES], | ||
[DAYS, HOURS], | ||
] | ||
) | ||
.required(), | ||
}) | ||
.required(); | ||
|
||
function getDurationUnitSchema(otherUnitName1: string, otherUnitName2: string) { | ||
return yup.number().when([otherUnitName1, otherUnitName2], { | ||
is: (v1: number | null, v2: number | null) => | ||
v1 === null && v2 === null, | ||
then: (schema) => schema.required(), | ||
otherwise: (schema) => schema.nullable(), | ||
}); | ||
} |
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't we simplify by saying at least one of these three is required ?
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 don't see how. We can do that for the validation but then the fields won't be red with "required" key word.
export const formSchema = yup | ||
.object() | ||
.shape({ | ||
[MESSAGE]: yup.string().max(100).required(), |
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.
100 is quite limiting, maybe double check with a PO
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.
Asked
Signed-off-by: Florent MILLOT <[email protected]>
Signed-off-by: Abdelsalem <[email protected]>
35af5e1
to
d93158a
Compare
Add the possibility to send an announcement to the connected users of other web app for a specified duration.