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
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
:key="idx"
v-model="selectedDeviceId"
class="radio-button"
:value="d.id"
:value="canLearnerSignUp(d.id) ? d.id : false"
:label="d.nickname"
:description="d.base_url"
:disabled="formDisabled || !isDeviceAvailable(d.id)"
:disabled="!canLearnerSignUp(d.id) || formDisabled || !isDeviceAvailable(d.id)"
/>
<KButton
:key="`forget-${idx}`"
Expand All @@ -65,10 +65,13 @@
:key="d.id"
v-model="selectedDeviceId"
class="radio-button"
:value="d.instance_id"
:value="canLearnerSignUp(d.id) ? d.instance_id : false"
:label="formatNameAndId(d.device_name, d.id)"
:description="formatBaseDevice(d)"
:disabled="formDisabled || fetchFailed || !isDeviceAvailable(d.id)"
:disabled="!canLearnerSignUp(d.id)
|| formDisabled
|| fetchFailed
|| !isDeviceAvailable(d.id)"
/>
</div>
</template>
Expand Down Expand Up @@ -123,8 +126,8 @@

<script>

import { computed } from 'kolibri.lib.vueCompositionApi';
import { useLocalStorage, get } from '@vueuse/core';
import { computed, ref } from 'kolibri.lib.vueCompositionApi';
import { useLocalStorage, get, computedAsync } from '@vueuse/core';
import find from 'lodash/find';
import UiAlert from 'kolibri-design-system/lib/keen/UiAlert';
import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings';
Expand All @@ -137,6 +140,7 @@
useDevicesForLearnOnlyDevice,
} from './useDevices.js';
import useConnectionChecker from './useConnectionChecker.js';
import { deviceFacilityCanSignUp } from './api.js';

export default {
name: 'SelectDeviceForm',
Expand Down Expand Up @@ -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?


const LODDevicesWithSignUpFacility = computedAsync(
async () => {
const devicesAvailable = get(devices);
const allDevices = {};
for (const i of devicesAvailable) {
const canSignUp = await deviceFacilityCanSignUp(i.id);
if (canSignUp) {
allDevices[i.id] = true;
}
}
return allDevices;
},
{},
isLoading
);

return {
// useDevices
devices,
Expand All @@ -205,6 +227,7 @@
discoveredDevices,
savedDevices,
storageDeviceId,
LODDevicesWithSignUpFacility,
};
},
props: {
Expand Down Expand Up @@ -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.

if (id in this.LODDevicesWithSignUpFacility) {
return true;
}
}
return false;
},
Wck-iipi marked this conversation as resolved.
Show resolved Hide resolved
},
$trs: {
deletingFailedText: {
Expand Down
17 changes: 17 additions & 0 deletions kolibri/core/assets/src/views/sync/SelectDeviceModalGroup/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,20 @@ export function channelIsAvailableAtDevice(channelId, device) {
export function updateConnectionStatus(device) {
return NetworkLocationResource.updateConnectionStatus(device.id);
}

/**
* @param {string} deviceId
* @return {Promise<boolean>}
*/
export function deviceFacilityCanSignUp(deviceId) {
return NetworkLocationResource.fetchFacilities(deviceId).then(({ device_id, facilities }) => {
if (deviceId === device_id) {
for (const facility of facilities) {
if (facility.learner_can_sign_up) {
return true;
}
}
}
return false;
});
}