summaryrefslogtreecommitdiff
path: root/lib/docu-list-rule/code-groups/table
diff options
context:
space:
mode:
author0-Zz-ang <s1998319@gmail.com>2025-08-25 09:23:30 +0900
committer0-Zz-ang <s1998319@gmail.com>2025-08-25 09:23:30 +0900
commitb12a06766e32e3c76544b1d12bec91653e1fe9db (patch)
tree57ca1ddff3342677d132e07b78fc03873a960255 /lib/docu-list-rule/code-groups/table
parentd38877eef87917087a4a217bea32ae84d6738a7d (diff)
docu-list-rule페이지 수정
Diffstat (limited to 'lib/docu-list-rule/code-groups/table')
-rw-r--r--lib/docu-list-rule/code-groups/table/code-groups-add-dialog.tsx66
-rw-r--r--lib/docu-list-rule/code-groups/table/code-groups-table-columns.tsx13
-rw-r--r--lib/docu-list-rule/code-groups/table/code-groups-table.tsx7
3 files changed, 6 insertions, 80 deletions
diff --git a/lib/docu-list-rule/code-groups/table/code-groups-add-dialog.tsx b/lib/docu-list-rule/code-groups/table/code-groups-add-dialog.tsx
index 33dfdd03..f5354161 100644
--- a/lib/docu-list-rule/code-groups/table/code-groups-add-dialog.tsx
+++ b/lib/docu-list-rule/code-groups/table/code-groups-add-dialog.tsx
@@ -34,11 +34,10 @@ import {
SelectValue,
} from "@/components/ui/select"
import { createCodeGroup } from "@/lib/docu-list-rule/code-groups/service"
-import { getProjectLists } from "@/lib/projects/service"
+import { useParams } from "next/navigation"
import { z } from "zod"
const createCodeGroupSchema = z.object({
- projectId: z.string().min(1, "프로젝트는 필수입니다."),
description: z.string().min(1, "Description은 필수입니다."),
codeFormat: z.string().optional().refine((val) => {
if (!val) return true; // 빈 값은 허용
@@ -54,51 +53,21 @@ interface CodeGroupsAddDialogProps {
}
export function CodeGroupsAddDialog({ onSuccess }: CodeGroupsAddDialogProps) {
+ const params = useParams()
+ const projectId = Number(params?.projectId)
const [open, setOpen] = React.useState(false)
const [isLoading, setIsLoading] = React.useState(false)
- const [projects, setProjects] = React.useState<Array<{ id: number; code: string; name: string; type: string }>>([])
const form = useForm<CreateCodeGroupFormValues>({
resolver: zodResolver(createCodeGroupSchema),
defaultValues: {
- projectId: "",
description: "",
codeFormat: "",
controlType: "",
},
})
- // 프로젝트 목록 로드
- React.useEffect(() => {
- if (open) {
- const loadProjects = async () => {
- try {
- const result = await getProjectLists({
- page: 1,
- perPage: 1000,
- search: "",
- sort: [],
- filters: [],
- joinOperator: "and",
- flags: [],
- code: "",
- name: "",
- type: ""
- })
- if (result.data) {
- // plant 타입의 프로젝트만 필터링
- const plantProjects = result.data.filter(project => project.type === 'plant')
- setProjects(plantProjects)
- }
- } catch (error) {
- console.error("Failed to load projects:", error)
- toast.error("프로젝트 목록을 불러오는데 실패했습니다.")
-
- }
- }
- loadProjects()
- }
- }, [open])
+
// Code Format을 기반으로 정규식 자동 생성 함수
const generateExpression = (codeFormat: string): string => {
@@ -157,7 +126,7 @@ export function CodeGroupsAddDialog({ onSuccess }: CodeGroupsAddDialogProps) {
const expressions = generateExpression(data.codeFormat || "")
const result = await createCodeGroup({
- projectId: parseInt(data.projectId),
+ projectId: projectId,
description: data.description,
codeFormat: data.codeFormat,
expressions: expressions,
@@ -201,31 +170,6 @@ export function CodeGroupsAddDialog({ onSuccess }: CodeGroupsAddDialogProps) {
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
<FormField
control={form.control}
- name="projectId"
- render={({ field }) => (
- <FormItem>
- <FormLabel>프로젝트 *</FormLabel>
- <Select onValueChange={field.onChange} defaultValue={field.value}>
- <FormControl>
- <SelectTrigger>
- <SelectValue placeholder="프로젝트를 선택하세요" />
- </SelectTrigger>
- </FormControl>
- <SelectContent>
- {projects.map((project) => (
- <SelectItem key={project.id} value={project.id.toString()}>
- {project.code} - {project.name}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
- <FormMessage />
- </FormItem>
- )}
- />
-
- <FormField
- control={form.control}
name="description"
render={({ field }) => (
<FormItem>
diff --git a/lib/docu-list-rule/code-groups/table/code-groups-table-columns.tsx b/lib/docu-list-rule/code-groups/table/code-groups-table-columns.tsx
index 01047c50..c15dd676 100644
--- a/lib/docu-list-rule/code-groups/table/code-groups-table-columns.tsx
+++ b/lib/docu-list-rule/code-groups/table/code-groups-table-columns.tsx
@@ -103,19 +103,6 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef<typeof
// ----------------------------------------------------------------
const dataColumns: ColumnDef<typeof codeGroups.$inferSelect>[] = [
{
- accessorKey: "projectCode",
- enableResizing: true,
- header: ({ column }) => (
- <DataTableColumnHeaderSimple column={column} title="프로젝트 코드" />
- ),
- meta: {
- excelHeader: "프로젝트 코드",
- type: "text",
- },
- cell: ({ row }) => row.getValue("projectCode") ?? "",
- minSize: 120
- },
- {
accessorKey: "groupId",
enableResizing: true,
header: ({ column }) => (
diff --git a/lib/docu-list-rule/code-groups/table/code-groups-table.tsx b/lib/docu-list-rule/code-groups/table/code-groups-table.tsx
index 0029ed91..fdddb2d6 100644
--- a/lib/docu-list-rule/code-groups/table/code-groups-table.tsx
+++ b/lib/docu-list-rule/code-groups/table/code-groups-table.tsx
@@ -75,12 +75,7 @@ export function CodeGroupsTable({ promises }: CodeGroupsTableProps) {
clearOnDefault: false,
})
- // 컴포넌트 마운트 후 그룹핑 설정
- React.useEffect(() => {
- if (data && table.getState().grouping.length === 0) {
- table.setGrouping(["projectCode"])
- }
- }, [table, data])
+
// 정렬 시 펼쳐진 상태 유지
React.useEffect(() => {