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

Fix Role permission, api resource not displaying bug #4387

Merged
merged 6 commits into from
Oct 27, 2023
Merged
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
5 changes: 5 additions & 0 deletions .changeset/purple-icons-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wso2is/console": patch
---

role permission, api resource not displaying bug fixed
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const BasicRoleDetails: FunctionComponent<BasicRoleProps> = (props: Basic
isLoading: isRolesListLoading,
error: rolesListError,
isValidating: isRolesListValidating
} = useRolesList( undefined, undefined, roleNameSearchQuery);
} = useRolesList(undefined, undefined, roleNameSearchQuery);

/**
* Dispatches the alert object to the redux store.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { addAlert } from "@wso2is/core/store";
import { Field, Form } from "@wso2is/form";
import { EmphasizedSegment, Heading } from "@wso2is/react-components";
import debounce, { DebouncedFunc } from "lodash-es/debounce";
import isEmpty from "lodash-es/isEmpty";
import React, {
FunctionComponent,
ReactElement,
Expand Down Expand Up @@ -303,18 +304,23 @@ export const UpdatedRolePermissionDetails: FunctionComponent<RolePermissionDetai
*/
const searchAPIResources: DebouncedFunc<(query: string) => void> =
useCallback(debounce((query: string) => {
setAPIResourceSearchQuery(`name co ${query}`);
setAPIResourceSearchQuery(
!isEmpty(query)
? `name co ${query}`
: null
);
mutateAPIResourcesListFetchRequest().finally(() => {
setAPIResourcesSearching(false);
setAPIResourceSearchQuery(undefined);
});
}, RoleConstants.DEBOUNCE_TIMEOUT), []);

/**
* Handles the selection of an API resource.
*/
const onAPIResourceSelected = (event: SyntheticEvent<HTMLElement>, data: DropdownProps): void => {
event.preventDefault();
setSelectedAPIResourceId(data.value.toString());
setAPIResourceSearchQuery(undefined);
};

/**
Expand Down Expand Up @@ -366,12 +372,14 @@ export const UpdatedRolePermissionDetails: FunctionComponent<RolePermissionDetai
onSubmit={ undefined }
>
<Field.Dropdown
search
selection
selectOnNavigation={ false }
ariaLabel="assignedApplication"
name="assignedApplication"
label={ t("console:manage.features.roles.addRoleWizard.forms.rolePermission." +
"apiResource.label") }
options={ apiResourcesListOptions }
search
data-componentid={ `${componentId}-typography-font-family-dropdown` }
placeholder={ t("console:manage.features.roles.addRoleWizard." +
"forms.rolePermission.apiResource.placeholder") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
* under the License.
*/

import { Autocomplete, AutocompleteRenderGetTagProps, AutocompleteRenderInputParams } from "@mui/material";
import Autocomplete, {
AutocompleteRenderGetTagProps,
AutocompleteRenderInputParams
} from "@oxygen-ui/react/Autocomplete";
import TextField from "@oxygen-ui/react/TextField";
import { IdentifiableComponentInterface } from "@wso2is/core/models";
import React, { FunctionComponent, HTMLAttributes, ReactElement, SyntheticEvent } from "react";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { addAlert } from "@wso2is/core/store";
import { Field, Form } from "@wso2is/form";
import { EmphasizedSegment } from "@wso2is/react-components";
import debounce, { DebouncedFunc } from "lodash-es/debounce";
import isEmpty from "lodash-es/isEmpty";
import React, { FunctionComponent, ReactElement, SyntheticEvent, useCallback, useEffect, useState } from "react";
import { Trans, useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";
Expand Down Expand Up @@ -173,7 +174,7 @@ export const RolePermissionsList: FunctionComponent<RolePermissionsListProp> =
}
});
}

setAPIResourcesListOptions(options);
}, [ authorizedAPIListForApplication, apiResourcesList, selectedAPIResources ]);

Expand All @@ -199,10 +200,13 @@ export const RolePermissionsList: FunctionComponent<RolePermissionsListProp> =
*/
const searchAPIResources: DebouncedFunc<(query: string) => void> =
useCallback(debounce((query: string) => {
setAPIResourceSearchQuery(`name co ${query}`);
setAPIResourceSearchQuery(
!isEmpty(query)
? `name co ${query}`
: null
);
mutateAPIResourcesListFetchRequest().finally(() => {
setAPIResourcesSearching(false);
setAPIResourceSearchQuery(undefined);
});
}, RoleConstants.DEBOUNCE_TIMEOUT), []);

Expand All @@ -224,6 +228,7 @@ export const RolePermissionsList: FunctionComponent<RolePermissionsListProp> =
* else add the API resource to the selected API resources list from the authorized API list.
*/
const onAPIResourceSelected = (event: SyntheticEvent<HTMLElement>, data: DropdownProps): void => {
event.preventDefault();
if(roleAudience === RoleAudienceTypes.ORGANIZATION) {
setSelectedAPIResourceId(data.value.toString());
} else {
Expand All @@ -240,6 +245,7 @@ export const RolePermissionsList: FunctionComponent<RolePermissionsListProp> =
...selectedAPIResources
]);
}
setAPIResourceSearchQuery(undefined);
};

/**
Expand Down Expand Up @@ -304,12 +310,14 @@ export const RolePermissionsList: FunctionComponent<RolePermissionsListProp> =
onSubmit={ undefined }
>
<Field.Dropdown
search
selection
selectOnNavigation={ false }
ariaLabel="assignedApplication"
name="assignedApplication"
label={ t("console:manage.features.roles.addRoleWizard.forms.rolePermission." +
"apiResource.label") }
options={ apiResourcesListOptions }
search
data-componentid={ `${componentId}-typography-font-family-dropdown` }
placeholder={ t("console:manage.features.roles.addRoleWizard.forms.rolePermission." +
"apiResource.placeholder") }
Expand Down
8 changes: 7 additions & 1 deletion apps/console/src/features/roles/pages/create-role-wizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ import { RoleAudienceTypes } from "../constants";
import {
CreateRoleFormData,
CreateRoleInterface,
CreateRolePermissionInterface,
CreateRoleStateInterface,
CreateRoleStepsFormTypes,
SelectedPermissionsInterface
} from "../models";
import { ScopeInterface } from "../models/apiResources";

/**
* Interface which captures create role props.
Expand Down Expand Up @@ -88,6 +90,10 @@ const CreateRoleWizard: FunctionComponent<CreateRoleProps> = (props: CreateRoleP

const roleAudience: string = stepperState[ CreateRoleStepsFormTypes.BASIC_DETAILS ].roleAudience;
const organizationId: string = store.getState().organization.organization.id;
const selectedPermissionsList: CreateRolePermissionInterface[] = selectedPermissions?.flatMap(
(permission: SelectedPermissionsInterface) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we improve formatting here

permission?.scopes?.map((scope: ScopeInterface) => ({ value: scope?.name })) || []
)) || [];

const roleData: CreateRoleInterface = {
audience: roleAudience === RoleAudienceTypes.ORGANIZATION
Expand All @@ -100,7 +106,7 @@ const CreateRoleWizard: FunctionComponent<CreateRoleProps> = (props: CreateRoleP
value: stepperState[ CreateRoleStepsFormTypes.BASIC_DETAILS ].assignedApplicationId
},
displayName: stepperState[ CreateRoleStepsFormTypes.BASIC_DETAILS ].roleName,
permissions: [],
permissions: selectedPermissionsList,
schemas: []
};

Expand Down
Loading