-
Notifications
You must be signed in to change notification settings - Fork 738
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
base: develop
Are you sure you want to change the base?
Refactor facilityconfig facility actions into composables #13014
Conversation
Build Artifacts
|
getFacilityConfig, | ||
setFacilityConfig, | ||
setFacilities, | ||
selectedFacility, |
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.
should we also migrate selectedFacility everywhere?
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 is it usually handled? Is it in the core vuex state, or has it been independently implemented in each of the plugins?
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.
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.
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, 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, |
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.
Have not removed the existing facilitiyId state just added this here to keep a local copy of facilityId.
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.
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.
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.
Its value is being used here. Any suggestions on how should I work around this?
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.
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'; |
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.
This function has been deleted from here, not sure why we've added this import?
getFacilityConfig, | ||
setFacilityConfig, | ||
setFacilities, | ||
selectedFacility, |
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 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(); |
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.
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, |
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.
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({ |
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 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.
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.
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() |
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.
Hrm, do you know if there's a reason we don't just use getFacilities
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.
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?
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.
ohh yes! it does the same thing will replace!
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.
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, |
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, 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!
Summary
WIP
…
References
…
Reviewer guidance
…