From b12a06766e32e3c76544b1d12bec91653e1fe9db Mon Sep 17 00:00:00 2001 From: 0-Zz-ang Date: Mon, 25 Aug 2025 09:23:30 +0900 Subject: docu-list-rule페이지 수정 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/docu-list-rule/code-groups/service.ts | 8 ++- .../code-groups/table/code-groups-add-dialog.tsx | 66 ++-------------------- .../table/code-groups-table-columns.tsx | 13 ----- .../code-groups/table/code-groups-table.tsx | 7 +-- lib/docu-list-rule/code-groups/validation.ts | 1 + 5 files changed, 14 insertions(+), 81 deletions(-) (limited to 'lib/docu-list-rule/code-groups') diff --git a/lib/docu-list-rule/code-groups/service.ts b/lib/docu-list-rule/code-groups/service.ts index c854f6c9..d9b3b859 100644 --- a/lib/docu-list-rule/code-groups/service.ts +++ b/lib/docu-list-rule/code-groups/service.ts @@ -15,6 +15,7 @@ export async function getCodeGroups(input: { filters: Array<{ id: string; value: string | string[] }> joinOperator: "and" | "or" sort: Array<{ id: string; desc: boolean }> + projectId?: string }) { unstable_noStore() @@ -25,10 +26,15 @@ export async function getCodeGroups(input: { // 검색 조건 (plant 타입 프로젝트만) let whereConditions = sql`${projects.type} = 'plant'` + // 프로젝트 ID 필터링 + if (input.projectId) { + whereConditions = sql`${whereConditions} AND ${codeGroups.projectId} = ${parseInt(input.projectId)}` + } + // 검색어 필터링 if (search) { const searchTerm = `%${search}%` - whereConditions = sql`${projects.type} = 'plant' AND ( + whereConditions = sql`${whereConditions} AND ( ${codeGroups.groupId} ILIKE ${searchTerm} OR ${codeGroups.description} ILIKE ${searchTerm} OR ${codeGroups.codeFormat} ILIKE ${searchTerm} OR 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>([]) const form = useForm({ 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, @@ -199,31 +168,6 @@ export function CodeGroupsAddDialog({ onSuccess }: CodeGroupsAddDialogProps) {
- ( - - 프로젝트 * - - - - )} - /> - [] = [ - { - accessorKey: "projectCode", - enableResizing: true, - header: ({ column }) => ( - - ), - meta: { - excelHeader: "프로젝트 코드", - type: "text", - }, - cell: ({ row }) => row.getValue("projectCode") ?? "", - minSize: 120 - }, { accessorKey: "groupId", enableResizing: true, 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(() => { diff --git a/lib/docu-list-rule/code-groups/validation.ts b/lib/docu-list-rule/code-groups/validation.ts index 9745841c..46ba02e8 100644 --- a/lib/docu-list-rule/code-groups/validation.ts +++ b/lib/docu-list-rule/code-groups/validation.ts @@ -24,6 +24,7 @@ export const searchParamsCodeGroupsCache = createSearchParamsCache({ description: parseAsString.withDefault(""), controlType: parseAsString.withDefault(""), isActive: parseAsString.withDefault(""), + projectId: parseAsString.withDefault(""), // advanced filter filters: getFiltersStateParser().withDefault([]), -- cgit v1.2.3