Skip to content

Commit

Permalink
feat: #1150 navigation to grant delegated admin screen (#1228)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicola Saglioni <nicola.saglioni@encora.com>
Co-authored-by: catherine meng <mcatherine1994@gmail.com>
  • Loading branch information
3 people committed Mar 12, 2024
1 parent 8f18c47 commit 44733c3
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 30 deletions.
4 changes: 3 additions & 1 deletion frontend/src/components/grantaccess/GrantAccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import UserNameInput from '@/components/grantaccess/form/UserNameInput.vue';
import ForestClientInput from '@/components/grantaccess/form/ForestClientInput.vue';
import FamLoginUserState from '@/store/FamLoginUserState';
import type { FamRoleDto } from 'fam-admin-mgmt-api/model';
import { setCurrentTabState } from '@/store/CurrentTabState';
import { TabKey } from '@/enum/TabEnum';
const defaultFormData = {
domain: UserType.I,
Expand Down Expand Up @@ -144,7 +146,7 @@ const handleSubmit = async () => {
errorCode,
role
);
setCurrentTabState(TabKey.UserAccess);
router.push('/dashboard');
};
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/grantaccess/GrantApplicationAdmin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { setNotificationMsg } from '@/store/NotificationState';
import LoginUserState from '@/store/FamLoginUserState';
import { computed, ref } from 'vue';
import { UserType } from 'fam-app-acsctl-api/model';
import { setCurrentTabState } from '@/store/CurrentTabState';
import { TabKey } from '@/enum/TabEnum';
const defaultFormData = {
userId: '',
Expand Down Expand Up @@ -100,6 +102,7 @@ const handleSubmit = async () => {
);
}
}
setCurrentTabState(TabKey.AdminAccess);
router.push('/dashboard');
};
</script>
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/grantaccess/GrantDelegatedAdmin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import type {
FamRoleDto,
FamAccessControlPrivilegeCreateRequest,
} from 'fam-admin-mgmt-api/model';
import { setCurrentTabState } from '@/store/CurrentTabState';
import { TabKey } from '@/enum/TabEnum';
const confirm = useConfirm();
Expand Down Expand Up @@ -140,8 +142,9 @@ const confirmSubmit = async () => {
successList,
errorList,
errorCode,
role,
role
);
setCurrentTabState(TabKey.DelegatedAdminAccess);
router.push('/dashboard');
};
Expand Down
58 changes: 35 additions & 23 deletions frontend/src/components/managePermissions/ManagePermissions.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<script setup lang="ts">
import { onUnmounted, ref, shallowRef, type PropType, computed } from 'vue';
import Dropdown, { type DropdownChangeEvent } from 'primevue/dropdown';
import TabView from 'primevue/tabview';
import TabView, { type TabViewChangeEvent } from 'primevue/tabview';
import TabPanel from 'primevue/tabpanel';
import ManagePermissionsTitle from '@/components/managePermissions/ManagePermissionsTitle.vue';
import UserDataTable from '@/components/managePermissions/table/UserDataTable.vue';
import ApplicationAdminTable from '@/components/managePermissions/table/ApplicationAdminTable.vue';
import LoginUserState from '@/store/FamLoginUserState';
import {
getCurrentTabState,
setCurrentTabState,
} from '@/store/CurrentTabState';
import DelegatedAdminTable from '@/components/managePermissions/table/DelegatedAdminTable.vue';
import {
isApplicationSelected,
Expand Down Expand Up @@ -35,6 +39,7 @@ import {
} from '@/services/fetchData';
import { Severity } from '@/enum/SeverityEnum';
import { IconSize } from '@/enum/IconEnum';
import { TabKey } from '@/enum/TabEnum';
const props = defineProps({
userRoleAssignments: {
Expand Down Expand Up @@ -63,28 +68,29 @@ const delegatedAdmins = shallowRef<FamAccessControlPrivilegeGetResponse[]>(
props.delegatedAdmins
);
const resetActiveTab = ref(0);
const applicationsUserAdministers = computed(() => {
return LoginUserState.getApplicationsUserAdministers();
});
const tabViewRef = ref();
onUnmounted(() => {
resetNotification();
});
const onApplicationSelected = async (e: DropdownChangeEvent) => {
setSelectedApplication(e.value ? JSON.stringify(e.value) : null);
// make the first tab active
resetActiveTab.value = 0;
if (e.value.id === FAM_APPLICATION_ID) {
setCurrentTabState(TabKey.AdminAccess);
applicationAdmins.value = await fetchApplicationAdmins();
} else {
if (!LoginUserState.isAdminOfSelectedApplication()) {
setCurrentTabState(TabKey.UserAccess);
}
userRoleAssignments.value = await fetchUserRoleAssignments(
selectedApplicationId.value
);
delegatedAdmins.value = await fetchDelegatedAdmins(
selectedApplicationId.value
);
Expand Down Expand Up @@ -149,6 +155,20 @@ const deleteDelegatedAdminAssignment = async (
);
}
};
// Tabs methods
const setCurrentTab = (event: TabViewChangeEvent) => {
setCurrentTabState(tabViewRef.value?.tabs[event.index].key);
};
const getCurrentTab = () => {
const tabIndex = tabViewRef.value?.tabs
.map((item: any) => {
return item.key;
})
.indexOf(getCurrentTabState());
return tabIndex > 0 ? tabIndex : 0;
};
</script>

<template>
Expand All @@ -171,7 +191,9 @@ const deleteDelegatedAdminAssignment = async (
<TablePlaceholder v-if="!isApplicationSelected" />
<TabView
v-else
v-model:active-index="resetActiveTab"
ref="tabViewRef"
:active-index="getCurrentTab()"
@tab-change="setCurrentTab($event)"
:pt="{
root: {
style: 'margin-top: 1.5rem',
Expand All @@ -182,30 +204,22 @@ const deleteDelegatedAdminAssignment = async (
}"
>
<TabPanel
:key="TabKey.AdminAccess"
header="Application admins"
v-if="selectedApplicationId === FAM_APPLICATION_ID"
>
<template #header>
<Icon
icon="enterprise"
:size="IconSize.small"
/>
<Icon icon="enterprise" :size="IconSize.small" />
</template>
<ApplicationAdminTable
:loading="isLoading()"
:applicationAdmins="applicationAdmins || []"
@deleteAppAdmin="deleteAppAdmin"
/>
</TabPanel>
<TabPanel
header="Users"
v-else
>
<TabPanel :key="TabKey.UserAccess" header="Users" v-else>
<template #header>
<Icon
icon="user"
:size="IconSize.small"
/>
<Icon icon="user" :size="IconSize.small" />
</template>

<UserDataTable
Expand All @@ -216,17 +230,15 @@ const deleteDelegatedAdminAssignment = async (
</TabPanel>

<TabPanel
:key="TabKey.DelegatedAdminAccess"
v-if="
LoginUserState.isAdminOfSelectedApplication() &&
selectedApplicationId !== FAM_APPLICATION_ID
"
header="Delegated admins"
>
<template #header>
<Icon
icon="enterprise"
:size="IconSize.small"
/>
<Icon icon="enterprise" :size="IconSize.small" />
</template>

<DelegatedAdminTable
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/enum/TabEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum TabKey {
AdminAccess = 'adminAccess',
UserAccess = 'userAccess',
DelegatedAdminAccess = 'delegatedAdminAccess'
}
7 changes: 3 additions & 4 deletions frontend/src/layouts/ProtectedLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const setSideNavOptions = () => {
if (LoginUserState.isAdminOfSelectedApplication()) {
disableSideNavOption('Add delegated admin', false);
} else {
disableSideNavOption('Add delegated admin', true);
}
}
};
Expand All @@ -52,10 +54,7 @@ const disableSideNavOption = (optionName: string, disabled: boolean) => {
};
</script>
<template>
<Header
title="FAM"
subtitle="Forests Access Management"
/>
<Header title="FAM" subtitle="Forests Access Management" />

<SideNav :data="navigationData" />
<div class="main">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/static/sideNav.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{
"name": "Add delegated admin",
"icon": "enterprise",
"link": "#",
"link": "/grant-delegated-admin",
"disabled": true
}
]
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/store/CurrentTabState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ref } from 'vue';

const currentTabState = ref<string>("");

export const setCurrentTabState = (status: string) => {
currentTabState.value = status;
}

export const getCurrentTabState = (): string => {
return currentTabState.value;
}

0 comments on commit 44733c3

Please sign in to comment.