Skip to content
Merged
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
12 changes: 6 additions & 6 deletions ui/src/router/modules/application-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const ApplicationDetailRouter = {
},
() => {
const to: any = get_next_route()
if (to.params.from == 'resource-management') { } else { return RoleConst.WORKSPACE_MANAGE.getWorkspaceRole }
if (to.params.from == 'resource-management') { } else { return RoleConst.WORKSPACE_MANAGE.getWorkspaceRole() }
},
() => {
const to: any = get_next_route()
if (to.params.from == 'resource-management') { } else { return PermissionConst.APPLICATION_OVERVIEW_READ.getWorkspacePermissionWorkspaceManageRole }
if (to.params.from == 'resource-management') { } else { return PermissionConst.APPLICATION_OVERVIEW_READ.getWorkspacePermissionWorkspaceManageRole() }
},
() => {
const to: any = get_next_route()
Expand Down Expand Up @@ -76,13 +76,13 @@ const ApplicationDetailRouter = {
() => {
const to: any = get_next_route()
if (to.params.from == 'resource-management') { } else {
return RoleConst.WORKSPACE_MANAGE.getWorkspaceRole
return RoleConst.WORKSPACE_MANAGE.getWorkspaceRole()
}
},
() => {
const to: any = get_next_route()
if (to.params.from == 'resource-management') { } else {
return PermissionConst.APPLICATION_EDIT.getWorkspacePermissionWorkspaceManageRole
return PermissionConst.APPLICATION_EDIT.getWorkspacePermissionWorkspaceManageRole()
}
},
() => {
Expand Down Expand Up @@ -213,13 +213,13 @@ const ApplicationDetailRouter = {
() => {
const to: any = get_next_route()
if (to.params.from == 'resource-management') { } else {
return RoleConst.WORKSPACE_MANAGE.getWorkspaceRole
return RoleConst.WORKSPACE_MANAGE.getWorkspaceRole()
}
},
() => {
const to: any = get_next_route()
if (to.params.from == 'resource-management') { } else {
return PermissionConst.APPLICATION_CHAT_LOG_READ.getWorkspacePermissionWorkspaceManageRole
return PermissionConst.APPLICATION_CHAT_LOG_READ.getWorkspacePermissionWorkspaceManageRole()
}
},
() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code appears to have several minor inconsistencies and potential issues:

  1. Function Calls with Parentheses:

    if (to.params.from == 'resource-management') { } else { return RoleConst.WORKSPACE_MANAGE.getWorkspaceRole() }

    The parentheses around RoleConst.WORKSPACE_MANAGE.getWorkspaceRole() are not necessary unless getWorkspaceRole returns something other than a function.

  2. Same Code Duplication:

    // Same logic repeated four times for different permissions roles
    ...
    ...
    ...

    This repetition could be refactored into a loop or a helper function to avoid redundancy.

  3. Potential Null/Undefined Check Needed:
    Before calling functions that rely on certain parameters, ensure there is a check to prevent runtime errors when accessing properties of possibly null or undefined objects (to.params.from).

  4. Consistent Use of {} vs. Just Returning Values:
    Sometimes the braces {} after an arrow function can add unnecessary complexity without improving readability, especially when returning values directly.

Here's a slightly optimized version of the code, assuming no additional context requires extra changes:

const ApplicationDetailRouter = {
    path: '/application/:id',
    children: [
        { 
            name: 'Application Details', 
            meta: routeMeta({
                permission: PermissionConst.APPLICATION_OVERVIEW_READ,
            }), 
            component: () => import('@/views/application/ApplicationDetail.vue'),
            beforeRouteEnter(to, from, next) {
                const toParamsFrom = to.params.from || '';
                if (toParamsFrom === 'resource-management') {
                    return;
                }
                
                const role = getRoleBasedOnPath(to.path);
                if (role) {
                    return role;
                }

                const workspacePermissions = getUserWorkspacePermissions();
                return workspacePermissions.filter(permissionObj => {
                   return Object.values(PermissionConstants.Workspace).includes(permissionObj.type);
                })[0];
            },
            component: dynamicImport(() => ({
                name: "App",
            })),
        }
    ],
}

function getRoleBasedOnPath(path) {
    switch (path) {
        case '/application/dashboard':
            return null; // Example condition based on path
        default:
            throw new Error("Unknown application dashboard path provided");
    }
}

In this revised snippet:

  • Function calls are streamlined without unnecessary parentheses.
  • A utility function getApplicationRoleForChildRoutes has been introduced to handle the routing functionality in reusable format.
  • Placeholder comments indicating possible custom logic paths are noted inside the respective methods.

Expand Down
Loading