Skip to content

Commit

Permalink
refactor: data table components
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Jan 9, 2024
1 parent ec234ff commit a69b22f
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 141 deletions.
4 changes: 2 additions & 2 deletions src/app/dashboard/lenses/new/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SubNav, SubNavTitle, SubNavSubtitle } from '@/components/sub-nav'
import { Section } from '@/components/section'
import { NewSolutionForm } from '@/components/lenses/new-form'
import { NewLensForm } from '@/components/lenses/new-form'

export default function Page() {
return (
Expand All @@ -14,7 +14,7 @@ export default function Page() {
</SubNavTitle>
</SubNav>
<Section>
<NewSolutionForm />
<NewLensForm />
</Section>
</>
)
Expand Down
86 changes: 0 additions & 86 deletions src/app/dashboard/solutions/data/data.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/app/dashboard/solutions/data/schema.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/dashboard/solutions/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AddSolution } from './components/add-solution'
import { AddSolution } from '@/components/solutions/add-solution'
import {
SubNav,
SubNavTitle,
SubNavActions,
SubNavSubtitle
} from '@/components/sub-nav'
import { Main } from '@/components/main'
import SolutionsDataTable from './components/data-table'
import SolutionsDataTable from '@/components/solutions/data-table'

export default function Page() {
return (
Expand Down
4 changes: 2 additions & 2 deletions src/app/dashboard/workloads/new/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SubNav, SubNavTitle, SubNavSubtitle } from '@/components/sub-nav'
import { Section } from '@/components/section'
import { NewProfilesForm } from './components/new-form'
import { NewWorkloadForm } from '@/components/workloads/new-form'
import { Suspense } from 'react'

export default function Page() {
Expand All @@ -17,7 +17,7 @@ export default function Page() {
</SubNav>
<Section>
<Suspense>
<NewProfilesForm />
<NewWorkloadForm />
</Suspense>
</Section>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/app/teams/[id]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SidebarNav } from '@/components/sidebar-nav'
import { PropsWithChildren } from 'react'
import type { PropsWithChildren } from 'react'

export type LayoutProps = {
children?: React.ReactNode
Expand Down
3 changes: 0 additions & 3 deletions src/components/data-table-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import { Cross2Icon } from '@radix-ui/react-icons'
import { Table } from '@tanstack/react-table'
import { CgSpinner } from 'react-icons/cg'

import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { DataTableViewOptions } from '@/components/data-table-view-options'

import { statuses } from './data/data'
import { DataTableFacetedFilter } from './data-table-faceted-filter'
import type { DataTableFacetedFilterProps } from './data-table-faceted-filter'
import { DataTableLoading } from './data-table-loading'

interface DataTableToolbarProps<TData> {
Expand Down
6 changes: 2 additions & 4 deletions src/components/lenses/new-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import { z } from 'zod'
import { useAction } from '@/trpc/client'
import { useRouter } from 'next/navigation'

export type NewSolutionFormProps = {}
export type NewLensFormProps = {}

export function NewSolutionForm({
...props
}: PropsWithChildren<NewSolutionFormProps>) {
export function NewLensForm({ ...props }: PropsWithChildren<NewLensFormProps>) {
const form = useForm<z.infer<typeof rhfActionSchema>>({
resolver: zodResolver(rhfActionSchema),
defaultValues: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { DotsHorizontalIcon } from '@radix-ui/react-icons'
import { Button } from '@/components/ui/button'
import { PlusIcon } from '@radix-ui/react-icons'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuShortcut,
DropdownMenuTrigger,
DropdownMenuLabel
} from '@/components/ui/dropdown-menu'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Checkbox } from '@/components/ui/checkbox'
import Link from 'next/link'
import { Solution } from '@/db/models/solution'
import { DataTableColumnHeader } from '@/components/data-table-column-header'
import { DataTableRowActions } from '@/app/dashboard/solutions/components/data-rows-actions'
import { DataTableRowActions } from './data-rows-actions'
import { buttonVariants } from '@/components/ui/button'
import { cn } from '@/lib/utils'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { DotsHorizontalIcon } from '@radix-ui/react-icons'
import { Row } from '@tanstack/react-table'

import { Button } from '@/components/ui/button'
import { api } from '@/trpc/client'
import {
Expand Down Expand Up @@ -47,20 +46,6 @@ export function DataTableRowActions<TData>({
<DropdownMenuItem>View</DropdownMenuItem>
</Link>
<DropdownMenuItem>Make a copy</DropdownMenuItem>
<DropdownMenuItem>Favorite</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuSub>
<DropdownMenuSubTrigger>Labels</DropdownMenuSubTrigger>
<DropdownMenuSubContent>
{/* <DropdownMenuRadioGroup value={}>
{labels.map(label => (
<DropdownMenuRadioItem key={label.value} value={label.value}>
{label.label}
</DropdownMenuRadioItem>
))}
</DropdownMenuRadioGroup> */}
</DropdownMenuSubContent>
</DropdownMenuSub>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => deleteWorkload(id)}>
Delete
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const rhfAction = createAction(
protectedProcedure.input(rhfActionSchema).mutation(
async opts =>
await createWorkload({
id: uuidv4(),
name: opts.input.name,
description: opts.input.description,
environmentsIds: opts.input.environmentsIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ import { useForm } from 'react-hook-form'
import { z } from 'zod'
import { useAction } from '@/trpc/client'
import { useRouter } from 'next/navigation'
import type { PropsWithChildren } from 'react'

export type NewProfilesFormProps = {
className?: string
}
export type NewWorkloadFormProps = {}

export function NewProfilesForm({ ...props }: NewProfilesFormProps) {
export function NewWorkloadForm({
...props
}: PropsWithChildren<NewWorkloadFormProps>) {
const profiles = use(api.listProfiles.query({}))
const environments = use(api.listEnvironments.query({}))
const lenses = use(api.listLenses.query({}))
Expand Down
8 changes: 6 additions & 2 deletions src/db/models/workload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
PrimaryKey,
Table,
UpdatedAt,
HasMany
HasMany,
AllowNull,
Default
} from 'sequelize-typescript'
import { Profile } from './profile'
import { Lens } from './lens'
Expand All @@ -36,7 +38,7 @@ export interface WorkloadAttributes {

export type WorkloadCreationAttributes = Omit<
WorkloadAttributes,
'createdAt' | 'updatedAt' | 'deletedAt'
'id' | 'createdAt' | 'updatedAt' | 'deletedAt'
>

@Table({
Expand All @@ -48,6 +50,8 @@ export class Workload extends Model<
WorkloadCreationAttributes
> {
@PrimaryKey
@AllowNull(false)
@Default(DataType.UUIDV4)
@Column(DataType.UUIDV4)
id!: string

Expand Down
3 changes: 0 additions & 3 deletions src/db/services/workloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ export async function createWorkload({
lensesIds: string[]
}) {
return await sequelize.transaction(async transaction => {
const id = uuidv4()

const workload = await Workload.create(
{
id,
profilesId,
name,
description
Expand Down

0 comments on commit a69b22f

Please sign in to comment.