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

Gives indication of user having permission to join the facility not showing the devices that don't have sign up enabled. #10703

Merged
merged 14 commits into from
Jun 9, 2023

Conversation

Wck-iipi
Copy link
Contributor

Summary

This does it by copying the logic for getting facility's information from SelectFacility and shows the devices accordingly. If the sign up is allowed, only then device is shown.

References

Fixes #10313

Reviewer guidance

Please test whether devices are not shown when permission to sign up is not given.


Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

PR process

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Reviewer checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

Wck-iipi added 2 commits May 15, 2023 01:20
In this, I have added a basic logic of how the problem will be solved.
@nucleogenesis nucleogenesis self-requested a review May 15, 2023 22:42
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'll hold approval until @pcenov / @radinamatic has a chance to do some manual QA here to be sure everything works as expected.

Overall, the code looks good. I added one thought about seemingly duplicitous code in how you're fetching facilities -- but I may be misreading there (cc @rtibbles @akolson ?) - so let's see what the outcome of some discussion around this brings us in the mean time.

@nucleogenesis nucleogenesis requested review from pcenov and akolson May 15, 2023 23:01
@nucleogenesis
Copy link
Member

@Wck-iipi I'm not seeing why the tests are failing in the Github Actions output - can you run yarn test locally to see if things fail there? If tests pass locally, then it's likely an issue with the Github Action or something.

@nucleogenesis nucleogenesis requested a review from bjester May 15, 2023 23:06
@Wck-iipi
Copy link
Contributor Author

@nucleogenesis Sorry about the test cases failing, I ran tests on my branch and then on develop and both were failing day before yesterday so I thought my code didn't break anything.
The reason for the tests failing was that it was expecting more KRadioButton whereas I had set the condition to only show the KRadioButton if you could sign up through them. Therefore, it expected 6 and got 0 KRadioButtons.
Therefore, I now have disabled the KRadioButton instead of hiding it so that it can pass the tests, and removed the unnecessary code.
The continue button, however, still is taking us to the sign up page irrespective of whether we have selected KRadioButton or not. This hasn't been fixed yet and I can fix it if you want to.
Regarding commonSyncElements, I tried to await and pass device.id to fetchNetworkLocationFacilities but it is not working at all and is giving no output. I couldn't even debug the error, it just doesn't respond. Thanks again for guiding me.

@Wck-iipi Wck-iipi requested a review from nucleogenesis May 16, 2023 20:30
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.

@Wck-iipi I learned in a follow-up discussion with @bjester that the logic used here is duplicitous of code already available between useDevices and the SelectDeviceModalGroup/api.js.

This logic I believe should instead implement a filtering function which checks if a device has a facility with sign-ups allowed. This would be akin to the facilityIsAvailableAtDevice function.

However, the new function would just take the deviceId and return if any of the facilities have the ability to allow sign ups like this (I've not tested this):

export function deviceFacilityCanSignUp(deviceId) {
    return NetworkLocationResource.fetchFacilities(deviceId)
        .then(({ facilities }) => {
             return facilities.some(f => f.learner_can_sign_up));
        });
}

In this case then, we can get the list of devices using useDevicesForLearnOnlyDevice from useDevices to get a pre-filtered list of devices which is necessary for this particular case. Then iterate over these devices, calling the new function above for each device, and you can then know which devices should be shown in this case.

In this case now the SelectDeviceForm doesn't have to worry about maintaining a list of facilities, but rather can just hone in on which devices are useful in a particular case.


The change requests here are substantial -- essentially reworking most of what you've added. This issue is also a relatively urgent fix in our pipeline, which I want to share because we don't expect that your contributions will necessarily align with our plans.

If you'd like to take another shot this week, please let me know along with any questions and I'll do my best to clarify. If not, then I totally understand and greatly appreciate the work you've put in on this. It opened up a greater discussion around keeping our code extensible which is invaluable in any case.

@Wck-iipi
Copy link
Contributor Author

@nucleogenesis I would love to continue to work on this.

@Wck-iipi
Copy link
Contributor Author

@nucleogenesis I have made some changes. Is this in the right direction?
Also, I don't know how to filter LODDevicesWithSignUpFacility with promise in deviceFacilityCanSignUp in

const LODDevicesWithSignUpFacility = computed(() =>
  get(devices).filter(async (d) => {
    await deviceFacilityCanSignUp(d.id)
  })
);

