그리드 정렬기능
This commit is contained in:
@@ -1 +1,2 @@
|
||||
export * from "./ui";
|
||||
export * from "./lib/user-message";
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
export type BusinessUserMessageHandler = (message: string) => void;
|
||||
|
||||
let userMessageHandler: BusinessUserMessageHandler | undefined;
|
||||
|
||||
/** 사용하는 앱이 공통 비즈니스 컴포넌트의 사용자 메시지 표시 방식을 연결한다. */
|
||||
export const setBusinessUserMessageHandler = (
|
||||
handler: BusinessUserMessageHandler,
|
||||
) => {
|
||||
userMessageHandler = handler;
|
||||
|
||||
return () => {
|
||||
if (userMessageHandler === handler) userMessageHandler = undefined;
|
||||
};
|
||||
};
|
||||
|
||||
/** 앱 핸들러가 연결되면 공통 UI를 사용하고, 미연결 앱은 기존 브라우저 알림을 유지한다. */
|
||||
export const showBusinessUserMessage = (message: unknown) => {
|
||||
const normalizedMessage = String(message ?? "").trim();
|
||||
if (!normalizedMessage) return;
|
||||
|
||||
if (userMessageHandler) {
|
||||
userMessageHandler(normalizedMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof window !== "undefined") window.alert(normalizedMessage);
|
||||
};
|
||||
@@ -60,6 +60,8 @@ function Gis({
|
||||
inlineLayerSettingView,
|
||||
treeSectionClassName = "",
|
||||
layerIconVisible,
|
||||
// 목록·액션 아이콘이 지도 레이어 체크를 선행 조건으로 요구하는지 여부다.
|
||||
layerIconRequiresChecked = true,
|
||||
isPlaying = false,
|
||||
setIsPlaying = () => { },
|
||||
targetLayerTypes = [],
|
||||
@@ -314,6 +316,7 @@ function Gis({
|
||||
}}
|
||||
imageVisible={imgVisble}
|
||||
layerIconVisible={layerIconVisible}
|
||||
layerIconRequiresChecked={layerIconRequiresChecked}
|
||||
sinkholeLegendIconVisible={sinkholeLegendIconVisible}
|
||||
isPlaying={isPlaying}
|
||||
setIsPlaying={setIsPlaying}
|
||||
|
||||
@@ -2,6 +2,7 @@ import GisApp from './lib/gis.core';
|
||||
import React, { useContext, useEffect, useRef, useState } from 'react';
|
||||
import { GisContext, setTree } from './Gis';
|
||||
import { Button } from "@common/components";
|
||||
import { showBusinessUserMessage } from '../../lib/user-message';
|
||||
import { gAlert, gConfirm } from './lib/util';
|
||||
// import { fclApi } from '../../js/apis/fcl/fclApi';
|
||||
|
||||
@@ -39,12 +40,12 @@ export default React.memo(function GisEdit() {
|
||||
let add = !btnEvt.add;
|
||||
if (add) {
|
||||
if (!checkedLayerIds?.current?.includes(selectedLyrId.current)) {
|
||||
alert('트리에서 레이어 체크 후 추가 가능합니다.');
|
||||
showBusinessUserMessage('트리에서 레이어 체크 후 추가 가능합니다.');
|
||||
return;
|
||||
}
|
||||
const errMsg = editModule.setDraw(selectedLyrId.current);
|
||||
if (errMsg) {
|
||||
alert(errMsg);
|
||||
showBusinessUserMessage(errMsg);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
import { ChevronLeft, ChevronRight } from "lucide-react";
|
||||
import React, { useEffect, useLayoutEffect, useState, useRef, useCallback } from "react";
|
||||
|
||||
import { showBusinessUserMessage } from "../../lib/user-message";
|
||||
import { useGisContext } from "./Gis";
|
||||
import GisApp from "./lib/gis.core";
|
||||
|
||||
@@ -29,6 +30,7 @@ import GisApp from "./lib/gis.core";
|
||||
* - onProgressChange(total, current): 애니메이션 진행상태 콜백
|
||||
* - layerSettingView: (선택) 좌측 레이어 트리 하단에 표시할 설정 영역
|
||||
* - layerIconVisible: (선택) 레이어 행 우측 액션 아이콘 노출 여부를 결정하는 함수
|
||||
* - layerIconRequiresChecked: (선택) 액션 실행 전에 레이어 체크를 요구할지 여부
|
||||
* - detachedToggleButton: (선택) 접기/펼치기 버튼을 패널 밖 고정 핸들로 노출할지 여부
|
||||
*/
|
||||
export default React.memo(function GisTree({
|
||||
@@ -46,6 +48,7 @@ export default React.memo(function GisTree({
|
||||
onProgressChange = () => { },
|
||||
layerSettingView: LayerSettingView = null,
|
||||
layerIconVisible,
|
||||
layerIconRequiresChecked = true,
|
||||
sinkholeLegendIconVisible = false,
|
||||
inlineLayerSettingView,
|
||||
treeSectionClassName = "",
|
||||
@@ -536,7 +539,7 @@ export default React.memo(function GisTree({
|
||||
* 각 레이어 행의 아이콘 클릭 시 호출. 선택되지 않은 레이어면 경고, 선택된 경우 콜백 전달.
|
||||
*/
|
||||
const handleLayerImgClick = (nodeNm, nodeId, node) => {
|
||||
if (!checked.includes(nodeId)) alert("시설을 선택해주세요");
|
||||
if (layerIconRequiresChecked && !checked.includes(nodeId)) showBusinessUserMessage("시설을 선택해주세요");
|
||||
else onLayerIconClick(nodeNm, node);
|
||||
};
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import GisOlStyle from './gis.style.js';
|
||||
import Tile from 'ol/layer/Tile.js';
|
||||
import TileWMS from 'ol/source/TileWMS.js';
|
||||
import gisCore from './gis.core.js';
|
||||
import { showBusinessUserMessage } from '../../../lib/user-message';
|
||||
import {
|
||||
buildFloodDngrSldBody,
|
||||
FLOOD_DNGR_MAP_LAYER_TYPE,
|
||||
@@ -673,7 +674,7 @@ GisOlLayer.prototype = {
|
||||
|
||||
// 1) 로드 완료시 extent 맞추기
|
||||
const onLoadEnd = () => {
|
||||
if (Object.keys(source.nullGeometryFeatures_).length > 0) alert('해당 시설의 위치 정보가 없습니다.');
|
||||
if (Object.keys(source.nullGeometryFeatures_).length > 0) showBusinessUserMessage('해당 시설의 위치 정보가 없습니다.');
|
||||
|
||||
const feats = source.getFeatures();
|
||||
if (feats && feats.length > 0) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { showBusinessUserMessage } from '../../../lib/user-message';
|
||||
|
||||
|
||||
//공통
|
||||
export const util = {
|
||||
@@ -537,7 +539,7 @@ export const getMessage = (msgGroup, msgKey, innerText, fix) => {
|
||||
|
||||
// global.js의 message를 읽어오는 alert
|
||||
export const gAlert = (msgGroup, msgKey, innerText, fix) => {
|
||||
alert(getMessage(msgGroup, msgKey, innerText, fix));
|
||||
showBusinessUserMessage(getMessage(msgGroup, msgKey, innerText, fix));
|
||||
};
|
||||
|
||||
// message를 confirm
|
||||
@@ -640,4 +642,4 @@ export const getFeatureLabelCoordinate = (feature) => {
|
||||
const y = coordinate[1];
|
||||
return `${x.toFixed(p)}_${y.toFixed(p)}`;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { SelectBox, type SelectDataType } from "../../../ui";
|
||||
import { Button } from "@common/components/ui";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { showBusinessUserMessage } from "../../../lib/user-message";
|
||||
import GisApp from "../lib/gis.core";
|
||||
import {
|
||||
getSigunguCenter,
|
||||
@@ -369,7 +370,7 @@ export const ProcSearchBar = ({
|
||||
|
||||
const handleSearch = useCallback(() => {
|
||||
if (sidoValue === "0") {
|
||||
alert("시도를 선택해 주세요.");
|
||||
showBusinessUserMessage("시도를 선택해 주세요.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { SelectBox, type SelectDataType } from "../../../ui";
|
||||
import { Button } from "@common/components/ui";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { showBusinessUserMessage } from "../../../lib/user-message";
|
||||
import SearchInputText from "./SearchInputText";
|
||||
import GisApp from "../lib/gis.core";
|
||||
import { getSigunguCenter, moveMapToCenter, sidoCenter } from "./utils";
|
||||
@@ -163,7 +164,7 @@ export const SearchBar = ({
|
||||
const handleSearch = async () => {
|
||||
if (!fcltyNm) {
|
||||
if (sidoValue === "0") {
|
||||
alert("시도를 선택해 주세요");
|
||||
showBusinessUserMessage("시도를 선택해 주세요");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -288,7 +289,7 @@ export const SearchBar = ({
|
||||
}
|
||||
|
||||
if (list.length === 0) {
|
||||
alert("검색 결과가 없습니다.");
|
||||
showBusinessUserMessage("검색 결과가 없습니다.");
|
||||
setSearchList([]);
|
||||
setFcltyNm("");
|
||||
return;
|
||||
@@ -352,7 +353,7 @@ export const SearchBar = ({
|
||||
nearest: true,
|
||||
});
|
||||
} else {
|
||||
alert("위치정보를 찾을 수 없습니다.");
|
||||
showBusinessUserMessage("위치정보를 찾을 수 없습니다.");
|
||||
console.warn("geometry를 찾을 수 없습니다:", data);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { showBusinessUserMessage } from "../../lib/user-message";
|
||||
|
||||
interface SortConfig {
|
||||
empty: boolean;
|
||||
sorted: boolean;
|
||||
unsorted: boolean;
|
||||
}
|
||||
|
||||
interface PageableConfig {
|
||||
sort: SortConfig;
|
||||
offset: number;
|
||||
@@ -138,7 +139,7 @@ export function searchFilter(search: string): boolean {
|
||||
|
||||
const expText = /[%=><]/;
|
||||
if (expText.test(search)) {
|
||||
alert("특수문자를 입력 할수 없습니다.");
|
||||
showBusinessUserMessage("특수문자를 입력 할수 없습니다.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -160,7 +161,7 @@ export function searchFilter(search: string): boolean {
|
||||
for (const sqlWord of sqlArray) {
|
||||
const regex = new RegExp(sqlWord, "gi");
|
||||
if (regex.test(search)) {
|
||||
alert(`"${sqlWord}"와(과) 같은 특정문자로 검색할 수 없습니다.`);
|
||||
showBusinessUserMessage(`"${sqlWord}"와(과) 같은 특정문자로 검색할 수 없습니다.`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// const addresssKey = 'devU01TX0FVVEgyMDI1MDgyNTEwMzkwNDExNjEwNTM='; //인증키 만료일은 2025-11-23
|
||||
|
||||
import type { Zip, ZipSearchParams } from "./zipService";
|
||||
import { showBusinessUserMessage } from "../../lib/user-message";
|
||||
|
||||
/**
|
||||
* 주소 API 응답 타입
|
||||
@@ -80,7 +81,6 @@ export const findAddress = async (searchQuery: ZipSearchParams): Promise<any> =>
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const searchFilter = (search: string) => {
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ export const searchFilter = (search: string) => {
|
||||
//특수문자 제거
|
||||
const expText = /[%=><]/;
|
||||
if (expText.test(search) == true) {
|
||||
alert("특수문자를 입력 할수 없습니다.");
|
||||
showBusinessUserMessage("특수문자를 입력 할수 없습니다.");
|
||||
search = search.split(expText).join("");
|
||||
return false;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ export const searchFilter = (search: string) => {
|
||||
regex = new RegExp(sqlArray[i] as string, "gi");
|
||||
|
||||
if (regex.test(search)) {
|
||||
alert("\"" + sqlArray[i] + "\"와(과) 같은 특정문자로 검색할 수 없습니다.");
|
||||
showBusinessUserMessage("\"" + sqlArray[i] + "\"와(과) 같은 특정문자로 검색할 수 없습니다.");
|
||||
search = search.replace(regex, "");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -339,3 +339,10 @@ export type {
|
||||
StandardDataTableRenderContext,
|
||||
StandardRowNumberParams,
|
||||
};
|
||||
export {
|
||||
StandardTableSortHeader,
|
||||
compareStandardTableValues,
|
||||
getNextStandardTableSort,
|
||||
sortStandardTableRows,
|
||||
} from "./sort";
|
||||
export type { StandardTableSortHeaderProps } from "./sort";
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
"use client";
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import { ChevronDown, ChevronUp } from "lucide-react";
|
||||
|
||||
import type { UiTableSort } from "../table/types";
|
||||
|
||||
const STANDARD_TABLE_SORT_COLLATOR = new Intl.Collator("ko-KR", {
|
||||
numeric: true,
|
||||
sensitivity: "base",
|
||||
});
|
||||
|
||||
const isEmptySortValue = (value: unknown) =>
|
||||
value === null ||
|
||||
value === undefined ||
|
||||
String(value).trim() === "" ||
|
||||
String(value).trim() === "-";
|
||||
|
||||
const toComparableNumber = (value: unknown) => {
|
||||
const normalized = String(value ?? "")
|
||||
.trim()
|
||||
.replace(/,/g, "")
|
||||
.replace(/%$/, "");
|
||||
if (!/^-?\d+(?:\.\d+)?$/.test(normalized)) return undefined;
|
||||
const number = Number(normalized);
|
||||
return Number.isFinite(number) ? number : undefined;
|
||||
};
|
||||
|
||||
/** 공통 표 헤더의 asc → desc → 기본 순환 상태를 계산한다. */
|
||||
export const getNextStandardTableSort = (
|
||||
sortKey: string,
|
||||
currentSort?: UiTableSort,
|
||||
): UiTableSort | undefined => {
|
||||
if (currentSort?.key !== sortKey) {
|
||||
return { key: sortKey, direction: "asc" };
|
||||
}
|
||||
if (currentSort.direction === "asc") {
|
||||
return { key: sortKey, direction: "desc" };
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/** 숫자·날짜·한글 표시값을 비교하고 빈 값은 방향과 무관하게 마지막에 둔다. */
|
||||
export const compareStandardTableValues = (
|
||||
leftValue: unknown,
|
||||
rightValue: unknown,
|
||||
direction: UiTableSort["direction"],
|
||||
) => {
|
||||
const leftEmpty = isEmptySortValue(leftValue);
|
||||
const rightEmpty = isEmptySortValue(rightValue);
|
||||
if (leftEmpty || rightEmpty) {
|
||||
if (leftEmpty && rightEmpty) return 0;
|
||||
return leftEmpty ? 1 : -1;
|
||||
}
|
||||
|
||||
const leftNumber = toComparableNumber(leftValue);
|
||||
const rightNumber = toComparableNumber(rightValue);
|
||||
const comparison =
|
||||
leftNumber !== undefined && rightNumber !== undefined
|
||||
? leftNumber - rightNumber
|
||||
: STANDARD_TABLE_SORT_COLLATOR.compare(
|
||||
String(leftValue),
|
||||
String(rightValue),
|
||||
);
|
||||
return direction === "asc" ? comparison : -comparison;
|
||||
};
|
||||
|
||||
/** 서버 페이징이 아닌 전체 보유 행을 원본 배열 변경 없이 안정 정렬한다. */
|
||||
export const sortStandardTableRows = <T extends object>(
|
||||
rows: T[],
|
||||
sort?: UiTableSort,
|
||||
resolveValue: (row: T, key: string) => unknown = (row, key) =>
|
||||
(row as Record<string, unknown>)[key],
|
||||
) => {
|
||||
if (!sort) return rows;
|
||||
return rows
|
||||
.map((row, originalIndex) => ({ row, originalIndex }))
|
||||
.sort((left, right) => {
|
||||
const comparison = compareStandardTableValues(
|
||||
resolveValue(left.row, sort.key),
|
||||
resolveValue(right.row, sort.key),
|
||||
sort.direction,
|
||||
);
|
||||
return comparison || left.originalIndex - right.originalIndex;
|
||||
})
|
||||
.map(({ row }) => row);
|
||||
};
|
||||
|
||||
interface StandardTableSortHeaderProps {
|
||||
label: string;
|
||||
title?: ReactNode;
|
||||
sortKey: string;
|
||||
sort?: UiTableSort;
|
||||
onSortChange: (sort: UiTableSort | undefined) => void;
|
||||
}
|
||||
|
||||
/** StandardDataTable 계열 화면이 동일한 아이콘·상태 전이를 사용하는 헤더 버튼이다. */
|
||||
export function StandardTableSortHeader({
|
||||
label,
|
||||
title = label,
|
||||
sortKey,
|
||||
sort,
|
||||
onSortChange,
|
||||
}: StandardTableSortHeaderProps) {
|
||||
const direction = sort?.key === sortKey ? sort.direction : undefined;
|
||||
const nextSort = getNextStandardTableSort(sortKey, sort);
|
||||
const nextAction =
|
||||
nextSort?.direction === "asc"
|
||||
? "오름차순"
|
||||
: nextSort?.direction === "desc"
|
||||
? "내림차순"
|
||||
: "기본순서";
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex w-full items-center justify-center gap-1.5 rounded-sm transition-colors hover:bg-background/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-foreground"
|
||||
aria-label={`${label} ${nextAction} 정렬`}
|
||||
onClick={() => onSortChange(nextSort)}
|
||||
>
|
||||
<span>{title}</span>
|
||||
<span
|
||||
className={`inline-flex shrink-0 items-center justify-center drop-shadow-sm ${
|
||||
direction
|
||||
? "text-yellow-300 drop-shadow-[0_1px_1px_rgba(0,0,0,0.8)]"
|
||||
: "text-white drop-shadow-[0_1px_1px_rgba(0,0,0,0.75)]"
|
||||
}`}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{direction === "asc" ? (
|
||||
<ChevronUp className="size-5 stroke-[3]" />
|
||||
) : direction === "desc" ? (
|
||||
<ChevronDown className="size-5 stroke-[3]" />
|
||||
) : (
|
||||
<span className="inline-flex flex-col -space-y-2">
|
||||
<ChevronUp className="size-4 stroke-[2.8]" />
|
||||
<ChevronDown className="size-4 stroke-[2.8]" />
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export type { StandardTableSortHeaderProps };
|
||||
Reference in New Issue
Block a user