mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 06:56:15 +00:00
#591 - tags
This commit is contained in:
@ -71,6 +71,26 @@ @theme {
|
||||
--color-badge-danger-foreground: var(--badge-danger-foreground);
|
||||
--color-badge-gray: var(--badge-gray);
|
||||
--color-badge-gray-foreground: var(--badge-gray-foreground);
|
||||
|
||||
--color-slate: var(--color-slate-500);
|
||||
--color-gray: var(--color-gray-500);
|
||||
--color-red: var(--color-red-500);
|
||||
--color-orange: var(--color-orange-500);
|
||||
--color-amber: var(--color-amber-500);
|
||||
--color-yellow: var(--color-yellow-500);
|
||||
--color-lime: var(--color-lime-500);
|
||||
--color-green: var(--color-green-500);
|
||||
--color-emerald: var(--color-emerald-500);
|
||||
--color-teal: var(--color-teal-500);
|
||||
--color-cyan: var(--color-cyan-500);
|
||||
--color-sky: var(--color-sky-500);
|
||||
--color-blue: var(--color-blue-500);
|
||||
--color-indigo: var(--color-indigo-500);
|
||||
--color-violet: var(--color-violet-500);
|
||||
--color-purple: var(--color-purple-500);
|
||||
--color-fuchsia: var(--color-fuchsia-500);
|
||||
--color-pink: var(--color-pink-500);
|
||||
--color-rose: var(--color-rose-500);
|
||||
}
|
||||
|
||||
/*
|
||||
|
26
resources/js/components/color-select.tsx
Normal file
26
resources/js/components/color-select.tsx
Normal file
@ -0,0 +1,26 @@
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import React from 'react';
|
||||
import { usePage } from '@inertiajs/react';
|
||||
import { SharedData } from '@/types';
|
||||
|
||||
export default function ColorSelect({ onValueChange, ...props }: React.ComponentProps<typeof Select>) {
|
||||
const page = usePage<SharedData>();
|
||||
|
||||
return (
|
||||
<Select {...props} onValueChange={onValueChange}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select a color" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
{page.props.configs.colors.map((value) => (
|
||||
<SelectItem key={`color-${value}`} value={value}>
|
||||
<div className="size-5 rounded-sm" style={{ backgroundColor: `var(--color-${value}-500)` }}></div>
|
||||
{value}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { type BreadcrumbItem, type NavItem } from '@/types';
|
||||
import { BellIcon, CloudIcon, CodeIcon, DatabaseIcon, KeyIcon, ListIcon, UserIcon, UsersIcon } from 'lucide-react';
|
||||
import { BellIcon, CloudIcon, CodeIcon, DatabaseIcon, KeyIcon, ListIcon, TagIcon, UserIcon, UsersIcon } from 'lucide-react';
|
||||
import { ReactNode } from 'react';
|
||||
import Layout from '@/layouts/app/layout';
|
||||
|
||||
@ -44,6 +44,11 @@ const sidebarNavItems: NavItem[] = [
|
||||
href: route('ssh-keys'),
|
||||
icon: KeyIcon,
|
||||
},
|
||||
{
|
||||
title: 'Tags',
|
||||
href: route('tags'),
|
||||
icon: TagIcon,
|
||||
},
|
||||
];
|
||||
|
||||
export default function SettingsLayout({ children, breadcrumbs }: { children: ReactNode; breadcrumbs?: BreadcrumbItem[] }) {
|
||||
|
176
resources/js/pages/tags/components/columns.tsx
Normal file
176
resources/js/pages/tags/components/columns.tsx
Normal file
@ -0,0 +1,176 @@
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import DateTime from '@/components/date-time';
|
||||
import { Tag } from '@/types/tag';
|
||||
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 { useForm } from '@inertiajs/react';
|
||||
import { LoaderCircleIcon, MoreVerticalIcon } from 'lucide-react';
|
||||
import FormSuccessful from '@/components/form-successful';
|
||||
import { FormEvent, useState } from 'react';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import ColorSelect from '@/components/color-select';
|
||||
|
||||
function Edit({ tag }: { tag: Tag }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm({
|
||||
name: tag.name,
|
||||
color: tag.color,
|
||||
});
|
||||
|
||||
const submit = (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
form.patch(route('tags.update', tag.id));
|
||||
};
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>Edit</DropdownMenuItem>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Edit {tag.name}</DialogTitle>
|
||||
<DialogDescription className="sr-only">Edit tag</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form id="edit-tag-form" className="p-4" onSubmit={submit}>
|
||||
<FormFields>
|
||||
<FormField>
|
||||
<Label htmlFor="name">Name</Label>
|
||||
<Input type="text" 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="color">Color</Label>
|
||||
<ColorSelect name="color" value={form.data.color} onValueChange={(value) => form.setData('color', value)} />
|
||||
<InputError message={form.errors.color} />
|
||||
</FormField>
|
||||
</FormFields>
|
||||
</Form>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button form="edit-tag-form" disabled={form.processing} onClick={submit}>
|
||||
{form.processing && <LoaderCircleIcon className="animate-spin" />}
|
||||
<FormSuccessful successful={form.recentlySuccessful} />
|
||||
Save
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function Delete({ tag }: { tag: Tag }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm();
|
||||
|
||||
const submit = () => {
|
||||
form.delete(route('tags.destroy', tag.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 {tag.name}</DialogTitle>
|
||||
<DialogDescription className="sr-only">Delete tag</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-2 p-4">
|
||||
<p>
|
||||
Are you sure you want to delete <strong>{tag.name}</strong>?
|
||||
</p>
|
||||
<InputError message={form.errors.provider} />
|
||||
</div>
|
||||
<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<Tag>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
enableHiding: true,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: 'Name',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
},
|
||||
{
|
||||
accessorKey: 'color',
|
||||
header: 'Color',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return <div className="size-5 rounded-sm" style={{ backgroundColor: `var(--color-${row.original.color}-500)` }}></div>;
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'created_at',
|
||||
header: 'Created at',
|
||||
enableColumnFilter: true,
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => {
|
||||
return <DateTime date={row.original.created_at} />;
|
||||
},
|
||||
},
|
||||
{
|
||||
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">
|
||||
<Edit tag={row.original} />
|
||||
<DropdownMenuSeparator />
|
||||
<Delete tag={row.original} />
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
79
resources/js/pages/tags/components/create-tag.tsx
Normal file
79
resources/js/pages/tags/components/create-tag.tsx
Normal file
@ -0,0 +1,79 @@
|
||||
import { LoaderCircle } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from '@/components/ui/dialog';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { FormEventHandler, ReactNode, useState } from 'react';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import InputError from '@/components/ui/input-error';
|
||||
import { Form, FormField, FormFields } from '@/components/ui/form';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import ColorSelect from '@/components/color-select';
|
||||
|
||||
type TagForm = {
|
||||
name: string;
|
||||
color: string;
|
||||
};
|
||||
|
||||
export default function CreateTag({ children }: { children: ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const form = useForm<Required<TagForm>>({
|
||||
name: '',
|
||||
color: '',
|
||||
});
|
||||
|
||||
const submit: FormEventHandler = (e) => {
|
||||
e.preventDefault();
|
||||
form.post(route('tags.store'), {
|
||||
onSuccess: () => {
|
||||
setOpen(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>{children}</DialogTrigger>
|
||||
<DialogContent className="max-h-screen overflow-y-auto sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Connect to storage provider</DialogTitle>
|
||||
<DialogDescription className="sr-only">Connect to a new storage provider</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form id="create-tag-form" onSubmit={submit} className="p-4">
|
||||
<FormFields>
|
||||
<FormField>
|
||||
<Label htmlFor="name">Name</Label>
|
||||
<Input type="text" 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="color">Color</Label>
|
||||
<ColorSelect name="color" value={form.data.color} onValueChange={(value) => form.setData('color', value)} />
|
||||
<InputError message={form.errors.color} />
|
||||
</FormField>
|
||||
</FormFields>
|
||||
</Form>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button type="button" variant="outline">
|
||||
Cancel
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<Button type="button" onClick={submit} disabled={form.processing}>
|
||||
{form.processing && <LoaderCircle className="animate-spin" />}
|
||||
Connect
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
36
resources/js/pages/tags/index.tsx
Normal file
36
resources/js/pages/tags/index.tsx
Normal file
@ -0,0 +1,36 @@
|
||||
import SettingsLayout from '@/layouts/settings/layout';
|
||||
import { Head, usePage } from '@inertiajs/react';
|
||||
import Container from '@/components/container';
|
||||
import Heading from '@/components/heading';
|
||||
import { DataTable } from '@/components/data-table';
|
||||
import { Tag } from '@/types/tag';
|
||||
import { columns } from '@/pages/tags/components/columns';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import React from 'react';
|
||||
import CreateTag from '@/pages/tags/components/create-tag';
|
||||
|
||||
type Page = {
|
||||
tags: {
|
||||
data: Tag[];
|
||||
};
|
||||
};
|
||||
|
||||
export default function Tags() {
|
||||
const page = usePage<Page>();
|
||||
return (
|
||||
<SettingsLayout>
|
||||
<Head title="Tags" />
|
||||
<Container className="max-w-5xl">
|
||||
<div className="flex items-start justify-between">
|
||||
<Heading title="Tags" description="Here you can manage tags" />
|
||||
<div className="flex items-center gap-2">
|
||||
<CreateTag>
|
||||
<Button>Create</Button>
|
||||
</CreateTag>
|
||||
</div>
|
||||
</div>
|
||||
<DataTable columns={columns} data={page.props.tags.data} />
|
||||
</Container>
|
||||
</SettingsLayout>
|
||||
);
|
||||
}
|
1
resources/js/types/index.d.ts
vendored
1
resources/js/types/index.d.ts
vendored
@ -49,6 +49,7 @@ export interface Configs {
|
||||
service_versions: {
|
||||
[service: string]: string[];
|
||||
};
|
||||
colors: string[];
|
||||
webservers: string[];
|
||||
databases: string[];
|
||||
php_versions: string[];
|
||||
|
10
resources/js/types/tag.d.ts
vendored
Normal file
10
resources/js/types/tag.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
export interface Tag {
|
||||
id: number;
|
||||
project_id: number;
|
||||
name: string;
|
||||
color: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
|
||||
[key: string]: unknown;
|
||||
}
|
Reference in New Issue
Block a user