Skip to content
Open
31 changes: 5 additions & 26 deletions web-admin/src/features/edit-session/EditButton.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<script lang="ts">
import { goto } from "$app/navigation";
import {
createAdminServiceGetCurrentUser,
V1DeploymentStatus,
} from "@rilldata/web-admin/client";
import {
injectBranchIntoPath,
requestSkipBranchInjection,
Expand All @@ -19,34 +15,17 @@
/** The project's primary branch, used as the source for new branches. */
export let primaryBranch: string | undefined = undefined;

const user = createAdminServiceGetCurrentUser();
const devDeployments = useDevDeployments(organization, project);

let dialogOpen = false;

$: currentUserId = $user.data?.user?.id;
$: deployments = $devDeployments.data?.deployments ?? [];
$: isLoading = $devDeployments.isLoading;

// If viewing a branch the user owns, clicking the button should go straight
// there — no dialog.
$: activeBranchDeployment =
activeBranch && currentUserId
? deployments.find(
(d) =>
d.branch === activeBranch &&
d.ownerUserId === currentUserId &&
d.editable &&
d.status !== V1DeploymentStatus.DEPLOYMENT_STATUS_DELETING &&
d.status !== V1DeploymentStatus.DEPLOYMENT_STATUS_DELETED,
)
: undefined;

$: directEditHref = activeBranchDeployment?.branch
? injectBranchIntoPath(
`/${organization}/${project}/-/edit`,
activeBranchDeployment.branch,
)
// On a branch view, jump straight into edit mode for that branch.
// On production view, fall through to the dialog so the user can pick
// an existing dev branch or create a new one.
$: directEditHref = activeBranch
? injectBranchIntoPath(`/${organization}/${project}/-/edit`, activeBranch)
: undefined;

function handleDirectEdit(e: MouseEvent) {
Expand Down
7 changes: 4 additions & 3 deletions web-admin/src/features/projects/ProjectHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
$: onPublicURLPage = isPublicURLPage($page);

$: activeBranch = extractBranchFromPath($page.url.pathname);
$: isBranchView = !!activeBranch && activeBranch !== primaryBranch;

$: loggedIn = !!$user.data?.user;
$: rillLogoHref = !loggedIn ? "https://www.rilldata.com" : "/";
Expand Down Expand Up @@ -214,7 +215,7 @@
{#if $cloudEditing && onProjectPage && projectPermissions.manageDev}
<EditButton {organization} {project} {activeBranch} {primaryBranch} />
{/if}
{#if onProjectPage && projectPermissions.manageProjectMembers}
{#if onProjectPage && projectPermissions.manageProjectMembers && !isBranchView}
<ShareProjectPopover
{organization}
{project}
Expand Down Expand Up @@ -248,7 +249,7 @@
{#if $dashboardChat && !onPublicURLPage}
<ChatToggle />
{/if}
{#if hasUserAccess}
{#if hasUserAccess && !isBranchView}
<ExploreBookmarks
{organization}
{project}
Expand All @@ -274,7 +275,7 @@
{#if $dashboardChat && !onPublicURLPage}
<ChatToggle />
{/if}
{#if hasUserAccess}
{#if hasUserAccess && !isBranchView}
<CanvasBookmarks {organization} {project} canvasName={dashboard} />
<ShareDashboardPopover
createMagicAuthTokens={projectPermissions.createMagicAuthTokens}
Expand Down
8 changes: 5 additions & 3 deletions web-admin/src/features/projects/ProjectTabs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

const { chat, reports, alerts } = featureFlags;

$: isBranchView = branchPrefix !== "";

$: tabs = [
{
route: `/${organization}/${project}${branchPrefix}`,
Expand All @@ -40,12 +42,12 @@
{
route: `/${organization}/${project}${branchPrefix}/-/reports`,
label: "Reports",
hasPermission: $reports,
hasPermission: $reports && !isBranchView,
},
{
route: `/${organization}/${project}${branchPrefix}/-/alerts`,
label: "Alerts",
hasPermission: $alerts,
hasPermission: $alerts && !isBranchView,
},
{
route: `/${organization}/${project}${branchPrefix}/-/status`,
Expand All @@ -55,7 +57,7 @@
{
route: `/${organization}/${project}${branchPrefix}/-/settings`,
label: "Settings",
hasPermission: projectPermissions.manageProject,
hasPermission: projectPermissions.manageProject && !isBranchView,
},
];

Expand Down
15 changes: 15 additions & 0 deletions web-admin/src/routes/[organization]/[project]/+layout.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import { type RpcStatus } from "@rilldata/web-admin/client";
import { hasBlockerIssues } from "@rilldata/web-admin/features/billing/selectors";
import {
branchPathPrefix,
extractBranchFromPath,
} from "@rilldata/web-admin/features/branches/branch-utils";
import { fetchAllProjectsHibernating } from "@rilldata/web-admin/features/organizations/selectors";
import { error, redirect } from "@sveltejs/kit";
import { isAxiosError } from "axios";
import { maybeRedirectToEditableDeployment } from "@rilldata/web-admin/features/branches/deployment-utils.ts";
import { isEditPage } from "@rilldata/web-admin/features/navigation/nav-utils.ts";

// Sections hidden on branch views; visiting them redirects to the branch home.
const BRANCH_HIDDEN_SECTIONS = /\/-\/(alerts|reports|settings)(\/|$)/;

export const load = async ({
params: { organization, project },
parent,
route,
url,
}) => {
const activeBranch = extractBranchFromPath(url.pathname);
if (activeBranch && BRANCH_HIDDEN_SECTIONS.test(url.pathname)) {
throw redirect(
307,
`/${organization}/${project}${branchPathPrefix(activeBranch)}`,
);
}

const { organizationPermissions, issues } = await parent();

if (!organizationPermissions.manageOrg) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import { page } from "$app/stores";
import ContentContainer from "@rilldata/web-common/components/layout/ContentContainer.svelte";
import LeftNav from "@rilldata/web-admin/components/nav/LeftNav.svelte";
import { extractBranchFromPath } from "@rilldata/web-admin/features/branches/branch-utils";

$: basePage = `/${$page.params.organization}/${$page.params.project}/-/status`;
$: isBranchView = !!extractBranchFromPath($page.url.pathname);

const navItems = [
$: navItems = [
{
label: "Overview",
route: "",
Expand All @@ -16,7 +18,7 @@
{
label: "Branches",
route: "/branches",
hasPermission: true,
hasPermission: !isBranchView,
},
{
label: "Resources",
Expand Down
Loading