Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat(canvas): show empty environments as placeholder cards

Andras Bacsaifdd69977a448
diff --git a/app/Services/EnvironmentCanvas.php b/app/Services/EnvironmentCanvas.php
index 500085b923..8372af3371 100644
--- a/app/Services/EnvironmentCanvas.php
+++ b/app/Services/EnvironmentCanvas.php
@@ -4,6 +4,7 @@ namespace App\Services;
use App\Models\Application;
use App\Models\Environment;
+use App\Models\Project;
use App\Models\ResourceLink;
use App\Models\Server;
use App\Models\Service;
@@ -22,6 +23,9 @@ class EnvironmentCanvas
{
public const MAX_COORDINATE = 100000;
+ /** Zone id of the placeholder cards of environments without resources. */
+ public const EMPTY_ZONE = 'empty';
+
/**
* Environment relations that hold standalone databases, keyed by relation name.
*/
@@ -148,6 +152,65 @@ class EnvironmentCanvas
];
}
+ /**
+ * Zone of the server, project and dashboard canvases for environments without resources (they have no server).
+ *
+ * @return array{id: string, name: string, icon: string}
+ */
+ public function emptyZone(): array
+ {
+ return ['id' => self::EMPTY_ZONE, 'name' => 'Empty environments', 'icon' => 'service'];
+ }
+
+ /**
+ * Zone for the placeholder cards of a project: the zone with most of the project's cards, or `$fallback`
+ * when the project has no cards.
+ *
+ * @param Collection<int, array<string, mixed>> $nodes cards of the canvas
+ * @return callable(Project): string
+ */
+ public function projectZones(Collection $nodes, string $fallback): callable
+ {
+ $zones = $nodes
+ ->filter(fn (array $node) => filled($node['zone']))
+ ->groupBy(fn (array $node) => data_get($node, 'project.uuid'))
+ ->map(fn (Collection $cards) => $cards->countBy('zone')->sortDesc()->keys()->first());
+
+ return fn (Project $project) => $zones->get($project->uuid, $fallback);
+ }
+
+ /**
+ * Placeholder card of an environment without resources, so the grouped canvases still show it.
+ * Without an environment, it stands for a project without environments.
+ * `$canAdd`: the card opens the deploy canvas for the environment instead of the environment page.
+ *
+ * @return array<string, mixed>
+ */
+ public function emptyNode(Project $project, ?Environment $environment, string $zone, string $context, bool $canAdd = false): array
+ {
+ $page = $environment
+ ? route('project.resource.index', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid])
+ : route('project.show', ['project_uuid' => $project->uuid]);
+ $add = $canAdd && $environment;
+
+ return [
+ 'id' => 'empty:'.($environment?->uuid ?? $project->uuid),
+ 'type' => 'empty',
+ 'name' => $environment ? 'No resources yet' : 'No environments yet',
+ 'subtitle' => $add ? 'Click to add a resource' : 'Open to see this '.($environment ? 'environment' : 'project'),
+ 'status' => null,
+ 'zone' => $zone,
+ 'extra_zones' => [],
+ 'urls' => [],
+ 'children' => [],
+ 'link' => $add ? route('deploy-canvas', ['project' => $project->uuid, 'environment' => $environment->uuid]) : $page,
+ 'context' => $context,
+ 'context_link' => $page,
+ 'project' => ['uuid' => $project->uuid, 'name' => $project->name],
+ 'environment' => $environment ? ['uuid' => $environment->uuid, 'name' => $environment->name] : null,
+ ];
+ }
+
/**
* Top-level resources of the environment (applications, services, standalone databases), keyed by uuid,
* with the relations the canvas reads.
diff --git a/app/Services/ProjectCanvas.php b/app/Services/ProjectCanvas.php
index a8a56f2d08..57619b2e30 100644
--- a/app/Services/ProjectCanvas.php
+++ b/app/Services/ProjectCanvas.php
@@ -6,6 +6,7 @@ use App\Models\Environment;
use App\Models\Project;
use App\Models\ResourceLink;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Collection;
/**
* Builds the project canvas: every resource of the project's environments, one zone per server,
@@ -19,12 +20,13 @@ class ProjectCanvas
/**
* The canvas of every project of a team: one zone per project, cards grouped by environment.
*
- * @return array{title: string, title_link: string, can_edit: bool, can_move: false, layout: 'server', zones: array<int, array<string, mixed>>, nodes: array<int, array<string, mixed>>, links: array<int, array<string, mixed>>, positions: array{}}
+ * @return array{title: string, title_link: string, can_edit: bool, can_move: false, can_move_groups: bool, layout: 'server', zones: array<int, array<string, mixed>>, nodes: array<int, array<string, mixed>>, links: array<int, array<string, mixed>>, positions: array{}}
*/
public function teamPayload(int $teamId, bool $canReadSensitive, bool $canEdit = false): array
{
$projects = Project::query()->where('team_id', $teamId)->orderBy('name')->get(['id', 'uuid', 'name', 'team_id']);
$environments = Environment::query()->whereIn('project_id', $projects->pluck('id'))
+ ->orderBy('id')
->get(['id', 'uuid', 'name', 'project_id']);
$resources = $this->servers->loadResources($environments->pluck('id'));
$links = ResourceLink::query()->whereIn('environment_id', $environments->pluck('id'))->orderBy('id')->get();
@@ -42,8 +44,10 @@ class ProjectCanvas
'title' => 'Projects',
'title_link' => route('project.index'),
'can_edit' => $canEdit,
- // Environment groups are auto-placed; cards inside a group keep their environment canvas arrangement.
+ // Environment groups and cards keep their environment canvas arrangement.
'can_move' => false,
+ // Admins move groups and cards here; the canvas saves them on their environment canvas.
+ 'can_move_groups' => $canEdit,
// Same grouped layout as the server canvas, with projects as the zones.
'layout' => 'server',
'zones' => $projects->map(fn (Project $project) => [
@@ -52,18 +56,20 @@ class ProjectCanvas
'icon' => 'projects',
'link' => route('project.show', ['project_uuid' => $project->uuid]),
])->values()->all(),
- 'nodes' => collect($graph['nodes'])->map(fn (array $node) => [...$node, ...$grouping->get($node['id'])])->values()->all(),
+ 'nodes' => collect($graph['nodes'])->map(fn (array $node) => [...$node, ...$grouping->get($node['id'])])
+ ->concat($projects->flatMap(fn (Project $project) => $this->emptyNodes($project, $environments->where('project_id', $project->id), $resources, $project->uuid, $canEdit)))
+ ->values()->all(),
'links' => $graph['links'],
'positions' => [],
];
}
/**
- * @return array{title: string, title_link: string, can_edit: bool, can_move: false, layout: 'server', zones: array<int, array<string, mixed>>, nodes: array<int, array<string, mixed>>, links: array<int, array<string, mixed>>, positions: array{}}
+ * @return array{title: string, title_link: string, can_edit: bool, can_move: false, can_move_groups: bool, layout: 'server', zones: array<int, array<string, mixed>>, nodes: array<int, array<string, mixed>>, links: array<int, array<string, mixed>>, positions: array{}}
*/
public function payload(Project $project, bool $canReadSensitive, bool $canEdit = false): array
{
- $environments = $project->environments()->get(['id', 'uuid', 'name', 'project_id']);
+ $environments = $project->environments()->orderBy('id')->get(['id', 'uuid', 'name', 'project_id']);
$resources = $this->servers->loadResources($environments->pluck('id'));
$links = ResourceLink::query()->whereIn('environment_id', $environments->pluck('id'))->orderBy('id')->get();
$graph = $this->canvas->graph($resources, $links, $canReadSensitive);
@@ -73,21 +79,48 @@ class ProjectCanvas
'context_link' => route('project.resource.index', ['project_uuid' => $project->uuid, 'environment_uuid' => $resource->environment->uuid]),
...$this->owner($resource),
]);
+ $nodes = collect($graph['nodes'])->map(fn (array $node) => [...$node, ...$context->get($node['id'])]);
+ // Placeholder cards sit on the server of the project's other environments.
+ $zone = $this->canvas->projectZones($nodes, $graph['zones'][0]['id'] ?? EnvironmentCanvas::EMPTY_ZONE)($project);
+ $empty = $this->emptyNodes($project, $environments, $resources, $zone, $canEdit);
return [
'title' => $project->name,
'title_link' => route('project.show', ['project_uuid' => $project->uuid]),
'can_edit' => $canEdit,
'can_move' => false,
+ // Admins move groups and cards here; the canvas saves them on their environment canvas.
+ 'can_move_groups' => $canEdit,
// Groups cards by environment inside each server zone, like the server canvas.
'layout' => 'server',
- 'zones' => $graph['zones'],
- 'nodes' => collect($graph['nodes'])->map(fn (array $node) => [...$node, ...$context->get($node['id'])])->values()->all(),
+ 'zones' => $empty->isNotEmpty() && $zone === EnvironmentCanvas::EMPTY_ZONE ? [...$graph['zones'], $this->canvas->emptyZone()] : $graph['zones'],
+ 'nodes' => $nodes->concat($empty)->values()->all(),
'links' => $graph['links'],
'positions' => [],
];
}
+ /**
+ * Placeholder cards of the project's environments without resources, or one for the project when it has no environments.
+ *
+ * @param Collection<int, Environment> $environments environments of the project
+ * @param Collection<string, Model> $resources
+ * @return Collection<int, array<string, mixed>>
+ */
+ private function emptyNodes(Project $project, Collection $environments, Collection $resources, string $zone, bool $canAdd): Collection
+ {
+ if ($environments->isEmpty()) {
+ return collect([$this->canvas->emptyNode($project, null, $zone, 'No environments')]);
+ }
+
+ $used = $resources->pluck('environment_id')->flip();
+
+ return $environments
+ ->reject(fn (Environment $environment) => $used->has($environment->id))
+ ->map(fn (Environment $environment) => $this->canvas->emptyNode($project, $environment, $zone, $environment->name, $canAdd))
+ ->values();
+ }
+
/**
* Project and environment of a card: the canvas saves links on that environment canvas.
*
diff --git a/app/Services/ServerCanvas.php b/app/Services/ServerCanvas.php
index aa69c51ad6..d822920a54 100644
--- a/app/Services/ServerCanvas.php
+++ b/app/Services/ServerCanvas.php
@@ -16,7 +16,7 @@ use Illuminate\Support\Facades\Cache;
/**
* Builds the server canvas: one zone per server with every resource of the team on it,
* in the same shape as the environment canvas. Cards and project / environment groups use the positions saved on
- * their environment canvas (node.saved); admins move whole groups here, which saves the moved cards on that environment
+ * their environment canvas (node.saved); admins move whole groups and single cards here, which saves the group's cards on that environment
* canvas, and change links through the environment canvas endpoints of each card.
*/
class ServerCanvas
@@ -29,9 +29,11 @@ class ServerCanvas
*/
public function payload(int $teamId, Collection $servers, ?Server $single, bool $canReadSensitive, bool $canEdit = false): array
{
- $environmentIds = Environment::query()
+ $environments = Environment::query()
->whereHas('project', fn ($query) => $query->where('team_id', $teamId))
- ->pluck('id');
+ ->with('project')
+ ->get(['id', 'uuid', 'name', 'project_id']);
+ $environmentIds = $environments->pluck('id');
$resources = $this->loadResources($environmentIds);
$links = ResourceLink::query()->whereIn('environment_id', $environmentIds)->orderBy('id')->get();
$graph = $this->canvas->graph($resources, $links, $canReadSensitive);
@@ -56,6 +58,13 @@ class ServerCanvas
})
->values();
$shown = $nodes->pluck('id')->flip();
+ // Every-server canvases: environments without resources show as placeholder cards next to the other environments of their project.
+ $used = $resources->pluck('environment_id')->flip();
+ $zoneOf = $this->canvas->projectZones($nodes, $serverUuids[0] ?? EnvironmentCanvas::EMPTY_ZONE);
+ $empty = $single ? collect() : $environments
+ ->reject(fn (Environment $environment) => $used->has($environment->id))
+ ->map(fn (Environment $environment) => $this->canvas->emptyNode($environment->project, $environment, $zoneOf($environment->project), $environment->project->name.' / '.$environment->name, $canEdit))
+ ->values();
return [
'title' => $single ? $single->name : 'Servers',
@@ -68,8 +77,10 @@ class ServerCanvas
'can_move_groups' => $canEdit,
// Tells the canvas to group cards by project / environment and place linked cards side by side.
'layout' => 'server',
- 'zones' => $servers->map(fn (Server $server) => [...$this->canvas->zone($server, $canReadSensitive), 'details' => $this->details($server)])->values()->all(),
- 'nodes' => $nodes->all(),
+ 'zones' => $servers->map(fn (Server $server) => [...$this->canvas->zone($server, $canReadSensitive), 'details' => $this->details($server)])
+ ->when($empty->contains('zone', EnvironmentCanvas::EMPTY_ZONE), fn (Collection $zones) => $zones->push($this->canvas->emptyZone()))
+ ->values()->all(),
+ 'nodes' => $nodes->concat($empty)->all(),
'links' => collect($graph['links'])->filter(fn (array $link) => $shown->has($link['source']) && $shown->has($link['target']))->values()->all(),
'positions' => [],
];
diff --git a/app/Services/SharedVariableCanvas.php b/app/Services/SharedVariableCanvas.php
index 3598848ed9..775faa8a48 100644
--- a/app/Services/SharedVariableCanvas.php
+++ b/app/Services/SharedVariableCanvas.php
@@ -30,6 +30,12 @@ class SharedVariableCanvas
public const RESOURCES_ZONE = 'resources';
+ /**
+ * Server variables that Coolify creates on every server. Resources get them only through a reference,
+ * but every server has them, so the canvas and the overview leave them out to stay readable.
+ */
+ public const BUILT_IN_SERVER_KEYS = ['COOLIFY_SERVER_UUID', 'COOLIFY_SERVER_NAME'];
+
public function __construct(private EnvironmentCanvas $canvas, private ServerCanvas $serverCanvas) {}
/**
@@ -37,9 +43,14 @@ class SharedVariableCanvas
*/
public function payload(string $scope, Model $owner, bool $canEdit): array
{
- $variables = $this->variables($owner);
+ $hidden = $scope === 'server' ? self::BUILT_IN_SERVER_KEYS : [];
+ $variables = $this->variables($owner)->reject(fn (SharedEnvironmentVariable $variable) => in_array($variable->key, $hidden, true))->values();
$resources = $this->resources($scope, $owner);
- $links = $this->links($scope, $variables, $resources);
+ // A reference to a hidden variable is not a reference to a deleted one: leave its link out too.
+ $links = collect($this->links($scope, $variables, $resources))
+ ->reject(fn (array $link) => in_array($link['key'], $hidden, true))
+ ->values()
+ ->all();
$missing = collect($links)
->where('missing', true)
@@ -254,7 +265,7 @@ class SharedVariableCanvas
->with(['project', 'environment.project', 'server'])
->get()
// Built-in server variables; the server variables page hides them too.
- ->reject(fn (SharedEnvironmentVariable $variable) => $variable->type === 'server' && in_array($variable->key, ['COOLIFY_SERVER_UUID', 'COOLIFY_SERVER_NAME'], true));
+ ->reject(fn (SharedEnvironmentVariable $variable) => $variable->type === 'server' && in_array($variable->key, self::BUILT_IN_SERVER_KEYS, true));
$scopes = collect(self::SCOPES)->mapWithKeys(function (string $scope) use ($variables) {
$ofScope = $variables->where('type', $scope);
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index e824d43ee5..0d36774e6e 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -4595,6 +4595,20 @@ function wireNavigate(): string
}
}
+/**
+ * Registers a resource menu that the main sidebar shows in place of its main menu on wide screens
+ * (see components/navbar.blade.php). The menu teleports itself into #main-nav-context-{depth}.
+ * Back on a menu shows the menu one depth lower, and Back at depth 0 shows the main menu.
+ */
+function registerMainNavContext(int $depth, string $label, string $backTitle): void
+{
+ $levels = request()->attributes->get('mainNavContext', []);
+ $levels[$depth] = ['label' => $label, 'backTitle' => $backTitle];
+ ksort($levels);
+
+ request()->attributes->set('mainNavContext', $levels);
+}
+
/**
* Flattens a grouped settings sidebar into the items that the command palette
* shows for the current page: every page, its child pages, and its in-page sections.
diff --git a/resources/css/app.css b/resources/css/app.css
index 730a982b7f..8e95f2f1d5 100644
--- a/resources/css/app.css
+++ b/resources/css/app.css
@@ -1889,7 +1889,7 @@ html[data-theme="custom"] textarea:disabled {
grid-column: 2;
}
- /* A resource menu that the main sidebar shows instead (navbar #main-nav-context). */
+ /* A resource menu that the main sidebar shows instead (navbar #main-nav-context-{depth}). */
.application-settings-navigation.in-main-nav {
display: none;
}
@@ -5360,7 +5360,7 @@ html:where(:not([data-nav-items="flat"])) :is(.menu-item, .menu-subitem):not(.si
outline-offset: 2px;
}
-/* Sidebar main menu/submenu swap: the submenu enters from the right, the main menu from the left.
+/* Sidebar menu swap: a deeper menu (submenu, resource menu) enters from the right, a lower one from the left.
CSS animations restart when an element is shown again, so x-show replays them on each swap. */
@keyframes nav-swap-forward {
from {
@@ -5544,7 +5544,7 @@ html.dark .canvas-zoom-max {
--canvas-dots-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath transform='translate(8 8) scale(0.0125)' d='M64 256H0V64h64Zm0-192V0h256v64Zm0 192h256v64H64Z' fill='rgb(255 255 255 / 0.09)'/%3E%3C/svg%3E");
}
-.canvas-zoom-max :is([data-ec-viewport], .cv-viewport) {
+.canvas-zoom-max [data-ec-viewport] {
background-image: var(--canvas-dots-image);
}
@@ -5667,7 +5667,7 @@ html.dark .canvas-zoom-max {
padding-top: var(--floating-top);
}
- html[data-nav-style="floating"] .app-main-full :is([data-ec-viewport], .cv-viewport) {
+ html[data-nav-style="floating"] .app-main-full [data-ec-viewport] {
background-image: none;
}
diff --git a/resources/js/canvas-core.js b/resources/js/canvas-core.js
index 41d6c26f23..4f2127df1c 100644
--- a/resources/js/canvas-core.js
+++ b/resources/js/canvas-core.js
@@ -95,6 +95,18 @@ export function setCanvasDots(root, size, x, y, atMaxZoom = false) {
root.classList.toggle('canvas-zoom-max', atMaxZoom);
}
+/**
+ * The browser zoom shortcut in a keydown event (Cmd/Ctrl with +, - or 0), so the
+ * canvas can zoom itself instead: 'in', 'out', 'reset', or null for other keys.
+ */
+export function zoomShortcut(e) {
+ if (!(e.ctrlKey || e.metaKey) || e.altKey) return null;
+ if (e.key === '+' || e.key === '=') return 'in';
+ if (e.key === '-' || e.key === '_') return 'out';
+ if (e.key === '0') return 'reset';
+ return null;
+}
+
/**
* Wheel zoom (ctrl/cmd) and pan, and drag-to-pan on the viewport background.
* getView() returns the current { x, y, z }, which is changed in place.
diff --git a/resources/js/canvas/CanvasControls.svelte b/resources/js/canvas/CanvasControls.svelte
index 0d887784f0..f4b2532891 100644
--- a/resources/js/canvas/CanvasControls.svelte
+++ b/resources/js/canvas/CanvasControls.svelte
@@ -1,13 +1,25 @@
<script>
// Zoom and fit controls that float in the bottom-left corner of a canvas.
// With `onrefresh` (environment canvas) it also has a Refresh button. `inline`: the parent places it.
+ // `children`: more actions after the zoom buttons (deploy canvas header).
import Icon from './environment/Icon.svelte';
+ import { zoomShortcut } from '../canvas-core.js';
- let { zoom, onzoom, onfit, onrefresh = null, loading = false, inline = false } = $props();
+ let { zoom, onzoom, onfit, onrefresh = null, loading = false, inline = false, children = null } = $props();
const button = 'grid h-7 min-w-7 place-items-center rounded-md px-1.5 text-neutral-500 transition-colors hover:bg-neutral-100 hover:text-neutral-900 disabled:pointer-events-none disabled:opacity-50 dark:text-fg-dim dark:hover:bg-white/[0.07] dark:hover:text-fg';
+
+ /** Cmd/Ctrl + / - / 0 zoom the canvas instead of the page. */
+ function onKeydown(e) {
+ const shortcut = e.defaultPrevented ? null : zoomShortcut(e);
+ if (!shortcut) return;
+ e.preventDefault();
+ onzoom(shortcut === 'in' ? zoom * 1.2 : shortcut === 'out' ? zoom / 1.2 : 1);
+ }
</script>
+<svelte:window onkeydown={onKeydown} />
+
<div class="{inline ? 'shrink-0' : 'absolute bottom-3 left-3 z-20'} flex items-center gap-0.5 rounded-lg border border-neutral-200 bg-white/85 p-0.5 shadow-sm backdrop-blur-sm dark:border-white/[0.08] dark:bg-panel/85" data-canvas-controls>
<button type="button" class={button} title="Zoom out" aria-label="Zoom out" onclick={() => onzoom(zoom / 1.2)}><Icon name="minus" /></button>
<button type="button" class="{button} w-12 text-[12px] font-medium tabular-nums" title="Reset zoom to 100%" onclick={() => onzoom(1)}>{Math.round(zoom * 100)}%</button>
@@ -17,4 +29,7 @@
{#if onrefresh}
<button type="button" class={button} title="Load the latest status" aria-label="Refresh" disabled={loading} onclick={onrefresh}><Icon name="refresh" class="size-3.5 {loading ? 'animate-spin' : ''}" /></button>
{/if}
+ {#if children}
+ <div class="ml-0.5 flex items-center gap-2 border-l border-neutral-200 pr-0.5 pl-2 dark:border-white/[0.08]">{@render children()}</div>
+ {/if}
</div>
diff --git a/resources/js/canvas/deploy/DeployCanvas.svelte b/resources/js/canvas/deploy/DeployCanvas.svelte
index 853f1ee749..89dab86f61 100644
--- a/resources/js/canvas/deploy/DeployCanvas.svelte
+++ b/resources/js/canvas/deploy/DeployCanvas.svelte
@@ -8,7 +8,7 @@
import PaletteItem from './PaletteItem.svelte';
import RunPanel from './RunPanel.svelte';
import CanvasControls from '../CanvasControls.svelte';
- import { closeMenu, cv, dock, els, fit, hideResult, leave, pan, pickNext, PORT_Y, resetCanvas } from './state.svelte.js';
+ import { closeMenu, cv, els, fit, hideResult, leave, pan, pickNext, PORT_Y, resetCanvas } from './state.svelte.js';
// The deploy canvas: header, step palette, and the canvas with the step
// cards. The state lives in state.svelte.js (init() runs before the mount).
@@ -19,6 +19,10 @@
// Small screens: a notice that the canvas is not optimized for mobile. CSS
// shows it below 768px; closed once, it stays closed.
let noticeOpen = $state(!load('mobile-notice-dismissed', false));
+ // Desktop: the header sits in the zoom controls bar (bottom left), as on the
+ // other canvases. Small screens: a box above the canvas.
+ const desktopQuery = matchMedia('(min-width: 1024px)');
+ let desktop = $state(desktopQuery.matches);
const stop = e => e.stopPropagation();
// A pill joined to the Deploy card: each address opens in a new tab.
@@ -60,7 +64,10 @@
const reset = () => { if (els.root?.isConnected) resetCanvas(); };
addEventListener('keydown', escape);
addEventListener('deploy-canvas-reset', reset);
+ const media = () => { desktop = desktopQuery.matches; };
+ desktopQuery.addEventListener('change', media);
return () => {
+ desktopQuery.removeEventListener('change', media);
theme.disconnect();
removeEventListener('keydown', escape);
removeEventListener('deploy-canvas-reset', reset);
@@ -69,20 +76,21 @@
});
</script>
-<div class="cv-root" class:cv-dark={dark} class:cv-folded={folded}>
- <!-- Header: placed by dock (app top bar, floating panel, or a box above the canvas). -->
- <div use:dock>
- <div class="mr-auto flex min-w-0 items-center gap-2">
- {#if cv.target}
- <!-- Opened from an environment's New resource page: back to that environment. -->
- <a class="cv-back button px-2!" href="/project/{cv.target.project}/environment/{cv.target.environment}" title="Back to the environment" aria-label="Back to the environment"><Icon name="back" cls="size-4" /></a>
- {/if}
- <span class="shrink-0 rounded-full border border-coollabs/30 bg-coollabs/10 px-2 py-0.5 text-xs font-medium text-coollabs dark:border-warning/30 dark:bg-warning/15 dark:text-warning">Beta</span>
- </div>
- <div class="flex shrink-0 items-center gap-2">
- <button type="button" class="button" title="Start again with an empty canvas" onclick={askReset}>Reset</button>
- </div>
+{#snippet header()}
+ <div class="mr-auto flex min-w-0 items-center gap-2">
+ {#if cv.target}
+ <!-- Opened from an environment's New resource page: back to that environment. -->
+ <a class="cv-back button px-2!" href="/project/{cv.target.project}/environment/{cv.target.environment}" title="Back to the environment" aria-label="Back to the environment"><Icon name="back" cls="size-4" /></a>
+ {/if}
+ <span class="shrink-0 rounded-full border border-coollabs/30 bg-coollabs/10 px-2 py-0.5 text-xs font-medium text-coollabs dark:border-warning/30 dark:bg-warning/15 dark:text-warning">Beta</span>
</div>
+ <button type="button" class="button shrink-0" title="Start again with an empty canvas" onclick={askReset}>Reset</button>
+{/snippet}
+
+<div class="cv-root" class:cv-dark={dark} class:cv-folded={folded} class:cv-docked={desktop}>
+ {#if !desktop}
+ <div class="cv-island cv-top">{@render header()}</div>
+ {/if}
{#if noticeOpen}
<div class="cv-island cv-notice" role="note">
@@ -134,7 +142,6 @@
{/if}
</div>
</div>
- <CanvasControls zoom={cv.view.z} onzoom={z => els.pz.zoomTo(z)} onfit={fit} />
<RunPanel />
{#if cv.menu}
<div class="cv-menu" style:left="{cv.menu.left}px" style:top="{cv.menu.top}px">
@@ -149,6 +156,9 @@
{/if}
</section>
+ <!-- Bottom left of the whole canvas, below the Steps panel. -->
+ <CanvasControls zoom={cv.view.z} onzoom={z => els.pz.zoomTo(z)} onfit={fit} children={desktop ? header : null} />
+
{#if cv.dropdown}
{#key cv.dropdown?.trigger}
<Dropdown />
diff --git a/resources/js/canvas/deploy/state.svelte.js b/resources/js/canvas/deploy/state.svelte.js
index 60331ea9f2..2cfb6c3c24 100644
--- a/resources/js/canvas/deploy/state.svelte.js
+++ b/resources/js/canvas/deploy/state.svelte.js
@@ -85,62 +85,10 @@ export function pan(viewport) {
canPan: e => [viewport, world, edges].includes(e.target),
onPanStart: closeMenu,
});
-}
-
-const DESKTOP = '(min-width: 1024px)';
-/**
- * use:dock on the header. Desktop: it docks into the app top bar, or with the
- * floating nav it is a separate panel next to the top bar (as on the
- * environment canvas) when it fits there. Small screens: a box above the canvas.
- */
-export function dock(top) {
- const root = top.closest('.cv-root');
- const stage = root.querySelector('.cv-stage');
- function place() {
- const desktop = matchMedia(DESKTOP).matches;
- const slot = desktop && document.getElementById('page-toolbar-slot');
- const topbar = document.querySelector('.app-topbar');
- top.removeAttribute('style');
- if (desktop && topbar && document.documentElement.dataset.navStyle === 'floating') {
- top.className = 'fixed z-40 flex items-center gap-3 rounded-lg border border-neutral-200 bg-white px-2 py-1.5 dark:border-white/[0.08] dark:bg-panel';
- root.append(top);
- const gap = 8;
- const head = topbar.getBoundingClientRect();
- const width = top.offsetWidth;
- if (head.right + gap + width <= innerWidth - gap) {
- // Centered over the canvas, but never over the top bar.
- const box = stage.getBoundingClientRect();
- const left = Math.max(box.left + (box.width - width) / 2, head.right + gap);
- Object.assign(top.style, { top: `${head.top}px`, left: `${left}px`, minHeight: `${head.height}px` });
- root.classList.add('cv-docked');
- return;
- }
- top.removeAttribute('style');
- }
- top.className = slot ? 'flex items-center gap-3 pl-3' : 'cv-island cv-top';
- root.classList.toggle('cv-docked', !!slot);
- if (slot) slot.replaceChildren(top);
- else root.prepend(top);
- }
- place();
- const replace = () => root.isConnected && place();
- // The floating header is centered over the canvas next to the app top bar, so follow their sizes.
- const sizes = new ResizeObserver(replace);
- for (const target of [stage, document.querySelector('.app-topbar')].filter(Boolean)) sizes.observe(target);
- const media = matchMedia(DESKTOP);
- media.addEventListener('change', replace);
- addEventListener('resize', replace);
- const navStyle = new MutationObserver(replace);
- navStyle.observe(document.documentElement, { attributes: true, attributeFilter: ['data-nav-style'] });
- return {
- destroy() {
- sizes.disconnect();
- media.removeEventListener('change', replace);
- removeEventListener('resize', replace);
- navStyle.disconnect();
- top.remove(); // it may sit in the app top bar
- },
- };
+ // The root paints the dots, so move them with the viewport when the Steps panel folds or the window resizes.
+ const sizes = new ResizeObserver(() => els.pz.apply());
+ sizes.observe(viewport);
+ return { destroy: () => sizes.disconnect() };
}
/** use:track on a card: its element (for measuring) and its size (for the lines). */
diff --git a/resources/js/canvas/deploy/styles.js b/resources/js/canvas/deploy/styles.js
index e05434669b..869e76d236 100644
--- a/resources/js/canvas/deploy/styles.js
+++ b/resources/js/canvas/deploy/styles.js
@@ -22,6 +22,11 @@ const CSS = `
display: grid; grid-template-columns: 15.5rem minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
gap: 8px; padding: 8px;
background: var(--cv-backdrop); color: var(--cv-text);
+ /* The dots cover the whole backdrop, also under the Steps panel. pan()
+ (canvas-core.js) lines them up with the viewport through these variables. */
+ background-image: var(--canvas-dots-image, radial-gradient(circle, light-dark(rgb(0 0 0 / 0.13), rgb(255 255 255 / 0.09)) 1px, transparent 1.3px));
+ background-size: var(--canvas-dots-size, 20px 20px);
+ background-position: var(--canvas-dots-position, 0 0);
color-scheme: light; font: 13px/1.4 var(--font-sans, ui-sans-serif, system-ui, sans-serif);
-webkit-font-smoothing: antialiased;
}
@@ -32,7 +37,7 @@ const CSS = `
.cv-root svg { width: 1rem; height: 1rem; flex: none; }
.cv-root button:not(.button, [data-canvas-controls] button) { font: inherit; }
- /* Header island on small screens; on desktop the header docks into the app top bar. */
+ /* Header island on small screens; on desktop the header is in the zoom controls bar. */
.cv-top { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; padding: 0.625rem 0.75rem; }
.cv-root.cv-docked { grid-template-rows: minmax(0, 1fr); }
.cv-btn {
@@ -61,7 +66,9 @@ const CSS = `
/* Palette island */
/* Hugs its steps instead of filling the row; scrolls when the screen is short. */
- .cv-palette { display: flex; flex-direction: column; align-self: start; max-height: 100%; overflow-y: auto; padding: 1rem 0.625rem 0.75rem; }
+ /* The zoom controls sit below the Steps panel, so the panel leaves room for them. */
+ .cv-palette { display: flex; flex-direction: column; align-self: start; max-height: calc(100% - 3.25rem); overflow-y: auto; padding: 1rem 0.625rem 0.75rem; }
+ .cv-root > [data-canvas-controls] { bottom: 8px; left: 8px; }
.cv-palette-head { padding: 0 0.5rem 0.75rem; margin: 0 -0.625rem 0.5rem; padding-inline: 1.125rem; border-bottom: 1px solid var(--cv-line); }
.cv-palette-head b { display: block; font-size: 14px; font-weight: 600; }
.cv-palette-head span { color: var(--cv-subtle); font-size: 12px; }
@@ -95,7 +102,8 @@ const CSS = `
.cv-stage { position: relative; overflow: hidden; border: 0; background: transparent; }
.cv-viewport {
position: absolute; inset: 0; cursor: grab; touch-action: none;
- background-image: radial-gradient(circle, light-dark(rgb(0 0 0 / 0.13), rgb(255 255 255 / 0.09)) 1px, transparent 1.3px);
+ /* The dots are on .cv-root, so the viewport has none of its own. */
+ background-image: none;
}
.cv-viewport.panning { cursor: grabbing; }
.cv-world { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
diff --git a/resources/js/canvas/environment/EmptyCard.svelte b/resources/js/canvas/environment/EmptyCard.svelte
new file mode 100644
index 0000000000..dc6721258d
--- /dev/null
+++ b/resources/js/canvas/environment/EmptyCard.svelte
@@ -0,0 +1,24 @@
+<script>
+ // Placeholder card of an environment (or project) without resources: opens the deploy canvas (admins) or its page on click.
+ import Icon from './Icon.svelte';
+
+ let { node, position } = $props();
+</script>
+
+<a
+ class="group absolute flex w-[260px] items-center gap-2.5 rounded-xl border border-dashed border-neutral-300 bg-white/60 p-3 hover:border-neutral-400 dark:border-white/[0.12] dark:bg-white/[0.02] dark:hover:border-white/[0.24]"
+ style:left={position ? `${position.x}px` : null}
+ style:top={position ? `${position.y}px` : null}
+ href={node.link}
+ draggable="false"
+ data-ec-card
+ data-id={node.id}
+>
+ <div class="flex size-8 shrink-0 items-center justify-center rounded-lg border border-dashed border-neutral-300 text-neutral-400 dark:border-white/[0.12] dark:text-fg-faint">
+ <Icon name="plus" class="size-3.5" />
+ </div>
+ <div class="min-w-0 flex-1">
+ <div class="truncate text-[13px] leading-4 font-semibold text-neutral-500 underline-offset-2 group-hover:underline dark:text-fg-dim">{node.name}</div>
+ <div class="mt-0.5 truncate text-[11px] leading-4 text-neutral-400 dark:text-fg-faint">{node.subtitle}</div>
+ </div>
+</a>
diff --git a/resources/js/canvas/environment/EnvironmentCanvas.svelte b/resources/js/canvas/environment/EnvironmentCanvas.svelte
index e8f854f30b..3baf907f12 100644
--- a/resources/js/canvas/environment/EnvironmentCanvas.svelte
+++ b/resources/js/canvas/environment/EnvironmentCanvas.svelte
@@ -17,6 +17,8 @@
filterGraph,
filterOptions,
fitView,
+ GROUP_HEADER,
+ GROUP_PADDING,
groupByUse,
groupFrames,
groupKey,
@@ -33,6 +35,7 @@
} from '../../environment-canvas.js';
import Card from './Card.svelte';
import Deployments from './Deployments.svelte';
+ import EmptyCard from './EmptyCard.svelte';
import Icon from './Icon.svelte';
import Panel from './Panel.svelte';
import Toolbar from './Toolbar.svelte';
@@ -103,10 +106,12 @@
let pz;
const canEdit = $derived(!!graph?.can_edit);
- // Only the environment canvas saves card positions; server, project and connect views are auto-placed.
+ // Only the environment canvas has its own card positions; server and project views save on it (canMoveGroups).
const canMove = $derived(canEdit && graph?.can_move !== false);
- // Server canvas: admins drag whole project / environment groups; each environment saves its group position.
+ // Server canvas: admins drag whole project / environment groups and their cards; each environment saves them.
const canMoveGroups = $derived(canEdit && !!graph?.can_move_groups);
+ /** Server view: key of the card's group when the card can be moved there (it is saved on its environment canvas). */
+ const movableGroupOf = node => (canMoveGroups && node ? groupKey([node], node.zone) : null);
let groupMeta = {}; // server view: frame top-left and zone inner top-left per group key (see layoutServerView)
// Environment canvas endpoints of a card (the server view has no endpoints of its own for changes).
const environmentBase = node => (serverView
@@ -468,23 +473,32 @@
if (e.button !== 0 || e.target.closest('a,button,input,[data-ec-port]')) return;
e.stopPropagation();
const start = { cx: e.clientX, cy: e.clientY, ...positions[id] };
+ const key = movableGroupOf(nodeById(id));
+ const meta = key ? groupMeta[key] : null;
+ const movable = canMove || !!meta;
// The other cards and frames stay put during the drag, so measure them once.
const rules = dragRules(graph, positions, sizes, id);
+ // Server view: the group frame stays inside its zone, below the zone header.
+ const fits = meta
+ ? b => b.x >= meta.inner.x + GROUP_PADDING && b.y >= meta.inner.y + GROUP_HEADER + GROUP_PADDING && rules.fits(b)
+ : rules.fits;
let moved = false;
capture(card, e.pointerId);
begin(`card:${id}`);
track(card, ev => {
if (!moved && Math.hypot(ev.clientX - start.cx, ev.clientY - start.cy) < 4) return;
- if (!canMove) return;
+ if (!movable) return;
const rect = rectOf(id);
const wanted = { x: start.x + (ev.clientX - start.cx) / view.z, y: start.y + (ev.clientY - start.cy) / view.z, w: rect.width, h: rect.height };
// Cards cannot cover each other or another zone: stop at the edge of what is in the way.
- const spot = freeSpot(wanted, rules.others, BOX_GAP, rules.fits);
+ const spot = freeSpot(wanted, rules.others, BOX_GAP, fits);
if (!spot) return;
moved = true;
positions[id] = { x: spot.x, y: spot.y };
}, () => {
- if (moved) queueSave({ [id]: { ...positions[id] } });
+ // Server view: save the whole group, so its other cards keep the place they have here.
+ if (moved && meta) saveGroup(graph.nodes.filter(n => groupKey([n], n.zone) === key).map(n => n.id), meta.shift);
+ else if (moved) queueSave({ [id]: { ...positions[id] } });
else select({ kind: 'node', id });
end(`card:${id}`);
});
@@ -933,24 +947,28 @@
</div>
<div class="absolute top-0 left-0">
{#each graph?.nodes || [] as node (node.id)}
- <Card
- {node}
- position={positions[node.id]}
- selected={selected?.kind === 'node' && selected.id === node.id}
- dropTarget={dropTarget === node.id}
- movable={canMove}
- port={canEdit && (connectView ? isSource(node) && !node.missing : !serverView || !!node.environment)
- ? (connectView ? text.port : 'Drag to another card to draw a link')
- : null}
- linkCount={linkCounts[node.id] || 0}
- zoneNames={zoneNames(node)}
- serverDown={downZones.has(node.zone)}
- statusText={graph?.layout === 'server'}
- onpress={(e, card) => startCardDrag(node.id, card, e)}
- onconnect={(e, port) => startConnect(node.id, port, e)}
- onselect={() => select({ kind: 'node', id: node.id })}
- onhover={on => hoverCard(node.id, on)}
- />
+ {#if node.type === 'empty'}
+ <EmptyCard {node} position={positions[node.id]} />
+ {:else}
+ <Card
+ {node}
+ position={positions[node.id]}
+ selected={selected?.kind === 'node' && selected.id === node.id}
+ dropTarget={dropTarget === node.id}
+ movable={canMove || !!movableGroupOf(node)}
+ port={canEdit && (connectView ? isSource(node) && !node.missing : !serverView || !!node.environment)
+ ? (connectView ? text.port : 'Drag to another card to draw a link')
+ : null}
+ linkCount={linkCounts[node.id] || 0}
+ zoneNames={zoneNames(node)}
+ serverDown={downZones.has(node.zone)}
+ statusText={graph?.layout === 'server'}
+ onpress={(e, card) => startCardDrag(node.id, card, e)}
+ onconnect={(e, port) => startConnect(node.id, port, e)}
+ onselect={() => select({ kind: 'node', id: node.id })}
+ onhover={on => hoverCard(node.id, on)}
+ />
+ {/if}
{/each}
</div>
<!-- Link end dots sit above the cards, on their edges (like the deploy canvas ports). -->
diff --git a/resources/js/deploy-canvas.test.js b/resources/js/deploy-canvas.test.js
index e4f9be5461..a8fbecc2d7 100644
--- a/resources/js/deploy-canvas.test.js
+++ b/resources/js/deploy-canvas.test.js
@@ -1,6 +1,6 @@
import test from 'node:test';
import assert from 'node:assert/strict';
-import { freeSpot } from './canvas-core.js';
+import { freeSpot, zoomShortcut } from './canvas-core.js';
import { canFollow, domainList, fresh, logoOf, onlyOption, parseEnvVars, planOf, splitImage, targetFrom, uniqueLabels, withDeploy, withoutSecrets, withTarget } from './deploy-canvas.js';
test('splits the tag out of an image name', () => {
@@ -176,3 +176,14 @@ test('shows the logo of what a source step creates, like the rest of Coolify', (
assert.equal(src('database', {}), null);
assert.equal(src('server', {}), null);
});
+
+test('reads the browser zoom shortcut so the canvas can zoom instead', () => {
+ const key = (key, mods = {}) => zoomShortcut({ key, ctrlKey: false, metaKey: false, altKey: false, ...mods });
+ assert.equal(key('=', { metaKey: true }), 'in');
+ assert.equal(key('+', { ctrlKey: true }), 'in');
+ assert.equal(key('-', { ctrlKey: true }), 'out');
+ assert.equal(key('0', { metaKey: true }), 'reset');
+ assert.equal(key('-'), null);
+ assert.equal(key('-', { ctrlKey: true, altKey: true }), null);
+ assert.equal(key('s', { metaKey: true }), null);
+});
diff --git a/resources/js/environment-canvas.js b/resources/js/environment-canvas.js
index 3149f366d3..9faeb3b3fe 100644
--- a/resources/js/environment-canvas.js
+++ b/resources/js/environment-canvas.js
@@ -135,7 +135,8 @@ const byTypeAndName = (a, b) => columnOf(a) - columnOf(b) || String(a.name).loca
/**
* Card positions inside one group, from (0, 0). Cards with a position saved on their environment
- * canvas (node.saved) keep that arrangement; the other cards follow below them. Otherwise linked
+ * canvas (node.saved) keep that arrangement; the other cards follow below them in the grid the environment
+ * canvas uses, so both canvases show the group the same way. Otherwise linked
* cards form chains from left to right (source before target, one column per step); every chain
* gets its own rows. Cards without links follow in a grid of SINGLE_COLUMNS.
*/
@@ -150,9 +151,9 @@ export function layoutBlock(nodes, links = []) {
const bottom = Math.max(...saved.map(n => out[n.id].y + estimateNodeHeight(n)));
const rest = nodes.filter(n => !out[n.id]);
if (!rest.length) return { positions: out, width, height: bottom };
- const below = layoutBlock(rest, links);
- for (const [id, p] of Object.entries(below.positions)) out[id] = { x: p.x, y: bottom + ROW_GAP + p.y };
- return { positions: out, width: Math.max(width, below.width), height: bottom + ROW_GAP + below.height };
+ // Same grid as the environment canvas (layoutGraph) puts below the saved cards, so both canvases match.
+ const height = placeGrid(rest, 0, bottom + ROW_GAP, out);
+ return { positions: out, width: Math.max(...Object.values(out).map(p => p.x)) + CARD_WIDTH, height };
}
const ids = new Set(nodes.map(n => n.id));
const inside = links.filter(l => ids.has(l.source) && ids.has(l.target) && l.source !== l.target);
@@ -217,9 +218,12 @@ export function layoutBlock(nodes, links = []) {
return { positions: out, width: columns * step - COLUMN_GAP, height: bottom };
}
-/** Server view: key of a project / environment group on one server ("<environment uuid>:<zone id>"). */
+/**
+ * Server view: key of a project / environment group on one server ("<environment uuid>:<zone id>").
+ * Groups of an empty environment (placeholder card) have none, so they cannot be moved.
+ */
export const groupKey = (nodes, zoneId) => {
- const environment = nodes.find(n => n.environment?.uuid)?.environment?.uuid;
+ const environment = nodes.find(n => n.type !== 'empty' && n.environment?.uuid)?.environment?.uuid;
return environment && zoneId ? `${environment}:${zoneId}` : null;
};
@@ -230,7 +234,7 @@ export const groupKey = (nodes, zoneId) => {
* GROUPS_PER_ROW per row. When `groups` is given, it gets per group key its frame top-left, the zone's inner
* top-left, and `shift`: environment canvas position = server view position - shift.
*/
-export function layoutServerView(graph, groups = null) {
+export function layoutServerView(graph, groups = null, { compact = false } = {}) {
const out = {};
let y = 0;
for (const zone of zoneGroups(graph)) {
@@ -240,15 +244,20 @@ export function layoutServerView(graph, groups = null) {
const block = layoutBlock(nodes, graph.links || []);
return {
key: groupKey(nodes, zone.id),
+ nodes,
block,
size: { w: block.width + GROUP_PADDING * 2, h: GROUP_HEADER + GROUP_PADDING * 2 + block.height },
at: saved.length ? { x: Math.min(...saved.map(n => Number(n.saved.x))), y: Math.min(...saved.map(n => Number(n.saved.y))) } : null,
};
});
+ // Empty environments (placeholder cards only) go next to the other groups after these are placed.
+ const isEmpty = b => b.nodes.every(n => n.type === 'empty');
const pinned = blocks.filter(b => b.at).sort((a, b) => a.at.y - b.at.y || a.at.x - b.at.x);
// The environment canvas puts its first cards below a zone header; those land at the zone's top-left here.
const shift = { x: inner.x + GROUP_PADDING, y: inner.y + GROUP_HEADER + GROUP_PADDING - ZONE_HEADER - ZONE_PADDING };
+ const frames = [];
const place = ({ key, block, size }, left, top) => {
+ frames.push({ x: left, y: top });
for (const [id, p] of Object.entries(block.positions)) {
out[id] = { x: left + GROUP_PADDING + p.x, y: top + GROUP_HEADER + GROUP_PADDING + p.y };
}
@@ -266,21 +275,39 @@ export function layoutServerView(graph, groups = null) {
...b.size,
};
const spot = freeSpot(wanted, taken, GROUP_GAP, inside) || wanted;
- taken.push(spot);
+ taken.push({ ...spot, project: b.nodes[0]?.project?.uuid });
bottom = Math.max(bottom, place(b, spot.x, spot.y));
}
let x = 0;
let rowTop = pinned.length ? bottom + GROUP_GAP : inner.y;
let rowBottom = rowTop;
- blocks.filter(b => !b.at).forEach((b, i) => {
+ blocks.filter(b => !b.at && !isEmpty(b)).forEach((b, i) => {
if (i > 0 && i % GROUPS_PER_ROW === 0) {
x = 0;
rowTop = rowBottom + GROUP_GAP;
}
+ taken.push({ x, y: rowTop, ...b.size, project: b.nodes[0]?.project?.uuid });
rowBottom = Math.max(rowBottom, place(b, x, rowTop));
x += b.size.w + GROUP_GAP;
});
- y = Math.max(bottom, rowBottom) + ZONE_PADDING + ZONE_GAP;
+ bottom = Math.max(bottom, rowBottom);
+ // Right of the last group of the same project (or of the zone), at the nearest free spot.
+ for (const b of blocks.filter(b => !b.at && isEmpty(b))) {
+ const project = b.nodes[0]?.project?.uuid;
+ const anchor = taken.filter(t => t.project === project).at(-1) || taken.at(-1);
+ const wanted = anchor ? { x: anchor.x + anchor.w + GROUP_GAP, y: anchor.y, ...b.size } : { ...inner, ...b.size };
+ const spot = freeSpot(wanted, taken, GROUP_GAP, inside) || wanted;
+ taken.push({ ...spot, project });
+ bottom = Math.max(bottom, place(b, spot.x, spot.y));
+ }
+ if (compact && frames.length) {
+ // The groups keep their arrangement, but start at the zone's top-left (no empty space from saved positions).
+ const dx = inner.x - Math.min(...frames.map(f => f.x));
+ const dy = inner.y - Math.min(...frames.map(f => f.y));
+ for (const n of zone.nodes) if (out[n.id]) out[n.id] = { x: out[n.id].x + dx, y: out[n.id].y + dy };
+ bottom += dy;
+ }
+ y = bottom + ZONE_PADDING + ZONE_GAP;
}
return out;
}
@@ -300,7 +327,7 @@ export function layoutConnectView(graph) {
out[n.id] = { x: 0, y };
y += estimateNodeHeight(n) + ROW_GAP;
}
- const offset = variables ? CARD_WIDTH + ZONE_PADDING * 2 + ZONE_GAP * 3 : 0;
+ const offset = variables ? CARD_WIDTH + ZONE_PADDING * 2 + ZONE_GAP * 2 : 0;
let top = 0;
if (connected) {
y = ZONE_HEADER + ZONE_PADDING;
@@ -315,7 +342,8 @@ export function layoutConnectView(graph) {
top = y - GROUP_GAP + ZONE_PADDING + ZONE_GAP;
}
const others = groups.filter(g => g.id !== SOURCES_ZONE && g.id !== CONNECTED_ZONE);
- const placed = layoutServerView({ zones: others.map(g => g.zone || { id: g.id }), nodes: others.flatMap(g => g.nodes) });
+ // Compact: groups cannot be moved here, so positions saved on the environment canvas must not leave gaps.
+ const placed = layoutServerView({ zones: others.map(g => g.zone || { id: g.id }), nodes: others.flatMap(g => g.nodes) }, null, { compact: true });
for (const [id, p] of Object.entries(placed)) out[id] = { x: p.x + offset, y: p.y + top };
return out;
}
diff --git a/resources/js/environment-canvas.test.js b/resources/js/environment-canvas.test.js
index 920f2bc841..e4240b62bf 100644
--- a/resources/js/environment-canvas.test.js
+++ b/resources/js/environment-canvas.test.js
@@ -7,6 +7,7 @@ import {
ROW_GAP,
ZONE_HEADER,
ZONE_PADDING,
+ ZONE_GAP,
canConnect,
canLink,
dragRules,
@@ -21,6 +22,7 @@ import {
statusWord,
READABLE_ZOOM,
groupFrames,
+ groupKey,
layoutBlock,
estimateNodeHeight,
layoutGraph,
@@ -291,6 +293,28 @@ test('server view: cards keep the arrangement saved on their environment canvas,
assert.ok(p.c.y >= p.b.y + estimateNodeHeight(g.nodes[1]) + ROW_GAP);
});
+test('server view: a group with one saved card matches the environment canvas arrangement', () => {
+ const apps = Array.from({ length: MAX_ROWS + 1 }, (_, i) => envNode(`n${i}`, 'application', 'z1', 'prod'));
+ const nodes = [envNode('a', 'application', 'z1', 'prod', { saved: { x: 1000, y: 697 } }), ...apps, envNode('d', 'database', 'z1', 'prod')];
+ const env = layoutGraph({ zones: [{ id: 'z1', name: 'web' }], nodes, links: [], positions: { a: { x: 1000, y: 697 } } });
+ const server = layoutServerView({ layout: 'server', zones: [{ id: 'z1', name: 'web' }], nodes, links: [{ source: 'n0', target: 'd' }] });
+ for (const n of nodes) {
+ assert.deepEqual({ x: server[n.id].x - server.a.x, y: server[n.id].y - server.a.y }, { x: env[n.id].x - env.a.x, y: env[n.id].y - env.a.y }, n.id);
+ }
+});
+
+test('server view: a moved card saved with its group on the environment canvas stays where it was dropped', () => {
+ const nodes = [envNode('a', 'application', 'z1', 'prod'), envNode('b', 'service', 'z1', 'prod'), envNode('d', 'database', 'z1', 'prod')];
+ const g = { layout: 'server', zones: [{ id: 'z1', name: 'web' }], nodes, links: [] };
+ const groups = {};
+ const before = layoutServerView(g, groups);
+ const { shift } = groups['prod:z1'];
+ const dropped = { ...before, b: { x: before.b.x + 120, y: before.b.y + 400 } };
+ const saved = Object.fromEntries(nodes.map(n => [n.id, { x: dropped[n.id].x - shift.x, y: dropped[n.id].y - shift.y }]));
+ const after = layoutServerView({ ...g, nodes: nodes.map(n => ({ ...n, saved: saved[n.id] })) });
+ assert.deepEqual(after, dropped);
+});
+
test('server view: zones with server details get the taller header', () => {
const g = {
layout: 'server',
@@ -561,3 +585,43 @@ test('server view: a dragged card stops before its group covers another group',
const [f1, f2] = groupFrames(g.nodes, positions);
assert.ok(apart(f1, f2), 'the project / environment frames do not overlap');
});
+
+test('groupKey: a group with only an empty-environment placeholder has no key, so it cannot be moved', () => {
+ const environment = { uuid: 'env', name: 'production' };
+ assert.equal(groupKey([{ id: 'empty:env', type: 'empty', environment }], 'empty'), null);
+ assert.equal(groupKey([{ id: 'a', type: 'application', environment }], 'srv'), 'env:srv');
+});
+
+test('layoutServerView: an empty environment sits right of the other groups of its project, not below them', () => {
+ const shop = { uuid: 'shop', name: 'Shop' };
+ const node = (id, context, extra = {}) => ({ id, type: 'application', zone: 'srv', context, project: shop, environment: { uuid: context }, ...extra });
+ const graph = {
+ layout: 'server',
+ zones: [{ id: 'srv', name: 'srv' }],
+ nodes: [
+ node('a', 'Shop / staging', { saved: { x: 0, y: 0 } }),
+ node('empty:prod', 'Shop / production', { type: 'empty' }),
+ ],
+ links: [],
+ };
+ const out = layoutServerView(graph);
+ assert.equal(out['empty:prod'].y, out.a.y);
+ assert.ok(out['empty:prod'].x >= out.a.x + CARD_WIDTH);
+});
+
+test('variables view: saved environment canvas positions do not push resources away from the variables', () => {
+ const g = {
+ layout: 'connect',
+ zones: [{ id: 'sources', name: 'Server variables', icon: 'variable' }, { id: 'resources', name: 'Other resources', icon: 'service' }],
+ nodes: [
+ node('variable:1', 'variable', 'sources', { name: 'COOLIFY_SERVER_NAME' }),
+ node('app', 'application', 'resources', { context: 'Shop / prod', environment: { uuid: 'e1' }, saved: { x: 900, y: 1200 } }),
+ ],
+ links: [],
+ positions: {},
+ };
+ const [variables, resources] = zoneBoxes(g, layoutGraph(g));
+
+ assert.equal(resources.y, variables.y, 'both zones start at the top');
+ assert.ok(resources.x - (variables.x + variables.width) <= ZONE_GAP * 2, 'resources sit next to the variables');
+});
diff --git a/resources/views/components/application/configuration-sidebar.blade.php b/resources/views/components/application/configuration-sidebar.blade.php
index 93934db322..8b61ea5b72 100644
--- a/resources/views/components/application/configuration-sidebar.blade.php
+++ b/resources/views/components/application/configuration-sidebar.blade.php
@@ -1,4 +1,4 @@
-@props(['application', 'currentRoute', 'flush' => false])
+@props(['application', 'currentRoute', 'flush' => false, 'navOnly' => false])
@php
$applicationRouteParameters = [
@@ -258,17 +258,14 @@
@php
// The main sidebar shows this menu on wide screens (see components/navbar.blade.php).
- request()->attributes->set('mainNavContext', [
- 'label' => 'Dashboard',
- 'backHref' => route('dashboard'),
- 'backTitle' => 'Back to the dashboard',
- ]);
+ registerMainNavContext(0, 'Dashboard', 'Back to the main menu');
@endphp
-{{-- Rendered twice: in the page (below xl), and teleported into the main sidebar (xl and up). --}}
-@foreach (['page', 'main-nav'] as $placement)
+{{-- Rendered twice: in the page (below xl), and teleported into the main sidebar (xl and up).
+ navOnly renders only the sidebar copy, as the parent menu of a deeper page (e.g. a backup). --}}
+@foreach ($navOnly ? ['main-nav'] : ['page', 'main-nav'] as $placement)
@if ($placement === 'main-nav')
-@teleport('#main-nav-context')
+@teleport('#main-nav-context-0')
<div class="nav-context-menu">
@else
<aside @class([
diff --git a/resources/views/components/backup-sidebar.blade.php b/resources/views/components/backup-sidebar.blade.php
index 61311c7f69..a17274bab3 100644
--- a/resources/views/components/backup-sidebar.blade.php
+++ b/resources/views/components/backup-sidebar.blade.php
@@ -38,6 +38,12 @@
['key' => 'danger', 'label' => 'Danger Zone', 'icon' => 'danger'],
];
$backLabel = $context === 'database' ? 'Back to database' : 'Back to backups';
+ // The resource menu that the page renders one Back away in the main sidebar.
+ $parentMenu = match ($context) {
+ 'application' => 'Application',
+ 'database' => 'Database',
+ default => 'Service',
+ };
$backParameters = match ($context) {
'database' => collect($parameters)->except('backup_uuid')->all(),
'service' => collect($parameters)->except(['stack_service_uuid', 'backup_uuid'])->all(),
@@ -45,7 +51,7 @@
};
@endphp
-<x-main-nav-menu :back-href="route($routes['back'], $backParameters)" :back-label="$context === 'database' ? 'Database' : 'Backups'"
+<x-main-nav-menu :depth="1" :back-label="$parentMenu" :back-title="'Back to the '.strtolower($parentMenu).' menu'"
data-settings-search-items="{{ json_encode(settingsSearchItems(['Backup' => collect($items)->map(fn (array $item): array => [...$item, 'route' => $routes[$item['key']]])], $parameters)) }}">
<nav aria-label="Backup settings"
class="grid grid-cols-2 gap-0.5 border-y border-neutral-200 py-3 sm:grid-cols-3 xl:grid-cols-1 xl:border-y-0 xl:py-0 dark:border-white/[0.06]">
diff --git a/resources/views/components/database/configuration-sidebar.blade.php b/resources/views/components/database/configuration-sidebar.blade.php
index 1b87ed2e79..65a7318f8f 100644
--- a/resources/views/components/database/configuration-sidebar.blade.php
+++ b/resources/views/components/database/configuration-sidebar.blade.php
@@ -1,4 +1,4 @@
-@props(['database', 'currentRoute'])
+@props(['database', 'currentRoute', 'navOnly' => false])
@php
$databaseRouteParameters = [
@@ -68,17 +68,14 @@
@php
// The main sidebar shows this menu on wide screens (see components/navbar.blade.php).
- request()->attributes->set('mainNavContext', [
- 'label' => 'Dashboard',
- 'backHref' => route('dashboard'),
- 'backTitle' => 'Back to the dashboard',
- ]);
+ registerMainNavContext(0, 'Dashboard', 'Back to the main menu');
@endphp
-{{-- Rendered twice: in the page (below xl), and teleported into the main sidebar (xl and up). --}}
-@foreach (['page', 'main-nav'] as $placement)
+{{-- Rendered twice: in the page (below xl), and teleported into the main sidebar (xl and up).
+ navOnly renders only the sidebar copy, as the parent menu of a deeper page (e.g. a backup). --}}
+@foreach ($navOnly ? ['main-nav'] : ['page', 'main-nav'] as $placement)
@if ($placement === 'main-nav')
-@teleport('#main-nav-context')
+@teleport('#main-nav-context-0')
<div class="nav-context-menu">
@else
<aside class="application-settings-navigation in-main-nav min-w-0 xl:self-start"
diff --git a/resources/views/components/main-nav-menu.blade.php b/resources/views/components/main-nav-menu.blade.php
index 96398cd4f0..3dc4687d2e 100644
--- a/resources/views/components/main-nav-menu.blade.php
+++ b/resources/views/components/main-nav-menu.blade.php
@@ -1,18 +1,17 @@
-@props(['backHref', 'backLabel', 'backTitle' => null])
+@props(['backLabel', 'backTitle' => 'Back to the main menu', 'depth' => 0, 'navOnly' => false])
@php
// The main sidebar replaces its menu with this one on wide screens (see components/navbar.blade.php).
- request()->attributes->set('mainNavContext', [
- 'label' => $backLabel,
- 'backHref' => $backHref,
- 'backTitle' => $backTitle ?? 'Back to '.$backLabel,
- ]);
+ registerMainNavContext($depth, $backLabel, $backTitle);
@endphp
{{-- A page menu, rendered twice: in the page (below xl, CSS hides it on xl), and teleported into the
- main sidebar (xl and up). The slot must not contain Livewire components (they would render twice). --}}
-<aside {{ $attributes->class('application-settings-navigation in-main-nav min-w-0 xl:self-start') }}>
- {{ $slot }}
-</aside>
-@teleport('#main-nav-context')
+ main sidebar (xl and up). The slot must not contain Livewire components (they would render twice).
+ navOnly renders only the sidebar copy: a deeper page uses it to keep its parent menu one Back away. --}}
+@unless ($navOnly)
+ <aside {{ $attributes->class('application-settings-navigation in-main-nav min-w-0 xl:self-start') }}>
+ {{ $slot }}
+ </aside>
+@endunless
+@teleport('#main-nav-context-'.$depth)
<div class="nav-context-menu">
{{ $slot }}
</div>
diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.php
index aac8cd05ff..cae2b5d731 100644
--- a/resources/views/components/navbar.blade.php
+++ b/resources/views/components/navbar.blade.php
@@ -20,9 +20,11 @@
// Label of the open submenu ('' = main menu). It starts on the submenu of the current page
// ([data-active-submenu], read in init). Back opens the main menu.
submenu: '',
- // Direction of the last main menu/submenu swap ('forward' or 'back'); it selects the enter animation.
- // A swap that loads a new page stores it in sessionStorage, so the new navbar plays it once.
- navSwap: sessionStorage.getItem('navSwap') || '',
+ // Depth of the open resource menu on wide screens (-1 = main menu or submenu). It starts on the
+ // deepest menu of the current page; Back opens the menu one depth lower.
+ navLevel: -1,
+ // Direction of the last menu swap ('forward' or 'back'); it selects the enter animation of every menu.
+ navSwap: '',
// macOS/iOS use ⌘; Windows/Linux use Ctrl+
modKeyLabel: (() => {
const platform = navigator.userAgentData?.platform || navigator.platform || '';
@@ -30,9 +32,19 @@
return /Mac|iPhone|iPad|iPod/i.test(platform) || /Mac OS X|Macintosh/i.test(ua) ? '⌘' : 'Ctrl+';
})(),
init() {
- // Cleared after this tick: the mobile and desktop navbars both read it on init.
- setTimeout(() => sessionStorage.removeItem('navSwap'));
this.submenu = this.$root.querySelector('[data-active-submenu]')?.dataset.activeSubmenu || '';
+ this.navLevel = Number([...this.$root.querySelectorAll('[data-nav-level]')].pop()?.dataset.navLevel ?? -1);
+ if (@js($desktop)) {
+ // The open resource menu depth is kept across page loads: a page that opens a deeper menu
+ // (e.g. a backup) plays the forward swap, and a page that opens a lower one plays the back swap.
+ const previousLevel = sessionStorage.getItem('navLevel');
+ if (previousLevel !== null && window.matchMedia('(min-width: 80rem)').matches) {
+ const levelChange = this.navLevel - Number(previousLevel);
+ this.navSwap = levelChange > 0 ? 'forward' : (levelChange < 0 ? 'back' : '');
+ }
+ sessionStorage.setItem('navLevel', this.navLevel);
+ this.$watch('navLevel', level => sessionStorage.setItem('navLevel', level));
+ }
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
const userSettings = localStorage.getItem('theme');
if (userSettings !== 'system') { return; }
@@ -89,7 +101,7 @@
$navSections = collect([
'Workspace' => [
// The dashboard lists projects and links to all of them, so project pages count as Dashboard.
- ['label' => 'Dashboard', 'icon' => 'dashboard', 'href' => '/', 'active' => request()->is('/', 'dashboard/*', 'projects', 'projects/*', 'project/*')],
+ ['label' => 'Dashboard', 'icon' => 'dashboard', 'href' => '/', 'active' => request()->is('/', 'dashboard/*', 'projects', 'projects/*', 'project/*', 'canvas')],
['label' => 'Monitoring', 'icon' => 'graph', 'children' => [
['label' => 'Analytics', 'icon' => 'analytics', 'href' => route('analytics'), 'active' => request()->is('analytics')],
['label' => 'Metrics', 'icon' => 'graph', 'href' => route('metrics'), 'active' => request()->is('metrics')],
@@ -97,7 +109,7 @@
['label' => 'Terminal', 'icon' => 'browser-terminal', 'href' => route('terminal'), 'active' => request()->is('terminal*'), 'navigate' => false, 'visible' => auth()->user()?->can('canAccessTerminal')],
],
'Infrastructure' => [
- ['label' => 'Servers', 'icon' => 'servers', 'href' => '/servers', 'active' => request()->is('server/*', 'servers')],
+ ['label' => 'Servers', 'icon' => 'servers', 'href' => '/servers', 'active' => request()->is('server/*', 'servers', 'servers/*')],
['label' => 'Integrations', 'icon' => 'link', 'children' => [
['label' => 'Sources', 'icon' => 'sources', 'href' => route('source.all'), 'active' => request()->is('sources', 'source/*')],
['label' => 'Destinations', 'icon' => 'destinations', 'href' => route('destination.index'), 'active' => request()->is('destinations', 'destination/*')],
@@ -136,7 +148,7 @@
['label' => 'API Tokens', 'icon' => 'code', 'href' => route('security.api-tokens'), 'active' => request()->is('security/api-tokens')],
]],
['label' => 'Subscription', 'icon' => 'subscription', 'href' => isCloud() ? route('subscription.show') : '', 'active' => request()->is('subscription*'), 'visible' => isCloud() && auth()->user()->isAdmin()],
- ['label' => 'Tags', 'icon' => 'tags', 'href' => route('tags.show'), 'active' => request()->is('tags*')],
+ ['label' => 'Tags', 'icon' => 'tags', 'href' => route('tags.show'), 'active' => request()->is('tags*', 'canvas/tags')],
['label' => 'Settings', 'icon' => 'settings', 'visible' => isInstanceAdmin(), 'children' => [
['label' => 'General', 'icon' => 'settings', 'href' => route('settings.index'), 'active' => request()->is('settings')],
['label' => 'Advanced', 'icon' => 'grid', 'href' => route('settings.advanced'), 'active' => request()->is('settings/advanced')],
@@ -158,28 +170,35 @@
})
->all());
$activeSubmenu = $navSections->flatten(1)->first(fn (array $item): bool => isset($item['children']) && $item['active']);
- // Set by a resource menu (e.g. components/application/configuration-sidebar.blade.php) that
- // teleports itself into #main-nav-context; only the desktop sidebar has the slot.
- $navContext = $desktop ? request()->attributes->get('mainNavContext') : null;
+ // Resource menus by depth, registered by registerMainNavContext() (e.g. from
+ // components/main-nav-menu.blade.php). Each one teleports itself into #main-nav-context-{depth};
+ // only the desktop sidebar has the slots.
+ $navContext = $desktop ? request()->attributes->get('mainNavContext', []) : [];
@endphp
- {{-- Wide screens on a resource page: the resource menu replaces the main menu; Back opens the dashboard. --}}
- @if ($navContext)
- <li class="hidden xl:contents">
- <ul role="list" class="flex flex-col gap-y-0.5">
+ {{-- Wide screens on a resource page: the deepest resource menu replaces the main menu. Back shows the
+ menu one depth lower, and then the main menu (or its submenu), without leaving the page. --}}
+ @foreach ($navContext as $depth => $navMenu)
+ @php
+ $previousDepth = collect($navContext)->keys()->filter(fn (int $key): bool => $key < $depth)->last() ?? -1;
+ @endphp
+ <li x-show="navLevel === {{ $depth }}" data-nav-level="{{ $depth }}" @unless ($loop->last) x-cloak @endunless
+ class="hidden xl:contents">
+ <ul role="list" class="flex flex-col gap-y-0.5" :class="navSwap && 'nav-swap-' + navSwap">
<li class="mb-1">
- <a href="{{ $navContext['backHref'] }}" {{ wireNavigate() }} title="{{ $navContext['backTitle'] }}" aria-label="{{ $navContext['backTitle'] }}"
+ <button type="button" @click="navLevel = {{ $previousDepth }}; navSwap = 'back'"
+ title="{{ $navMenu['backTitle'] }}" aria-label="{{ $navMenu['backTitle'] }}"
class="menu-item menu-back bg-transparent! hover:bg-neutral-100! dark:hover:bg-white/[0.06]!" :class="collapsed && 'lg:justify-center lg:px-0'">
<span class="menu-back-icon flex shrink-0 items-center justify-center">
<x-reicon name="chevron-down" class="size-3 rotate-90 text-neutral-500 dark:text-fg-dim" />
</span>
<span class="flex-1 truncate pr-6 text-center font-medium text-black dark:text-fg"
- :class="collapsed && 'lg:hidden'">{{ $navContext['label'] }}</span>
- </a>
+ :class="collapsed && 'lg:hidden'">{{ $navMenu['label'] }}</span>
+ </button>
</li>
- <li id="main-nav-context" class="nav-context min-w-0"></li>
+ <li id="main-nav-context-{{ $depth }}" class="nav-context min-w-0"></li>
</ul>
</li>
- @endif
+ @endforeach
{{-- Submenus: a parent entry opens its submenu in place, and the user picks a page (the mobile
drawer stays open until then). Back shows the main menu without leaving the page. --}}
@php
@@ -188,8 +207,8 @@
@foreach ($renderedSubmenus as $submenuItem)
<li x-show="submenu === @js($submenuItem['label'])"
@if ($submenuItem['active']) data-active-submenu="{{ $submenuItem['label'] }}" @else x-cloak @endif
- @class(['contents', 'xl:hidden' => $navContext])>
- <ul role="list" class="flex flex-col gap-y-0.5" :class="navSwap === 'forward' && 'nav-swap-forward'">
+ @class(['contents', 'xl:hidden' => $navContext]) :class="{ 'xl:hidden': navLevel !== -1 }">
+ <ul role="list" class="flex flex-col gap-y-0.5" :class="navSwap && 'nav-swap-' + navSwap">
<li class="mb-1">
<button type="button" @click="submenu = ''; navSwap = 'back'" title="Back to the main menu" aria-label="Back to the main menu"
class="menu-item menu-back bg-transparent! hover:bg-neutral-100! dark:hover:bg-white/[0.06]!" :class="collapsed && 'lg:justify-center lg:px-0'">
@@ -230,8 +249,8 @@
</ul>
</li>
@endforeach
- <li x-show="!submenu" @if ($activeSubmenu) x-cloak @endif @class(['contents', 'xl:hidden' => $navContext])>
- <ul role="list" class="flex flex-col gap-y-0.5" :class="navSwap === 'back' && 'nav-swap-back'">
+ <li x-show="!submenu" @if ($activeSubmenu) x-cloak @endif @class(['contents', 'xl:hidden' => $navContext]) :class="{ 'xl:hidden': navLevel !== -1 }">
+ <ul role="list" class="flex flex-col gap-y-0.5" :class="navSwap && 'nav-swap-' + navSwap">
@foreach ($navSections as $sectionLabel => $sectionItems)
@if ($loop->first)
<li class="nav-section" :class="collapsed && 'lg:hidden'">{{ $sectionLabel }}</li>
@@ -269,7 +288,8 @@
@endif
@if (auth()->id() === 0 && (isCloud() || isDev()))
{{-- Part of the main menu: hidden while a submenu or a resource menu shows. --}}
- <li x-show="!submenu" @if ($activeSubmenu ?? null) x-cloak @endif @class(['xl:hidden' => $navContext ?? null])>
+ <li x-show="!submenu" @if ($activeSubmenu ?? null) x-cloak @endif @class(['xl:hidden' => $navContext ?? []])
+ :class="{ 'xl:hidden': navLevel !== -1 }">
<a title="Admin" {{ wireNavigate() }}
class="{{ request()->is('admin') ? 'menu-item-active menu-item' : 'menu-item' }}"
:class="collapsed && 'lg:justify-center lg:px-0'" href="{{ route('admin.index') }}">
diff --git a/resources/views/components/server/sidebar.blade.php b/resources/views/components/server/sidebar.blade.php
index 87db27e21e..3ff08eec17 100644
--- a/resources/views/components/server/sidebar.blade.php
+++ b/resources/views/components/server/sidebar.blade.php
@@ -226,18 +226,14 @@
@php
// The main sidebar shows this menu on wide screens (see components/navbar.blade.php).
- request()->attributes->set('mainNavContext', [
- 'label' => 'Servers',
- 'backHref' => route('server.index'),
- 'backTitle' => 'Back to the servers',
- ]);
+ registerMainNavContext(0, 'Servers', 'Back to the main menu');
@endphp
{{-- Rendered twice: in the page (below xl), and teleported into the main sidebar (xl and up).
Both copies keep their own warning state (proxy, Sentinel). --}}
@foreach (['page', 'main-nav'] as $placement)
@if ($placement === 'main-nav')
-@teleport('#main-nav-context')
+@teleport('#main-nav-context-0')
<div class="nav-context-menu"
x-data="{
proxyConfigurationPending: @js($server->hasPendingProxyConfiguration()),
diff --git a/resources/views/components/service-database/sidebar.blade.php b/resources/views/components/service-database/sidebar.blade.php
index 861da3a15e..ab6425211e 100644
--- a/resources/views/components/service-database/sidebar.blade.php
+++ b/resources/views/components/service-database/sidebar.blade.php
@@ -3,7 +3,7 @@
'serviceDatabase',
])
-<x-main-nav-menu :back-href="route('project.service.configuration', [...$parameters, 'stack_service_uuid' => null])" back-label="Service">
+<x-main-nav-menu :depth="1" back-label="Service" back-title="Back to the service menu">
<nav aria-label="Compose resource settings"
class="grid grid-cols-2 gap-0.5 border-y border-neutral-200 py-3 sm:grid-cols-3 xl:grid-cols-1 xl:border-y-0 xl:py-0 dark:border-white/[0.06]">
<div class="nav-section hidden xl:block">Compose resource</div>
diff --git a/resources/views/components/service/configuration-sidebar.blade.php b/resources/views/components/service/configuration-sidebar.blade.php
index 4b560db5ad..461d43c395 100644
--- a/resources/views/components/service/configuration-sidebar.blade.php
+++ b/resources/views/components/service/configuration-sidebar.blade.php
@@ -1,4 +1,4 @@
-@props(['service', 'currentRoute'])
+@props(['service', 'currentRoute', 'navOnly' => false])
@php
$serviceRouteParameters = [
@@ -55,7 +55,7 @@
$activeGroup = (string) $groupedItems->search(fn ($items) => $items->contains(fn ($item) => $item['active'] ?? false));
@endphp
-<x-main-nav-menu :back-href="route('dashboard')" back-label="Dashboard" back-title="Back to the dashboard"
+<x-main-nav-menu back-label="Dashboard" :nav-only="$navOnly"
data-settings-search-items="{{ json_encode(settingsSearchItems($groupedItems, $serviceRouteParameters)) }}">
<nav aria-label="Service settings"
x-data="settingsSidebarAccordion({ activeGroup: @js($activeGroup), storageKey: 'coolify.settings-sidebar.service' })"
diff --git a/resources/views/livewire/dashboard.blade.php b/resources/views/livewire/dashboard.blade.php
index 1ab3979406..ea32fa396d 100644
--- a/resources/views/livewire/dashboard.blade.php
+++ b/resources/views/livewire/dashboard.blade.php
@@ -99,11 +99,11 @@
</x-modal-input>
</x-slot:titleAction>
@endcan
- @if ($dashboardProjects->isNotEmpty())
- <x-slot:actions>
- <x-canvas-view-toggle />
- </x-slot:actions>
- @endif
+ {{-- The dashboard canvas link lives here, so it never adds a row above the page. --}}
+ <x-slot:actions>
+ <x-canvas-view-toggle :views="$dashboardProjects->isNotEmpty() ? null : []"
+ :list-url="route('dashboard')" :canvas-url="route('dashboard.canvas')" />
+ </x-slot:actions>
</x-section-heading>
@if ($dashboardProjects->isEmpty())
diff --git a/resources/views/livewire/dashboard/active-deployments.blade.php b/resources/views/livewire/dashboard/active-deployments.blade.php
index 9b1db779f2..7d2e88b2ff 100644
--- a/resources/views/livewire/dashboard/active-deployments.blade.php
+++ b/resources/views/livewire/dashboard/active-deployments.blade.php
@@ -24,18 +24,11 @@
$hasAnyDeployments = $hasActiveDeployments || $hasRecentDeployments;
@endphp
-{{-- The dashboard's canvas link sits in the Deployments heading, or
- alone at the top right when there are no deployments. --}}
-<div wire:poll.3000ms="refreshDeployments" @class(['min-w-0', 'mb-0!' => $hasAnyDeployments, '-mb-4' => ! $hasAnyDeployments])>
+<div wire:poll.3000ms="refreshDeployments" @class(['min-w-0', 'mb-0!' => $hasAnyDeployments, 'hidden' => ! $hasAnyDeployments])>
@if ($hasAnyDeployments)
{{-- Container breakpoints: the table needs room, which the dashboard column may not have. --}}
<section class="@container mb-0! min-w-0">
- <x-section-heading title="Deployments">
- <x-slot:actions>
- <x-canvas-view-toggle :views="[]"
- :list-url="route('dashboard')" :canvas-url="route('dashboard.canvas')" />
- </x-slot:actions>
- </x-section-heading>
+ <x-section-heading title="Deployments" />
<div class="flex min-w-0 flex-col gap-4">
@if ($hasActiveDeployments)
@@ -177,10 +170,5 @@
@endif
</div>
</section>
- @else
- <div class="flex justify-end">
- <x-canvas-view-toggle :views="[]"
- :list-url="route('dashboard')" :canvas-url="route('dashboard.canvas')" />
- </div>
@endif
</div>
diff --git a/resources/views/livewire/destination/sidebar.blade.php b/resources/views/livewire/destination/sidebar.blade.php
index b3752be2e0..2185785061 100644
--- a/resources/views/livewire/destination/sidebar.blade.php
+++ b/resources/views/livewire/destination/sidebar.blade.php
@@ -22,7 +22,7 @@
])->filter();
@endphp
-<x-main-nav-menu :back-href="route('destination.index')" back-label="Destinations" back-title="Back to the destinations"
+<x-main-nav-menu back-label="Destinations" back-title="Back to Integrations"
data-settings-search-items="{{ json_encode(settingsSearchItems(['Destination' => $destinationMenuItems], $destinationRouteParameters)) }}">
<nav aria-label="Destination settings"
class="grid grid-cols-2 gap-0.5 border-y border-neutral-200 py-3 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-1 xl:border-y-0 xl:py-0 dark:border-white/[0.06]">
diff --git a/resources/views/livewire/project/application/backup/show.blade.php b/resources/views/livewire/project/application/backup/show.blade.php
index a5a8e84fae..0b9b31bfb6 100644
--- a/resources/views/livewire/project/application/backup/show.blade.php
+++ b/resources/views/livewire/project/application/backup/show.blade.php
@@ -7,6 +7,9 @@
<section class="application-settings-workspace mt-4 w-full max-w-none lg:mt-0">
<div class="grid min-w-0 gap-8 xl:grid-cols-[210px_minmax(0,1fr)] xl:gap-8">
+ {{-- The application menu, one Back away from the backup menu in the main sidebar. --}}
+ <x-application.configuration-sidebar :application="$application"
+ current-route="project.application.backup.index" nav-only />
<x-backup-sidebar context="application" :parameters="$parameters" :section="$section" />
<div class="min-w-0">
diff --git a/resources/views/livewire/project/database/backup/execution.blade.php b/resources/views/livewire/project/database/backup/execution.blade.php
index 19ef5948b1..7fc0c715c4 100644
--- a/resources/views/livewire/project/database/backup/execution.blade.php
+++ b/resources/views/livewire/project/database/backup/execution.blade.php
@@ -24,6 +24,8 @@
<section class="application-settings-workspace mt-4 w-full max-w-none lg:mt-0">
<div class="grid min-w-0 gap-8 xl:grid-cols-[210px_minmax(0,1fr)] xl:gap-8">
+ {{-- The database menu, one Back away from the backup menu in the main sidebar. --}}
+ <x-database.configuration-sidebar :database="$database" current-route="project.database.backup.index" nav-only />
<x-backup-sidebar context="database" :parameters="$parameters" :section="$section" />
<div class="min-w-0">
diff --git a/resources/views/livewire/project/environment-canvas.blade.php b/resources/views/livewire/project/environment-canvas.blade.php
index 61d53cfdde..35535969e4 100644
--- a/resources/views/livewire/project/environment-canvas.blade.php
+++ b/resources/views/livewire/project/environment-canvas.blade.php
@@ -4,7 +4,7 @@
</x-slot>
<div data-environment-canvas data-project="{{ $project->uuid }}" data-environment="{{ $environment->uuid }}"
data-team="{{ $project->team_id }}" data-user="{{ auth()->id() }}"
- data-new="{{ auth()->user()->can('createAnyResource') ? route('project.resource.create', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid]) : '' }}"
+ data-new="{{ auth()->user()->can('createAnyResource') ? route('deploy-canvas', ['project' => $project->uuid, 'environment' => $environment->uuid]) : '' }}"
class="relative h-full" wire:ignore>
{{-- The canvas moves this group into its toolbar; the page actions come last, at the right end. --}}
<div data-ec-views class="flex items-center gap-2">
@@ -26,8 +26,9 @@
</a>
@endcan
@can('createAnyResource')
- <a href="{{ route('project.resource.create', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid]) }}"
- {{ wireNavigate() }} class="button button-highlighted whitespace-nowrap">
+ {{-- A full page load: the deploy canvas uses the minimal layout. --}}
+ <a href="{{ route('deploy-canvas', ['project' => $project->uuid, 'environment' => $environment->uuid]) }}"
+ class="button button-highlighted whitespace-nowrap">
<x-reicon name="plus" class="size-3.5" />
New resource
</a>
diff --git a/resources/views/livewire/project/resource/index.blade.php b/resources/views/livewire/project/resource/index.blade.php
index 6c7d33685b..c4c02f4ed8 100644
--- a/resources/views/livewire/project/resource/index.blade.php
+++ b/resources/views/livewire/project/resource/index.blade.php
@@ -12,6 +12,11 @@
</p>
</div>
<div class="flex w-fit shrink-0 items-center gap-2">
+ @if ($environment->isEmpty())
+ {{-- The list toolbar (with its canvas switch) is hidden when there are no resources. --}}
+ <x-canvas-view-toggle :views="['list' => ['List view', 'unordered-list']]"
+ :canvas-url="route('project.environment.canvas', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid])" />
+ @endif
<a href="{{ route('shared-variables.environment.show', ['project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid]) }}"
{{ wireNavigate() }}
class="button whitespace-nowrap"
diff --git a/resources/views/livewire/project/service/configuration.blade.php b/resources/views/livewire/project/service/configuration.blade.php
index dfad82ca14..c2223fede6 100644
--- a/resources/views/livewire/project/service/configuration.blade.php
+++ b/resources/views/livewire/project/service/configuration.blade.php
@@ -63,7 +63,7 @@
<section class="application-settings-workspace mt-4 w-full max-w-none lg:mt-0">
<div class="grid min-w-0 gap-8 xl:grid-cols-[210px_minmax(0,1fr)] xl:gap-8">
- <x-main-nav-menu :back-href="route('dashboard')" back-label="Dashboard" back-title="Back to the dashboard"
+ <x-main-nav-menu back-label="Dashboard"
data-settings-search-items="{{ json_encode(settingsSearchItems($groupedItems, $serviceRouteParameters)) }}">
<nav aria-label="Service settings"
x-data="settingsSidebarAccordion({ activeGroup: @js($activeGroup), storageKey: 'coolify.settings-sidebar.service' })"
diff --git a/resources/views/livewire/project/service/index.blade.php b/resources/views/livewire/project/service/index.blade.php
index 76e9cb4c20..b7fab27f02 100644
--- a/resources/views/livewire/project/service/index.blade.php
+++ b/resources/views/livewire/project/service/index.blade.php
@@ -4,10 +4,14 @@
@endunless
<section @class(['application-settings-workspace mt-4 w-full max-w-none lg:mt-0' => ! $embedded])>
<div @class(['grid min-w-0 gap-8 xl:grid-cols-[210px_minmax(0,1fr)] xl:gap-8' => ! $embedded])>
+ @unless ($embedded)
+ {{-- The service menu, one Back away from this compose resource menu in the main sidebar. --}}
+ <x-service.configuration-sidebar :service="$service" current-route="project.service.configuration" nav-only />
+ @endunless
@if (! $embedded && $resourceType === 'database')
<x-service-database.sidebar :parameters="$parameters" :serviceDatabase="$serviceDatabase" />
@elseif (! $embedded)
- <x-main-nav-menu :back-href="route('project.service.configuration', [...$parameters, 'stack_service_uuid' => null])" back-label="Service">
+ <x-main-nav-menu :depth="1" back-label="Service" back-title="Back to the service menu">
<nav aria-label="Compose resource settings"
class="grid grid-cols-2 gap-0.5 border-y border-neutral-200 py-3 sm:grid-cols-3 xl:grid-cols-1 xl:border-y-0 xl:py-0 dark:border-white/[0.06]">
<div class="nav-section hidden xl:block">Compose resource</div>
diff --git a/resources/views/livewire/settings/advanced.blade.php b/resources/views/livewire/settings/advanced.blade.php
index 39caf1d23e..3a3229d6a4 100644
--- a/resources/views/livewire/settings/advanced.blade.php
+++ b/resources/views/livewire/settings/advanced.blade.php
@@ -173,7 +173,7 @@
</x-application.settings-section>
<x-application.settings-section id="file-download-storage-section" title="File downloads"
- helper="Choose how files from the container file browser are downloaded. Streaming sends each file through this Coolify instance, up to 1 GB. With S3, the server uploads the file to the bucket and the browser downloads it from S3, up to 5 GB. S3 download links expire after 15 minutes, and the files are deleted after 6 hours.">
+ helper="Choose how files from the container file browser and backups are downloaded. Streaming sends each file through this Coolify instance (file browser: up to 1 GB). With S3, the server uploads the file to the bucket and the browser downloads it from S3, up to 5 GB; larger backups are streamed. S3 download links expire after 15 minutes, and the files are deleted after 6 hours.">
<div class="flex max-w-md flex-col gap-4">
<x-forms.listbox id="file_download_storage" label="Download method" onChange="instantSave"
:options="[
diff --git a/resources/views/livewire/source/github/change.blade.php b/resources/views/livewire/source/github/change.blade.php
index 28f419d03c..6a74d5fb0b 100644
--- a/resources/views/livewire/source/github/change.blade.php
+++ b/resources/views/livewire/source/github/change.blade.php
@@ -47,7 +47,7 @@
@if ($showSettingsSidebar)
<section class="application-settings-workspace mt-4 w-full max-w-none lg:mt-0">
<div class="grid min-w-0 gap-8 xl:grid-cols-[210px_minmax(0,1fr)] xl:gap-8">
- <x-main-nav-menu :back-href="route('source.all')" back-label="Sources" back-title="Back to the sources"
+ <x-main-nav-menu back-label="Sources" back-title="Back to Integrations"
data-settings-search-items="{{ json_encode(settingsSearchItems(['GitHub App' => $settingsMenuItems], $githubAppRouteParameters)) }}">
<nav aria-label="GitHub App settings"
class="grid grid-cols-2 gap-0.5 border-y border-neutral-200 py-3 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-1 xl:border-y-0 xl:py-0 dark:border-white/[0.06]">
diff --git a/resources/views/livewire/storage/show.blade.php b/resources/views/livewire/storage/show.blade.php
index 140c3a4e96..aacc03706a 100644
--- a/resources/views/livewire/storage/show.blade.php
+++ b/resources/views/livewire/storage/show.blade.php
@@ -36,7 +36,7 @@
@if ($showSettingsSidebar)
<section class="application-settings-workspace mt-4 w-full max-w-none lg:mt-0">
<div class="grid min-w-0 gap-8 xl:grid-cols-[210px_minmax(0,1fr)] xl:gap-8">
- <x-main-nav-menu :back-href="route('storage.index')" back-label="S3 Storage" back-title="Back to the S3 storages"
+ <x-main-nav-menu back-label="S3 Storage" back-title="Back to Integrations"
data-settings-search-items="{{ json_encode(settingsSearchItems(['S3 storage' => $settingsMenuItems], $storageRouteParameters)) }}">
<nav aria-label="S3 storage settings"
class="grid grid-cols-2 gap-0.5 border-y border-neutral-200 py-3 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-1 xl:border-y-0 xl:py-0 dark:border-white/[0.06]">
diff --git a/tests/Feature/EnvironmentCanvasTest.php b/tests/Feature/EnvironmentCanvasTest.php
index ab4e403489..d424ee22b6 100644
--- a/tests/Feature/EnvironmentCanvasTest.php
+++ b/tests/Feature/EnvironmentCanvasTest.php
@@ -414,6 +414,18 @@ describe('canvas authorization', function () {
});
describe('canvas page', function () {
+ test('add resource opens the deploy canvas for this environment', function () {
+ $deployCanvasUrl = route('deploy-canvas', ['project' => $this->project->uuid, 'environment' => $this->environment->uuid]);
+
+ $this->actingAs($this->admin)->withSession(['currentTeam' => $this->team])
+ ->withoutVite()
+ ->get(route('project.environment.canvas', ['project_uuid' => $this->project->uuid, 'environment_uuid' => $this->environment->uuid]))
+ ->assertOk()
+ ->assertSee('data-new="'.e($deployCanvasUrl).'"', false)
+ ->assertSee('href="'.e($deployCanvasUrl).'"', false)
+ ->assertDontSee(route('project.resource.create', ['project_uuid' => $this->project->uuid, 'environment_uuid' => $this->environment->uuid]), false);
+ });
+
test('a team member can open the canvas page', function () {
$member = User::factory()->create();
$this->team->members()->attach($member->id, ['role' => 'member']);
diff --git a/tests/Feature/ProjectAndEnvironmentSettingsButtonTest.php b/tests/Feature/ProjectAndEnvironmentSettingsButtonTest.php
index 514ebac4c3..bd6f8bdfc8 100644
--- a/tests/Feature/ProjectAndEnvironmentSettingsButtonTest.php
+++ b/tests/Feature/ProjectAndEnvironmentSettingsButtonTest.php
@@ -55,3 +55,18 @@ test('environment resources page header links to environment settings', function
->assertSee('Environment settings', false)
->assertSee($editUrl, false);
});
+
+test('empty environment resources page header links to the canvas', function () {
+ $canvasUrl = route('project.environment.canvas', [
+ 'project_uuid' => $this->project->uuid,
+ 'environment_uuid' => $this->environment->uuid,
+ ]);
+
+ $this->get(route('project.resource.index', [
+ 'project_uuid' => $this->project->uuid,
+ 'environment_uuid' => $this->environment->uuid,
+ ]))
+ ->assertSuccessful()
+ ->assertSee('No resources yet')
+ ->assertSee($canvasUrl, false);
+});
diff --git a/tests/Feature/ProjectCanvasTest.php b/tests/Feature/ProjectCanvasTest.php
index fa9b792967..d198517f46 100644
--- a/tests/Feature/ProjectCanvasTest.php
+++ b/tests/Feature/ProjectCanvasTest.php
@@ -74,6 +74,7 @@ test('the project canvas shows the resources of every environment, grouped by en
->assertJsonPath('title', 'Shop')
->assertJsonPath('can_edit', true)
->assertJsonPath('can_move', false)
+ ->assertJsonPath('can_move_groups', true)
->assertJsonPath('layout', 'server')
->assertJsonPath('links.0.id', $link->uuid)
// Auto-placed: a position saved on one environment canvas does not fit next to the other environments.
@@ -100,7 +101,14 @@ test('members see the project canvases but cannot edit them', function () {
projectCanvasSession($this, $member, $this->team)
->getJson('/canvas/api/projects/canvas')
->assertOk()
- ->assertJsonPath('can_edit', false);
+ ->assertJsonPath('can_edit', false)
+ ->assertJsonPath('can_move_groups', false);
+ projectCanvasSession($this, $member, $this->team)
+ ->getJson("/canvas/api/projects/{$this->project->uuid}/canvas")
+ ->assertJsonPath('can_move_groups', false);
+ projectCanvasSession($this, $this->admin, $this->team)
+ ->getJson('/canvas/api/projects/canvas')
+ ->assertJsonPath('can_move_groups', true);
});
test('the project canvas is out of reach from another team', function () {
@@ -161,11 +169,63 @@ test('the projects canvas shows every project of the team as a zone, grouped by
expect(collect($response->json('zones'))->pluck('name')->all())->toBe(['Blog', 'Shop'])
->and(collect($response->json('nodes'))->mapWithKeys(fn ($node) => [$node['name'] => [$node['zone'], $node['context']]])->sortKeys()->all())->toBe([
+ 'No resources yet' => [$this->project->uuid, 'production'],
'storefront' => [$this->project->uuid, 'staging'],
'wordpress' => [$blog->uuid, 'production'],
]);
});
+test('the project canvases show empty environments and projects as placeholder cards', function () {
+ projectCanvasApp($this->staging, $this->server, 'storefront');
+ $bare = Project::factory()->create(['team_id' => $this->team->id, 'name' => 'Bare']);
+ $bare->environments()->delete();
+
+ $project = projectCanvasSession($this, $this->admin, $this->team)
+ ->getJson("/canvas/api/projects/{$this->project->uuid}/canvas")
+ ->assertOk();
+ $placeholder = collect($project->json('nodes'))->firstWhere('type', 'empty');
+
+ // Next to the other environments: on the server of the project's resources.
+ expect(collect($project->json('zones'))->pluck('name')->all())->toBe(['web-server'])
+ ->and($placeholder)->toMatchArray([
+ 'id' => "empty:{$this->production->uuid}",
+ 'zone' => $this->server->uuid,
+ 'context' => 'production',
+ // Admins add the first resource on the deploy canvas, with the environment chosen.
+ 'link' => route('deploy-canvas', ['project' => $this->project->uuid, 'environment' => $this->production->uuid]),
+ 'context_link' => route('project.resource.index', ['project_uuid' => $this->project->uuid, 'environment_uuid' => $this->production->uuid]),
+ 'environment' => ['uuid' => $this->production->uuid, 'name' => 'production'],
+ ]);
+
+ // Members cannot add resources: the card opens the environment page.
+ $member = User::factory()->create();
+ $this->team->members()->attach($member->id, ['role' => 'member']);
+ $memberView = projectCanvasSession($this, $member, $this->team)
+ ->getJson("/canvas/api/projects/{$this->project->uuid}/canvas")
+ ->assertOk();
+ expect(collect($memberView->json('nodes'))->firstWhere('type', 'empty')['link'])
+ ->toBe(route('project.resource.index', ['project_uuid' => $this->project->uuid, 'environment_uuid' => $this->production->uuid]));
+
+ // A project without resources has no server: its environments get their own zone.
+ $alone = projectCanvasSession($this, $this->admin, $this->team)
+ ->getJson("/canvas/api/projects/{$bare->uuid}/canvas")
+ ->assertOk();
+ expect(collect($alone->json('zones'))->pluck('name')->all())->toBe(['Empty environments'])
+ ->and($alone->json('nodes.0.name'))->toBe('No environments yet');
+
+ $team = projectCanvasSession($this, $this->admin, $this->team)
+ ->getJson('/canvas/api/projects/canvas')
+ ->assertOk();
+
+ // A project without environments gets one placeholder in its zone.
+ expect(collect($team->json('nodes'))->firstWhere('zone', $bare->uuid))->toMatchArray([
+ 'type' => 'empty',
+ 'name' => 'No environments yet',
+ 'link' => route('project.show', ['project_uuid' => $bare->uuid]),
+ 'environment' => null,
+ ]);
+});
+
test('the projects page reopens the canvas when the user left it on the canvas view', function () {
projectCanvasSession($this, $this->admin, $this->team)
->get(route('project.canvas.index'))
diff --git a/tests/Feature/ResourceMenuInMainNavTest.php b/tests/Feature/ResourceMenuInMainNavTest.php
index 65413b8c45..7776e99551 100644
--- a/tests/Feature/ResourceMenuInMainNavTest.php
+++ b/tests/Feature/ResourceMenuInMainNavTest.php
@@ -5,6 +5,7 @@ use App\Models\Environment;
use App\Models\InstanceSettings;
use App\Models\Project;
use App\Models\S3Storage;
+use App\Models\ScheduledDatabaseBackup;
use App\Models\Server;
use App\Models\StandaloneDocker;
use App\Models\StandalonePostgresql;
@@ -53,18 +54,19 @@ test('an application page teleports its menu into the main sidebar ', function (
$html = $response->getContent();
expect($html)
- ->toContain('id="main-nav-context"')
- ->toContain('x-teleport="#main-nav-context"')
+ ->toContain('id="main-nav-context-0"')
+ ->toContain('x-teleport="#main-nav-context-0"')
->toContain('application-settings-navigation in-main-nav')
- ->toMatch('#href="'.preg_quote(route('dashboard'), '#').'"[^>]*title="Back to the dashboard"#')
- ->and(substr_count($html, 'id="main-nav-context"'))->toBe(1);
+ ->toMatch('#<button type="button" @click="navLevel = -1; navSwap = \'back\'"\s+title="Back to the main menu"#')
+ ->not->toContain('id="main-nav-context-1"')
+ ->and(substr_count($html, 'id="main-nav-context-0"'))->toBe(1);
});
test('pages without a resource menu keep the main menu on wide screens', function () {
$response = $this->get(route('project.resource.index', ['project_uuid' => $this->project->uuid, 'environment_uuid' => $this->environment->uuid]));
$response->assertSuccessful();
- expect($response->getContent())->not->toContain('id="main-nav-context"');
+ expect($response->getContent())->not->toContain('id="main-nav-context-');
});
test('a database page teleports its menu into the main sidebar', function () {
@@ -81,38 +83,66 @@ test('a database page teleports its menu into the main sidebar', function () {
]))->assertSuccessful()->getContent();
expect($html)
- ->toContain('id="main-nav-context"')
- ->toContain('x-teleport="#main-nav-context"')
+ ->toContain('id="main-nav-context-0"')
+ ->toContain('x-teleport="#main-nav-context-0"')
->toContain('application-settings-navigation in-main-nav');
});
-test('a server page teleports its menu into the main sidebar with a back row to the servers', function () {
+test('a server page teleports its menu into the main sidebar with a back row to the main menu', function () {
$html = $this->get(route('server.show', ['server_uuid' => $this->server->uuid]))
->assertSuccessful()
->getContent();
expect($html)
- ->toContain('x-teleport="#main-nav-context"')
+ ->toContain('x-teleport="#main-nav-context-0"')
->toContain('application-settings-navigation in-main-nav')
- ->toMatch('#href="'.preg_quote(route('server.index'), '#').'"[^>]*title="Back to the servers"#')
+ ->toMatch('#@click="navLevel = -1; navSwap = \'back\'"\s+title="Back to the main menu"#')
->and(substr_count($html, 'proxyConfigurationPending: '))->toBe(2);
});
-test('integration detail pages teleport their menu with a back row to their list', function () {
+test('integration detail pages teleport their menu with a back row to the integrations submenu', function () {
$storage = S3Storage::create([
'name' => 'backup-bucket', 'region' => 'us-east-1', 'key' => 'access-key', 'secret' => 'secret-key',
'bucket' => 'coolify-backups', 'endpoint' => 'https://s3.example.com', 'team_id' => $this->team->id, 'is_usable' => true,
]);
$pages = [
- [route('storage.show', ['storage_uuid' => $storage->uuid]), route('storage.index'), 'Back to the S3 storages'],
- [route('destination.show', ['destination_uuid' => $this->destination->uuid]), route('destination.index'), 'Back to the destinations'],
+ route('storage.show', ['storage_uuid' => $storage->uuid]),
+ route('destination.show', ['destination_uuid' => $this->destination->uuid]),
];
- foreach ($pages as [$url, $backHref, $backTitle]) {
+ foreach ($pages as $url) {
expect($this->get($url)->assertSuccessful()->getContent())
- ->toContain('x-teleport="#main-nav-context"')
+ ->toContain('x-teleport="#main-nav-context-0"')
->toContain('application-settings-navigation in-main-nav')
- ->toMatch('#href="'.preg_quote($backHref, '#').'"[^>]*title="'.$backTitle.'"#');
+ ->toMatch('#@click="navLevel = -1; navSwap = \'back\'"\s+title="Back to Integrations"#')
+ ->toContain('data-active-submenu="Integrations"');
}
});
+
+test('a database backup page keeps the database menu one back away in the main sidebar', function () {
+ $database = StandalonePostgresql::create([
+ 'name' => 'orders-db', 'postgres_user' => 'postgres', 'postgres_password' => 'password', 'postgres_db' => 'db',
+ 'image' => 'postgres:17', 'environment_id' => $this->environment->id,
+ 'destination_id' => $this->destination->id, 'destination_type' => $this->destination->getMorphClass(),
+ ]);
+ $backup = ScheduledDatabaseBackup::create([
+ 'frequency' => '0 0 * * *', 'save_s3' => false, 'database_id' => $database->id,
+ 'database_type' => $database->getMorphClass(), 'team_id' => $this->team->id,
+ ]);
+
+ $html = $this->get(route('project.database.backup.execution', [
+ 'project_uuid' => $this->project->uuid,
+ 'environment_uuid' => $this->environment->uuid,
+ 'database_uuid' => $database->uuid,
+ 'backup_uuid' => $backup->uuid,
+ ]))->assertSuccessful()->getContent();
+
+ expect($html)
+ ->toContain('x-teleport="#main-nav-context-0"')
+ ->toContain('x-teleport="#main-nav-context-1"')
+ ->toMatch('#@click="navLevel = -1; navSwap = \'back\'"\s+title="Back to the main menu"#')
+ ->toMatch('#@click="navLevel = 0; navSwap = \'back\'"\s+title="Back to the database menu"#')
+ ->and(substr_count($html, 'aria-label="Database settings"'))->toBe(1)
+ ->and(substr_count($html, 'aria-label="Backup settings"'))->toBe(2);
+});
diff --git a/tests/Feature/ServerCanvasTest.php b/tests/Feature/ServerCanvasTest.php
index 71ed3d6240..cf8bd8878e 100644
--- a/tests/Feature/ServerCanvasTest.php
+++ b/tests/Feature/ServerCanvasTest.php
@@ -74,14 +74,18 @@ test('the servers canvas shows every server of the team with its resources and l
->assertJsonPath('positions', [])
->assertJsonPath('links.0.id', $link->uuid);
+ $resources = collect($response->json('nodes'))->where('type', '!=', 'empty');
+
+ // The project's empty production environment shows as a placeholder card on the server of its other environments.
expect(collect($response->json('zones'))->pluck('name')->all())->toBe(['db-server', 'web-server'])
->and(collect($response->json('nodes'))->mapWithKeys(fn ($node) => [$node['name'] => [$node['zone'], $node['context']]])->all())->toBe([
'storefront' => [$this->web->uuid, 'Shop / staging'],
'orders-api' => [$this->db->uuid, 'Shop / staging'],
+ 'No resources yet' => [$this->web->uuid, 'Shop / production'],
])
->and($response->json('nodes.0.project'))->toBe(['uuid' => $this->project->uuid, 'name' => 'Shop'])
->and($response->json('nodes.0.environment'))->toBe(['uuid' => $this->environment->uuid, 'name' => 'staging'])
- ->and(collect($response->json('nodes'))->pluck('context_link')->unique()->all())->toBe([
+ ->and($resources->pluck('context_link')->unique()->all())->toBe([
route('project.resource.index', ['project_uuid' => $this->project->uuid, 'environment_uuid' => $this->environment->uuid]),
])
->and(collect($response->json('zones'))->pluck('link')->all())->toBe([
@@ -90,6 +94,17 @@ test('the servers canvas shows every server of the team with its resources and l
]);
});
+test('the servers canvas puts empty environments of a project without resources on the first server', function () {
+ $bare = Project::factory()->create(['team_id' => $this->team->id, 'name' => 'Bare']);
+
+ $response = serverCanvasSession($this, $this->admin, $this->team)
+ ->getJson('/canvas/api/servers/canvas')
+ ->assertOk();
+
+ expect(collect($response->json('zones'))->pluck('name')->all())->toBe(['db-server', 'web-server'])
+ ->and(collect($response->json('nodes'))->where('project.uuid', $bare->uuid)->pluck('zone')->all())->toBe([$this->db->uuid]);
+});
+
test('one server canvas shows only that server, and links that leave it are hidden', function () {
$app = serverCanvasApp($this->environment, $this->web, 'storefront');
$api = serverCanvasApp($this->environment, $this->db, 'orders-api');
diff --git a/tests/Feature/SharedVariableCanvasTest.php b/tests/Feature/SharedVariableCanvasTest.php
index 98b15c266a..92b3db0f6c 100644
--- a/tests/Feature/SharedVariableCanvasTest.php
+++ b/tests/Feature/SharedVariableCanvasTest.php
@@ -218,6 +218,20 @@ test('a server canvas only shows resources on that server', function () {
expect(collect($response->json('nodes'))->where('type', '!=', 'variable')->pluck('name')->all())->toBe(['storefront']);
});
+test('the server canvas hides the built-in server variables and the references to them', function () {
+ $this->server->environment_variables()->create(['key' => 'REGION', 'value' => 'eu', 'team_id' => $this->team->id]);
+ sharedVariableCanvasEnv($this->storefront, 'HOST', '{{server.COOLIFY_SERVER_NAME}}');
+ sharedVariableCanvasEnv($this->storefront, 'REGION', '{{server.REGION}}');
+
+ $response = sharedVariableCanvasAs($this, $this->admin, $this->team)
+ ->getJson("/canvas/api/shared-variables/server/{$this->server->uuid}/canvas")
+ ->assertOk();
+
+ // Coolify creates COOLIFY_SERVER_UUID / COOLIFY_SERVER_NAME on every server; they are not shown, not even as deleted.
+ expect(collect($response->json('nodes'))->where('type', 'variable')->pluck('name')->all())->toBe(['REGION'])
+ ->and(collect($response->json('links'))->pluck('key')->all())->toBe(['REGION']);
+});
+
test('another team cannot open or change the canvas of a scope it does not own', function () {
$otherTeam = Team::factory()->create(['show_boarding' => false]);
$otherTeam->members()->attach($this->admin->id, ['role' => 'owner']);