Added null safety checks in AdminX actions (#18356)

no issue

- added additional null safety checks to the actions utility in AdminX.
---

<!-- Leave the line below if you'd like GitHub Copilot to generate a
summary from your commit -->
<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at e10aa52</samp>

Refactored `action.context` access in `actions.ts` to use optional
chaining. This makes the code more concise and robust.
This commit is contained in:
Ronald Langeveld 2023-09-26 18:29:43 +07:00 committed by GitHub
parent f296761577
commit 6eb5dfa29b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -193,13 +193,13 @@ export const getActionTitle = (action: Action) => {
let actionName = action.event;
if (action.event === 'edited') {
if (action.context.action_name) {
actionName = action.context.action_name as string;
if (action.context?.action_name) {
actionName = action.context?.action_name as string;
}
}
if (action.context.count && (action.context.count as number) > 1) {
return `${action.context.count} ${resourceType}s ${actionName}`;
if (action.context?.count && (action.context?.count as number) > 1) {
return `${action.context?.count} ${resourceType}s ${actionName}`;
}
return `${resourceType.slice(0, 1).toUpperCase()}${resourceType.slice(1)} ${actionName}`;
@ -209,11 +209,11 @@ export const getContextResource = (action: Action) => {
if (action.resource_type === 'setting') {
if (action.context?.group && action.context?.key) {
return {
group: action.context.group as string,
key: action.context.key as string
group: action.context?.group as string,
key: action.context?.key as string
};
}
}
};
export const isBulkAction = (action: Action) => typeof action.context.count === 'number' && action.context.count > 1;
export const isBulkAction = (action: Action) => typeof action.context?.count === 'number' && action.context?.count > 1;