[st] feat: 검증 미통과 내역 - 조회 바로가기 기능
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import type { MenuItem } from "@/entities/menu";
|
||||
import type { SearchFormValues } from "@/components/type/SearchForm.type";
|
||||
import { doNameList } from "@/components/util/column/input/DoList";
|
||||
import {
|
||||
SEWAGE_PIPE_INP_TAB_KEYS,
|
||||
SEWAGE_PIPE_MAINTAIN_INP_TAB_KEYS,
|
||||
SEWERAGE_PENETRATION_RATE_INP_TAB_KEYS,
|
||||
} from "@/components/util/MenuMatchList";
|
||||
|
||||
/** 검증 결과에서 입력 화면 자동 조회에 사용하는 조건 */
|
||||
export type StatisticsInputPendingSearch = {
|
||||
statsYr: string;
|
||||
sewerBzmnCd: string;
|
||||
ctpvNm: string;
|
||||
sggNm: string;
|
||||
};
|
||||
|
||||
export function verificationSearchToFormValues(
|
||||
s: StatisticsInputPendingSearch,
|
||||
): SearchFormValues {
|
||||
const ctpvNmTrimmed = s.ctpvNm?.trim() ?? "";
|
||||
const sggNmTrimmed = s.sggNm?.trim() ?? "";
|
||||
/** 시군구 필수 도(`DoList.ts`의 `doNameList`)일 때만 API `sggNm`을 검색폼에 반영 */
|
||||
const useSggNm =
|
||||
sggNmTrimmed.length > 0 && doNameList.includes(ctpvNmTrimmed);
|
||||
|
||||
return {
|
||||
year: s.statsYr,
|
||||
bsnmCd: s.sewerBzmnCd,
|
||||
sido: s.ctpvNm,
|
||||
gugun: useSggNm ? sggNmTrimmed : "ALL",
|
||||
};
|
||||
}
|
||||
|
||||
/** `statistics-page` 동적 import 경로의 파일명(확장자 제외)과 일치해야 함 */
|
||||
export const STATISTICS_INPUT_URL_PATH = {
|
||||
SEWAGE_PIPE: "SewagePipeInp",
|
||||
SEWAGE_PIPE_MAINTAIN: "SewagePipeMaintainInp",
|
||||
SEWERAGE_PENETRATION_RATE: "SeweragePenetrationRateInp",
|
||||
} as const;
|
||||
|
||||
function normalizeSewagePipeTabKey(tabKey: string): string {
|
||||
if (
|
||||
tabKey === "adminAreaConnectionInp" ||
|
||||
tabKey === "treatmentPlantConnectionInp"
|
||||
) {
|
||||
return "ST00020006";
|
||||
}
|
||||
return tabKey;
|
||||
}
|
||||
|
||||
const NAV_ROWS: { urlPath: string; tabKeys: readonly string[] }[] = [
|
||||
{ urlPath: STATISTICS_INPUT_URL_PATH.SEWAGE_PIPE, tabKeys: SEWAGE_PIPE_INP_TAB_KEYS },
|
||||
{
|
||||
urlPath: STATISTICS_INPUT_URL_PATH.SEWAGE_PIPE_MAINTAIN,
|
||||
tabKeys: SEWAGE_PIPE_MAINTAIN_INP_TAB_KEYS,
|
||||
},
|
||||
{
|
||||
urlPath: STATISTICS_INPUT_URL_PATH.SEWERAGE_PENETRATION_RATE,
|
||||
tabKeys: SEWERAGE_PENETRATION_RATE_INP_TAB_KEYS,
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* 검증 결과 등의 `statsCd`(또는 입력 화면 탭 키와 동일한 코드)로
|
||||
* 열 입력 화면 `urlPath`와 활성 탭 키를 반환합니다.
|
||||
*/
|
||||
export function resolveInputPageNavigationFromStatsCd(statsCd: string): {
|
||||
urlPath: string;
|
||||
tabKey: string;
|
||||
} | null {
|
||||
const trimmed = statsCd.trim();
|
||||
if (!trimmed) return null;
|
||||
|
||||
for (const row of NAV_ROWS) {
|
||||
if (row.tabKeys.includes(trimmed)) {
|
||||
const tabKey =
|
||||
row.urlPath === STATISTICS_INPUT_URL_PATH.SEWAGE_PIPE
|
||||
? normalizeSewagePipeTabKey(trimmed)
|
||||
: trimmed;
|
||||
return { urlPath: row.urlPath, tabKey };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function findMenuItemByUrlPath(
|
||||
menus: MenuItem[],
|
||||
urlPath: string,
|
||||
): MenuItem | null {
|
||||
for (const item of menus) {
|
||||
if (item.urlPath === urlPath) return item;
|
||||
if (item.children?.length) {
|
||||
const found = findMenuItemByUrlPath(item.children, urlPath);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user