add new list view for ent - wiki
This commit is contained in:
@@ -280,8 +280,13 @@ export default function Page() {
|
|||||||
const ids = new Set<string>();
|
const ids = new Set<string>();
|
||||||
for (const ref of snapshotEntitiesVisible) ids.add(String(ref.id));
|
for (const ref of snapshotEntitiesVisible) ids.add(String(ref.id));
|
||||||
const rows = Array.from(ids).map((id) => {
|
const rows = Array.from(ids).map((id) => {
|
||||||
|
const ref = snapshotEntitiesVisible.find((entity) => String(entity.id) === id) || null;
|
||||||
const found = entities.find((e) => e.id === id) || null;
|
const found = entities.find((e) => e.id === id) || null;
|
||||||
return { id, name: found?.name || id };
|
return {
|
||||||
|
id,
|
||||||
|
name: found?.name || id,
|
||||||
|
isNew: ref?.source === "inline" && ref?.operation === "create",
|
||||||
|
};
|
||||||
});
|
});
|
||||||
rows.sort((a, b) => a.name.localeCompare(b.name));
|
rows.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
return rows;
|
return rows;
|
||||||
@@ -328,41 +333,6 @@ export default function Page() {
|
|||||||
return normalizeFeatureBindingIds(selectedFeature);
|
return normalizeFeatureBindingIds(selectedFeature);
|
||||||
}, [selectedFeature]);
|
}, [selectedFeature]);
|
||||||
|
|
||||||
const createdEntities = useMemo(() => {
|
|
||||||
return (snapshotEntities || [])
|
|
||||||
.filter((e) => e && e.source === "inline" && e.operation === "create")
|
|
||||||
.map((e) => ({
|
|
||||||
id: String(e.id || ""),
|
|
||||||
name: String(e.name || "").trim() || String(e.id || ""),
|
|
||||||
}))
|
|
||||||
.filter((e) => e.id.length > 0 && e.name.length > 0);
|
|
||||||
}, [snapshotEntities]);
|
|
||||||
|
|
||||||
const createdGeometries = useMemo(() => {
|
|
||||||
const rows: Array<{
|
|
||||||
id: string | number;
|
|
||||||
geometryType: string;
|
|
||||||
semanticType?: string | null;
|
|
||||||
entityNames: string[];
|
|
||||||
}> = [];
|
|
||||||
|
|
||||||
for (const change of editor.changes.values()) {
|
|
||||||
if (change.action !== "create") continue;
|
|
||||||
const feature = change.feature;
|
|
||||||
const entityNames = normalizeFeatureEntityIds(feature)
|
|
||||||
.map((entityId) => entities.find((entity) => entity.id === entityId)?.name || entityId);
|
|
||||||
|
|
||||||
rows.push({
|
|
||||||
id: feature.properties.id,
|
|
||||||
geometryType: feature.geometry.type,
|
|
||||||
semanticType: feature.properties.type || getDefaultTypeIdForFeature(feature),
|
|
||||||
entityNames,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return rows;
|
|
||||||
}, [editor.changes, entities]);
|
|
||||||
|
|
||||||
const wikiDirty = useMemo(() => {
|
const wikiDirty = useMemo(() => {
|
||||||
const prev = normalizeWikisForCompare(baselineSnapshot?.wikis);
|
const prev = normalizeWikisForCompare(baselineSnapshot?.wikis);
|
||||||
const next = normalizeWikisForCompare(snapshotWikis);
|
const next = normalizeWikisForCompare(snapshotWikis);
|
||||||
@@ -1274,8 +1244,6 @@ export default function Page() {
|
|||||||
commits={sectionCommits}
|
commits={sectionCommits}
|
||||||
changesCount={pendingSaveCount}
|
changesCount={pendingSaveCount}
|
||||||
undoStack={editor.undoStack}
|
undoStack={editor.undoStack}
|
||||||
createdEntities={createdEntities}
|
|
||||||
createdGeometries={createdGeometries}
|
|
||||||
width={leftPanelWidth}
|
width={leftPanelWidth}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import { ToolsPanel } from "./editor/ToolsPanel";
|
|||||||
import { CommitPanel } from "./editor/CommitPanel";
|
import { CommitPanel } from "./editor/CommitPanel";
|
||||||
import { CommitHistoryPanel } from "./editor/CommitHistoryPanel";
|
import { CommitHistoryPanel } from "./editor/CommitHistoryPanel";
|
||||||
import { UndoListPanel } from "./editor/UndoListPanel";
|
import { UndoListPanel } from "./editor/UndoListPanel";
|
||||||
import { SessionPanel } from "./editor/SessionPanel";
|
|
||||||
import { SubmitModal } from "./editor/SubmitModal";
|
import { SubmitModal } from "./editor/SubmitModal";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -38,16 +37,6 @@ type Props = {
|
|||||||
}>;
|
}>;
|
||||||
changesCount: number;
|
changesCount: number;
|
||||||
undoStack: UndoAction[];
|
undoStack: UndoAction[];
|
||||||
createdEntities: Array<{
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
}>;
|
|
||||||
createdGeometries: Array<{
|
|
||||||
id: string | number;
|
|
||||||
geometryType: string;
|
|
||||||
semanticType?: string | null;
|
|
||||||
entityNames: string[];
|
|
||||||
}>;
|
|
||||||
width?: number;
|
width?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -72,8 +61,6 @@ export default function Editor({
|
|||||||
commits,
|
commits,
|
||||||
changesCount,
|
changesCount,
|
||||||
undoStack,
|
undoStack,
|
||||||
createdEntities,
|
|
||||||
createdGeometries,
|
|
||||||
width = 280,
|
width = 280,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [isSubmitModalOpen, setIsSubmitModalOpen] = useState(false);
|
const [isSubmitModalOpen, setIsSubmitModalOpen] = useState(false);
|
||||||
@@ -159,11 +146,6 @@ export default function Editor({
|
|||||||
|
|
||||||
<UndoListPanel undoStack={undoStack} />
|
<UndoListPanel undoStack={undoStack} />
|
||||||
|
|
||||||
<SessionPanel
|
|
||||||
createdEntities={createdEntities}
|
|
||||||
createdGeometries={createdGeometries}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<SubmitModal
|
<SubmitModal
|
||||||
isSubmitModalOpen={isSubmitModalOpen}
|
isSubmitModalOpen={isSubmitModalOpen}
|
||||||
submitContent={submitContent}
|
submitContent={submitContent}
|
||||||
|
|||||||
@@ -3,9 +3,19 @@
|
|||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import type { WikiSnapshot } from "@/uhm/types/wiki";
|
import type { WikiSnapshot } from "@/uhm/types/wiki";
|
||||||
import type { EntityWikiLinkSnapshot } from "@/uhm/types/projects";
|
import type { EntityWikiLinkSnapshot } from "@/uhm/types/projects";
|
||||||
|
import NewBadge from "@/uhm/components/editor/NewBadge";
|
||||||
|
|
||||||
type EntityChoice = { id: string; name: string };
|
type EntityChoice = { id: string; name: string; isNew?: boolean };
|
||||||
type WikiChoice = { id: string; title: string };
|
type WikiChoice = { id: string; title: string; isNew?: boolean };
|
||||||
|
type BindingRow = {
|
||||||
|
entityId: string;
|
||||||
|
entityName: string;
|
||||||
|
entityIsNew: boolean;
|
||||||
|
wikiId: string;
|
||||||
|
wikiTitle: string;
|
||||||
|
wikiIsNew: boolean;
|
||||||
|
linkIsNew: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
entities: EntityChoice[];
|
entities: EntityChoice[];
|
||||||
@@ -28,7 +38,11 @@ export default function EntityWikiBindingsPanel({ entities, wikis, links, setLin
|
|||||||
() =>
|
() =>
|
||||||
(wikis || [])
|
(wikis || [])
|
||||||
.filter((w) => w && typeof w.id === "string" && w.id.trim().length > 0)
|
.filter((w) => w && typeof w.id === "string" && w.id.trim().length > 0)
|
||||||
.map((w) => ({ id: w.id, title: wikiTitle(w) })),
|
.map((w) => ({
|
||||||
|
id: w.id,
|
||||||
|
title: wikiTitle(w),
|
||||||
|
isNew: w.source === "inline" && w.operation === "create",
|
||||||
|
})),
|
||||||
[wikis]
|
[wikis]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -48,6 +62,41 @@ export default function EntityWikiBindingsPanel({ entities, wikis, links, setLin
|
|||||||
return set;
|
return set;
|
||||||
}, [activeEntityId, links]);
|
}, [activeEntityId, links]);
|
||||||
|
|
||||||
|
const activeBindingRows = useMemo<BindingRow[]>(() => {
|
||||||
|
const byKey = new Map<string, EntityWikiLinkSnapshot>();
|
||||||
|
for (const link of links || []) {
|
||||||
|
const entityId = String(link?.entity_id || "").trim();
|
||||||
|
const wikiId = String(link?.wiki_id || "").trim();
|
||||||
|
if (!entityId || !wikiId) continue;
|
||||||
|
if (link.operation === "delete") continue;
|
||||||
|
byKey.set(`${entityId}::${wikiId}`, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rows = Array.from(byKey.values()).map((link) => {
|
||||||
|
const entityId = String(link.entity_id);
|
||||||
|
const wikiId = String(link.wiki_id);
|
||||||
|
const entity = entityChoices.find((item) => item.id === entityId) || null;
|
||||||
|
const wiki = wikiChoices.find((item) => item.id === wikiId) || null;
|
||||||
|
return {
|
||||||
|
entityId,
|
||||||
|
entityName: entity?.name || entityId,
|
||||||
|
entityIsNew: Boolean(entity?.isNew),
|
||||||
|
wikiId,
|
||||||
|
wikiTitle: wiki?.title || wikiId,
|
||||||
|
wikiIsNew: Boolean(wiki?.isNew),
|
||||||
|
linkIsNew: link.operation === "binding",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
rows.sort((a, b) => {
|
||||||
|
if (a.linkIsNew !== b.linkIsNew) return a.linkIsNew ? -1 : 1;
|
||||||
|
const entityCompare = a.entityName.localeCompare(b.entityName);
|
||||||
|
if (entityCompare !== 0) return entityCompare;
|
||||||
|
return a.wikiTitle.localeCompare(b.wikiTitle);
|
||||||
|
});
|
||||||
|
return rows;
|
||||||
|
}, [entityChoices, links, wikiChoices]);
|
||||||
|
|
||||||
const toggle = (wikiId: string) => {
|
const toggle = (wikiId: string) => {
|
||||||
if (!activeEntityId) return;
|
if (!activeEntityId) return;
|
||||||
const id = String(wikiId || "").trim();
|
const id = String(wikiId || "").trim();
|
||||||
@@ -69,6 +118,7 @@ export default function EntityWikiBindingsPanel({ entities, wikis, links, setLin
|
|||||||
|
|
||||||
const activeWikiLinked = activeEntityId && activeWikiId ? activeLinks.has(activeWikiId) : false;
|
const activeWikiLinked = activeEntityId && activeWikiId ? activeLinks.has(activeWikiId) : false;
|
||||||
const activeWikiChoice = activeWikiId ? wikiChoices.find((w) => w.id === activeWikiId) || null : null;
|
const activeWikiChoice = activeWikiId ? wikiChoices.find((w) => w.id === activeWikiId) || null : null;
|
||||||
|
const activeEntityChoice = activeEntityId ? entityChoices.find((e) => e.id === activeEntityId) || null : null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -82,7 +132,7 @@ export default function EntityWikiBindingsPanel({ entities, wikis, links, setLin
|
|||||||
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: "8px" }}>
|
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: "8px" }}>
|
||||||
<div style={{ fontWeight: 700, fontSize: "14px" }}>Entity ↔ Wiki</div>
|
<div style={{ fontWeight: 700, fontSize: "14px" }}>Entity ↔ Wiki</div>
|
||||||
<div style={{ display: "flex", alignItems: "center", gap: 8 }}>
|
<div style={{ display: "flex", alignItems: "center", gap: 8 }}>
|
||||||
<div style={{ fontSize: "12px", color: "#94a3b8" }}>{links.length}</div>
|
<div style={{ fontSize: "12px", color: "#94a3b8" }}>{activeBindingRows.length}</div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setCollapsed((v) => !v)}
|
onClick={() => setCollapsed((v) => !v)}
|
||||||
@@ -134,8 +184,9 @@ export default function EntityWikiBindingsPanel({ entities, wikis, links, setLin
|
|||||||
</select>
|
</select>
|
||||||
{activeEntityId ? (
|
{activeEntityId ? (
|
||||||
<ActiveSelectionLabel
|
<ActiveSelectionLabel
|
||||||
label={entityChoices.find((e) => e.id === activeEntityId)?.name || activeEntityId}
|
label={activeEntityChoice?.name || activeEntityId}
|
||||||
id={activeEntityId}
|
id={activeEntityId}
|
||||||
|
isNew={Boolean(activeEntityChoice?.isNew)}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
@@ -173,6 +224,7 @@ export default function EntityWikiBindingsPanel({ entities, wikis, links, setLin
|
|||||||
<ActiveSelectionLabel
|
<ActiveSelectionLabel
|
||||||
label={activeWikiChoice.title}
|
label={activeWikiChoice.title}
|
||||||
id={activeWikiChoice.id}
|
id={activeWikiChoice.id}
|
||||||
|
isNew={Boolean(activeWikiChoice.isNew)}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
@@ -275,6 +327,82 @@ export default function EntityWikiBindingsPanel({ entities, wikis, links, setLin
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
borderTop: "1px solid #1f2937",
|
||||||
|
paddingTop: 8,
|
||||||
|
display: "grid",
|
||||||
|
gap: 6,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div style={{ fontSize: 12, color: "#94a3b8" }}>
|
||||||
|
All bindings ({activeBindingRows.length})
|
||||||
|
</div>
|
||||||
|
{activeBindingRows.length ? (
|
||||||
|
<div style={{ display: "grid", gap: 6, maxHeight: 260, overflowY: "auto", paddingRight: 4 }}>
|
||||||
|
{activeBindingRows.map((row) => (
|
||||||
|
<div
|
||||||
|
key={`${row.entityId}::${row.wikiId}`}
|
||||||
|
style={{
|
||||||
|
padding: 8,
|
||||||
|
borderRadius: 6,
|
||||||
|
border: row.linkIsNew ? "1px solid rgba(45, 212, 191, 0.55)" : "1px solid #1f2937",
|
||||||
|
background: row.linkIsNew ? "rgba(20, 184, 166, 0.12)" : "#111827",
|
||||||
|
display: "grid",
|
||||||
|
gap: 5,
|
||||||
|
}}
|
||||||
|
title={`${row.entityId} ↔ ${row.wikiId}`}
|
||||||
|
>
|
||||||
|
<div style={{ display: "flex", alignItems: "center", gap: 6, minWidth: 0 }}>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: "#e5e7eb",
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: 800,
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
overflow: "hidden",
|
||||||
|
textOverflow: "ellipsis",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{row.entityName}
|
||||||
|
</span>
|
||||||
|
{row.entityIsNew ? <NewBadge title="Entity mới trong phiên này" /> : null}
|
||||||
|
{row.linkIsNew ? <NewBadge title="Binding mới trong phiên này" /> : null}
|
||||||
|
</div>
|
||||||
|
<div style={{ display: "flex", alignItems: "center", gap: 6, minWidth: 0 }}>
|
||||||
|
<span style={{ color: "#93c5fd", fontSize: 11, flex: "0 0 auto" }}>Wiki</span>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color: "#cbd5e1",
|
||||||
|
fontSize: 12,
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
overflow: "hidden",
|
||||||
|
textOverflow: "ellipsis",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{row.wikiTitle}
|
||||||
|
</span>
|
||||||
|
{row.wikiIsNew ? <NewBadge title="Wiki mới trong phiên này" /> : null}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
color: "#64748b",
|
||||||
|
fontSize: 11,
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
overflow: "hidden",
|
||||||
|
textOverflow: "ellipsis",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{row.entityId} ↔ {row.wikiId}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div style={{ fontSize: 12, color: "#94a3b8" }}>No entity-wiki binding yet.</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -284,9 +412,11 @@ export default function EntityWikiBindingsPanel({ entities, wikis, links, setLin
|
|||||||
function ActiveSelectionLabel({
|
function ActiveSelectionLabel({
|
||||||
label,
|
label,
|
||||||
id,
|
id,
|
||||||
|
isNew,
|
||||||
}: {
|
}: {
|
||||||
label: string;
|
label: string;
|
||||||
id: string;
|
id: string;
|
||||||
|
isNew?: boolean;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div style={{ marginTop: 6, display: "flex", alignItems: "center", gap: 6, minWidth: 0 }}>
|
<div style={{ marginTop: 6, display: "flex", alignItems: "center", gap: 6, minWidth: 0 }}>
|
||||||
@@ -296,6 +426,7 @@ function ActiveSelectionLabel({
|
|||||||
<span style={{ color: "#64748b", fontSize: 11, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }}>
|
<span style={{ color: "#64748b", fontSize: 11, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }}>
|
||||||
{id}
|
{id}
|
||||||
</span>
|
</span>
|
||||||
|
{isNew ? <NewBadge /> : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
import { Panel } from "./Panel";
|
|
||||||
|
|
||||||
type SessionPanelProps = {
|
|
||||||
createdEntities: Array<{
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
}>;
|
|
||||||
createdGeometries: Array<{
|
|
||||||
id: string | number;
|
|
||||||
geometryType: string;
|
|
||||||
semanticType?: string | null;
|
|
||||||
entityNames: string[];
|
|
||||||
}>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function SessionPanel({
|
|
||||||
createdEntities,
|
|
||||||
createdGeometries,
|
|
||||||
}: SessionPanelProps) {
|
|
||||||
return (
|
|
||||||
<Panel title="This Session" defaultOpen={false}>
|
|
||||||
<div style={{ fontSize: 13, color: "#cbd5e1", marginBottom: 6 }}>
|
|
||||||
Entities ({createdEntities.length})
|
|
||||||
</div>
|
|
||||||
{createdEntities.length === 0 ? (
|
|
||||||
<div style={{ color: "#64748b", fontSize: 12, marginBottom: 10 }}>Chưa tạo entity mới</div>
|
|
||||||
) : (
|
|
||||||
<ul style={{ listStyle: "none", margin: 0, padding: 0, fontSize: 12, marginBottom: 10 }}>
|
|
||||||
{createdEntities.map((entity) => (
|
|
||||||
<li
|
|
||||||
key={entity.id}
|
|
||||||
style={{ padding: "6px 0", borderBottom: "1px solid #1f2937", color: "#e2e8f0" }}
|
|
||||||
title={entity.id}
|
|
||||||
>
|
|
||||||
{entity.name}
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div style={{ fontSize: 13, color: "#cbd5e1", marginBottom: 6 }}>
|
|
||||||
Geometries mới chưa commit ({createdGeometries.length})
|
|
||||||
</div>
|
|
||||||
{createdGeometries.length === 0 ? (
|
|
||||||
<div style={{ color: "#64748b", fontSize: 12 }}>Chưa có geometry mới chờ commit</div>
|
|
||||||
) : (
|
|
||||||
<ul style={{ listStyle: "none", margin: 0, padding: 0, fontSize: 12 }}>
|
|
||||||
{createdGeometries.map((geometry) => (
|
|
||||||
<li
|
|
||||||
key={String(geometry.id)}
|
|
||||||
style={{ padding: "6px 0", borderBottom: "1px solid #1f2937", color: "#e2e8f0" }}
|
|
||||||
>
|
|
||||||
#{geometry.id} [{geometry.geometryType}]{" "}
|
|
||||||
{geometry.semanticType ? `- ${geometry.semanticType}` : ""}
|
|
||||||
{geometry.entityNames.length ? ` | ${geometry.entityNames.join(", ")}` : ""}
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
)}
|
|
||||||
</Panel>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user