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

Refactor facilityconfig facility actions into composables #13014

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

ozer550
Copy link
Member

@ozer550 ozer550 commented Jan 20, 2025

Summary

WIP

References

Reviewer guidance

@github-actions github-actions bot added APP: Device Re: Device App (content import/export, facility-syncing, user permissions, etc.) APP: Facility Re: Facility App (user/class management, facility settings, csv import/export, etc.) APP: Coach Re: Coach App (lessons, quizzes, groups, reports, etc.) APP: User Re: User app (sign-in, sign-up, user profile, etc.) DEV: frontend DEV: tools Internal tooling for development labels Jan 20, 2025
@ozer550 ozer550 requested a review from rtibbles January 21, 2025 06:56
getFacilityConfig,
setFacilityConfig,
setFacilities,
selectedFacility,
Copy link
Member Author

Choose a reason for hiding this comment

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

should we also migrate selectedFacility everywhere?

Copy link
Member

Choose a reason for hiding this comment

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

How is it usually handled? Is it in the core vuex state, or has it been independently implemented in each of the plugins?

Copy link
Member Author

Choose a reason for hiding this comment

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

So the existing getFacilityConfig actions was getting the value of selectedFacility from here. Hence I migrated it in our composable. there are multiple places where it is actually being implemented independently.

Copy link
Member

Choose a reason for hiding this comment

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

OK, I think we can do the selectedFacility migration as a follow up issue, if you'd like to have a go at writing that up? Feel free to run a draft by me!

const state = reactive({
facilityConfig: {},
facilities: [],
facilityId: Lockr.get('facilityId') || null,
Copy link
Member Author

Choose a reason for hiding this comment

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

Have not removed the existing facilitiyId state just added this here to keep a local copy of facilityId.

Copy link
Member

Choose a reason for hiding this comment

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

Hrm, but we're not actually setting this anywhere either. Let's remove this, it's not in the original, so not sure that we need it, and if we're not setting it, it's not doing anything anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Its value is being used here. Any suggestions on how should I work around this?

Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

This looks mostly how I would expect! A couple of comments where we could do a little additional cleanup.

I tend to distrust reactive, in general individual bits of state using ref are more predictable reactivity wise, hence my preference for that.

@@ -17,6 +17,8 @@ import FacilityUserResource from 'kolibri-common/apiResources/FacilityUserResour
import samePageCheckGenerator from 'kolibri-common/utils/samePageCheckGenerator';
import { createTranslator } from 'kolibri/utils/i18n';
import useUser from 'kolibri/composables/useUser';
import useFacilities from 'kolibri-common/composables/useFacilities';
import { getFacilities } from '../../../../kolibri/core/assets/src/state/modules/core/actions';
Copy link
Member

Choose a reason for hiding this comment

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

This function has been deleted from here, not sure why we've added this import?

getFacilityConfig,
setFacilityConfig,
setFacilities,
selectedFacility,
Copy link
Member

Choose a reason for hiding this comment

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

How is it usually handled? Is it in the core vuex state, or has it been independently implemented in each of the plugins?

@@ -63,6 +65,8 @@ function fetchUserPermissions(userId) {
* @returns Promise<void>
*/
export function showUserPermissionsPage(store, userId) {
const { getfacilities } = useFacilities();
Copy link
Member

Choose a reason for hiding this comment

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

This should be getFacilities - maybe that's why you had to add the import above?

const state = reactive({
facilityConfig: {},
facilities: [],
facilityId: Lockr.get('facilityId') || null,
Copy link
Member

Choose a reason for hiding this comment

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

Hrm, but we're not actually setting this anywhere either. Let's remove this, it's not in the original, so not sure that we need it, and if we're not setting it, it's not doing anything anyway.

import FacilityDatasetResource from 'kolibri-common/apiResources/FacilityDatasetResource';
import Lockr from 'lockr';

const state = reactive({
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer that we not exactly map the vuex state here.

I think it would be cleaner to define each bit of state as a separate ref.

So:

const facilityConfig = ref({});
const facilities = ref([]);
const facilityId = ref(null);

Would then need to update the state access and update accordingly.

Copy link
Member

Choose a reason for hiding this comment

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

If you want to keep them encapsulated and not externally editable, you could prefix their names with _ and still return computed props instead.

import { ComponentMap } from '../../constants';

export function showSignUpPage(store, fromRoute) {
const { setFacilities } = useFacilities();

// Don't do anything if going between Sign Up steps
if (fromRoute.name === ComponentMap.SIGN_UP) {
return Promise.resolve();
}
return FacilityResource.fetchCollection()
Copy link
Member

Choose a reason for hiding this comment

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

Hrm, do you know if there's a reason we don't just use getFacilities here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The existing functionality was using set facilities, I just replaced it. Are you suggesting that instead of calling the fetchCollection we directly call getFacilities here?

Copy link
Member Author

Choose a reason for hiding this comment

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

ohh yes! it does the same thing will replace!

@rtibbles rtibbles self-assigned this Jan 23, 2025
Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

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

Code wise this looks how I expect, and I have no concerns. This will be ready for QA once it has been undrafted and has a complete PR description! Please make sure to describe the specific workflows that are impacted by these changes to allow for complete testing.

getFacilityConfig,
setFacilityConfig,
setFacilities,
selectedFacility,
Copy link
Member

Choose a reason for hiding this comment

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

OK, I think we can do the selectedFacility migration as a follow up issue, if you'd like to have a go at writing that up? Feel free to run a draft by me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APP: Coach Re: Coach App (lessons, quizzes, groups, reports, etc.) APP: Device Re: Device App (content import/export, facility-syncing, user permissions, etc.) APP: Facility Re: Facility App (user/class management, facility settings, csv import/export, etc.) APP: User Re: User app (sign-in, sign-up, user profile, etc.) DEV: frontend DEV: tools Internal tooling for development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants