Skip to content

Modern Docker Management, Designed for Everyone

fix: inconsistient behavior with pull and redeploy button via project table (#1953)

Kyle Mendell0ad837c27569
diff --git a/cli/go.mod b/cli/go.mod
index 07b4067c7..229717c51 100644
--- a/cli/go.mod
+++ b/cli/go.mod
@@ -10,6 +10,7 @@ require (
github.com/fatih/color v1.18.0
github.com/getarcaneapp/arcane/types v1.15.3
github.com/go-viper/mapstructure/v2 v2.5.0
+ github.com/mattn/go-runewidth v0.0.20
github.com/sirupsen/logrus v1.9.4
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
@@ -37,7 +38,6 @@ require (
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
- github.com/mattn/go-runewidth v0.0.20 // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
diff --git a/frontend/src/routes/(app)/projects/projects-table.actions.ts b/frontend/src/routes/(app)/projects/projects-table.actions.ts
new file mode 100644
index 000000000..024738da9
--- /dev/null
+++ b/frontend/src/routes/(app)/projects/projects-table.actions.ts
@@ -0,0 +1,266 @@
+import { openConfirmDialog } from '$lib/components/confirm-dialog';
+import { m } from '$lib/paraglide/messages';
+import { deployOptionsStore } from '$lib/stores/deploy-options.store.svelte';
+import { gitOpsSyncService } from '$lib/services/gitops-sync-service';
+import { projectService } from '$lib/services/project-service';
+import type { SearchPaginationSortRequest } from '$lib/types/pagination.type';
+import { handleApiResultWithCallbacks } from '$lib/utils/api.util';
+import { tryCatch } from '$lib/utils/try-catch';
+import { toast } from 'svelte-sonner';
+import type { ActionStatus } from './projects-table.helpers';
+
+type BulkLoadingState = {
+ up: boolean;
+ down: boolean;
+ redeploy: boolean;
+};
+
+type ActionDeps = {
+ getRequestOptions: () => SearchPaginationSortRequest;
+ refreshProjects: (options?: SearchPaginationSortRequest) => Promise<void>;
+ setSelectedIds: (next: string[]) => void;
+ actionStatus: Record<string, ActionStatus>;
+ isBulkLoading: BulkLoadingState;
+ getEnvId: () => string | undefined;
+};
+
+type ProjectActionKind = 'start' | 'stop' | 'restart' | 'redeploy';
+
+type ProjectActionConfig = {
+ status: ActionStatus;
+ run: (id: string) => Promise<unknown>;
+ success: () => string;
+ failure: () => string;
+};
+
+type BulkActionConfig = {
+ title: (count: number) => string;
+ message: (count: number) => string;
+ label: string;
+ loadingKey: keyof BulkLoadingState;
+ run: (id: string) => Promise<unknown>;
+ success: (count: number) => string;
+ partial: (success: number, total: number, failed: number) => string;
+ failure: () => string;
+ destructive?: boolean;
+};
+
+type DestroyConfirmResult = {
+ checkboxes?: {
+ volumes?: boolean;
+ files?: boolean;
+ };
+ volumes?: boolean;
+ files?: boolean;
+};
+
+type ProjectActions = {
+ performProjectAction: (action: ProjectActionKind, id: string) => Promise<void>;
+ handleDestroyProject: (id: string) => Promise<void>;
+ handleSyncFromGit: (projectId: string, gitOpsSyncId: string) => Promise<void>;
+ handleBulkUp: (ids: string[]) => Promise<void>;
+ handleBulkDown: (ids: string[]) => Promise<void>;
+ handleBulkRedeploy: (ids: string[]) => Promise<void>;
+};
+
+const projectActionConfigs: Record<ProjectActionKind, ProjectActionConfig> = {
+ start: {
+ status: 'starting',
+ run: (id) => projectService.deployProject(id, deployOptionsStore.getRequestOptions()),
+ success: () => m.compose_start_success(),
+ failure: () => m.compose_start_failed()
+ },
+ stop: {
+ status: 'stopping',
+ run: (id) => projectService.downProject(id),
+ success: () => m.compose_stop_success(),
+ failure: () => m.compose_stop_failed()
+ },
+ restart: {
+ status: 'restarting',
+ run: (id) => projectService.restartProject(id),
+ success: () => m.compose_restart_success(),
+ failure: () => m.compose_restart_failed()
+ },
+ redeploy: {
+ status: 'redeploying',
+ run: (id) => projectService.redeployProject(id),
+ success: () => m.compose_pull_success(),
+ failure: () => m.compose_pull_failed()
+ }
+};
+
+export function createProjectActions({
+ getRequestOptions,
+ refreshProjects,
+ setSelectedIds,
+ actionStatus,
+ isBulkLoading,
+ getEnvId
+}: ActionDeps): ProjectActions {
+ async function performProjectAction(action: ProjectActionKind, id: string): Promise<void> {
+ const config = projectActionConfigs[action];
+ actionStatus[id] = config.status;
+
+ try {
+ await handleApiResultWithCallbacks({
+ result: await tryCatch(config.run(id)),
+ message: config.failure(),
+ setLoadingState: (value) => {
+ actionStatus[id] = value ? config.status : '';
+ },
+ onSuccess: async () => {
+ toast.success(config.success());
+ await refreshProjects();
+ }
+ });
+ } catch (error) {
+ toast.error(m.common_action_failed());
+ actionStatus[id] = '';
+ }
+ }
+
+ async function handleDestroyProject(id: string): Promise<void> {
+ openConfirmDialog({
+ title: m.common_confirm_removal_title(),
+ message: m.compose_confirm_removal_message(),
+ checkboxes: [
+ {
+ id: 'volumes',
+ label: m.confirm_remove_volumes_warning(),
+ initialState: false
+ },
+ {
+ id: 'files',
+ label: m.confirm_remove_project_files(),
+ initialState: false
+ }
+ ],
+ confirm: {
+ label: m.compose_destroy(),
+ destructive: true,
+ action: async (result: DestroyConfirmResult) => {
+ const removeVolumes = !!(result?.checkboxes?.volumes ?? result?.volumes);
+ const removeFiles = !!(result?.checkboxes?.files ?? result?.files);
+ actionStatus[id] = 'destroying';
+
+ await handleApiResultWithCallbacks({
+ result: await tryCatch(projectService.destroyProject(id, removeVolumes, removeFiles)),
+ message: m.compose_destroy_failed(),
+ setLoadingState: (value) => {
+ actionStatus[id] = value ? 'destroying' : '';
+ },
+ onSuccess: async () => {
+ toast.success(m.compose_destroy_success());
+ await refreshProjects();
+ }
+ });
+ }
+ }
+ });
+ }
+
+ async function handleSyncFromGit(projectId: string, gitOpsSyncId: string): Promise<void> {
+ const envId = getEnvId();
+ if (!envId) return;
+
+ actionStatus[projectId] = 'syncing';
+ const result = await tryCatch(gitOpsSyncService.performSync(envId, gitOpsSyncId));
+
+ await handleApiResultWithCallbacks({
+ result,
+ message: m.git_sync_failed(),
+ setLoadingState: (value) => {
+ actionStatus[projectId] = value ? 'syncing' : '';
+ },
+ onSuccess: async () => {
+ toast.success(m.git_sync_success());
+ await refreshProjects();
+ }
+ });
+ }
+
+ async function runBulkAction(ids: string[], config: BulkActionConfig): Promise<void> {
+ if (!ids || ids.length === 0) return;
+
+ openConfirmDialog({
+ title: config.title(ids.length),
+ message: config.message(ids.length),
+ confirm: {
+ label: config.label,
+ destructive: config.destructive ?? false,
+ action: async () => {
+ isBulkLoading[config.loadingKey] = true;
+
+ try {
+ const results = await Promise.allSettled(ids.map((id) => config.run(id)));
+
+ const successCount = results.filter((result) => result.status === 'fulfilled').length;
+ const failureCount = results.length - successCount;
+
+ if (successCount === ids.length) {
+ toast.success(config.success(successCount));
+ } else if (successCount > 0) {
+ toast.warning(config.partial(successCount, ids.length, failureCount));
+ } else {
+ toast.error(config.failure());
+ }
+
+ await refreshProjects(getRequestOptions());
+ setSelectedIds([]);
+ } finally {
+ isBulkLoading[config.loadingKey] = false;
+ }
+ }
+ }
+ });
+ }
+
+ async function handleBulkUp(ids: string[]): Promise<void> {
+ await runBulkAction(ids, {
+ title: (count) => m.projects_bulk_up_confirm_title({ count }),
+ message: (count) => m.projects_bulk_up_confirm_message({ count }),
+ label: m.common_up(),
+ loadingKey: 'up',
+ run: (id) => projectService.deployProject(id, deployOptionsStore.getRequestOptions()),
+ success: (count) => m.projects_bulk_up_success({ count }),
+ partial: (success, total, failed) => m.projects_bulk_up_partial({ success, total, failed }),
+ failure: () => m.compose_start_failed()
+ });
+ }
+
+ async function handleBulkDown(ids: string[]): Promise<void> {
+ await runBulkAction(ids, {
+ title: (count) => m.projects_bulk_down_confirm_title({ count }),
+ message: (count) => m.projects_bulk_down_confirm_message({ count }),
+ label: m.common_down(),
+ loadingKey: 'down',
+ run: (id) => projectService.downProject(id),
+ success: (count) => m.projects_bulk_down_success({ count }),
+ partial: (success, total, failed) => m.projects_bulk_down_partial({ success, total, failed }),
+ failure: () => m.compose_stop_failed()
+ });
+ }
+
+ async function handleBulkRedeploy(ids: string[]): Promise<void> {
+ await runBulkAction(ids, {
+ title: (count) => m.projects_bulk_redeploy_confirm_title({ count }),
+ message: (count) => m.projects_bulk_redeploy_confirm_message({ count }),
+ label: m.compose_pull_redeploy(),
+ loadingKey: 'redeploy',
+ run: (id) => projectService.redeployProject(id),
+ success: (count) => m.projects_bulk_redeploy_success({ count }),
+ partial: (success, total, failed) => m.projects_bulk_redeploy_partial({ success, total, failed }),
+ failure: () => m.compose_pull_failed()
+ });
+ }
+
+ return {
+ performProjectAction,
+ handleDestroyProject,
+ handleSyncFromGit,
+ handleBulkUp,
+ handleBulkDown,
+ handleBulkRedeploy
+ };
+}
diff --git a/frontend/src/routes/(app)/projects/projects-table.helpers.ts b/frontend/src/routes/(app)/projects/projects-table.helpers.ts
new file mode 100644
index 000000000..f06146441
--- /dev/null
+++ b/frontend/src/routes/(app)/projects/projects-table.helpers.ts
@@ -0,0 +1 @@
+export type ActionStatus = 'starting' | 'stopping' | 'restarting' | 'redeploying' | 'destroying' | 'syncing' | '';
diff --git a/frontend/src/routes/(app)/projects/projects-table.svelte b/frontend/src/routes/(app)/projects/projects-table.svelte
index 1c11a681c..67245527a 100644
--- a/frontend/src/routes/(app)/projects/projects-table.svelte
+++ b/frontend/src/routes/(app)/projects/projects-table.svelte
@@ -6,11 +6,7 @@
import { EditIcon, StartIcon, RestartIcon, StopIcon, TrashIcon, RedeployIcon, EllipsisIcon } from '$lib/icons';
import { Spinner } from '$lib/components/ui/spinner/index.js';
import { goto } from '$app/navigation';
- import { toast } from 'svelte-sonner';
- import { openConfirmDialog } from '$lib/components/confirm-dialog';
import StatusBadge from '$lib/components/badges/status-badge.svelte';
- import { handleApiResultWithCallbacks } from '$lib/utils/api.util';
- import { tryCatch } from '$lib/utils/try-catch';
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
import { getStatusVariant } from '$lib/utils/status.utils';
import { capitalizeFirstLetter } from '$lib/utils/string.utils';
@@ -19,11 +15,11 @@
import { UniversalMobileCard } from '$lib/components/arcane-table';
import { m } from '$lib/paraglide/messages';
import { projectService } from '$lib/services/project-service';
- import { deployOptionsStore } from '$lib/stores/deploy-options.store.svelte';
- import { gitOpsSyncService } from '$lib/services/gitops-sync-service';
import { FolderOpenIcon, LayersIcon, CalendarIcon, ProjectsIcon, GitBranchIcon, RefreshIcon } from '$lib/icons';
import { environmentStore } from '$lib/stores/environment.store.svelte';
import IconImage from '$lib/components/icon-image.svelte';
+ import type { ActionStatus } from './projects-table.helpers';
+ import { createProjectActions } from './projects-table.actions';
let {
projects = $bindable(),
@@ -37,16 +33,7 @@
onRefreshData?: (options: SearchPaginationSortRequest) => Promise<void>;
} = $props();
- let isLoading = $state({
- start: false,
- stop: false,
- restart: false,
- remove: false,
- destroy: false,
- pull: false,
- updating: false,
- syncing: false
- });
+ let actionStatus = $state<Record<string, ActionStatus>>({});
let isBulkLoading = $state({
up: false,
@@ -66,211 +53,23 @@
return project.status.toLowerCase() === 'unknown' && project.statusReason ? project.statusReason : undefined;
}
- async function performProjectAction(action: string, id: string) {
- isLoading[action as keyof typeof isLoading] = true;
-
- try {
- if (action === 'start') {
- handleApiResultWithCallbacks({
- result: await tryCatch(projectService.deployProject(id, deployOptionsStore.getRequestOptions())),
- message: m.compose_start_failed(),
- setLoadingState: (value) => (isLoading.start = value),
- onSuccess: async () => {
- toast.success(m.compose_start_success());
- await refreshProjects();
- }
- });
- } else if (action === 'stop') {
- handleApiResultWithCallbacks({
- result: await tryCatch(projectService.downProject(id)),
- message: m.compose_stop_failed(),
- setLoadingState: (value) => (isLoading.stop = value),
- onSuccess: async () => {
- toast.success(m.compose_stop_success());
- await refreshProjects();
- }
- });
- } else if (action === 'restart') {
- handleApiResultWithCallbacks({
- result: await tryCatch(projectService.restartProject(id)),
- message: m.compose_restart_failed(),
- setLoadingState: (value) => (isLoading.restart = value),
- onSuccess: async () => {
- toast.success(m.compose_restart_success());
- await refreshProjects();
- }
- });
- } else if (action === 'redeploy') {
- handleApiResultWithCallbacks({
- result: await tryCatch(projectService.redeployProject(id)),
- message: m.compose_pull_failed(),
- setLoadingState: (value) => (isLoading.pull = value),
- onSuccess: async () => {
- toast.success(m.compose_pull_success());
- await refreshProjects();
- }
- });
- } else if (action === 'destroy') {
- openConfirmDialog({
- title: m.common_confirm_removal_title(),
- message: m.compose_confirm_removal_message(),
- checkboxes: [
- {
- id: 'volumes',
- label: m.confirm_remove_volumes_warning(),
- initialState: false
- },
- {
- id: 'files',
- label: m.confirm_remove_project_files(),
- initialState: false
- }
- ],
- confirm: {
- label: m.compose_destroy(),
- destructive: true,
- action: async (result: any) => {
- const removeVolumes = !!(result?.checkboxes?.volumes ?? result?.volumes);
- const removeFiles = !!(result?.checkboxes?.files ?? result?.files);
-
- handleApiResultWithCallbacks({
- result: await tryCatch(projectService.destroyProject(id, removeVolumes, removeFiles)),
- message: m.compose_destroy_failed(),
- setLoadingState: (value) => (isLoading.destroy = value),
- onSuccess: async () => {
- toast.success(m.compose_destroy_success());
- await refreshProjects();
- }
- });
- }
- }
- });
- }
- } catch (error) {
- toast.error(m.common_action_failed());
- }
- }
-
- async function handleSyncFromGit(gitOpsSyncId: string) {
- if (!envId) return;
- isLoading.syncing = true;
- const result = await tryCatch(gitOpsSyncService.performSync(envId, gitOpsSyncId));
- handleApiResultWithCallbacks({
- result,
- message: m.git_sync_failed(),
- setLoadingState: (value) => (isLoading.syncing = value),
- onSuccess: async () => {
- toast.success(m.git_sync_success());
- await refreshProjects();
- }
- });
- }
-
- async function handleBulkUp(ids: string[]) {
- if (!ids || ids.length === 0) return;
-
- openConfirmDialog({
- title: m.projects_bulk_up_confirm_title({ count: ids.length }),
- message: m.projects_bulk_up_confirm_message({ count: ids.length }),
- confirm: {
- label: m.common_up(),
- destructive: false,
- action: async () => {
- isBulkLoading.up = true;
-
- const deployOptions = deployOptionsStore.getRequestOptions();
- const results = await Promise.allSettled(ids.map((id) => projectService.deployProject(id, deployOptions)));
-
- const successCount = results.filter((r) => r.status === 'fulfilled').length;
- const failureCount = results.length - successCount;
-
- isBulkLoading.up = false;
-
- if (successCount === ids.length) {
- toast.success(m.projects_bulk_up_success({ count: successCount }));
- } else if (successCount > 0) {
- toast.warning(m.projects_bulk_up_partial({ success: successCount, total: ids.length, failed: failureCount }));
- } else {
- toast.error(m.compose_start_failed());
- }
-
- await refreshProjects();
- selectedIds = [];
- }
- }
- });
- }
-
- async function handleBulkDown(ids: string[]) {
- if (!ids || ids.length === 0) return;
-
- openConfirmDialog({
- title: m.projects_bulk_down_confirm_title({ count: ids.length }),
- message: m.projects_bulk_down_confirm_message({ count: ids.length }),
- confirm: {
- label: m.common_down(),
- destructive: false,
- action: async () => {
- isBulkLoading.down = true;
-
- const results = await Promise.allSettled(ids.map((id) => projectService.downProject(id)));
-
- const successCount = results.filter((r) => r.status === 'fulfilled').length;
- const failureCount = results.length - successCount;
-
- isBulkLoading.down = false;
-
- if (successCount === ids.length) {
- toast.success(m.projects_bulk_down_success({ count: successCount }));
- } else if (successCount > 0) {
- toast.warning(m.projects_bulk_down_partial({ success: successCount, total: ids.length, failed: failureCount }));
- } else {
- toast.error(m.compose_stop_failed());
- }
-
- await refreshProjects();
- selectedIds = [];
- }
- }
- });
- }
-
- async function handleBulkRedeploy(ids: string[]) {
- if (!ids || ids.length === 0) return;
-
- openConfirmDialog({
- title: m.projects_bulk_redeploy_confirm_title({ count: ids.length }),
- message: m.projects_bulk_redeploy_confirm_message({ count: ids.length }),
- confirm: {
- label: m.compose_pull_redeploy(),
- destructive: false,
- action: async () => {
- isBulkLoading.redeploy = true;
-
- const results = await Promise.allSettled(ids.map((id) => projectService.redeployProject(id)));
-
- const successCount = results.filter((r) => r.status === 'fulfilled').length;
- const failureCount = results.length - successCount;
-
- isBulkLoading.redeploy = false;
-
- if (successCount === ids.length) {
- toast.success(m.projects_bulk_redeploy_success({ count: successCount }));
- } else if (successCount > 0) {
- toast.warning(m.projects_bulk_redeploy_partial({ success: successCount, total: ids.length, failed: failureCount }));
- } else {
- toast.error(m.compose_pull_failed());
- }
+ let mobileFieldVisibility = $state<Record<string, boolean>>({});
+ const envId = $derived(environmentStore.selected?.id);
- await refreshProjects();
- selectedIds = [];
- }
- }
+ const { performProjectAction, handleDestroyProject, handleSyncFromGit, handleBulkUp, handleBulkDown, handleBulkRedeploy } =
+ createProjectActions({
+ getRequestOptions: () => requestOptions,
+ refreshProjects,
+ setSelectedIds: (next) => {
+ selectedIds = next;
+ },
+ actionStatus,
+ isBulkLoading,
+ getEnvId: () => envId
});
- }
const isAnyLoading = $derived(
- Object.values(isLoading).some((loading) => loading) || Object.values(isBulkLoading).some((loading) => loading)
+ Object.values(actionStatus).some((status) => status !== '') || Object.values(isBulkLoading).some((loading) => loading)
);
const columns = [
@@ -319,9 +118,6 @@
icon: RedeployIcon
}
]);
-
- let mobileFieldVisibility = $state<Record<string, boolean>>({});
- const envId = $derived(environmentStore.selected?.id);
</script>
{#snippet NameCell({ item }: { item: Project })}
@@ -429,6 +225,7 @@
{/snippet}
{#snippet RowActions({ item }: { item: Project })}
+ {@const status = actionStatus[item.id]}
<DropdownMenu.Root>
<DropdownMenu.Trigger>
{#snippet child({ props })}
@@ -447,10 +244,10 @@
{#if item.gitOpsManagedBy}
<DropdownMenu.Item
- onclick={() => handleSyncFromGit(item.gitOpsManagedBy!)}
- disabled={isLoading.syncing || isAnyLoading}
+ onclick={() => handleSyncFromGit(item.id, item.gitOpsManagedBy!)}
+ disabled={status === 'syncing' || isAnyLoading}
>
- {#if isLoading.syncing}
+ {#if status === 'syncing'}
<Spinner class="size-4" />
{:else}
<RefreshIcon class="size-4" />
@@ -462,8 +259,11 @@
<DropdownMenu.Separator />
{#if item.status !== 'running'}
- <DropdownMenu.Item onclick={() => performProjectAction('start', item.id)} disabled={isLoading.start || isAnyLoading}>
- {#if isLoading.start}
+ <DropdownMenu.Item
+ onclick={() => performProjectAction('start', item.id)}
+ disabled={status === 'starting' || isAnyLoading}
+ >
+ {#if status === 'starting'}
<Spinner class="size-4" />
{:else}
<StartIcon class="size-4" />
@@ -471,8 +271,11 @@
{m.common_up()}
</DropdownMenu.Item>
{:else}
- <DropdownMenu.Item onclick={() => performProjectAction('stop', item.id)} disabled={isLoading.stop || isAnyLoading}>
- {#if isLoading.stop}
+ <DropdownMenu.Item
+ onclick={() => performProjectAction('stop', item.id)}
+ disabled={status === 'stopping' || isAnyLoading}
+ >
+ {#if status === 'stopping'}
<Spinner class="size-4" />
{:else}
<StopIcon class="size-4" />
@@ -482,9 +285,9 @@
<DropdownMenu.Item
onclick={() => performProjectAction('restart', item.id)}
- disabled={isLoading.restart || isAnyLoading}
+ disabled={status === 'restarting' || isAnyLoading}
>
- {#if isLoading.restart}
+ {#if status === 'restarting'}
<Spinner class="size-4" />
{:else}
<RestartIcon class="size-4" />
@@ -493,8 +296,11 @@
</DropdownMenu.Item>
{/if}
- <DropdownMenu.Item onclick={() => performProjectAction('redeploy', item.id)} disabled={isLoading.pull || isAnyLoading}>
- {#if isLoading.pull}
+ <DropdownMenu.Item
+ onclick={() => performProjectAction('redeploy', item.id)}
+ disabled={status === 'redeploying' || isAnyLoading}
+ >
+ {#if status === 'redeploying'}
<Spinner class="size-4" />
{:else}
<RedeployIcon class="size-4" />
@@ -506,10 +312,10 @@
<DropdownMenu.Item
variant="destructive"
- onclick={() => performProjectAction('destroy', item.id)}
- disabled={isLoading.remove || isAnyLoading}
+ onclick={() => handleDestroyProject(item.id)}
+ disabled={status === 'destroying' || isAnyLoading}
>
- {#if isLoading.remove}
+ {#if status === 'destroying'}
<Spinner class="size-4" />
{:else}
<TrashIcon class="size-4" />