mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 06:56:15 +00:00
#591 - sites
This commit is contained in:
118
resources/js/pages/commands/components/columns.tsx
Normal file
118
resources/js/pages/commands/components/columns.tsx
Normal file
@ -0,0 +1,118 @@
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Link, useForm } from '@inertiajs/react';
|
||||
import { LoaderCircleIcon, MoreVerticalIcon, PlayIcon } from 'lucide-react';
|
||||
import FormSuccessful from '@/components/form-successful';
|
||||
import { useState } from 'react';
|
||||
import { Command } from '@/types/command';
|
||||
import EditCommand from '@/pages/commands/components/edit-command';
|
||||
import CopyableBadge from '@/components/copyable-badge';
|
||||
import Execute from '@/pages/commands/components/execute';
|
||||
|
||||
function Delete({ command }: { command: Command }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm();
|
||||
|
||||
const submit = () => {
|
||||
form.delete(route('commands.destroy', { server: command.server_id, site: command.site_id, command: command.id }), {
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<DropdownMenuItem variant="destructive" onSelect={(e) => e.preventDefault()}>
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Delete command</DialogTitle>
|
||||
<DialogDescription className="sr-only">Delete command</DialogDescription>
|
||||
</DialogHeader>
|
||||
<p className="p-4">Are you sure you want to this command?</p>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button variant="destructive" disabled={form.processing} onClick={submit}>
|
||||
{form.processing && <LoaderCircleIcon className="animate-spin" />}
|
||||
<FormSuccessful successful={form.recentlySuccessful} />
|
||||
Delete
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export const columns: ColumnDef<Command>[] = [
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: 'Name',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: 'command',
|
||||
header: 'Command',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return <CopyableBadge text={row.original.command} />;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
enableColumnFilter: false,
|
||||
enableSorting: false,
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<Execute command={row.original}>
|
||||
<Button variant="outline" className="size-8">
|
||||
<PlayIcon className="size-3" />
|
||||
</Button>
|
||||
</Execute>
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreVerticalIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<EditCommand command={row.original}>
|
||||
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>Edit</DropdownMenuItem>
|
||||
</EditCommand>
|
||||
<Link
|
||||
href={route('commands.show', {
|
||||
server: row.original.server_id,
|
||||
site: row.original.site_id,
|
||||
command: row.original.id,
|
||||
})}
|
||||
>
|
||||
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>Executions</DropdownMenuItem>
|
||||
</Link>
|
||||
<DropdownMenuSeparator />
|
||||
<Delete command={row.original} />
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
87
resources/js/pages/commands/components/create-command.tsx
Normal file
87
resources/js/pages/commands/components/create-command.tsx
Normal file
@ -0,0 +1,87 @@
|
||||
import { Server } from '@/types/server';
|
||||
import React, { FormEvent, ReactNode, useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { useForm, usePage } from '@inertiajs/react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { LoaderCircle } from 'lucide-react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Site } from '@/types/site';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
|
||||
export default function CreateCommand({ children }: { children: ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const page = usePage<{
|
||||
server: Server;
|
||||
site: Site;
|
||||
}>();
|
||||
|
||||
const form = useForm<{
|
||||
name: string;
|
||||
command: string;
|
||||
}>({
|
||||
name: '',
|
||||
command: '',
|
||||
});
|
||||
|
||||
const submit = (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
form.post(route('commands.store', { server: page.props.server.id, site: page.props.site.id }), {
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>{children}</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Create command</DialogTitle>
|
||||
<DialogDescription className="sr-only">Create a new command</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form id="create-command-form" onSubmit={submit} className="p-4">
|
||||
<FormFields>
|
||||
<FormField>
|
||||
<Label htmlFor="name">Name</Label>
|
||||
<Input id="name" name="name" value={form.data.name} onChange={(e) => form.setData('name', e.target.value)} />
|
||||
<InputError message={form.errors.name} />
|
||||
</FormField>
|
||||
|
||||
<FormField>
|
||||
<Label htmlFor="command">Command</Label>
|
||||
<Textarea id="command" name="command" value={form.data.command} onChange={(e) => form.setData('command', e.target.value)} />
|
||||
<p className="text-muted-foreground text-sm">
|
||||
You can use variables like {'${VARIABLE_NAME}'} in the command. The variables will be asked when executing the command
|
||||
</p>
|
||||
<InputError message={form.errors.command} />
|
||||
</FormField>
|
||||
</FormFields>
|
||||
</Form>
|
||||
<DialogFooter>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button form="create-command-form" type="button" onClick={submit} disabled={form.processing}>
|
||||
{form.processing && <LoaderCircle className="animate-spin" />}
|
||||
Create
|
||||
</Button>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">Cancel</Button>
|
||||
</DialogClose>
|
||||
</div>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
81
resources/js/pages/commands/components/edit-command.tsx
Normal file
81
resources/js/pages/commands/components/edit-command.tsx
Normal file
@ -0,0 +1,81 @@
|
||||
import React, { FormEvent, ReactNode, useState } from 'react';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { LoaderCircle } from 'lucide-react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Command } from '@/types/command';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
|
||||
export default function EditCommand({ command, children }: { command: Command; children: ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const form = useForm<{
|
||||
name: string;
|
||||
command: string;
|
||||
}>({
|
||||
name: command.name,
|
||||
command: command.command,
|
||||
});
|
||||
|
||||
const submit = (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
form.put(route('commands.update', { server: command.server_id, site: command.site_id, command: command.id }), {
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>{children}</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Edit command</DialogTitle>
|
||||
<DialogDescription className="sr-only">Create a new command</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form id="create-command-form" onSubmit={submit} className="p-4">
|
||||
<FormFields>
|
||||
<FormField>
|
||||
<Label htmlFor="name">Name</Label>
|
||||
<Input id="name" name="name" value={form.data.name} onChange={(e) => form.setData('name', e.target.value)} />
|
||||
<InputError message={form.errors.name} />
|
||||
</FormField>
|
||||
<FormField>
|
||||
<Label htmlFor="command">Command</Label>
|
||||
<Textarea id="command" name="command" value={form.data.command} onChange={(e) => form.setData('command', e.target.value)} />
|
||||
<p className="text-muted-foreground text-sm">
|
||||
You can use variables like {'${VARIABLE_NAME}'} in the command. The variables will be asked when executing the command
|
||||
</p>
|
||||
<InputError message={form.errors.command} />
|
||||
</FormField>
|
||||
</FormFields>
|
||||
</Form>
|
||||
<DialogFooter>
|
||||
<div className="flex items-center gap-2">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button form="create-command-form" type="button" onClick={submit} disabled={form.processing}>
|
||||
{form.processing && <LoaderCircle className="animate-spin" />}
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
69
resources/js/pages/commands/components/execute.tsx
Normal file
69
resources/js/pages/commands/components/execute.tsx
Normal file
@ -0,0 +1,69 @@
|
||||
import React, { ReactNode, useState } from 'react';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { LoaderCircleIcon } from 'lucide-react';
|
||||
import FormSuccessful from '@/components/form-successful';
|
||||
import { Command } from '@/types/command';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
|
||||
export default function Execute({ command, children }: { command: Command; children: ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm<Record<string, string>>({});
|
||||
|
||||
const submit = () => {
|
||||
form.post(route('commands.execute', { server: command.server_id, site: command.site_id, command: command.id }), {
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>{children}</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Execute</DialogTitle>
|
||||
<DialogDescription className="sr-only">Execute command</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-2 p-4">
|
||||
<p>Are you sure you want to run this command?</p>
|
||||
<Form id="execute-command-form" onSubmit={submit}>
|
||||
<FormFields>
|
||||
{command.variables.map((variable: string) => (
|
||||
<FormField key={`variable-${variable}`}>
|
||||
<Label htmlFor={variable}>{variable}</Label>
|
||||
<Input id={variable} name={variable} value={form.data[variable] || ''} onChange={(e) => form.setData(variable, e.target.value)} />
|
||||
<InputError message={form.errors[variable as keyof typeof form.errors]} />
|
||||
</FormField>
|
||||
))}
|
||||
</FormFields>
|
||||
</Form>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button disabled={form.processing} onClick={submit}>
|
||||
{form.processing && <LoaderCircleIcon className="animate-spin" />}
|
||||
<FormSuccessful successful={form.recentlySuccessful} />
|
||||
Execute
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
53
resources/js/pages/commands/components/execution-columns.tsx
Normal file
53
resources/js/pages/commands/components/execution-columns.tsx
Normal file
@ -0,0 +1,53 @@
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { MoreVerticalIcon } from 'lucide-react';
|
||||
import DateTime from '@/components/date-time';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { CommandExecution } from '@/types/command-execution';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Download, View } from '@/pages/server-logs/components/columns';
|
||||
|
||||
export const columns: ColumnDef<CommandExecution>[] = [
|
||||
{
|
||||
accessorKey: 'created_at',
|
||||
header: 'Deployed At',
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return <DateTime date={row.original.created_at} />;
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'status',
|
||||
header: 'Status',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return <Badge variant={row.original.status_color}>{row.original.status}</Badge>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
enableColumnFilter: false,
|
||||
enableSorting: false,
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<div className="flex items-center justify-end">
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreVerticalIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<View serverLog={row.original.log} />
|
||||
<Download serverLog={row.original.log}>
|
||||
<DropdownMenuItem>Download</DropdownMenuItem>
|
||||
</Download>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
44
resources/js/pages/commands/index.tsx
Normal file
44
resources/js/pages/commands/index.tsx
Normal file
@ -0,0 +1,44 @@
|
||||
import { Head, usePage } from '@inertiajs/react';
|
||||
import { Server } from '@/types/server';
|
||||
import Container from '@/components/container';
|
||||
import HeaderContainer from '@/components/header-container';
|
||||
import Heading from '@/components/heading';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import ServerLayout from '@/layouts/server/layout';
|
||||
import { PlusIcon } from 'lucide-react';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { columns } from '@/pages/commands/components/columns';
|
||||
import CreateCommand from '@/pages/commands/components/create-command';
|
||||
import { PaginatedData } from '@/types';
|
||||
import { Command } from '@/types/command';
|
||||
import { Site } from '@/types/site';
|
||||
|
||||
export default function Commands() {
|
||||
const page = usePage<{
|
||||
server: Server;
|
||||
site: Site;
|
||||
commands: PaginatedData<Command>;
|
||||
}>();
|
||||
|
||||
return (
|
||||
<ServerLayout>
|
||||
<Head title={`Commands - ${page.props.site.domain} - ${page.props.server.name}`} />
|
||||
|
||||
<Container className="max-w-5xl">
|
||||
<HeaderContainer>
|
||||
<Heading title="Commands" description="These are the commands that you can run on your site's location" />
|
||||
<div className="flex items-center gap-2">
|
||||
<CreateCommand>
|
||||
<Button>
|
||||
<PlusIcon />
|
||||
<span className="hidden lg:block">Create</span>
|
||||
</Button>
|
||||
</CreateCommand>
|
||||
</div>
|
||||
</HeaderContainer>
|
||||
|
||||
<DataTable columns={columns} paginatedData={page.props.commands} />
|
||||
</Container>
|
||||
</ServerLayout>
|
||||
);
|
||||
}
|
35
resources/js/pages/commands/show.tsx
Normal file
35
resources/js/pages/commands/show.tsx
Normal file
@ -0,0 +1,35 @@
|
||||
import { Head, usePage } from '@inertiajs/react';
|
||||
import { Server } from '@/types/server';
|
||||
import Container from '@/components/container';
|
||||
import HeaderContainer from '@/components/header-container';
|
||||
import Heading from '@/components/heading';
|
||||
import ServerLayout from '@/layouts/server/layout';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { PaginatedData } from '@/types';
|
||||
import { columns } from '@/pages/commands/components/execution-columns';
|
||||
import { Site } from '@/types/site';
|
||||
import { CommandExecution } from '@/types/command-execution';
|
||||
|
||||
type Page = {
|
||||
server: Server;
|
||||
site: Site;
|
||||
executions: PaginatedData<CommandExecution>;
|
||||
};
|
||||
|
||||
export default function Show() {
|
||||
const page = usePage<Page>();
|
||||
|
||||
return (
|
||||
<ServerLayout>
|
||||
<Head title={`Executions - ${page.props.site.domain} - ${page.props.server.name}`} />
|
||||
|
||||
<Container className="max-w-5xl">
|
||||
<HeaderContainer>
|
||||
<Heading title={`Command executions`} description="Here you can see the command executions" />
|
||||
</HeaderContainer>
|
||||
|
||||
<DataTable columns={columns} paginatedData={page.props.executions} />
|
||||
</Container>
|
||||
</ServerLayout>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user