0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00

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; let actionName = action.event;
if (action.event === 'edited') { if (action.event === 'edited') {
if (action.context.action_name) { if (action.context?.action_name) {
actionName = action.context.action_name as string; actionName = action.context?.action_name as string;
} }
} }
if (action.context.count && (action.context.count as number) > 1) { if (action.context?.count && (action.context?.count as number) > 1) {
return `${action.context.count} ${resourceType}s ${actionName}`; return `${action.context?.count} ${resourceType}s ${actionName}`;
} }
return `${resourceType.slice(0, 1).toUpperCase()}${resourceType.slice(1)} ${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.resource_type === 'setting') {
if (action.context?.group && action.context?.key) { if (action.context?.group && action.context?.key) {
return { return {
group: action.context.group as string, group: action.context?.group as string,
key: action.context.key 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;