대시보드 관리 목록/ 편집/ 뷰 분리

This commit is contained in:
dohyeons
2025-10-15 17:11:26 +09:00
parent d4949983fb
commit 59bd654107
7 changed files with 296 additions and 49 deletions

View File

@@ -187,8 +187,8 @@ export function ListWidget({ element, onConfigUpdate }: ListWidgetProps) {
);
}
// 데이터 또는 설정 없음
if (!data || config.columns.length === 0) {
// 데이터 없음
if (!data) {
return (
<div className="flex h-full w-full flex-col items-center justify-center gap-4 p-4">
<div className="text-center">
@@ -200,6 +200,17 @@ export function ListWidget({ element, onConfigUpdate }: ListWidgetProps) {
);
}
// 컬럼 설정이 없으면 자동으로 모든 컬럼 표시
const displayColumns =
config.columns.length > 0
? config.columns
: data.columns.map((col) => ({
id: col,
name: col,
dataKey: col,
visible: true,
}));
// 페이지네이션
const totalPages = Math.ceil(data.rows.length / config.pageSize);
const startIdx = (currentPage - 1) * config.pageSize;
@@ -219,7 +230,7 @@ export function ListWidget({ element, onConfigUpdate }: ListWidgetProps) {
{config.showHeader && (
<TableHeader>
<TableRow>
{config.columns
{displayColumns
.filter((col) => col.visible)
.map((col) => (
<TableHead
@@ -227,7 +238,7 @@ export function ListWidget({ element, onConfigUpdate }: ListWidgetProps) {
className={col.align === "center" ? "text-center" : col.align === "right" ? "text-right" : ""}
style={{ width: col.width ? `${col.width}px` : undefined }}
>
{col.label}
{col.label || col.name}
</TableHead>
))}
</TableRow>
@@ -237,7 +248,7 @@ export function ListWidget({ element, onConfigUpdate }: ListWidgetProps) {
{paginatedRows.length === 0 ? (
<TableRow>
<TableCell
colSpan={config.columns.filter((col) => col.visible).length}
colSpan={displayColumns.filter((col) => col.visible).length}
className="text-center text-gray-500"
>
@@ -246,14 +257,14 @@ export function ListWidget({ element, onConfigUpdate }: ListWidgetProps) {
) : (
paginatedRows.map((row, idx) => (
<TableRow key={idx} className={config.stripedRows ? undefined : ""}>
{config.columns
{displayColumns
.filter((col) => col.visible)
.map((col) => (
<TableCell
key={col.id}
className={col.align === "center" ? "text-center" : col.align === "right" ? "text-right" : ""}
>
{String(row[col.field] ?? "")}
{String(row[col.dataKey || col.field] ?? "")}
</TableCell>
))}
</TableRow>
@@ -279,15 +290,15 @@ export function ListWidget({ element, onConfigUpdate }: ListWidgetProps) {
{paginatedRows.map((row, idx) => (
<Card key={idx} className="p-4 transition-shadow hover:shadow-md">
<div className="space-y-2">
{config.columns
{displayColumns
.filter((col) => col.visible)
.map((col) => (
<div key={col.id}>
<div className="text-xs font-medium text-gray-500">{col.label}</div>
<div className="text-xs font-medium text-gray-500">{col.label || col.name}</div>
<div
className={`font-medium text-gray-900 ${col.align === "center" ? "text-center" : col.align === "right" ? "text-right" : ""}`}
>
{String(row[col.field] ?? "")}
{String(row[col.dataKey || col.field] ?? "")}
</div>
</div>
))}