mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
Improved null handling on Admin X actions (#18346)
refs https://ghost.slack.com/archives/C0568LN2CGJ/p1695642553045059 - The previous commit didn't quite handle things as expected. This adds more null handling. --- <!-- Leave the line below if you'd like GitHub Copilot to generate a summary from your commit --> <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 1a69211</samp> This pull request improves the robustness and accuracy of the admin settings API for actions. It adds checks and logic to handle missing or invalid data and custom post types in `actions.ts`.
This commit is contained in:
parent
677c829c4b
commit
1f2f0a7322
1 changed files with 25 additions and 12 deletions
|
@ -110,8 +110,19 @@ export const getActorLinkTarget = (action: Action): InternalLink | ExternalLink
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getLinkTarget = (action: Action): InternalLink | ExternalLink | undefined => {
|
export const getLinkTarget = (action: Action): InternalLink | ExternalLink | undefined => {
|
||||||
|
if (!action.resource_type || !action.event || !action.resource) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let resourceType = action.resource_type;
|
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') {
|
if (action.event !== 'deleted') {
|
||||||
switch (action.resource_type) {
|
switch (action.resource_type) {
|
||||||
case 'page':
|
case 'page':
|
||||||
|
@ -172,6 +183,9 @@ export const getLinkTarget = (action: Action): InternalLink | ExternalLink | und
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getActionTitle = (action: Action) => {
|
export const getActionTitle = (action: Action) => {
|
||||||
|
if (!action.resource_type || !action.event) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
let resourceType = action.resource_type;
|
let resourceType = action.resource_type;
|
||||||
|
|
||||||
if (resourceType === 'api_key') {
|
if (resourceType === 'api_key') {
|
||||||
|
@ -185,7 +199,7 @@ export const getActionTitle = (action: Action) => {
|
||||||
const contextExists = action.context !== null;
|
const contextExists = action.context !== null;
|
||||||
|
|
||||||
if (resourceType === 'post' && contextExists) {
|
if (resourceType === 'post' && contextExists) {
|
||||||
if (action.context.type) {
|
if (action.context?.type) {
|
||||||
resourceType = action.context.type as string;
|
resourceType = action.context.type as string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,12 +207,12 @@ export const getActionTitle = (action: Action) => {
|
||||||
let actionName = action.event;
|
let actionName = action.event;
|
||||||
|
|
||||||
if (action.event === 'edited' && contextExists) {
|
if (action.event === 'edited' && contextExists) {
|
||||||
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 (contextExists && 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}`;
|
return `${action.context.count} ${resourceType}s ${actionName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,14 +220,13 @@ export const getActionTitle = (action: Action) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getContextResource = (action: Action) => {
|
export const getContextResource = (action: Action) => {
|
||||||
if (action.resource_type === 'setting') {
|
if (action.resource_type === 'setting' && action.context && 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) => {
|
||||||
export const isBulkAction = (action: Action) => typeof action.context.count === 'number' && action.context.count > 1;
|
return action.context !== null && typeof action.context?.count === 'number' && action.context.count > 1;
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue