Skip to content

Commit

Permalink
add space role assignment flyout help text to match updated designs
Browse files Browse the repository at this point in the history
  • Loading branch information
eokoneyo committed Sep 18, 2024
1 parent bdc1a5c commit 385d2a1
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('PrivilegesRolesForm', () => {
jest.clearAllMocks();
});

it('renders the privilege permission selector disabled when no role is selected', async () => {
it('does not display the privilege selection buttons or customization form when no role is selected', async () => {
getRolesSpy.mockResolvedValue([]);
getAllKibanaPrivilegeSpy.mockResolvedValue(createRawKibanaPrivileges(kibanaFeatures));

Expand All @@ -141,17 +141,8 @@ describe('PrivilegesRolesForm', () => {
await waitFor(() => null);

['all', 'read', 'custom'].forEach((privilege) => {
expect(screen.getByTestId(`${privilege}-privilege-button`)).toBeDisabled();
expect(screen.queryByTestId(`${privilege}-privilege-button`)).not.toBeInTheDocument();
});
});

it('does not display the the privilege customization form disabled when no role is selected', async () => {
getRolesSpy.mockResolvedValue([]);
getAllKibanaPrivilegeSpy.mockResolvedValue(createRawKibanaPrivileges(kibanaFeatures));

renderPrivilegeRolesForm();

await waitFor(() => null);

expect(
screen.queryByTestId('space-assign-role-privilege-customization-form')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,145 +389,151 @@ export const PrivilegesRolesForm: FC<PrivilegesRolesFormProps> = (props) => {
</EuiFormRow>
)}
</React.Fragment>
<EuiFormRow>
{selectedRolesCombinedPrivileges.length > 1 ? (
<EuiCallOut
size="s"
color="warning"
iconType="iInCircle"
data-test-subj="privilege-conflict-callout"
title={i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privilegeConflictMsg.title',
{
defaultMessage: 'Selected roles have different privileges granted',
}
)}
>
{i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privilegeConflictMsg.description',
{
defaultMessage:
'Updating the settings here in a bulk will override current individual settings.',
}
)}
</EuiCallOut>
) : (
<EuiCallOut
size="s"
color="primary"
iconType="iInCircle"
data-test-subj="privilege-info-callout"
title={i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privilegeConflictMsg.title',
{
defaultMessage: 'Privileges will apply to all current and future spaces.',
}
)}
/>
)}
</EuiFormRow>
<EuiFormRow
label={i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privilegesLabelText',
{
defaultMessage: 'Define role privileges',
}
)}
>
<EuiButtonGroup
data-test-subj="space-assign-role-privilege-selection-switch"
legend={i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privilegeSelectionLegendText',
{
defaultMessage: 'select the privilege for the features enabled in this space',
}
)}
isDisabled={!Boolean(selectedRoles.length)}
options={[
{
id: FEATURE_PRIVILEGES_ALL,
label: i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privileges.all',
{
defaultMessage: 'All',
}
),
},
{
id: FEATURE_PRIVILEGES_READ,
label: i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privileges.read',
{ defaultMessage: 'Read' }
),
},
{
id: FEATURE_PRIVILEGES_CUSTOM,
label: i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privileges.custom',
{ defaultMessage: 'Customize' }
),
},
].map((privilege) => ({
...privilege,
'data-test-subj': `${privilege.id}-privilege-button`,
}))}
color="primary"
idSelected={roleSpacePrivilege}
onChange={(id) => onRoleSpacePrivilegeChange(id as KibanaRolePrivilege)}
isFullWidth
/>
</EuiFormRow>
{Boolean(selectedRoles.length) && (
<EuiFormRow data-test-subj="space-assign-role-privilege-customization-form">
<React.Fragment>
{Boolean(selectedRoles.length) && (
<React.Fragment>
{!kibanaPrivileges ? (
<EuiLoadingSpinner size="l" />
) : (
<KibanaPrivilegeTable
showTitle={false}
disabled={roleSpacePrivilege !== FEATURE_PRIVILEGES_CUSTOM}
role={roleCustomizationAnchor.value!}
privilegeIndex={roleCustomizationAnchor.privilegeIndex}
onChange={(featureId, selectedPrivileges) => {
// apply selected changes only to the designated customization anchor, this way we delay reconciling the intending privileges
// to all of the selected roles till we decide to commit the changes chosen
setRoleCustomizationAnchor(({ value, privilegeIndex }) => {
let privilege;

if ((privilege = value!.kibana?.[privilegeIndex!])) {
privilege.feature[featureId] = selectedPrivileges;
<EuiFormRow>
{selectedRolesCombinedPrivileges.length > 1 ? (
<EuiCallOut
size="s"
color="warning"
iconType="iInCircle"
data-test-subj="privilege-conflict-callout"
title={i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privilegeConflictMsg.title',
{
defaultMessage: 'Selected roles have different privileges granted',
}

return { value, privilegeIndex };
});
}}
onChangeAll={(_privilege) => {
// apply selected changes only to the designated customization anchor, this way we delay reconciling the intending privileges
// to all of the selected roles till we decide to commit the changes chosen
setRoleCustomizationAnchor(({ value, privilegeIndex }) => {
let privilege;

if ((privilege = value!.kibana?.[privilegeIndex!])) {
privilege.base = _privilege;
)}
>
{i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privilegeConflictMsg.description',
{
defaultMessage:
'Updating the settings here in a bulk will override current individual settings.',
}

return { value, privilegeIndex };
});
}}
kibanaPrivileges={new KibanaPrivileges(kibanaPrivileges, features)}
privilegeCalculator={
new PrivilegeFormCalculator(
new KibanaPrivileges(kibanaPrivileges, features),
roleCustomizationAnchor.value!
)
)}
</EuiCallOut>
) : (
<EuiCallOut
size="s"
color="primary"
iconType="iInCircle"
data-test-subj="privilege-info-callout"
title={i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privilegeConflictMsg.title',
{
defaultMessage: 'Privileges will apply only to this space.',
}
)}
/>
)}
</EuiFormRow>
<EuiFormRow
label={i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privilegesLabelText',
{
defaultMessage: 'Define role privileges',
}
allSpacesSelected={false}
canCustomizeSubFeaturePrivileges={false}
)}
>
<EuiButtonGroup
data-test-subj="space-assign-role-privilege-selection-switch"
legend={i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privilegeSelectionLegendText',
{
defaultMessage: 'select the privilege for the features enabled in this space',
}
)}
isDisabled={!Boolean(selectedRoles.length)}
options={[
{
id: FEATURE_PRIVILEGES_ALL,
label: i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privileges.all',
{
defaultMessage: 'All',
}
),
},
{
id: FEATURE_PRIVILEGES_READ,
label: i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privileges.read',
{ defaultMessage: 'Read' }
),
},
{
id: FEATURE_PRIVILEGES_CUSTOM,
label: i18n.translate(
'xpack.spaces.management.spaceDetails.roles.assign.privileges.custom',
{ defaultMessage: 'Customize' }
),
},
].map((privilege) => ({
...privilege,
'data-test-subj': `${privilege.id}-privilege-button`,
}))}
color="primary"
idSelected={roleSpacePrivilege}
onChange={(id) => onRoleSpacePrivilegeChange(id as KibanaRolePrivilege)}
isFullWidth
/>
</EuiFormRow>
{Boolean(selectedRoles.length) && (
<EuiFormRow data-test-subj="space-assign-role-privilege-customization-form">
<React.Fragment>
{!kibanaPrivileges ? (
<EuiLoadingSpinner size="l" />
) : (
<KibanaPrivilegeTable
showTitle={false}
disabled={roleSpacePrivilege !== FEATURE_PRIVILEGES_CUSTOM}
role={roleCustomizationAnchor.value!}
privilegeIndex={roleCustomizationAnchor.privilegeIndex}
onChange={(featureId, selectedPrivileges) => {
// apply selected changes only to the designated customization anchor, this way we delay reconciling the intending privileges
// to all of the selected roles till we decide to commit the changes chosen
setRoleCustomizationAnchor(({ value, privilegeIndex }) => {
let privilege;

if ((privilege = value!.kibana?.[privilegeIndex!])) {
privilege.feature[featureId] = selectedPrivileges;
}

return { value, privilegeIndex };
});
}}
onChangeAll={(_privilege) => {
// apply selected changes only to the designated customization anchor, this way we delay reconciling the intending privileges
// to all of the selected roles till we decide to commit the changes chosen
setRoleCustomizationAnchor(({ value, privilegeIndex }) => {
let privilege;

if ((privilege = value!.kibana?.[privilegeIndex!])) {
privilege.base = _privilege;
}

return { value, privilegeIndex };
});
}}
kibanaPrivileges={new KibanaPrivileges(kibanaPrivileges, features)}
privilegeCalculator={
new PrivilegeFormCalculator(
new KibanaPrivileges(kibanaPrivileges, features),
roleCustomizationAnchor.value!
)
}
allSpacesSelected={false}
canCustomizeSubFeaturePrivileges={false}
/>
)}
</React.Fragment>
</EuiFormRow>
)}
</React.Fragment>
</EuiFormRow>
)}
)}
</React.Fragment>
</EuiForm>
);
};
Expand Down

0 comments on commit 385d2a1

Please sign in to comment.