mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 15:02:34 +00:00
#591 - node
This commit is contained in:
77
resources/js/pages/node/components/columns.tsx
Normal file
77
resources/js/pages/node/components/columns.tsx
Normal file
@ -0,0 +1,77 @@
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuSeparator, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { MoreVerticalIcon } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { Service } from '@/types/service';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import DateTime from '@/components/date-time';
|
||||
import Uninstall from '@/pages/services/components/uninstall';
|
||||
import { Action } from '@/pages/services/components/action';
|
||||
import DefaultCli from '@/pages/node/components/default-cli';
|
||||
|
||||
export const columns: ColumnDef<Service>[] = [
|
||||
{
|
||||
accessorKey: 'version',
|
||||
header: 'Version',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: 'created_at',
|
||||
header: 'Installed at',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return <DateTime date={row.original.created_at} />;
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'is_default',
|
||||
header: 'Default cli',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return <Badge variant={row.original.is_default ? 'default' : 'outline'}>{row.original.is_default ? 'Yes' : 'No'}</Badge>;
|
||||
},
|
||||
},
|
||||
{
|
||||
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">
|
||||
<DefaultCli service={row.original} />
|
||||
<DropdownMenuSeparator />
|
||||
<Action type="start" service={row.original} />
|
||||
<Action type="stop" service={row.original} />
|
||||
<Action type="restart" service={row.original} />
|
||||
<Action type="enable" service={row.original} />
|
||||
<Action type="disable" service={row.original} />
|
||||
<DropdownMenuSeparator />
|
||||
<Uninstall service={row.original} />
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
64
resources/js/pages/node/components/default-cli.tsx
Normal file
64
resources/js/pages/node/components/default-cli.tsx
Normal file
@ -0,0 +1,64 @@
|
||||
import { Service } from '@/types/service';
|
||||
import React, { FormEvent, useState } from 'react';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { DropdownMenuItem } from '@/components/ui/dropdown-menu';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { LoaderCircleIcon } from 'lucide-react';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
|
||||
export default function DefaultCli({ service }: { service: Service }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm<{
|
||||
version: string;
|
||||
}>({
|
||||
version: service.version,
|
||||
});
|
||||
|
||||
const submit = (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
form.post(route('node.default-cli', { server: service.server_id, service: service.id }), {
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<DropdownMenuItem disabled={service.is_default} onSelect={(e) => e.preventDefault()}>
|
||||
Make default cli
|
||||
</DropdownMenuItem>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Make default cli</DialogTitle>
|
||||
<DialogDescription className="sr-only">Make default cli</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-2 p-4">
|
||||
<p>Are you sure you want to make Nodejs {form.data.version} the default cli?</p>
|
||||
<InputError message={form.errors.version} />
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button form="install-extension-form" disabled={form.processing} onClick={submit} className="ml-2">
|
||||
{form.processing && <LoaderCircleIcon className="animate-spin" />}
|
||||
Save
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user