and would love your guidance. Thanks.

@nucleogenesis
Copy link
Member

I wonder if maybe computedAsync would help out in this case?

In any case, perhaps if deviceFacilityCanSignUp returned an object w/ the device ID like { deviceId: uuid, canSignUp: bool } then you could map the devices and use Promise.all:

Promise.all(
    get(devices).map(d => deviceFacilityCanSignUp(d.id)
).then(resolvedValues => {
    // resolvedValues would be a list of those objects with the `deviceId` and `canSignUp` keys
    // so then now we have a list of deviceIds which match what we care about so we can return get(devices) filtered by that
});

... I think ... I hope that helps 😅


The latest commit looks like you're headed in the right direction 🙂 🚀

@Wck-iipi
Copy link
Contributor Author

Wck-iipi commented May 18, 2023

@nucleogenesis I have added the required code. However, this won't pass 2 tests. The first one

 {
    id: '1',
    instance_id: '1',
    nickname: 'Available Server',
    base_url: 'http://localhost:8000',
    application: 'kolibri',
    available: true,
},

sends above data and expects the KRadioButton to be enabled. But it is disabled as no information about the SignUp is provided(this line to be exact is causing the KRadioButton of dynamic device to be disabled). I can update the test case if you want to.

About the second test case failing, I have absolutely no idea why it is failing, LearningActivityBar is not even related to my commit. I ran tests on develop branch as well but it gave same test as wrong. Can you please check if the second test LearningActivityBar › on a large screen › download › doesn't show the downloading loader by default is failing due to my commit or not. Thanks again for your guidance.

@Wck-iipi Wck-iipi requested review from akolson and nucleogenesis May 28, 2023 18:19
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.

@Wck-iipi

I apologize for my delay in re-reviewing your work here I should have come back to this much sooner.

I have tested it and it works as expected and the code updates all look great to me.

I'm going to approve and merge this. From our whole team, thank you so much for taking this complex and critical issue and being patient with our feedback here as I know you have gone through your exams during this time. Your work is greatly appreciated and I hope we get to work with you again!

Please feel free to submit another PR adding your name and Github username to the AUTHORS.md file in the root of the repo if you'd like to be included there ❤️

@@ -186,6 +190,24 @@
const discoveredDevices = computed(() => get(devices).filter(d => d.dynamic));
const savedDevices = computed(() => get(devices).filter(d => !d.dynamic));

const isLoading = ref(false);
Copy link
Member

Choose a reason for hiding this comment

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

@Wck-iipi

Is it okay to show "There are no devices yet" when there are devices but there are none that can sign up or should I use another string?

I'm not seeing anywhere that this ref's value is being read back. This could be used to conditionally put a <KCircularLoader /> component (which is globally available, no need to import it from anywhere) in place of where either the data or the "no data" message should go?

@@ -356,6 +379,14 @@
this.$emit('removed_address');
});
},
canLearnerSignUp(id) {
if (this.LODDevicesWithSignUpFacility) {
Copy link
Member

Choose a reason for hiding this comment

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

Because this is an asyncComputed property I think you should be using isLoading here as well because if the async operation hasn't resolved then we can just return false.

This is a place where managing tests can get really tough because you'll need to be sure that the async data is available, so I suspect that in the failing test you'll need to be sure that this new method is represented properly.

@nucleogenesis
Copy link
Member

Actually I'll fix the tests and push to your remote so we can get this merged 😄

@nucleogenesis nucleogenesis merged commit 9025057 into learningequality:develop Jun 9, 2023
bjester added a commit to bjester/kolibri that referenced this pull request Nov 8, 2023
…Solution"

This reverts commit 9025057, reversing
changes made to 0e2dc3a.
bjester added a commit to bjester/kolibri that referenced this pull request Nov 17, 2023
…Solution"

This reverts commit 9025057, reversing
changes made to 0e2dc3a.
bjester added a commit to bjester/kolibri that referenced this pull request Nov 21, 2023
…Solution"

This reverts commit 9025057, reversing
changes made to 0e2dc3a.
@Wck-iipi Wck-iipi deleted the 10313Solution branch March 24, 2024 11:38
@Wck-iipi Wck-iipi restored the 10313Solution branch March 24, 2024 11:38
@Wck-iipi Wck-iipi deleted the 10313Solution branch March 25, 2024 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants