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

Moved core notifications handling into NotificationsRoot component #12644

Merged
merged 20 commits into from
Oct 9, 2024

Conversation

iamshobhraj
Copy link
Contributor

Description

Moved core notifications handling from actions.js file to NotificationRoot component that were earlier handled through core vuex state. Removed vuex mutations in kolibri_app.js and its spec file.

issue addressed

Addresses #12626
Removes use of vuex in favour of composables.

Changelog

Copy link
Member

@nucleogenesis nucleogenesis left a comment

Choose a reason for hiding this comment

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

Thank you for your PR! I've added a note about a property that was removed that I'm not sure was intentional.

Additionally, it appears you've included two empty config files .bas_hprofile and .bash_profile.

The notifications code looks good to me, but I'll see about testing this locally to be sure there are no regressions.

notificationModalShown: true,
};
},
computed: {
...mapState({
error: state => state.core.error,
Copy link
Member

Choose a reason for hiding this comment

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

I'm not seeing why error was removed here, was this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mapState was removed to completely decouple the component from vuex store, but i did not think of error handling. Should i handle the error locally in getnotification method or keep the mapState for error property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nucleogenesis i removed the empty bashrc files. As for the error handling, it is being handled locally in the methods. If you want me to handle error with mapState, should i do that?

Copy link
Member

Choose a reason for hiding this comment

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

My apologies for missing this last week @iamshobhraj

The mapState function is assigning this.error to the value of state.core.error so that this.error is reactive whenever state.core.error changes.

Elsewhere in the component, this.error is expected to exist so we should keep mapState imported and keep this particular line mapping to the error.

To be a bit more clear, basically you just need to remove the line notifications: ... but not the error: ... line.

@iamshobhraj
Copy link
Contributor Author

iamshobhraj commented Sep 15, 2024

@nucleogenesis Could you please tell me whats causing this error. I removed the empty bash files, fixed the import errors but I am still getting an error with this api endpoint while testing.

/home/secant/opensource/new/kolibri/kolibri/core/assets/src/api-resource.js:512
      return this._url ? this._url : this.resource.collectionUrl();
                                                   ^

TypeError: this.resource.collectionUrl is not a function
    at Collection.get (/home/secant/opensource/new/kolibri/kolibri/core/assets/src/api-resource.js:512:52)
    at /home/secant/opensource/new/kolibri/kolibri/core/assets/src/api-resource.js:347:27
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.20.4
/home/secant/opensource/new/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:232
  return data.map(function (notification) {
              ^

TypeError: Cannot read properties of undefined (reading 'map')
    at _notificationListState (/home/secant/opensource/new/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:232:15)
    at _callee$ (/home/secant/opensource/new/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:168:37)
    at tryCatch (/home/secant/opensource/new/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:21:1062)
    at Generator.<anonymous> (/home/secant/opensource/new/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:21:3008)
    at Generator.next (/home/secant/opensource/new/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:21:1699)
    at asyncGeneratorStep (/home/secant/opensource/new/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:22:70)
    at _next (/home/secant/opensource/new/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:23:163)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    

@nucleogenesis
Copy link
Member

@iamshobhraj - I'm not sure exactly what the cause would be. Seems that notifications here is ending up undefined/null.

const notifications = await PingbackNotificationResource.fetchCollection();
this.notifications = _notificationListState(notifications);

Do you see any errors in your dev tools' "Network" tab for the request for the notifications? Maybe there is a permissions or other issue at hand

I'm not seeing anything along these lines, but I can't help but wonder if something about the change from using then() to using async/await in handling the PingbackNotificationResource.fetchCollection() call.

@rtibbles
Copy link
Member

@iamshobhraj - I just tested your PR locally, and did not see the error you are seeing. It tends to indicate that something has gone wrong in the backend, because the URL has not been properly registered. My first suggestion would be to make sure that your Python dependencies in your virtual environment are up to date https://kolibri-dev.readthedocs.io/en/develop/getting_started.html#install-python-dependencies

If that's still not working, I'd recommend running make clean in the project directory, and rerunning the dev server.

What I see when I run your code is that it seems to be working as intended, with the only exception being the issue that @nucleogenesis previously pointed out.

@iamshobhraj
Copy link
Contributor Author

iamshobhraj commented Sep 27, 2024

@rtibbles @nucleogenesis I'm sorry for late response. I made the changes requested. But i am still getting this error while testing locally after setting up the project again on my machine. notifications is getting set to undefined and PingbackNotificationResource.fetchCollection(); isnt returning any data.

home/secant/kolibri/kolibri/core/assets/src/api-resource.js:512
      return this._url ? this._url : this.resource.collectionUrl();
                                                   ^

TypeError: this.resource.collectionUrl is not a function
    at Collection.get (/home/secant/kolibri/kolibri/core/assets/src/api-resource.js:512:52)
    at /home/secant/kolibri/kolibri/core/assets/src/api-resource.js:347:27
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.19.0
/home/secant/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:239
  return data.map(function (notification) {
              ^

TypeError: Cannot read properties of undefined (reading 'map')
    at _notificationListState (/home/secant/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:239:15)
    at _callee$ (/home/secant/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:175:37)
    at tryCatch (/home/secant/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:21:1062)
    at Generator.<anonymous> (/home/secant/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:21:3008)
    at Generator.next (/home/secant/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:21:1699)
    at asyncGeneratorStep (/home/secant/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:22:70)
    at _next (/home/secant/kolibri/kolibri/core/assets/src/views/NotificationsRoot.vue:23:163)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

@rtibbles
Copy link
Member

Did you try the steps I suggested here?

My first suggestion would be to make sure that your Python dependencies in your virtual environment are up to date https://kolibri-dev.readthedocs.io/en/develop/getting_started.html#install-python-dependencies

If that's still not working, I'd recommend running make clean in the project directory, and rerunning the dev server.

If the URL doesn't exist, something is going wrong with the Python backend (but the error is being silently caught by Django).

@iamshobhraj
Copy link
Contributor Author

Did you try the steps I suggested here?

My first suggestion would be to make sure that your Python dependencies in your virtual environment are up to date https://kolibri-dev.readthedocs.io/en/develop/getting_started.html#install-python-dependencies

If that's still not working, I'd recommend running make clean in the project directory, and rerunning the dev server.

If the URL doesn't exist, something is going wrong with the Python backend (but the error is being silently caught by Django).

yes, i followed it step by step again on my.

@rtibbles
Copy link
Member

In the browser console if you enter:

console.log(Object.keys(kolibriCoreAppGlobal.urls))

What do you get as the output (it may be very long)?

@iamshobhraj
Copy link
Contributor Author

console.log(Object.keys(kolibriCoreAppGlobal.urls))

output

@rtibbles
Copy link
Member

Hrm, so I am seeing the "kolibri:core:pingbacknotification-list", key in the url object, so it is being defined, and passed from the backend, so that can't be the issue.

I will test again locally on my machine, as I still don't quite understand how this is happening and only specifically on your device, seemingly.

@iamshobhraj
Copy link
Contributor Author

iamshobhraj commented Sep 27, 2024

@rtibbles i found the issue. notifciations was set to data property which is initially empty. So thats why data.map is thowing an error. I fixed it by checking if notifications is falsy or empty before attempting to map over it. I am really sorry for any inconvenience this may have caused you.

@nucleogenesis
Copy link
Member

@iamshobhraj thank you for your continued work on this!

I investigated the failing tests and seems like the tests just need to be updated according to the kinds of changes you made.

This commit passes them locally for me: 9f5de38

As for the linting, you'll need to look at the linting issues in the PR actions output, or you can run yarn lint-frontend:format to see the report locally.

@nucleogenesis
Copy link
Member

Hey @iamshobhraj - would you be able to update your PR? I think that with the linting and tests fixed, this should be ready to merge.

This is work that is currently blocking some upcoming work, so if you don't have time to come back to this someone on our team will likely push some commits here and merge it.

Thank you again for your efforts and work on this!

@iamshobhraj
Copy link
Contributor Author

@nucleogenesis sorry for the delay. I have exams in my university so I was away. I'll make sure to add the changes tonight. Sorry for the inconvenience.

@nucleogenesis
Copy link
Member

@iamshobhraj no worries at all! If you need time for your exams or study today or can't get to it for any other reason, I can get the PR ready to merge no problem. Thanks again for everything you've done on this! <3

@iamshobhraj
Copy link
Contributor Author

@nucleogenesis i made the changes to test file as per changes made in component file. also fixed the linting error.

Copy link
Member

@nucleogenesis nucleogenesis left a comment

Choose a reason for hiding this comment

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

I re-read the original issue to be sure this covers everything and you checked all of the boxes there! Wonderful work @iamshobhraj thank you!

@nucleogenesis nucleogenesis merged commit 8a0029f into learningequality:develop Oct 9, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants