Skip to content

Commit

Permalink
Merge pull request #6862 from PasinduYeshan/fix/rbpe-1
Browse files Browse the repository at this point in the history
Update rule based password expiry UI
  • Loading branch information
PasinduYeshan authored Sep 3, 2024
2 parents 6045985 + 60c435a commit d845ccc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/mean-avocados-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@wso2is/admin.validation.v1": patch
"@wso2is/i18n": patch
---

Change wordings of rule based password expiry
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import TextField from "@oxygen-ui/react/TextField";
import { ChevronDownIcon, ChevronUpIcon, PlusIcon, TrashIcon } from "@oxygen-ui/react-icons";
import { userstoresConfig } from "@wso2is/admin.extensions.v1";
import { GroupsInterface } from "@wso2is/admin.groups.v1";
import { RoleAudienceTypes } from "@wso2is/admin.roles.v2/constants";
import {
GovernanceConnectorConstants
} from "@wso2is/admin.server-configurations.v1/constants/governance-connector-constants";
Expand All @@ -57,10 +58,13 @@ interface PasswordExpiryRuleListProps {

type Resource = RolesInterface | GroupsInterface;

enum Direction {
UP = "up",
DOWN = "down"
}

export const PasswordExpiryRuleList: FunctionComponent<PasswordExpiryRuleListProps> = (
props: PasswordExpiryRuleListProps
) => {
const {
{
componentId,
ruleList,
isPasswordExpiryEnabled,
Expand All @@ -73,7 +77,8 @@ export const PasswordExpiryRuleList: FunctionComponent<PasswordExpiryRuleListPro
onDefaultPasswordExpiryTimeChange,
onRuleChange,
onRuleError
} = props;
}: PasswordExpiryRuleListProps
) => {

const [ rules, setRules ] = useState<PasswordExpiryRule[]>(ruleList);
const [ hasErrors, setHasErrors ] = useState<{ [key: string]: { values: boolean; expiryDays: boolean } }>({});
Expand Down Expand Up @@ -180,12 +185,13 @@ export const PasswordExpiryRuleList: FunctionComponent<PasswordExpiryRuleListPro
* @param index - index of the rule.
* @param direction - direction to move the rule.
*/
const movePriority = (index: number, direction: "up" | "down") => {
if ((direction === "up" && index === 0) || (direction === "down" && index === rules.length - 1)) {
const movePriority = (index: number, direction: Direction) => {
if ((direction === Direction.UP && index === 0) || (direction === Direction.DOWN && index === rules.length - 1))
{
return;
}
const updatedRules: PasswordExpiryRule[] = [ ...rules ];
const swapIndex: number = direction === "up" ? index - 1 : index + 1;
const swapIndex: number = direction === Direction.UP ? index - 1 : index + 1;

[ updatedRules[index], updatedRules[swapIndex] ] = [ updatedRules[swapIndex], updatedRules[index] ];
updatedRules.forEach((rule: PasswordExpiryRule, i: number) => rule.priority = i + 1);
Expand Down Expand Up @@ -250,7 +256,7 @@ export const PasswordExpiryRuleList: FunctionComponent<PasswordExpiryRuleListPro
if (isRole) {
const { audience } = resource as RolesInterface;

return audience?.type === "application"
return audience?.type?.toLowerCase() === RoleAudienceTypes.APPLICATION.toLowerCase()
? `application | ${audience?.display}`
: audience?.type ?? "";
}
Expand Down Expand Up @@ -327,7 +333,7 @@ export const PasswordExpiryRuleList: FunctionComponent<PasswordExpiryRuleListPro
<ListItemText primary={ getResourceDisplayName(firstItem, isRoleAttribute) } />
</div>
{ selected?.length > 1 && (
<Chip label={ `+${selected?.length - 1} more` } size="small" />
<Chip label={ `+${selected?.length - 1} ${t("common:more")}` } size="small" />
) }
</div>
);
Expand Down Expand Up @@ -423,7 +429,7 @@ export const PasswordExpiryRuleList: FunctionComponent<PasswordExpiryRuleListPro
<Grid md={ 1 }>
<div className="priority-arrows">
<IconButton
onClick={ () => movePriority(index, "up") }
onClick={ () => movePriority(index, Direction.UP) }
disabled={ !isPasswordExpiryEnabled || index === 0 || isReadOnly }
data-componentid={ `${componentId}-move-up-${index}` }
>
Expand All @@ -435,7 +441,7 @@ export const PasswordExpiryRuleList: FunctionComponent<PasswordExpiryRuleListPro
disabled={ !isPasswordExpiryEnabled
|| index === rules.length - 1
|| isReadOnly }
onClick={ () => movePriority(index, "down") }
onClick={ () => movePriority(index, Direction.DOWN) }
data-componentid={ `${componentId}-move-down-${index}` }
>
<ChevronDownIcon
Expand Down
2 changes: 1 addition & 1 deletion modules/i18n/src/translations/en-US/portals/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const validation: validationNS = {
applyMessage: "days password expiry.",
defaultRuleApplyMessage: "days password expiry if no other rules match to the user.",
defaultRuleSkipMessage: "password expiry if no other rules match to the user.",
ifUserHas: "If user has",
ifUserHas: "If user belongs to",
info: "Rules will be applied in the order listed below, from top to bottom. Use the arrows to adjust the priority.",
skipMessage: "password expiry."
}
Expand Down

0 comments on commit d845ccc

Please sign in to comment.