diff --git a/apps/admin-x-settings/src/api/actions.ts b/apps/admin-x-settings/src/api/actions.ts index 3057e1fa2d..8d888603bd 100644 --- a/apps/admin-x-settings/src/api/actions.ts +++ b/apps/admin-x-settings/src/api/actions.ts @@ -110,19 +110,8 @@ export const getActorLinkTarget = (action: Action): InternalLink | ExternalLink }; export const getLinkTarget = (action: Action): InternalLink | ExternalLink | undefined => { - if (!action.resource_type || !action.event || !action.resource) { - return; - } let resourceType = action.resource_type; - const contextExists = action.context !== null; - - if (resourceType === 'post' && contextExists) { - if (action.context?.type) { - resourceType = action.context?.type as string; - } - } - if (action.event !== 'deleted') { switch (action.resource_type) { case 'page': @@ -183,9 +172,6 @@ export const getLinkTarget = (action: Action): InternalLink | ExternalLink | und }; export const getActionTitle = (action: Action) => { - if (!action.resource_type || !action.event) { - return ''; - } let resourceType = action.resource_type; if (resourceType === 'api_key') { @@ -196,23 +182,23 @@ export const getActionTitle = (action: Action) => { resourceType = 'tier'; } - const contextExists = action.context !== null; - - if (resourceType === 'post' && contextExists) { + // 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; + resourceType = action.context?.type as string; } } let actionName = action.event; - if (action.event === 'edited' && contextExists) { - if (action.context?.action_name) { + if (action.event === 'edited') { + if (action.context.action_name) { actionName = action.context.action_name as string; } } - if (contextExists && 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}`; } @@ -220,13 +206,14 @@ export const getActionTitle = (action: Action) => { }; export const getContextResource = (action: Action) => { - if (action.resource_type === 'setting' && action.context && action.context?.group && action.context?.key) { - return { - group: action.context.group as string, - key: action.context.key as string - }; + 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 + }; + } } }; -export const isBulkAction = (action: Action) => { - return action.context !== null && typeof action.context?.count === 'number' && action.context.count > 1; -}; + +export const isBulkAction = (action: Action) => typeof action.context.count === 'number' && action.context.count > 1;