Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions app/(main)/[owner]/[repo]/[branch]/actions/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"use client";

import { ActionsPage } from "@/components/actions/actions-page";
import { DocumentTitle, formatRepoBranchTitle } from "@/components/document-title";
import { useConfig } from "@/contexts/config-context";
import { useUser } from "@/contexts/user-context";
import { hasGithubIdentity } from "@/lib/authz";
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { getRootActions, getSchemaActions } from "@/lib/repo-actions";

export default function Page() {
const { config } = useConfig();
const { user } = useUser();

if (!config) throw new Error("Configuration not found.");

if (!hasGithubIdentity(user)) {
return (
<Empty className="absolute inset-0 border-0 rounded-none">
<EmptyHeader>
<EmptyTitle>Access denied</EmptyTitle>
<EmptyDescription>Only GitHub users can view action history.</EmptyDescription>
</EmptyHeader>
</Empty>
);
}

const actionLabels = {
...Object.fromEntries(getRootActions(config.object).map((action) => [action.name, action.label])),
...Object.fromEntries(
((config.object as any).content ?? []).flatMap((item: any) =>
getSchemaActions(item).concat(getSchemaActions(item, "collection"), getSchemaActions(item, "entry"))
.map((action) => [action.name, action.label] as const),
),
),
...Object.fromEntries(
((config.object as any).media ?? []).flatMap((item: any) =>
((item.actions ?? []) as Array<{ name: string; label: string }>).map((action) => [action.name, action.label] as const),
),
),
};

const contextLabels = {
...Object.fromEntries(
((config.object as any).content ?? []).flatMap((item: any) => {
const label = item.label || item.name;
if (item.type === "collection") {
return [
[`collection:${item.name}`, label] as const,
[`entry:${item.name}`, label] as const,
];
}

return [[`file:${item.name}`, label] as const];
}),
),
...Object.fromEntries(
((config.object as any).media ?? []).map((item: any) => [
`media:${item.name}`,
item.label || item.name,
]),
),
};

return (
<>
<DocumentTitle
title={formatRepoBranchTitle("Actions", config.owner, config.repo, config.branch)}
/>
<div className="flex w-full flex-1 flex-col">
<ActionsPage
owner={config.owner}
repo={config.repo}
branch={config.branch}
actionLabels={actionLabels}
contextLabels={contextLabels}
/>
</div>
</>
);
}
4 changes: 2 additions & 2 deletions app/(main)/[owner]/[repo]/[branch]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default async function Layout({
<EmptyDescription>{`The branch "${decodedBranch}" could not be found. It may have been removed or renamed.`}</EmptyDescription>
</EmptyHeader>
<EmptyContent>
<Link className={buttonVariants({ variant: "default", size: "sm" })} href={`/${owner}/${repo}`}>
<Link className={buttonVariants({ variant: "default" })} href={`/${owner}/${repo}`}>
Open default branch
</Link>
</EmptyContent>
Expand All @@ -82,7 +82,7 @@ export default async function Layout({
<EmptyDescription>You do not have permission to access this repository.</EmptyDescription>
</EmptyHeader>
<EmptyContent>
<Link className={buttonVariants({ variant: "default", size: "sm" })} href="/">
<Link className={buttonVariants({ variant: "default" })} href="/">
Choose another repository
</Link>
</EmptyContent>
Expand Down
2 changes: 1 addition & 1 deletion app/(main)/[owner]/[repo]/[branch]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function Page() {
</EmptyHeader>
<EmptyContent>
<Link
className={buttonVariants({ variant: "default", size: "sm" })}
className={buttonVariants({ variant: "default" })}
href={`https://github.com/${config?.owner}/${config?.repo}/edit/${encodeURIComponent(config!.branch)}/.pages.yml`}
>
Edit configuration on GitHub
Expand Down
6 changes: 3 additions & 3 deletions app/(main)/[owner]/[repo]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default async function Layout({
<EmptyDescription>Create a branch and add a &quot;.pages.yml&quot; file to configure this repository.</EmptyDescription>
</EmptyHeader>
<EmptyContent>
<Link className={buttonVariants({ variant: "default", size: "sm" })} href="/">
<Link className={buttonVariants({ variant: "default" })} href="/">
Choose another repository
</Link>
</EmptyContent>
Expand Down Expand Up @@ -71,7 +71,7 @@ export default async function Layout({
<EmptyDescription>It may have been removed, renamed, or the URL may be incorrect.</EmptyDescription>
</EmptyHeader>
<EmptyContent>
<Link className={buttonVariants({ variant: "default", size: "sm" })} href="/">
<Link className={buttonVariants({ variant: "default" })} href="/">
Choose another repository
</Link>
</EmptyContent>
Expand All @@ -85,7 +85,7 @@ export default async function Layout({
<EmptyDescription>You do not have permission to access this repository.</EmptyDescription>
</EmptyHeader>
<EmptyContent>
<Link className={buttonVariants({ variant: "default", size: "sm" })} href="/">
<Link className={buttonVariants({ variant: "default" })} href="/">
Choose another repository
</Link>
</EmptyContent>
Expand Down
8 changes: 1 addition & 7 deletions app/(main)/[owner]/[repo]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useRepo } from "@/contexts/repo-context";
import { useUser } from "@/contexts/user-context";

export default function Page() {
const { owner, repo, defaultBranch } = useRepo();
const router = useRouter();
const { user } = useUser();

if (!user) throw new Error("User not found");
if (!user.accounts) throw new Error("Accounts not found");
if (!user.accounts.find((account) => account.login.toLowerCase() === owner.toLowerCase())) throw new Error(`GitHub application not installed for "${owner}"`);

useEffect(() => {
// If no branch is provided, redirect to the default branch
router.replace(`/${owner}/${repo}/${encodeURIComponent(defaultBranch as string)}`);
}, [owner, repo, defaultBranch, router]);

return null;
};
};
2 changes: 1 addition & 1 deletion app/(main)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function Page() {
</EmptyHeader>
<EmptyContent>
<form action={handleAppInstall}>
<SubmitButton type="submit" size="sm">
<SubmitButton type="submit">
<svg
role="img"
viewBox="0 0 24 24"
Expand Down
Loading