Fixed actions crashing on post history - Admin X (#18344)

refs https://ghost.slack.com/archives/C0568LN2CGJ/p1695642553045059

- this attempts to fix an undefined error on AdminX when accessing
history log.
- At the moment I only have it reproducible on staging, so if this doesn't fix it, it will potentially be reverted.

---

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

Improve context handling for action events in `actions.ts`. Use a
variable to simplify and customize the action name and title based on
the context.
This commit is contained in:
Ronald Langeveld 2023-09-26 12:30:49 +07:00 committed by GitHub
parent 41576d2dc3
commit 677c829c4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -182,23 +182,23 @@ export const getActionTitle = (action: Action) => {
resourceType = 'tier';
}
// Because a `page` and `post` both use the same model, we store the
// actual type in the context, so let's check if that exists
if (resourceType === 'post') {
if (action.context?.type) {
resourceType = action.context?.type as string;
const contextExists = action.context !== null;
if (resourceType === 'post' && contextExists) {
if (action.context.type) {
resourceType = action.context.type as string;
}
}
let actionName = action.event;
if (action.event === 'edited') {
if (action.event === 'edited' && contextExists) {
if (action.context.action_name) {
actionName = action.context.action_name as string;
}
}
if (action.context.count && (action.context.count as number) > 1) {
if (contextExists && action.context.count && (action.context.count as number) > 1) {
return `${action.context.count} ${resourceType}s ${actionName}`;
}