ccd5897915
F1: single-container "Update now" and bulk "Update" now require PortainerStackUpdate when the resolved path is a stack, disabling the action with a tooltip / skipping it rather than letting the click 403. F2: resolveContainerUpdatePath only matches a Docker Compose stack; a same-named swarm/kubernetes stack is treated as external. F3: SecondaryActions no longer renders an empty ButtonGroup when all of recreate/duplicate/update-now are hidden. F4: bulk update reports an explicit no-op toast and counts containers vs stacks honestly in the success summary. F5: bulk toasts use trimmed container names (no leading slash). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { COMPOSE_STACK_NAME_LABEL } from '@/react/constants';
|
|
import { Stack, StackType } from '@/react/common/stacks/types';
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
|
|
|
import { ContainerUpdatePath } from './types';
|
|
|
|
/**
|
|
* Decide how a container's image update must be applied, given the list of
|
|
* Portainer-managed stacks. Pure and side-effect free so it can be unit-tested
|
|
* and reused by the details button, the bulk action and the M4 auto-update job.
|
|
*
|
|
* - No compose project label -> `standalone` (recreate-with-pull).
|
|
* - Compose project that matches a Portainer Docker Compose `Stack` (same name +
|
|
* endpoint + compose type) -> `stack` (redeploy-with-pull, keeps the container
|
|
* in its stack).
|
|
* - Compose project with no matching Portainer compose stack -> `external`:
|
|
* managed outside Portainer (or a same-named stack of another type), so we
|
|
* must not recreate it (would detach it / drift).
|
|
*/
|
|
export function resolveContainerUpdatePath(
|
|
context: { labels?: Record<string, string>; environmentId: EnvironmentId },
|
|
stacks: Stack[]
|
|
): ContainerUpdatePath {
|
|
const projectName = context.labels?.[COMPOSE_STACK_NAME_LABEL];
|
|
|
|
if (!projectName) {
|
|
return { kind: 'standalone' };
|
|
}
|
|
|
|
// Match by name + endpoint, but only a Docker Compose stack: a same-named
|
|
// swarm/kubernetes stack must not be redeployed via the compose update path.
|
|
const stack = stacks.find(
|
|
(s) =>
|
|
s.Name === projectName &&
|
|
s.EndpointId === context.environmentId &&
|
|
s.Type === StackType.DockerCompose
|
|
);
|
|
|
|
if (!stack) {
|
|
return { kind: 'external' };
|
|
}
|
|
|
|
return {
|
|
kind: 'stack',
|
|
stackId: stack.Id,
|
|
isGitStack: !!stack.GitConfig,
|
|
};
|
|
}
|