Skip to content
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

Pause ALL my notifications #910

Merged
merged 13 commits into from
Jun 17, 2024
Merged

Conversation

dzonidoo
Copy link
Contributor

https://sofab.atlassian.net/browse/CPCN-186

Checklist

  • This pull request is not adding new forms that use redux
  • This pull request is adding missing TypeScript types to modified code segments where it's easy to do so with confidence
  • This pull request is replacing lodash.get with optional chaining for modified code segments

@tomaskikutis tomaskikutis requested review from thecalcc and removed request for petrjasek May 23, 2024 10:01
@tomaskikutis
Copy link
Member

@thecalcc can you review this?


class NotificationList extends React.Component<any, any> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's quick, can you type the props as well?

)}
ref={(elem: any) => this.elem = elem}
title={gettext('Notifications')}>
<h3 className="a11y-only">Notification bell</h3>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add gettext here, we shouldn't care if it's hidden


export const UPDATE_NOTIFICATION_COUNT = 'UPDATE_NOTIFICATION_COUNT';
export function updateNotificationCount(count: any) {
return {type: UPDATE_NOTIFICATION_COUNT, count};
}

export const INIT_DATA = 'INIT_DATA';
export function initData(data: any) {
return {type: INIT_DATA, data};
export function initData(notificationData: any, profileData: any) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you type props here?

Comment on lines +48 to +51
if (this.formRef.current == null) {
throw new Error('ref missing');
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this meant to stop the function execution? What does throwing an error serve us here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few reasons for this. One is to stop the execution in case it is null and another is to tell compiler that if execution is not stopped, it should be treated as non-null.

We could also achieve this using if/else or early return. But - it is preferrable to throw errors when we're guarding against invalid application states.

Comment on lines 54 to 56
const hasErrors = [...inputs].some(input => {
return input.checkValidity() !== true;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason here to spread inputs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

querySelectorAll returns a collection which is not an array and doesn't have array methods. @dzonidoo use Array.from(inputs) instead.

Comment on lines 74 to 75
const newMaxDate = new Date(state);
newMaxDate.setDate(newMaxDate.getDate() + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do this in one line, but if you think readability is better this way, let's keep it.

Add 1 to a constant that explains what its purpose is, we can't have magic numbers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when 0 and 1 are used, most of the times it's obvious what's being done thus 0/1 are not considered magic numbers.

disabledMaxOption(state: string | undefined) {
if (state != '' && state != undefined) {
const newMaxDate = new Date(state);
newMaxDate.setDate(newMaxDate.getDate() - 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same goes for here, I bet 1 is some kind of offset, I understand it but others would need to know also

type="date"
name="date-from"
className="form-control"
onChange={(event) => this.updateDate(event, 'pauseFrom')}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we're expecting a return from this function which isn't the case, can you add curly braces to it?

Copy link
Member

@tomaskikutis tomaskikutis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thecalcc you shouldn't approve a PR until your comments are addressed/answered.

I'll also block the merging so after you finish the review, I'll take a look too.

@thecalcc
Copy link
Contributor

@thecalcc you shouldn't approve a PR until your comments are addressed/answered.

I'll also block the merging so after you finish the review, I'll take a look too.

I clicked approve by mistake, my bad

@dzonidoo dzonidoo requested a review from thecalcc May 23, 2024 13:19
@petrjasek petrjasek added this to the v2.8 milestone May 24, 2024
Copy link
Contributor

@thecalcc thecalcc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would component prop types take too long to be properly typed?

@dzonidoo
Copy link
Contributor Author

Actually yes...

@thecalcc
Copy link
Contributor

thecalcc commented May 27, 2024

Actually yes...

@dzonidoo ok got it. What about not adding new redux forms, is it possible that we don't use redux?

@dzonidoo
Copy link
Contributor Author

@thecalcc its not.. we need it

Copy link
Member

@tomaskikutis tomaskikutis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look @thecalcc, I'll take over from here. I wish you did a more in-depth job, I still have lots of comments after your review.

@dzonidoo there's a bug I found not related to this PR - do apply the following patch to fix it. (it was crashing when notification schedule isn't set)
image

assets/components/NotificationList.tsx Outdated Show resolved Hide resolved
assets/components/NotificationList.tsx Outdated Show resolved Hide resolved
assets/components/NotificationList.tsx Outdated Show resolved Hide resolved
assets/user-profile/actions.ts Outdated Show resolved Hide resolved
assets/components/NotificationList.tsx Outdated Show resolved Hide resolved
assets/user-profile/components/PauseNotificationModal.tsx Outdated Show resolved Hide resolved
assets/user-profile/components/PauseNotificationModal.tsx Outdated Show resolved Hide resolved
Comment on lines +48 to +51
if (this.formRef.current == null) {
throw new Error('ref missing');
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few reasons for this. One is to stop the execution in case it is null and another is to tell compiler that if execution is not stopped, it should be treated as non-null.

We could also achieve this using if/else or early return. But - it is preferrable to throw errors when we're guarding against invalid application states.

Comment on lines 54 to 56
const hasErrors = [...inputs].some(input => {
return input.checkValidity() !== true;
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

querySelectorAll returns a collection which is not an array and doesn't have array methods. @dzonidoo use Array.from(inputs) instead.

Comment on lines 74 to 75
const newMaxDate = new Date(state);
newMaxDate.setDate(newMaxDate.getDate() + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when 0 and 1 are used, most of the times it's obvious what's being done thus 0/1 are not considered magic numbers.

@tomaskikutis
Copy link
Member

tomaskikutis commented May 31, 2024

What about not adding new redux forms, is it possible that we don't use redux?

where did you see Redux being used for forms @thecalcc ? If data that you gather from a form is being sent to a redux action, it doesn't make it a redux based form. Those are when validation and form data while typing live inside redux store.

@dzonidoo dzonidoo requested a review from tomaskikutis June 4, 2024 17:01
assets/helpers/notification.tsx Outdated Show resolved Hide resolved
assets/components/NotificationList.tsx Outdated Show resolved Hide resolved
assets/components/NotificationList.tsx Outdated Show resolved Hide resolved
assets/user-profile/components/PauseNotificationModal.tsx Outdated Show resolved Hide resolved
assets/user-profile/components/PauseNotificationModal.tsx Outdated Show resolved Hide resolved
assets/notifications/components/NotificationsApp.tsx Outdated Show resolved Hide resolved
assets/search/components/TopicEditor.tsx Outdated Show resolved Hide resolved
assets/user-profile/components/profile/UserProfile.tsx Outdated Show resolved Hide resolved
assets/user-profile/components/PauseNotificationModal.tsx Outdated Show resolved Hide resolved
@dzonidoo dzonidoo requested a review from tomaskikutis June 12, 2024 12:42
Copy link
Member

@tomaskikutis tomaskikutis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also check one other comment I left unresolved

@@ -70,9 +85,11 @@ class NotificationList extends React.Component<any, any> {
}

render() {
const notificationArePaused: boolean = new Date(this.props.fullUser.notification_schedule?.pauseFrom ?? '') < new Date();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should't be creating a date from an empty string. If it's not defined, simply set notificationArePaused to false and compare dates only if it's defined.

@dzonidoo dzonidoo requested a review from tomaskikutis June 17, 2024 10:54
@dzonidoo dzonidoo merged commit 6072e7a into superdesk:develop Jun 17, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants