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

[MS] Added org switch #5744

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -35,7 +35,7 @@ import {
import {
checkmark,
} from 'ionicons/icons';
import { MsDropdownOption, getMsOptionByKey } from '@/components/core/ms-types';
import { MsDropdownOption, getMsOptionByKey, MsModalResult } from '@/components/core/ms-types';

const props = defineProps<{
defaultOption?: any
Expand All @@ -50,9 +50,7 @@ function onOptionClick(option?: MsDropdownOption): void {
if (option) {
selectedOption.value = option;
}
popoverController.dismiss({
option: selectedOption.value,
});
popoverController.dismiss({option: selectedOption.value}, MsModalResult.Confirm);
}
</script>

Expand Down
36 changes: 35 additions & 1 deletion client/src/parsec/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
ClientInfo,
ClientInfoError,
UserProfile,
DeviceInfo,
ClientListUserDevicesError,
ClientListUserDevicesErrorTag,
OwnDeviceInfo,
Expand Down Expand Up @@ -133,3 +132,38 @@ export async function listOwnDevices(): Promise<Result<Array<OwnDeviceInfo>, Cli
}]};
}
}

export enum ConnectedDeviceErrorTag {
Internal = 'Internal'
}

export interface ConnectedDeviceError {
tag: ConnectedDeviceErrorTag.Internal
}

export interface ConnectedDevice extends AvailableDevice {
handle: Handle
isCurrent: boolean
}

// Simulate what will be a call to the bindings
export async function listConnectedDevices(): Promise<Result<Array<ConnectedDevice>, ConnectedDeviceError>> {
if (!needsMocks()) {
return {ok: true, value: []};
}
const devices = await listAvailableDevices();
const deviceList: Array<ConnectedDevice> = [];
const currentHandle = getParsecHandle();

if (devices.length > 1) {
let connectedDevice = devices[0];
(connectedDevice as ConnectedDevice).handle = DEFAULT_HANDLE;
(connectedDevice as ConnectedDevice).isCurrent = (connectedDevice as ConnectedDevice).handle === currentHandle;
deviceList.push(connectedDevice as ConnectedDevice);
connectedDevice = devices[1];
(connectedDevice as ConnectedDevice).handle = DEFAULT_HANDLE + 1;
(connectedDevice as ConnectedDevice).isCurrent = false;
deviceList.push(connectedDevice as ConnectedDevice);
}
return {ok: true, value: deviceList};
}
49 changes: 47 additions & 2 deletions client/src/views/sidebar-menu/SidebarMenuPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
v-show="!isOrganizationManagementRoute()"
>
<!-- active organization -->
<ion-card class="organization-card">
<ion-card
class="organization-card"
@click="openOrganizationChoice($event)"
>
<ion-card-header class="organization-card__header">
<div class="organization-card__container">
<ion-avatar class="orga-avatar">
Expand All @@ -37,7 +40,6 @@
<!-- Keep it hidden for now since we have no way of switching org -->
<div
class="organization-card__icon"
v-show="false"
>
<!-- new icon to provide -->
<svg
Expand Down Expand Up @@ -256,6 +258,7 @@ import {
menuController,
GestureDetail,
IonButton,
popoverController,
} from '@ionic/vue';
import {
business,
Expand All @@ -276,7 +279,11 @@ import {
ClientInfo,
UserProfile,
WorkspaceInfo,
listConnectedDevices,
Handle,
} from '@/parsec';
import MsDropdownPopover from '@/components/core/ms-dropdown/MsDropdownPopover.vue';
import { MsDropdownOption, MsModalResult } from '@/components/core/ms-types';

const workspaces: Ref<Array<WorkspaceInfo>> = ref([]);

Expand Down Expand Up @@ -304,6 +311,44 @@ function navigateToWorkspaceList(): void {
menuController.close();
}

async function openOrganizationChoice(clickEvent: Event): Promise<void> {
const result = await listConnectedDevices();

if (!result.ok) {
// Failed to list, probably should display an error, will decide later
return;
}
let defaultHandle: Handle | null = null;
const options: MsDropdownOption[] = result.value.map((device) => {
if (device.isCurrent) {
defaultHandle = device.handle;
}
return {label: `${device.organizationId} - ${device.humanHandle.label}`, key: device.handle};
});
options.push({label: '...another organization', key: null});

const popover = await popoverController.create({
component: MsDropdownPopover,
componentProps: {
options: options,
defaultOption: defaultHandle,
},
showBackdrop: false,
event: clickEvent,
});
await popover.present();
const { data, role } = await popover.onWillDismiss();
await popover.dismiss();
if (role !== MsModalResult.Confirm || !data || data.option.key === defaultHandle) {
return;
}
if (data.option.key === null) {
console.log('Switch to login page');
} else {
console.log(`Switch to org with handle ${data.option.key}`);
}
}

onMounted(async () => {
const infoResult = await parsecGetClientInfo();

Expand Down