Skip to content

Commit

Permalink
Add support for claim property key validation
Browse files Browse the repository at this point in the history
  • Loading branch information
AfraHussaindeen committed Nov 30, 2024
1 parent 7c8f7f2 commit 299f7cc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 52 deletions.
1 change: 1 addition & 0 deletions apps/console/src/public/deployment.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,7 @@
"enabled": true
}
},
"isClaimUniquenessValidationEnabled": false,
"isClientSecretHashEnabled": false,
"isCookieConsentBannerEnabled": true,
"isCustomClaimMappingEnabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ export const EditAdditionalPropertiesLocalClaims:

const RESTRICTED_PROPERTY_KEYS: string[] = [ "isUnique" ];

const [ showWarning, setShowWarning ] = useState<boolean>(false);

const [ submit, setSubmit ] = useTrigger();

const dispatch: Dispatch = useDispatch();
Expand Down Expand Up @@ -100,46 +98,6 @@ export const EditAdditionalPropertiesLocalClaims:
return (
<EmphasizedSegment>
<Grid>
<Grid.Row columns={ 1 }>
<Grid.Column width={ 16 }>
{ showWarning && (
<Message
type="warning"
content={ (
<Trans
i18nKey={
UIConfig?.isClaimUniquenessValidationEnabled
? "claims:local.additionalProperties." +
"isUniqueDeprecationMessage.uniquenessEnabled"
: "claims:local.additionalProperties." +
"isUniqueDeprecationMessage.uniquenessDisabled"
}
>
{ UIConfig?.isClaimUniquenessValidationEnabled ? (
<>
The &apos;isUnique&apos; property is deprecated. Please use the
<Link
external={ false }
onClick={ () => {
history.push({
pathname: AppConstants.getPaths()
.get("LOCAL_CLAIMS_EDIT")
.replace(":id", claim.id)
});
} }
> Uniqueness Validation Dropdown </Link>
to configure claim uniqueness.
</>
) : (
"The 'isUnique' property is deprecated."
) }
</Trans>
) }
data-componentid={ `${ testId }-restricted-warning` }
/>
) }
</Grid.Column>
</Grid.Row>
<Grid.Row columns={ 1 }>
<Grid.Column tablet={ 16 } computer={ 12 } largeScreen={ 9 } widescreen={ 6 } mobile={ 16 }>
<p>{ t("claims:local.additionalProperties.hint") }</p>
Expand All @@ -158,17 +116,47 @@ export const EditAdditionalPropertiesLocalClaims:
"valueRequiredErrorMessage"
) }
requiredField={ true }
update={ (data: KeyValue[]) => {
const hasRestrictedKey: boolean = data.some(
(item: KeyValue) => item.key === RESTRICTED_PROPERTY_KEYS[0]
);

setShowWarning(hasRestrictedKey);
keyValidation={ (key: string) => {
if (RESTRICTED_PROPERTY_KEYS.includes(key)) {

if (hasRestrictedKey) {
return;
return false;
}

return true;
} }
keyValidationWarningMessage={
UIConfig?.isClaimUniquenessValidationEnabled ? (
<Trans
i18nKey={
"claims:local.additionalProperties." +
"isUniqueDeprecationMessage.uniquenessEnabled"
}
>
The &apos;isUnique&apos; property is deprecated. Please use
<Link
external={ false }
onClick={ () => {
history.push({
pathname: AppConstants.getPaths()
.get("LOCAL_CLAIMS_EDIT")
.replace(":id", claim.id)
});
} }
> Uniqueness Validation </Link>
option to configure claim uniqueness.
</Trans>
) : (
<Trans
i18nKey={
"claims:local.additionalProperties." +
"isUniqueDeprecationMessage.uniquenessDisabled"
}
>
The &apos;isUnique&apos; property is deprecated.
</Trans>
)
}
update={ (data: KeyValue[]) => {
const claimData: Claim = { ...claim };

delete claimData.id;
Expand Down
25 changes: 25 additions & 0 deletions modules/forms/src/components/dynamic-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ export interface DynamicFieldPropsInterface extends TestableComponentInterface {
* Make the form read only.
*/
readOnly?: boolean;
/**
* Validation function for the key field
*/
keyValidation?: (key: string) => boolean;
/**
* Warning message to show when key validation fails
* Can be string or JSX content
*/
keyValidationWarningMessage?: string | ReactElement;
}

/**
Expand Down Expand Up @@ -128,6 +137,8 @@ export const DynamicField: FunctionComponent<DynamicFieldPropsInterface> = (
requiredField,
duplicateKeyErrorMsg,
readOnly,
keyValidation,
keyValidationWarningMessage,
[ "data-testid" ]: testId
} = props;

Expand All @@ -138,6 +149,7 @@ export const DynamicField: FunctionComponent<DynamicFieldPropsInterface> = (
const [ updateMapIndex, setUpdateMapIndex ] = useState<number>(null);
const [ showAddErrorMsg, setAddShowErrorMsg ] = useState(false);
const [ showEditErrorMsg, setShowEditErrorMsg ] = useState(false);
const [ showKeyValidationWarningMsg, setShowKeyValidationWarningMsg ] = useState(false);

const initRender = useRef(true);

Expand Down Expand Up @@ -203,9 +215,22 @@ export const DynamicField: FunctionComponent<DynamicFieldPropsInterface> = (
</Message>
)
}
{
showKeyValidationWarningMsg && (
<Message warning>
{ keyValidationWarningMessage }
</Message>
)
}
<Forms
onSubmit={
(values: Map<string, FormValue>) => {
if (keyValidation && !keyValidation(values.get("key").toString())) {
setShowKeyValidationWarningMsg(true);

return;
}
setShowKeyValidationWarningMsg(false);
if (!showAddErrorMsg) {
const tempFields: Map<number, KeyValue> = new Map<number, KeyValue>(fields);
const newIndex: number = tempFields.size > 0
Expand Down
4 changes: 2 additions & 2 deletions modules/i18n/src/translations/en-US/portals/claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ export const claims: ClaimsNS = {
hint: "Use when writing an extension using current attributes",
isUniqueDeprecationMessage: {
uniquenessDisabled: "The 'isUnique' property is deprecated.",
uniquenessEnabled: "The 'isUnique' property is deprecated. Please use the " +
"<1>Uniqueness Validation Dropdown</1> to configure claim uniqueness."
uniquenessEnabled: "The 'isUnique' property is deprecated. Please use " +
"<1>Uniqueness Validation</1> option to configure claim uniqueness."
},
key: "Name",
keyRequiredErrorMessage: "Enter a name",
Expand Down

0 comments on commit 299f7cc

Please sign in to comment.