@collabdt/core 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/core/components/AppSidebarContent.d.ts +2 -2
- package/dist/core/components/AppSidebarContent.d.ts.map +1 -1
- package/dist/core/components/AppSidebarContent.js +5 -4
- package/dist/core/components/AppSidebarContent.js.map +1 -1
- package/dist/core/components/Logo.d.ts +2 -0
- package/dist/core/components/Logo.d.ts.map +1 -1
- package/dist/core/components/Logo.js +8 -14
- package/dist/core/components/Logo.js.map +1 -1
- package/dist/core/components/Toolbar.d.ts +2 -2
- package/dist/core/components/Toolbar.d.ts.map +1 -1
- package/dist/core/components/Toolbar.js +4 -4
- package/dist/core/components/Toolbar.js.map +1 -1
- package/dist/core/components/authentication/AuthPage.d.ts +2 -2
- package/dist/core/components/authentication/AuthPage.d.ts.map +1 -1
- package/dist/core/components/authentication/AuthPage.js +6 -36
- package/dist/core/components/authentication/AuthPage.js.map +1 -1
- package/dist/core/components/authentication/Signin.d.ts +2 -2
- package/dist/core/components/authentication/Signin.d.ts.map +1 -1
- package/dist/core/components/authentication/Signin.js +2 -2
- package/dist/core/components/authentication/Signin.js.map +1 -1
- package/dist/core/components/settings/index.d.ts +2 -2
- package/dist/core/components/settings/index.d.ts.map +1 -1
- package/dist/core/components/settings/index.js +2 -2
- package/dist/core/components/settings/index.js.map +1 -1
- package/dist/core/components/settings/src/OrganizationSettingsPanel.d.ts +2 -2
- package/dist/core/components/settings/src/OrganizationSettingsPanel.d.ts.map +1 -1
- package/dist/core/components/settings/src/OrganizationSettingsPanel.js +3 -3
- package/dist/core/components/settings/src/OrganizationSettingsPanel.js.map +1 -1
- package/dist/core/components/settings/src/SettingsContent.d.ts +2 -2
- package/dist/core/components/settings/src/SettingsContent.d.ts.map +1 -1
- package/dist/core/components/settings/src/SettingsContent.js +2 -2
- package/dist/core/components/settings/src/SettingsContent.js.map +1 -1
- package/dist/core/components/ui/AppSidebar.d.ts +3 -1
- package/dist/core/components/ui/AppSidebar.d.ts.map +1 -1
- package/dist/core/components/ui/AppSidebar.js +2 -2
- package/dist/core/components/ui/AppSidebar.js.map +1 -1
- package/dist/core/components/ui/NavUser.d.ts +3 -1
- package/dist/core/components/ui/NavUser.d.ts.map +1 -1
- package/dist/core/components/ui/NavUser.js +15 -11
- package/dist/core/components/ui/NavUser.js.map +1 -1
- package/dist/core/components/ui/Sidebar.d.ts +1 -1
- package/dist/core/components/ui/Sidebar.d.ts.map +1 -1
- package/dist/core/components/ui/Sidebar.js +3 -3
- package/dist/core/components/ui/Sidebar.js.map +1 -1
- package/dist/core/components/ui/ViewerSidebar/index.d.ts +2 -2
- package/dist/core/components/ui/ViewerSidebar/index.d.ts.map +1 -1
- package/dist/core/components/ui/ViewerSidebar/index.js +2 -2
- package/dist/core/components/ui/ViewerSidebar/index.js.map +1 -1
- package/dist/core/components/usage/SortHeader.d.ts +18 -0
- package/dist/core/components/usage/SortHeader.d.ts.map +1 -0
- package/dist/core/components/usage/SortHeader.js +25 -0
- package/dist/core/components/usage/SortHeader.js.map +1 -0
- package/dist/core/components/usage/StatCard.d.ts +9 -0
- package/dist/core/components/usage/StatCard.d.ts.map +1 -0
- package/dist/core/components/usage/StatCard.js +18 -0
- package/dist/core/components/usage/StatCard.js.map +1 -0
- package/dist/core/components/usage/UsagePanels.d.ts +15 -0
- package/dist/core/components/usage/UsagePanels.d.ts.map +1 -0
- package/dist/core/components/usage/UsagePanels.js +43 -0
- package/dist/core/components/usage/UsagePanels.js.map +1 -0
- package/dist/core/components/usage/UserUsageTable.d.ts +14 -0
- package/dist/core/components/usage/UserUsageTable.d.ts.map +1 -0
- package/dist/core/components/usage/UserUsageTable.js +64 -0
- package/dist/core/components/usage/UserUsageTable.js.map +1 -0
- package/dist/core/components/usage/VolumeOverview.d.ts +5 -0
- package/dist/core/components/usage/VolumeOverview.d.ts.map +1 -0
- package/dist/core/components/usage/VolumeOverview.js +81 -0
- package/dist/core/components/usage/VolumeOverview.js.map +1 -0
- package/dist/core/components/usage/usagePalette.d.ts +21 -0
- package/dist/core/components/usage/usagePalette.d.ts.map +1 -0
- package/dist/core/components/usage/usagePalette.js +10 -0
- package/dist/core/components/usage/usagePalette.js.map +1 -0
- package/dist/core/components/viewers/Data/siteDetails/AssociatedBuildings.js.map +1 -1
- package/dist/core/components/viewers/Viewer.d.ts +2 -2
- package/dist/core/components/viewers/Viewer.d.ts.map +1 -1
- package/dist/core/components/viewers/Viewer.js +3 -3
- package/dist/core/components/viewers/Viewer.js.map +1 -1
- package/dist/core/components/viewers/map/datasets/RowActions.js +9 -9
- package/dist/core/components/viewers/map/datasets/RowActions.js.map +1 -1
- package/dist/core/components/viewers/map/datasets/src/orgFileDatasets.d.ts +4 -0
- package/dist/core/components/viewers/map/datasets/src/orgFileDatasets.d.ts.map +1 -0
- package/dist/core/components/viewers/map/datasets/src/{minioDatasets.js → orgFileDatasets.js} +5 -5
- package/dist/core/components/viewers/map/datasets/src/orgFileDatasets.js.map +1 -0
- package/dist/core/components/viewers/map/datasets/src/useOrganizationalDatasets.d.ts +1 -1
- package/dist/core/components/viewers/map/datasets/src/useOrganizationalDatasets.js +4 -4
- package/dist/core/components/viewers/map/datasets/src/useOrganizationalDatasets.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/SiteLayer/siteGeometry.d.ts +3 -3
- package/dist/core/components/viewers/map/src/MapLayers/src/SiteLayer/siteGeometry.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/SiteLayer/siteGeometry.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/SiteLayer/useShowSitesOnMap.d.ts +1 -1
- package/dist/core/components/viewers/map/src/MapLayers/src/SiteLayer/useShowSitesOnMap.js.map +1 -1
- package/dist/core/components/viewers/map/src/MapSidebar/index.d.ts +2 -2
- package/dist/core/components/viewers/map/src/MapSidebar/index.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/MapSidebar/index.js +1 -1
- package/dist/core/components/viewers/map/src/MapSidebar/index.js.map +1 -1
- package/dist/core/components/viewers/map/src/tools/AddTools/AddDataset/DatasetAdder.d.ts +1 -1
- package/dist/core/components/viewers/map/src/tools/AddTools/AddDataset/DatasetAdder.js +1 -1
- package/dist/core/components/viewers/map/src/tools/AddTools/AddDataset/DatasetAdder.js.map +1 -1
- package/dist/core/components/viewers/map/src/tools/AddTools/AddFile/utils/uploadToPresignedURLS.js.map +1 -1
- package/dist/core/components/viewers/map/src/tools/AddTools/AddSite/persistSite.d.ts +3 -3
- package/dist/core/components/viewers/map/src/tools/AddTools/AddSite/persistSite.js.map +1 -1
- package/dist/core/components/viewers/map/src/tools/mapTools.d.ts +1 -1
- package/dist/core/components/viewers/map/src/tools/mapTools.d.ts.map +1 -1
- package/dist/core/components/viewers/map/src/tools/mapTools.js.map +1 -1
- package/dist/core/hooks/ports/apiAdapter.d.ts +3 -0
- package/dist/core/hooks/ports/apiAdapter.d.ts.map +1 -1
- package/dist/core/hooks/provider.d.ts +2 -0
- package/dist/core/hooks/provider.d.ts.map +1 -1
- package/dist/core/hooks/provider.js +3 -1
- package/dist/core/hooks/provider.js.map +1 -1
- package/dist/core/hooks/usage/createUsageHooks.d.ts +15 -0
- package/dist/core/hooks/usage/createUsageHooks.d.ts.map +1 -0
- package/dist/core/hooks/usage/createUsageHooks.js +16 -0
- package/dist/core/hooks/usage/createUsageHooks.js.map +1 -0
- package/dist/core/hooks/usage/usage.d.ts +11 -0
- package/dist/core/hooks/usage/usage.d.ts.map +1 -0
- package/dist/core/hooks/usage/usage.js +11 -0
- package/dist/core/hooks/usage/usage.js.map +1 -0
- package/dist/core/hooks/useFirstLoadableImage.d.ts +3 -0
- package/dist/core/hooks/useFirstLoadableImage.d.ts.map +1 -0
- package/dist/core/hooks/useFirstLoadableImage.js +46 -0
- package/dist/core/hooks/useFirstLoadableImage.js.map +1 -0
- package/dist/core/i18n/messages/en.json +31 -0
- package/dist/core/i18n/messages/es.json +31 -0
- package/dist/core/i18n/messages/fr.json +31 -0
- package/dist/core/plugins/sdk/types.d.ts +2 -0
- package/dist/core/plugins/sdk/types.d.ts.map +1 -1
- package/dist/core/plugins/sdk/types.js.map +1 -1
- package/dist/core/store/AppConfig/context.d.ts +1 -1
- package/dist/core/store/AppConfig/context.d.ts.map +1 -1
- package/dist/core/store/AppConfig/context.js.map +1 -1
- package/dist/core/store/MapSites/reducer.d.ts +2 -2
- package/dist/core/store/MapSites/reducer.d.ts.map +1 -1
- package/dist/core/store/MapSites/reducer.js.map +1 -1
- package/dist/core/types/usage.d.ts +36 -0
- package/dist/core/types/usage.d.ts.map +1 -0
- package/dist/core/types/usage.js +1 -0
- package/dist/core/types/usage.js.map +1 -0
- package/dist/core/utils/csv.d.ts +7 -0
- package/dist/core/utils/csv.d.ts.map +1 -0
- package/dist/core/utils/csv.js +23 -0
- package/dist/core/utils/csv.js.map +1 -0
- package/dist/core/utils/orgLogo.d.ts +6 -0
- package/dist/core/utils/orgLogo.d.ts.map +1 -0
- package/dist/core/utils/orgLogo.js +15 -0
- package/dist/core/utils/orgLogo.js.map +1 -0
- package/dist/core/utils/usageCsv.d.ts +3 -0
- package/dist/core/utils/usageCsv.d.ts.map +1 -0
- package/dist/core/utils/usageCsv.js +14 -0
- package/dist/core/utils/usageCsv.js.map +1 -0
- package/dist/core/utils/usageFormat.d.ts +6 -0
- package/dist/core/utils/usageFormat.d.ts.map +1 -0
- package/dist/core/utils/usageFormat.js +34 -0
- package/dist/core/utils/usageFormat.js.map +1 -0
- package/package.json +1 -1
- package/dist/core/components/viewers/map/datasets/src/minioDatasets.d.ts +0 -4
- package/dist/core/components/viewers/map/datasets/src/minioDatasets.d.ts.map +0 -1
- package/dist/core/components/viewers/map/datasets/src/minioDatasets.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
"use client";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useLocale, useTranslations } from "next-intl";
|
|
6
|
+
import { useMemo, useState } from "react";
|
|
7
|
+
import { gbFormatter, numberFormatter, relativeTime } from "../../utils/usageFormat";
|
|
8
|
+
import { Card, CardContent, CardHeader, CardTitle } from "../ui/Card";
|
|
9
|
+
import { Table, TableBody, TableCell, TableHeader, TableRow } from "../ui/Table";
|
|
10
|
+
import { compareValues, nextSort, SortHeader } from "./SortHeader";
|
|
11
|
+
const TEXT_COLUMNS = ["name", "organization"];
|
|
12
|
+
function sortValue(row, key) {
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
if (key === "name") return ((_a = row.name) != null ? _a : "").toLowerCase();
|
|
15
|
+
if (key === "organization") return ((_b = row.organizationTitle) != null ? _b : row.organizationName).toLowerCase();
|
|
16
|
+
if (key === "lastUploadAt") return (_c = row.lastUploadAt) != null ? _c : "";
|
|
17
|
+
return row[key];
|
|
18
|
+
}
|
|
19
|
+
function sortUserRows(rows, sort) {
|
|
20
|
+
const direction = sort.descending ? -1 : 1;
|
|
21
|
+
return [...rows].sort((a, b) => direction * compareValues(sortValue(a, sort.key), sortValue(b, sort.key)));
|
|
22
|
+
}
|
|
23
|
+
function UserUsageTable({ rows, showOrganization, actions }) {
|
|
24
|
+
const t = useTranslations("UsageReport.table");
|
|
25
|
+
const locale = useLocale();
|
|
26
|
+
const gb = gbFormatter(locale);
|
|
27
|
+
const count = numberFormatter(locale, 0);
|
|
28
|
+
const [sort, setSort] = useState({ key: "storedGB", descending: true });
|
|
29
|
+
const sorted = useMemo(() => sortUserRows(rows, sort), [rows, sort]);
|
|
30
|
+
const onSort = (key) => setSort((current) => nextSort(current, key, TEXT_COLUMNS));
|
|
31
|
+
return /* @__PURE__ */ jsxs(Card, { children: [
|
|
32
|
+
/* @__PURE__ */ jsxs(CardHeader, { className: "flex flex-row flex-wrap items-center justify-between gap-3 space-y-0", children: [
|
|
33
|
+
/* @__PURE__ */ jsx(CardTitle, { children: t("title") }),
|
|
34
|
+
actions
|
|
35
|
+
] }),
|
|
36
|
+
/* @__PURE__ */ jsx(CardContent, { children: sorted.length === 0 ? /* @__PURE__ */ jsx("p", { className: "py-8 text-center text-sm text-muted-foreground", children: t("empty") }) : /* @__PURE__ */ jsxs(Table, { children: [
|
|
37
|
+
/* @__PURE__ */ jsx(TableHeader, { children: /* @__PURE__ */ jsxs(TableRow, { children: [
|
|
38
|
+
/* @__PURE__ */ jsx(SortHeader, { column: "name", sort, onSort, children: t("user") }),
|
|
39
|
+
showOrganization && /* @__PURE__ */ jsx(SortHeader, { column: "organization", sort, onSort, children: t("organization") }),
|
|
40
|
+
/* @__PURE__ */ jsx(SortHeader, { column: "storedGB", sort, onSort, numeric: true, children: t("stored") }),
|
|
41
|
+
/* @__PURE__ */ jsx(SortHeader, { column: "fileCount", sort, onSort, numeric: true, children: t("files") }),
|
|
42
|
+
/* @__PURE__ */ jsx(SortHeader, { column: "lastUploadAt", sort, onSort, numeric: true, children: t("lastUpload") })
|
|
43
|
+
] }) }),
|
|
44
|
+
/* @__PURE__ */ jsx(TableBody, { children: sorted.map((row) => {
|
|
45
|
+
var _a, _b, _c, _d;
|
|
46
|
+
return /* @__PURE__ */ jsxs(TableRow, { children: [
|
|
47
|
+
/* @__PURE__ */ jsx(TableCell, { children: row.userId === null ? /* @__PURE__ */ jsx("span", { className: "italic text-muted-foreground", children: t("unattributed") }) : /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
48
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium", children: (_b = row.name) != null ? _b : t("deletedUser") }),
|
|
49
|
+
row.email && /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: row.email })
|
|
50
|
+
] }) }),
|
|
51
|
+
showOrganization && /* @__PURE__ */ jsx(TableCell, { children: (_c = row.organizationTitle) != null ? _c : row.organizationName }),
|
|
52
|
+
/* @__PURE__ */ jsx(TableCell, { className: "text-right tabular-nums", children: gb(row.storedGB) }),
|
|
53
|
+
/* @__PURE__ */ jsx(TableCell, { className: "text-right tabular-nums", children: count(row.fileCount) }),
|
|
54
|
+
/* @__PURE__ */ jsx(TableCell, { className: "text-right text-muted-foreground", children: (_d = relativeTime(locale, row.lastUploadAt)) != null ? _d : "\u2014" })
|
|
55
|
+
] }, `${(_a = row.userId) != null ? _a : "none"}-${row.organizationName}`);
|
|
56
|
+
}) })
|
|
57
|
+
] }) })
|
|
58
|
+
] });
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
UserUsageTable,
|
|
62
|
+
sortUserRows
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=UserUsageTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/components/usage/UserUsageTable.tsx"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport { useLocale, useTranslations } from 'next-intl'\n\nimport { useMemo, useState } from 'react'\n\nimport { gbFormatter, numberFormatter, relativeTime } from '../../utils/usageFormat'\nimport { Card, CardContent, CardHeader, CardTitle } from '../ui/Card'\nimport { Table, TableBody, TableCell, TableHeader, TableRow } from '../ui/Table'\n\nimport { compareValues, nextSort, SortHeader } from './SortHeader'\n\n\nimport type { SortState as GenericSortState } from './SortHeader'\nimport type { UserUsageRow } from '../../types/usage'\nimport type { ReactNode } from 'react'\n\ntype SortKey = 'name' | 'organization' | 'storedGB' | 'fileCount' | 'lastUploadAt'\ntype SortState = GenericSortState<SortKey>\n\nconst TEXT_COLUMNS: readonly SortKey[] = ['name', 'organization']\n\nfunction sortValue(row: UserUsageRow, key: SortKey): string | number {\n if (key === 'name') return (row.name ?? '').toLowerCase()\n if (key === 'organization') return (row.organizationTitle ?? row.organizationName).toLowerCase()\n if (key === 'lastUploadAt') return row.lastUploadAt ?? ''\n return row[key]\n}\n\nexport function sortUserRows(rows: readonly UserUsageRow[], sort: SortState): UserUsageRow[] {\n const direction = sort.descending ? -1 : 1\n return [...rows].sort((a, b) => direction * compareValues(sortValue(a, sort.key), sortValue(b, sort.key)))\n}\n\ninterface UserUsageTableProps {\n rows: readonly UserUsageRow[]\n showOrganization: boolean\n actions?: ReactNode\n}\n\nexport function UserUsageTable({ rows, showOrganization, actions }: UserUsageTableProps) {\n const t = useTranslations('UsageReport.table')\n const locale = useLocale()\n const gb = gbFormatter(locale)\n const count = numberFormatter(locale, 0)\n const [sort, setSort] = useState<SortState>({ key: 'storedGB', descending: true })\n const sorted = useMemo(() => sortUserRows(rows, sort), [rows, sort])\n const onSort = (key: SortKey) => setSort(current => nextSort(current, key, TEXT_COLUMNS))\n\n return (\n <Card>\n <CardHeader className=\"flex flex-row flex-wrap items-center justify-between gap-3 space-y-0\">\n <CardTitle>{t('title')}</CardTitle>\n {actions}\n </CardHeader>\n <CardContent>\n {sorted.length === 0 ? (\n <p className=\"py-8 text-center text-sm text-muted-foreground\">{t('empty')}</p>\n ) : (\n <Table>\n <TableHeader>\n <TableRow>\n <SortHeader column=\"name\" sort={sort} onSort={onSort}>{t('user')}</SortHeader>\n {showOrganization && <SortHeader column=\"organization\" sort={sort} onSort={onSort}>{t('organization')}</SortHeader>}\n <SortHeader column=\"storedGB\" sort={sort} onSort={onSort} numeric>{t('stored')}</SortHeader>\n <SortHeader column=\"fileCount\" sort={sort} onSort={onSort} numeric>{t('files')}</SortHeader>\n <SortHeader column=\"lastUploadAt\" sort={sort} onSort={onSort} numeric>{t('lastUpload')}</SortHeader>\n </TableRow>\n </TableHeader>\n <TableBody>\n {sorted.map(row => (\n <TableRow key={`${row.userId ?? 'none'}-${row.organizationName}`}>\n <TableCell>\n {row.userId === null ? (\n <span className=\"italic text-muted-foreground\">{t('unattributed')}</span>\n ) : (\n <div className=\"flex flex-col\">\n <span className=\"font-medium\">{row.name ?? t('deletedUser')}</span>\n {row.email && <span className=\"text-xs text-muted-foreground\">{row.email}</span>}\n </div>\n )}\n </TableCell>\n {showOrganization && <TableCell>{row.organizationTitle ?? row.organizationName}</TableCell>}\n <TableCell className=\"text-right tabular-nums\">{gb(row.storedGB)}</TableCell>\n <TableCell className=\"text-right tabular-nums\">{count(row.fileCount)}</TableCell>\n <TableCell className=\"text-right text-muted-foreground\">{relativeTime(locale, row.lastUploadAt) ?? '—'}</TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n )}\n </CardContent>\n </Card>\n )\n}\n"],"mappings":";AAsDM,SACE,KADF;AAjDN,SAAS,WAAW,uBAAuB;AAE3C,SAAS,SAAS,gBAAgB;AAElC,SAAS,aAAa,iBAAiB,oBAAoB;AAC3D,SAAS,MAAM,aAAa,YAAY,iBAAiB;AACzD,SAAS,OAAO,WAAW,WAAW,aAAa,gBAAgB;AAEnE,SAAS,eAAe,UAAU,kBAAkB;AAUpD,MAAM,eAAmC,CAAC,QAAQ,cAAc;AAEhE,SAAS,UAAU,KAAmB,KAA+B;AAzBrE;AA0BE,MAAI,QAAQ,OAAQ,UAAQ,SAAI,SAAJ,YAAY,IAAI,YAAY;AACxD,MAAI,QAAQ,eAAgB,UAAQ,SAAI,sBAAJ,YAAyB,IAAI,kBAAkB,YAAY;AAC/F,MAAI,QAAQ,eAAgB,SAAO,SAAI,iBAAJ,YAAoB;AACvD,SAAO,IAAI,GAAG;AAChB;AAEO,SAAS,aAAa,MAA+B,MAAiC;AAC3F,QAAM,YAAY,KAAK,aAAa,KAAK;AACzC,SAAO,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,MAAM,YAAY,cAAc,UAAU,GAAG,KAAK,GAAG,GAAG,UAAU,GAAG,KAAK,GAAG,CAAC,CAAC;AAC3G;AAQO,SAAS,eAAe,EAAE,MAAM,kBAAkB,QAAQ,GAAwB;AACvF,QAAM,IAAI,gBAAgB,mBAAmB;AAC7C,QAAM,SAAS,UAAU;AACzB,QAAM,KAAK,YAAY,MAAM;AAC7B,QAAM,QAAQ,gBAAgB,QAAQ,CAAC;AACvC,QAAM,CAAC,MAAM,OAAO,IAAI,SAAoB,EAAE,KAAK,YAAY,YAA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;AAAA,UAC/E,oBAAC,aAAU,WAAU,2BAA2B,aAAG,IAAI,QAAQ,GAAE;AAAA,UACjE,oBAAC,aAAU,WAAU,2BAA2B,gBAAM,IAAI,SAAS,GAAE;AAAA,UACrE,oBAAC,aAAU,WAAU,oCAAoC,6BAAa,QAAQ,IAAI,YAAY,MAArC,YAA0C,UAAI;AAAA,aAd1F,IAAG,SAAI,WAAJ,YAAc,MAAM,IAAI,IAAI,gBAAgB,EAe9D;AAAA,OACD,GACH;AAAA,OACF,GAEJ;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VolumeOverview.d.ts","sourceRoot":"","sources":["../../../../src/core/components/usage/VolumeOverview.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAA8B,YAAY,EAAE,MAAM,mBAAmB,CAAA;AA6EjF,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,+BAwBlE"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
"use client";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { CalendarClock, Database, Files } from "lucide-react";
|
|
6
|
+
import { useLocale, useTranslations } from "next-intl";
|
|
7
|
+
import { Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts";
|
|
8
|
+
import { gbFormatter, monthLabel, numberFormatter } from "../../utils/usageFormat";
|
|
9
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui/Card";
|
|
10
|
+
import { ChartContainer, ChartTooltip, ChartTooltipContent } from "../ui/chart";
|
|
11
|
+
import { StatCard } from "./StatCard";
|
|
12
|
+
import { USAGE_COLORS } from "./usagePalette";
|
|
13
|
+
const CHART_HEIGHT = 220;
|
|
14
|
+
function uploadedRowFormatter(gb, label) {
|
|
15
|
+
return (value) => /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center justify-between gap-4", children: [
|
|
16
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: label }),
|
|
17
|
+
/* @__PURE__ */ jsx("span", { className: "font-mono font-medium tabular-nums text-foreground", children: gb(Number(value)) })
|
|
18
|
+
] });
|
|
19
|
+
}
|
|
20
|
+
function UploadsByMonthChart({ months }) {
|
|
21
|
+
const t = useTranslations("UsageReport.chart");
|
|
22
|
+
const locale = useLocale();
|
|
23
|
+
const gb = gbFormatter(locale);
|
|
24
|
+
const config = { uploadedGB: { label: t("uploaded"), theme: USAGE_COLORS.storage } };
|
|
25
|
+
const shortMonth = (month) => monthLabel(locale, month);
|
|
26
|
+
return /* @__PURE__ */ jsxs(Card, { children: [
|
|
27
|
+
/* @__PURE__ */ jsxs(CardHeader, { children: [
|
|
28
|
+
/* @__PURE__ */ jsx(CardTitle, { children: t("title") }),
|
|
29
|
+
/* @__PURE__ */ jsx(CardDescription, { children: t("description") })
|
|
30
|
+
] }),
|
|
31
|
+
/* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsx(ChartContainer, { config, className: "aspect-auto w-full", style: { height: CHART_HEIGHT }, children: /* @__PURE__ */ jsxs(BarChart, { data: [...months], margin: { left: 4, right: 8, top: 4, bottom: 4 }, children: [
|
|
32
|
+
/* @__PURE__ */ jsx(CartesianGrid, { vertical: false, className: "stroke-border/60" }),
|
|
33
|
+
/* @__PURE__ */ jsx(XAxis, { dataKey: "month", tickLine: false, axisLine: false, tickMargin: 6, tickFormatter: (value) => shortMonth(String(value)) }),
|
|
34
|
+
/* @__PURE__ */ jsx(YAxis, { tickLine: false, axisLine: false, width: 64, tickFormatter: (value) => gb(Number(value)) }),
|
|
35
|
+
/* @__PURE__ */ jsx(ChartTooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, { labelFormatter: (value) => shortMonth(String(value)), formatter: uploadedRowFormatter(gb, t("uploaded")) }) }),
|
|
36
|
+
/* @__PURE__ */ jsx(Bar, { dataKey: "uploadedGB", fill: "var(--color-uploadedGB)", radius: [4, 4, 0, 0] })
|
|
37
|
+
] }) }) })
|
|
38
|
+
] });
|
|
39
|
+
}
|
|
40
|
+
function TypeBreakdown({ types }) {
|
|
41
|
+
const t = useTranslations("UsageReport.byType");
|
|
42
|
+
const locale = useLocale();
|
|
43
|
+
const gb = gbFormatter(locale);
|
|
44
|
+
const largest = Math.max(...types.map((type) => type.storedGB), 0);
|
|
45
|
+
return /* @__PURE__ */ jsxs(Card, { children: [
|
|
46
|
+
/* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsx(CardTitle, { children: t("title") }) }),
|
|
47
|
+
/* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsx("ul", { className: "space-y-3", children: types.map((type) => /* @__PURE__ */ jsxs("li", { className: "space-y-1", children: [
|
|
48
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-baseline justify-between gap-4 text-sm", children: [
|
|
49
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: type.type }),
|
|
50
|
+
/* @__PURE__ */ jsxs("span", { className: "shrink-0 tabular-nums text-muted-foreground", children: [
|
|
51
|
+
gb(type.storedGB),
|
|
52
|
+
" \xB7 ",
|
|
53
|
+
t("files", { count: type.fileCount })
|
|
54
|
+
] })
|
|
55
|
+
] }),
|
|
56
|
+
/* @__PURE__ */ jsx("div", { className: "h-1.5 w-full rounded-full bg-muted", children: /* @__PURE__ */ jsx("div", { className: "h-full rounded-full bg-primary", style: { width: `${largest > 0 ? 100 * type.storedGB / largest : 0}%` } }) })
|
|
57
|
+
] }, type.type)) }) })
|
|
58
|
+
] });
|
|
59
|
+
}
|
|
60
|
+
function VolumeOverview({ report }) {
|
|
61
|
+
const t = useTranslations("UsageReport.stats");
|
|
62
|
+
const locale = useLocale();
|
|
63
|
+
const gb = gbFormatter(locale);
|
|
64
|
+
const count = numberFormatter(locale, 0);
|
|
65
|
+
const lastMonth = report.byMonth.at(-1);
|
|
66
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
|
|
67
|
+
/* @__PURE__ */ jsxs("section", { className: "grid gap-4 sm:grid-cols-3", children: [
|
|
68
|
+
/* @__PURE__ */ jsx(StatCard, { icon: Database, label: t("stored"), value: gb(report.totals.storedGB), children: report.totals.unsizedCount > 0 && /* @__PURE__ */ jsx("p", { children: t("unsized", { count: report.totals.unsizedCount }) }) }),
|
|
69
|
+
/* @__PURE__ */ jsx(StatCard, { icon: Files, label: t("files"), value: count(report.totals.fileCount) }),
|
|
70
|
+
/* @__PURE__ */ jsx(StatCard, { icon: CalendarClock, label: t("latestMonth"), value: lastMonth ? gb(lastMonth.uploadedGB) : "\u2014", children: lastMonth && /* @__PURE__ */ jsx("p", { children: monthLabel(locale, lastMonth.month) }) })
|
|
71
|
+
] }),
|
|
72
|
+
/* @__PURE__ */ jsxs("div", { className: "grid gap-6 xl:grid-cols-[minmax(0,7fr)_minmax(0,5fr)]", children: [
|
|
73
|
+
/* @__PURE__ */ jsx(UploadsByMonthChart, { months: report.byMonth }),
|
|
74
|
+
/* @__PURE__ */ jsx(TypeBreakdown, { types: report.byType })
|
|
75
|
+
] })
|
|
76
|
+
] });
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
VolumeOverview
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=VolumeOverview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/components/usage/VolumeOverview.tsx"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\nimport { CalendarClock, Database, Files } from 'lucide-react'\nimport { useLocale, useTranslations } from 'next-intl'\nimport { Bar, BarChart, CartesianGrid, XAxis, YAxis } from 'recharts'\n\nimport { gbFormatter, monthLabel, numberFormatter } from '../../utils/usageFormat'\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/Card'\nimport { ChartContainer, ChartTooltip, ChartTooltipContent } from '../ui/chart'\n\nimport { StatCard } from './StatCard'\nimport { USAGE_COLORS } from './usagePalette'\n\nimport type { MonthlyUploads, TypeVolume, VolumeReport } from '../../types/usage'\nimport type { ChartConfig } from '../ui/chart'\nimport type { ComponentProps } from 'react'\n\nconst CHART_HEIGHT = 220\n\ntype TooltipFormatter = NonNullable<ComponentProps<typeof ChartTooltipContent>['formatter']>\n\nfunction uploadedRowFormatter(gb: (value: number) => string, label: string): TooltipFormatter {\n return value => (\n <div className=\"flex w-full items-center justify-between gap-4\">\n <span className=\"text-muted-foreground\">{label}</span>\n <span className=\"font-mono font-medium tabular-nums text-foreground\">{gb(Number(value))}</span>\n </div>\n )\n}\n\nfunction UploadsByMonthChart({ months }: { months: readonly MonthlyUploads[] }) {\n const t = useTranslations('UsageReport.chart')\n const locale = useLocale()\n const gb = gbFormatter(locale)\n const config = { uploadedGB: { label: t('uploaded'), theme: USAGE_COLORS.storage } } satisfies ChartConfig\n const shortMonth = (month: string) => monthLabel(locale, month)\n\n return (\n <Card>\n <CardHeader>\n <CardTitle>{t('title')}</CardTitle>\n <CardDescription>{t('description')}</CardDescription>\n </CardHeader>\n <CardContent>\n <ChartContainer config={config} className=\"aspect-auto w-full\" style={{ height: CHART_HEIGHT }}>\n <BarChart data={[...months]} margin={{ left: 4, right: 8, top: 4, bottom: 4 }}>\n <CartesianGrid vertical={false} className=\"stroke-border/60\" />\n <XAxis dataKey=\"month\" tickLine={false} axisLine={false} tickMargin={6} tickFormatter={value => shortMonth(String(value))} />\n <YAxis tickLine={false} axisLine={false} width={64} tickFormatter={value => gb(Number(value))} />\n <ChartTooltip content={<ChartTooltipContent labelFormatter={value => shortMonth(String(value))} formatter={uploadedRowFormatter(gb, t('uploaded'))} />} />\n <Bar dataKey=\"uploadedGB\" fill=\"var(--color-uploadedGB)\" radius={[4, 4, 0, 0]} />\n </BarChart>\n </ChartContainer>\n </CardContent>\n </Card>\n )\n}\n\nfunction TypeBreakdown({ types }: { types: readonly TypeVolume[] }) {\n const t = useTranslations('UsageReport.byType')\n const locale = useLocale()\n const gb = gbFormatter(locale)\n const largest = Math.max(...types.map(type => type.storedGB), 0)\n\n return (\n <Card>\n <CardHeader>\n <CardTitle>{t('title')}</CardTitle>\n </CardHeader>\n <CardContent>\n <ul className=\"space-y-3\">\n {types.map(type => (\n <li key={type.type} className=\"space-y-1\">\n <div className=\"flex items-baseline justify-between gap-4 text-sm\">\n <span className=\"truncate\">{type.type}</span>\n <span className=\"shrink-0 tabular-nums text-muted-foreground\">\n {gb(type.storedGB)} · {t('files', { count: type.fileCount })}\n </span>\n </div>\n <div className=\"h-1.5 w-full rounded-full bg-muted\">\n <div className=\"h-full rounded-full bg-primary\" style={{ width: `${largest > 0 ? (100 * type.storedGB) / largest : 0}%` }} />\n </div>\n </li>\n ))}\n </ul>\n </CardContent>\n </Card>\n )\n}\n\nexport function VolumeOverview({ report }: { report: VolumeReport }) {\n const t = useTranslations('UsageReport.stats')\n const locale = useLocale()\n const gb = gbFormatter(locale)\n const count = numberFormatter(locale, 0)\n const lastMonth = report.byMonth.at(-1)\n\n return (\n <div className=\"flex flex-col gap-6\">\n <section className=\"grid gap-4 sm:grid-cols-3\">\n <StatCard icon={Database} label={t('stored')} value={gb(report.totals.storedGB)}>\n {report.totals.unsizedCount > 0 && <p>{t('unsized', { count: report.totals.unsizedCount })}</p>}\n </StatCard>\n <StatCard icon={Files} label={t('files')} value={count(report.totals.fileCount)} />\n <StatCard icon={CalendarClock} label={t('latestMonth')} value={lastMonth ? gb(lastMonth.uploadedGB) : '—'}>\n {lastMonth && <p>{monthLabel(locale, lastMonth.month)}</p>}\n </StatCard>\n </section>\n <div className=\"grid gap-6 xl:grid-cols-[minmax(0,7fr)_minmax(0,5fr)]\">\n <UploadsByMonthChart months={report.byMonth} />\n <TypeBreakdown types={report.byType} />\n </div>\n </div>\n )\n}\n"],"mappings":";AA0BI,SACE,KADF;AArBJ,SAAS,eAAe,UAAU,aAAa;AAC/C,SAAS,WAAW,u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IAAI,gBAAgB,mBAAmB;AAC7C,QAAM,SAAS,UAAU;AACzB,QAAM,KAAK,YAAY,MAAM;AAC7B,QAAM,QAAQ,gBAAgB,QAAQ,CAAC;AACvC,QAAM,YAAY,OAAO,QAAQ,GAAG,EAAE;AAEtC,SACE,qBAAC,SAAI,WAAU,uBACb;AAAA,yBAAC,aAAQ,WAAU,6BACjB;AAAA,0BAAC,YAAS,MAAM,UAAU,OAAO,EAAE,QAAQ,GAAG,OAAO,GAAG,OAAO,OAAO,QAAQ,GAC3E,iBAAO,OAAO,eAAe,KAAK,oBAAC,OAAG,YAAE,WAAW,EAAE,OAAO,OAAO,OAAO,aAAa,CAAC,GAAE,GAC7F;AAAA,MACA,oBAAC,YAAS,MAAM,OAAO,OAAO,EAAE,OAAO,GAAG,OAAO,MAAM,OAAO,OAAO,SAAS,GAAG;AAAA,MACjF,oBAAC,YAAS,MAAM,eAAe,OAAO,EAAE,aAAa,GAAG,OAAO,YAAY,GAAG,UAAU,UAAU,IAAI,UACnG,uBAAa,oBAAC,OAAG,qBAAW,QAAQ,UAAU,KAAK,GAAE,GACxD;AAAA,OACF;AAAA,IACA,qBAAC,SAAI,WAAU,yDACb;AAAA,0BAAC,uBAAoB,QAAQ,OAAO,SAAS;AAAA,MAC7C,oBAAC,iBAAc,OAAO,OAAO,QAAQ;AAAA,OACvC;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Validated categorical pair (storage, egress) plus a recessive neutral for the shared baseline, per theme. */
|
|
2
|
+
export declare const USAGE_COLORS: {
|
|
3
|
+
readonly storage: {
|
|
4
|
+
readonly light: "#2a78d6";
|
|
5
|
+
readonly dark: "#3987e5";
|
|
6
|
+
};
|
|
7
|
+
readonly egress: {
|
|
8
|
+
readonly light: "#eb6834";
|
|
9
|
+
readonly dark: "#d95926";
|
|
10
|
+
};
|
|
11
|
+
readonly shared: {
|
|
12
|
+
readonly light: "#898781";
|
|
13
|
+
readonly dark: "#898781";
|
|
14
|
+
};
|
|
15
|
+
readonly spike: {
|
|
16
|
+
readonly light: "#d03b3b";
|
|
17
|
+
readonly dark: "#d03b3b";
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type UsageColorKey = keyof typeof USAGE_COLORS;
|
|
21
|
+
//# sourceMappingURL=usagePalette.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usagePalette.d.ts","sourceRoot":"","sources":["../../../../src/core/components/usage/usagePalette.ts"],"names":[],"mappings":"AAGA,gHAAgH;AAChH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;CAKf,CAAA;AAEV,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,YAAY,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const USAGE_COLORS = {
|
|
2
|
+
storage: { light: "#2a78d6", dark: "#3987e5" },
|
|
3
|
+
egress: { light: "#eb6834", dark: "#d95926" },
|
|
4
|
+
shared: { light: "#898781", dark: "#898781" },
|
|
5
|
+
spike: { light: "#d03b3b", dark: "#d03b3b" }
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
USAGE_COLORS
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=usagePalette.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/components/usage/usagePalette.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\n/** Validated categorical pair (storage, egress) plus a recessive neutral for the shared baseline, per theme. */\nexport const USAGE_COLORS = {\n storage: { light: '#2a78d6', dark: '#3987e5' },\n egress: { light: '#eb6834', dark: '#d95926' },\n shared: { light: '#898781', dark: '#898781' },\n spike: { light: '#d03b3b', dark: '#d03b3b' },\n} as const\n\nexport type UsageColorKey = keyof typeof USAGE_COLORS\n"],"mappings":"AAIO,MAAM,eAAe;AAAA,EAC1B,SAAS,EAAE,OAAO,WAAW,MAAM,UAAU;AAAA,EAC7C,QAAQ,EAAE,OAAO,WAAW,MAAM,UAAU;AAAA,EAC5C,QAAQ,EAAE,OAAO,WAAW,MAAM,UAAU;AAAA,EAC5C,OAAO,EAAE,OAAO,WAAW,MAAM,UAAU;AAC7C;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/core/components/viewers/Data/siteDetails/AssociatedBuildings.tsx"],"sourcesContent":["\"use client\"\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\n// Dependencies\n\n// Utils\n\n// Shadcn Components\n\n// Custom Components\n\n// Icons\nimport * as LR from 'lucide-react'\nimport { useSession } from 'next-auth/react'\nimport { useTranslations } from 'next-intl'\nimport * as React from 'react'\nimport { toast } from 'sonner'\n\nimport { DataTable, Input, Button, LoadingSpinner } from '../../../../components/ui/'\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuTrigger,\n DropdownMenuSeparator,\n DropdownMenuLabel,\n} from '../../../../components/ui/DropdownMenu'\nimport { useBuildings, useCreateBuilding } from '../../../../hooks/buildings/buildings'\nimport { useUser } from '../../../../hooks/users/users'\nimport { useMapContext } from '../../../../store'\nimport { filterPointsInRing, fetchSiteBoundaryRing, type Ring } from '../../map/src/MapLayers/src/SiteLayer/siteGeometry'\nimport { AssociateBuildingsDialog } from '../../map/src/tools/AddTools/AddSite/AssociateBuildingsDialog'\nimport { fetchSuggestions, parseLocation } from '../../map/utils/geocoder'\nimport FiltersDialog from '../advancedFilter/FiltersDialog'\nimport { useAssociatedBuildingsColumns } from '../utils/Columns'\nimport { filterHelper } from '../utils/filterHelper'\n\nimport type { Building } from '../../../../types/dbTypes'\n\n\ninterface AssociatedBuildingsTableProps {\n buildings: Building[]\n onRowClick?: (building: Building) => void\n siteId?: number\n siteName?: string\n onAttachBuilding?: (building: Building) => void\n onDetachBuilding?: (building: Building) => void\n editing?: boolean\n setEditing?: (editing: boolean) => void\n}\n\nconst AssociatedBuildingsTable: React.FC<AssociatedBuildingsTableProps> = ({\n buildings,\n onRowClick,\n siteId,\n siteName,\n onAttachBuilding,\n onDetachBuilding,\n editing,\n setEditing,\n}) => {\n // Translations\n const t = useTranslations('AssociatedBuildings')\n const tf = (key: string, fallback: string, values?: Record<string, string | number>) =>\n (t.has(key) ? t(key, values) : fallback)\n\n const [searchTerm, setSearchTerm] = React.useState('')\n const [attachSearchTerm, setAttachSearchTerm] = React.useState('')\n const [filters, setFilters] = React.useState([\n {\n id: 1,\n field: '',\n fieldType: null,\n operator: null,\n value: null,\n secondValue: null,\n },\n ])\n const [activeFilters, setActiveFilters] = React.useState([])\n // Track newly attached buildings for preview\n const [previewBuildings, setPreviewBuildings] = React.useState<Building[]>([])\n // Buildings detached this session — hidden from the list; the disconnect is\n // staged on the parent (via onDetachBuilding) and persisted on Save.\n const [detachedIds, setDetachedIds] = React.useState<Set<number>>(new Set())\n\n const [isCreatingBuilding, setIsCreatingBuilding] = React.useState(false)\n\n const [geocodedSuggestions, setGeocodedSuggestions] = React.useState([])\n const [isLoadingGeocoded, setIsLoadingGeocoded] = React.useState(false)\n\n const { state: mapState } = useMapContext()\n const { organizationCountry } = mapState.map\n\n // Fetch all available buildings\n const { buildings: allBuildings, isLoading } = useBuildings()\n\n // The site's saved boundary polygon (loaded from minio) used to suggest the\n // buildings that fall inside it when attaching.\n const [boundaryRing, setBoundaryRing] = React.useState<Ring | null>(null)\n const [showSuggestDialog, setShowSuggestDialog] = React.useState(false)\n\n React.useEffect(() => {\n if (!siteId || siteId < 0) { setBoundaryRing(null); return }\n let cancelled = false\n void fetchSiteBoundaryRing(siteId).then(ring => { if (!cancelled) setBoundaryRing(ring) })\n return () => { cancelled = true }\n }, [siteId])\n\n // Buildings inside the boundary that aren't already attached/previewed.\n const suggestedBuildings = React.useMemo(() => {\n if (!boundaryRing || !allBuildings) return []\n const excluded = new Set([...buildings, ...previewBuildings].map(b => b.id))\n return filterPointsInRing(boundaryRing, allBuildings, b =>\n (typeof b.buildingLongitude === 'number' && typeof b.buildingLatitude === 'number')\n ? [b.buildingLongitude, b.buildingLatitude]\n : null)\n .filter(b => !excluded.has(b.id))\n }, [boundaryRing, allBuildings, buildings, previewBuildings])\n\n const { createBuilding } = useCreateBuilding()\n\n // Session and user data\n const { data: session, status } = useSession()\n const { user, isError, updateUser } = useUser(session?.user?.id || '')\n\n // Combine original buildings with preview buildings\n const displayBuildings = React.useMemo(() => {\n // Create a unique set of buildings based on ID\n const combinedBuildings = [...buildings]\n\n // Only add preview buildings that aren't already in the original buildings array\n for (const previewBuilding of previewBuildings) {\n if (!combinedBuildings.some(b => b.id === previewBuilding.id)) {\n combinedBuildings.push({\n ...previewBuilding,\n })\n }\n }\n\n return combinedBuildings.filter(b => !detachedIds.has(b.id))\n }, [buildings, previewBuildings, detachedIds])\n\n // Detach a building from the site (staged on the parent, persisted on Save).\n const handleDetach = (building: Building) => {\n if (setEditing) setEditing(true)\n setDetachedIds(prev => {\n const next = new Set(prev)\n next.add(building.id)\n return next\n })\n setPreviewBuildings(prev => prev.filter(b => b.id !== building.id))\n onDetachBuilding?.(building)\n }\n\n // Leaving edit mode (Save or Cancel) discards the staged detaches: on Save the\n // buildings prop already reflects the removals; on Cancel the rows reappear.\n React.useEffect(() => {\n if (!editing) setDetachedIds(new Set())\n }, [editing])\n\n // Apply filters to the buildings data\n const filteredBuildings = React.useMemo(() => {\n // First apply search filter\n let filtered = displayBuildings.filter(building =>\n [\n building.buildingName,\n building.buildingAddress,\n building.buildingCountrySubdivision,\n building.buildingMunicipality,\n building.buildingProjectType,\n ].some(value =>\n String(value || '').toLowerCase().includes(searchTerm.toLowerCase()),\n ),\n )\n\n // Then apply advanced filters\n if (activeFilters && activeFilters.length > 0) {\n filtered = filterHelper(filtered, activeFilters)\n }\n\n return filtered\n }, [displayBuildings, searchTerm, activeFilters])\n\n // Filter buildings for attachment dropdown\n const filteredAttachableBuildings = React.useMemo(() => {\n if (!allBuildings) return []\n\n // Filter out buildings that are already attached to this site\n // or are in the preview list\n const existingBuildingIds = new Set([...buildings, ...previewBuildings].map(b => b.id))\n const availableBuildings = allBuildings.filter(b => !existingBuildingIds.has(b.id))\n\n // Return empty array when search term is empty\n if (!attachSearchTerm.trim()) return []\n\n return availableBuildings\n .filter(building =>\n [\n building.buildingName,\n building.buildingAddress,\n ].some(value =>\n String(value || '').toLowerCase().includes(attachSearchTerm.toLowerCase()),\n ),\n )\n .sort((a, b) => {\n // Sort by relevance (name > address)\n const aNameMatch = a.buildingName?.toLowerCase().includes(attachSearchTerm.toLowerCase())\n const bNameMatch = b.buildingName?.toLowerCase().includes(attachSearchTerm.toLowerCase())\n\n if (aNameMatch && !bNameMatch) return -1\n if (!aNameMatch && bNameMatch) return 1\n\n return 0\n })\n .slice(0, 3) // Limit to 3 results\n }, [allBuildings, attachSearchTerm, buildings, previewBuildings])\n\n // Filter geocoded suggestions to exclude addresses that match existing buildings\n const filteredGeocodedSuggestions = React.useMemo(() => {\n if (!geocodedSuggestions.length || !allBuildings) return geocodedSuggestions\n\n // Get all existing building addresses\n const existingAddresses = new Set(\n allBuildings\n .map(b => b.buildingAddress?.toLowerCase().trim())\n .filter(Boolean)\n )\n\n // Filter out geocoded results that match existing building addresses\n return geocodedSuggestions.filter((feature) => {\n const geocodedAddress = feature.properties?.label?.toLowerCase().trim()\n return geocodedAddress && !existingAddresses.has(geocodedAddress)\n }).slice(0, 3) // Limit to 3 results\n }, [geocodedSuggestions, allBuildings])\n\n // Debounced fetch for geocoded addresses\n React.useEffect(() => {\n const fetchGeocoded = async () => {\n if (!attachSearchTerm.trim() || attachSearchTerm.length < 3) {\n setGeocodedSuggestions([])\n setIsLoadingGeocoded(false)\n return\n }\n\n setIsLoadingGeocoded(true)\n try {\n const results = await fetchSuggestions(attachSearchTerm, organizationCountry)\n setGeocodedSuggestions(results || [])\n } catch (error) {\n console.error('Error fetching geocoded suggestions:', error)\n setGeocodedSuggestions([])\n } finally {\n setIsLoadingGeocoded(false)\n }\n }\n\n const timeoutId = setTimeout(() => { void fetchGeocoded() }, 300)\n\n return () => clearTimeout(timeoutId)\n }, [attachSearchTerm])\n\n const handleApplyFilters = (appliedFilters) => {\n setActiveFilters(appliedFilters)\n }\n\n const handleAttachBuilding = async (building: Building) => {\n // Enable editing mode if setEditing is provided\n if (setEditing) {\n setEditing(true)\n }\n // Add to preview list for immediate feedback\n setPreviewBuildings(prev => [...prev, building])\n // Reset search field\n setAttachSearchTerm('')\n // Call the onAttachBuilding prop to update parent state\n if (onAttachBuilding) {\n onAttachBuilding(building)\n }\n }\n\n const handleCreateAndAttach = async (feature: any) => {\n if (!user?.organizationId) {\n toast.error('Organization not found')\n return\n }\n\n setIsCreatingBuilding(true)\n try {\n // Parse the feature data\n const coordinates = feature.geometry?.coordinates || []\n const properties = feature.properties || {}\n\n const buildingData = {\n buildingAddress: properties.label || attachSearchTerm,\n buildingLongitude: coordinates[0],\n buildingLatitude: coordinates[1],\n buildingStreetName: properties.street,\n buildingCountrySubdivision: properties.region_a || properties.region,\n buildingMunicipality: properties.locality || properties.county,\n buildingPostalCode: properties.postalcode,\n }\n\n // Create the building\n const result = await createBuilding({\n buildingData,\n organizationId: user?.organizationId ? String(user.organizationId) : null,\n })\n // Auto-attach the newly created building\n if (result) {\n if (setEditing) {\n setEditing(true)\n }\n setPreviewBuildings(prev => {\n const updated = [...prev, result]\n return updated\n })\n if (onAttachBuilding) {\n onAttachBuilding(result)\n }\n toast.success(t('createAttachToastSuccess'))\n }\n setAttachSearchTerm('')\n setGeocodedSuggestions([])\n } catch (error) {\n console.error('Create and attach building failed:', error)\n toast.error(t('createAttachToastError'))\n } finally {\n setIsCreatingBuilding(false)\n }\n }\n\n return (\n <div className=\"flex flex-col\">\n <div className=\"flex flex-row justify-between\">\n {/* search & filters */}\n <div className=\"flex flex-row gap-12 sm:gap-2 justify-between sm:justify-start w-full\">\n <div className=\"pb-4\">\n <Input\n placeholder={t('searchPlaceholder1')}\n value={searchTerm}\n onChange={e => setSearchTerm(e.target.value)}\n />\n </div>\n <FiltersDialog\n data={displayBuildings}\n isBuilding={true}\n filters={filters}\n activeFilters={activeFilters}\n setFilters={setFilters}\n setActiveFilters={setActiveFilters}\n onApplyFilters={handleApplyFilters}\n />\n </div>\n\n {/* attach building dropdown */}\n <DropdownMenu>\n <DropdownMenuTrigger asChild>\n <Button variant=\"secondary\">{t('attachTrigger')}</Button>\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\" className=\"w-[300px]\">\n {suggestedBuildings.length > 0 && (\n <>\n <DropdownMenuItem\n onClick={() => setShowSuggestDialog(true)}\n className=\"font-medium\"\n >\n <LR.MapPin className=\"h-4 w-4\" />\n {tf('suggestInside', `Review ${suggestedBuildings.length} building(s) inside the boundary`, { count: suggestedBuildings.length })}\n </DropdownMenuItem>\n <DropdownMenuSeparator />\n </>\n )}\n <div className=\"relative\">\n <LR.Search className=\"absolute left-3 top-2.5 h-4 w-4 text-muted-foreground\" />\n <Input\n placeholder={t('searchPlaceholder2')}\n className=\"pl-8\"\n value={attachSearchTerm}\n autoFocus\n onChange={e => setAttachSearchTerm(e.target.value)}\n onKeyDown={e => e.stopPropagation()}\n />\n </div>\n\n {isLoading || isLoadingGeocoded ? (\n <DropdownMenuItem disabled>\n <LoadingSpinner />\n </DropdownMenuItem>\n ) : attachSearchTerm.trim() === '' ? (\n <DropdownMenuItem disabled>\n Type to search for buildings\n </DropdownMenuItem>\n ) : (\n <>\n {/* Existing Buildings Section */}\n {filteredAttachableBuildings.length > 0 && (\n <>\n <DropdownMenuLabel>Existing Buildings</DropdownMenuLabel>\n {filteredAttachableBuildings.map(building => (\n <DropdownMenuItem\n key={building.id}\n onClick={() => { void handleAttachBuilding(building) }}\n >\n <div className=\"flex flex-col\">\n <span className=\"flex items-center\">\n {building.buildingName || 'Unnamed Building'}\n </span>\n {building.buildingAddress && (\n <span className=\"text-muted-foreground text-sm\">\n {building.buildingAddress}\n </span>\n )}\n </div>\n </DropdownMenuItem>\n ))}\n </>\n )}\n\n {/* Separator if both sections have content */}\n {filteredAttachableBuildings.length > 0 && filteredGeocodedSuggestions.length > 0 && (\n <DropdownMenuSeparator />\n )}\n\n {/* Geocoded Addresses Section */}\n {filteredGeocodedSuggestions.length > 0 && (\n <>\n <DropdownMenuLabel>Create New Building</DropdownMenuLabel>\n {filteredGeocodedSuggestions.map((feature) => {\n const location = parseLocation(feature)\n const uniqueKey = feature.properties?.gid\n || `${feature.properties?.name}-${feature.geometry?.coordinates?.[0]}-${feature.geometry?.coordinates?.[1]}`\n\n return (\n <DropdownMenuItem\n key={uniqueKey}\n onClick={() => { void handleCreateAndAttach(feature) }}\n disabled={isCreatingBuilding}\n >\n <div className=\"flex items-center gap-2 w-full\">\n <LR.Plus className=\"h-4 w-4 flex-shrink-0\" />\n <div className=\"flex flex-col flex-1 min-w-0\">\n <span className=\"font-medium truncate\">{location.name}</span>\n <span className=\"text-muted-foreground text-sm truncate\">\n {location.region}\n </span>\n </div>\n </div>\n </DropdownMenuItem>\n )\n })}\n </>\n )}\n\n {/* No results at all */}\n {filteredAttachableBuildings.length === 0 && filteredGeocodedSuggestions.length === 0 && (\n <DropdownMenuItem disabled>\n No buildings or addresses found\n </DropdownMenuItem>\n )}\n </>\n )}\n </DropdownMenuContent>\n </DropdownMenu>\n </div>\n\n {previewBuildings.length > 0 && editing && (\n <div className=\"mb-4 p-3 bg-muted rounded-md border border-border\">\n <p className=\"text-sm text-foreground\">\n <strong>{previewBuildings.length}</strong>\n {' '}\n {t('msg1')}\n {previewBuildings.length > 1 ? 's' : ''}\n {' '}\n {t('msg2')}\n </p>\n </div>\n )}\n\n <div className=\"py-4\">\n <DataTable\n columns={useAssociatedBuildingsColumns()}\n data={filteredBuildings || []}\n onRowClick={onRowClick}\n trailingCell={editing\n ? (({ row }: any) => (\n <button\n type=\"button\"\n title={tf('detachTitle', 'Detach building')}\n onClick={(e) => { e.stopPropagation(); handleDetach(row.original as Building) }}\n className=\"hover:opacity-70 p-1\"\n >\n <LR.X className=\"h-4 w-4\" />\n </button>\n ))\n : undefined}\n className=\"\"\n showPagination={true}\n />\n </div>\n\n {showSuggestDialog && siteId && (\n <AssociateBuildingsDialog\n siteId={siteId}\n siteName={siteName ?? ''}\n buildings={suggestedBuildings}\n onClose={() => setShowSuggestDialog(false)}\n onAssociated={(associated) => {\n // The dialog already persisted the association via updateSite; just\n // reflect it in the visible list (previewBuildings feeds the table).\n setPreviewBuildings(prev => [\n ...prev,\n ...associated.filter(b => !prev.some(p => p.id === b.id)),\n ])\n }}\n />\n )}\n </div>\n )\n}\n\nexport default AssociatedBuildingsTable"],"mappings":";;;;;;;;;;;;;;;;;AAiVQ,SA0BM,UAxBF,KAFJ;AAnUR,YAAY,QAAQ;AACpB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,YAAY,WAAW;AACvB,SAAS,aAAa;AAEtB,SAAS,WAAW,OAAO,QAAQ,sBAAsB;AACzD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,yBAAyB;AAChD,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB,6BAAwC;AACrE,SAAS,gCAAgC;AACzC,SAAS,kBAAkB,qBAAqB;AAChD,OAAO,mBAAmB;AAC1B,SAAS,qCAAqC;AAC9C,SAAS,oBAAoB;AAgB7B,MAAM,2BAAoE,CAAC;AAAA,EACzE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AA9DN;AAgEE,QAAM,IAAI,gBAAgB,qBAAqB;AAC/C,QAAM,KAAK,CAAC,KAAa,UAAkB,WACxC,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,MAAM,IAAI;AAEjC,QAAM,CAAC,YAAY,aAAa,IAAI,MAAM,SAAS,EAAE;AACrD,QAAM,CAAC,kBAAkB,mBAAm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AAAA;AAAA,IAClB,GACF;AAAA,IAEC,qBAAqB,UACpB;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,UAAU,8BAAY;AAAA,QACtB,WAAW;AAAA,QACX,SAAS,MAAM,qBAAqB,KAAK;AAAA,QACzC,cAAc,CAAC,eAAe;AAG5B,8BAAoB,UAAQ;AAAA,YAC1B,GAAG;AAAA,YACH,GAAG,WAAW,OAAO,OAAK,CAAC,KAAK,KAAK,OAAK,EAAE,OAAO,EAAE,EAAE,CAAC;AAAA,UAC1D,CAAC;AAAA,QACH;AAAA;AAAA,IACF;AAAA,KAEJ;AAEJ;AAEA,IAAO,8BAAQ;","names":["_a"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/core/components/viewers/Data/siteDetails/AssociatedBuildings.tsx"],"sourcesContent":["\"use client\"\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\n// Dependencies\n\n// Utils\n\n// Shadcn Components\n\n// Custom Components\n\n// Icons\nimport * as LR from 'lucide-react'\nimport { useSession } from 'next-auth/react'\nimport { useTranslations } from 'next-intl'\nimport * as React from 'react'\nimport { toast } from 'sonner'\n\nimport { DataTable, Input, Button, LoadingSpinner } from '../../../../components/ui/'\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuTrigger,\n DropdownMenuSeparator,\n DropdownMenuLabel,\n} from '../../../../components/ui/DropdownMenu'\nimport { useBuildings, useCreateBuilding } from '../../../../hooks/buildings/buildings'\nimport { useUser } from '../../../../hooks/users/users'\nimport { useMapContext } from '../../../../store'\nimport { filterPointsInRing, fetchSiteBoundaryRing, type Ring } from '../../map/src/MapLayers/src/SiteLayer/siteGeometry'\nimport { AssociateBuildingsDialog } from '../../map/src/tools/AddTools/AddSite/AssociateBuildingsDialog'\nimport { fetchSuggestions, parseLocation } from '../../map/utils/geocoder'\nimport FiltersDialog from '../advancedFilter/FiltersDialog'\nimport { useAssociatedBuildingsColumns } from '../utils/Columns'\nimport { filterHelper } from '../utils/filterHelper'\n\nimport type { Building } from '../../../../types/dbTypes'\n\n\ninterface AssociatedBuildingsTableProps {\n buildings: Building[]\n onRowClick?: (building: Building) => void\n siteId?: number\n siteName?: string\n onAttachBuilding?: (building: Building) => void\n onDetachBuilding?: (building: Building) => void\n editing?: boolean\n setEditing?: (editing: boolean) => void\n}\n\nconst AssociatedBuildingsTable: React.FC<AssociatedBuildingsTableProps> = ({\n buildings,\n onRowClick,\n siteId,\n siteName,\n onAttachBuilding,\n onDetachBuilding,\n editing,\n setEditing,\n}) => {\n // Translations\n const t = useTranslations('AssociatedBuildings')\n const tf = (key: string, fallback: string, values?: Record<string, string | number>) =>\n (t.has(key) ? t(key, values) : fallback)\n\n const [searchTerm, setSearchTerm] = React.useState('')\n const [attachSearchTerm, setAttachSearchTerm] = React.useState('')\n const [filters, setFilters] = React.useState([\n {\n id: 1,\n field: '',\n fieldType: null,\n operator: null,\n value: null,\n secondValue: null,\n },\n ])\n const [activeFilters, setActiveFilters] = React.useState([])\n // Track newly attached buildings for preview\n const [previewBuildings, setPreviewBuildings] = React.useState<Building[]>([])\n // Buildings detached this session — hidden from the list; the disconnect is\n // staged on the parent (via onDetachBuilding) and persisted on Save.\n const [detachedIds, setDetachedIds] = React.useState<Set<number>>(new Set())\n\n const [isCreatingBuilding, setIsCreatingBuilding] = React.useState(false)\n\n const [geocodedSuggestions, setGeocodedSuggestions] = React.useState([])\n const [isLoadingGeocoded, setIsLoadingGeocoded] = React.useState(false)\n\n const { state: mapState } = useMapContext()\n const { organizationCountry } = mapState.map\n\n // Fetch all available buildings\n const { buildings: allBuildings, isLoading } = useBuildings()\n\n // The site's saved boundary polygon (loaded from object storage) used to suggest the\n // buildings that fall inside it when attaching.\n const [boundaryRing, setBoundaryRing] = React.useState<Ring | null>(null)\n const [showSuggestDialog, setShowSuggestDialog] = React.useState(false)\n\n React.useEffect(() => {\n if (!siteId || siteId < 0) { setBoundaryRing(null); return }\n let cancelled = false\n void fetchSiteBoundaryRing(siteId).then(ring => { if (!cancelled) setBoundaryRing(ring) })\n return () => { cancelled = true }\n }, [siteId])\n\n // Buildings inside the boundary that aren't already attached/previewed.\n const suggestedBuildings = React.useMemo(() => {\n if (!boundaryRing || !allBuildings) return []\n const excluded = new Set([...buildings, ...previewBuildings].map(b => b.id))\n return filterPointsInRing(boundaryRing, allBuildings, b =>\n (typeof b.buildingLongitude === 'number' && typeof b.buildingLatitude === 'number')\n ? [b.buildingLongitude, b.buildingLatitude]\n : null)\n .filter(b => !excluded.has(b.id))\n }, [boundaryRing, allBuildings, buildings, previewBuildings])\n\n const { createBuilding } = useCreateBuilding()\n\n // Session and user data\n const { data: session, status } = useSession()\n const { user, isError, updateUser } = useUser(session?.user?.id || '')\n\n // Combine original buildings with preview buildings\n const displayBuildings = React.useMemo(() => {\n // Create a unique set of buildings based on ID\n const combinedBuildings = [...buildings]\n\n // Only add preview buildings that aren't already in the original buildings array\n for (const previewBuilding of previewBuildings) {\n if (!combinedBuildings.some(b => b.id === previewBuilding.id)) {\n combinedBuildings.push({\n ...previewBuilding,\n })\n }\n }\n\n return combinedBuildings.filter(b => !detachedIds.has(b.id))\n }, [buildings, previewBuildings, detachedIds])\n\n // Detach a building from the site (staged on the parent, persisted on Save).\n const handleDetach = (building: Building) => {\n if (setEditing) setEditing(true)\n setDetachedIds(prev => {\n const next = new Set(prev)\n next.add(building.id)\n return next\n })\n setPreviewBuildings(prev => prev.filter(b => b.id !== building.id))\n onDetachBuilding?.(building)\n }\n\n // Leaving edit mode (Save or Cancel) discards the staged detaches: on Save the\n // buildings prop already reflects the removals; on Cancel the rows reappear.\n React.useEffect(() => {\n if (!editing) setDetachedIds(new Set())\n }, [editing])\n\n // Apply filters to the buildings data\n const filteredBuildings = React.useMemo(() => {\n // First apply search filter\n let filtered = displayBuildings.filter(building =>\n [\n building.buildingName,\n building.buildingAddress,\n building.buildingCountrySubdivision,\n building.buildingMunicipality,\n building.buildingProjectType,\n ].some(value =>\n String(value || '').toLowerCase().includes(searchTerm.toLowerCase()),\n ),\n )\n\n // Then apply advanced filters\n if (activeFilters && activeFilters.length > 0) {\n filtered = filterHelper(filtered, activeFilters)\n }\n\n return filtered\n }, [displayBuildings, searchTerm, activeFilters])\n\n // Filter buildings for attachment dropdown\n const filteredAttachableBuildings = React.useMemo(() => {\n if (!allBuildings) return []\n\n // Filter out buildings that are already attached to this site\n // or are in the preview list\n const existingBuildingIds = new Set([...buildings, ...previewBuildings].map(b => b.id))\n const availableBuildings = allBuildings.filter(b => !existingBuildingIds.has(b.id))\n\n // Return empty array when search term is empty\n if (!attachSearchTerm.trim()) return []\n\n return availableBuildings\n .filter(building =>\n [\n building.buildingName,\n building.buildingAddress,\n ].some(value =>\n String(value || '').toLowerCase().includes(attachSearchTerm.toLowerCase()),\n ),\n )\n .sort((a, b) => {\n // Sort by relevance (name > address)\n const aNameMatch = a.buildingName?.toLowerCase().includes(attachSearchTerm.toLowerCase())\n const bNameMatch = b.buildingName?.toLowerCase().includes(attachSearchTerm.toLowerCase())\n\n if (aNameMatch && !bNameMatch) return -1\n if (!aNameMatch && bNameMatch) return 1\n\n return 0\n })\n .slice(0, 3) // Limit to 3 results\n }, [allBuildings, attachSearchTerm, buildings, previewBuildings])\n\n // Filter geocoded suggestions to exclude addresses that match existing buildings\n const filteredGeocodedSuggestions = React.useMemo(() => {\n if (!geocodedSuggestions.length || !allBuildings) return geocodedSuggestions\n\n // Get all existing building addresses\n const existingAddresses = new Set(\n allBuildings\n .map(b => b.buildingAddress?.toLowerCase().trim())\n .filter(Boolean)\n )\n\n // Filter out geocoded results that match existing building addresses\n return geocodedSuggestions.filter((feature) => {\n const geocodedAddress = feature.properties?.label?.toLowerCase().trim()\n return geocodedAddress && !existingAddresses.has(geocodedAddress)\n }).slice(0, 3) // Limit to 3 results\n }, [geocodedSuggestions, allBuildings])\n\n // Debounced fetch for geocoded addresses\n React.useEffect(() => {\n const fetchGeocoded = async () => {\n if (!attachSearchTerm.trim() || attachSearchTerm.length < 3) {\n setGeocodedSuggestions([])\n setIsLoadingGeocoded(false)\n return\n }\n\n setIsLoadingGeocoded(true)\n try {\n const results = await fetchSuggestions(attachSearchTerm, organizationCountry)\n setGeocodedSuggestions(results || [])\n } catch (error) {\n console.error('Error fetching geocoded suggestions:', error)\n setGeocodedSuggestions([])\n } finally {\n setIsLoadingGeocoded(false)\n }\n }\n\n const timeoutId = setTimeout(() => { void fetchGeocoded() }, 300)\n\n return () => clearTimeout(timeoutId)\n }, [attachSearchTerm])\n\n const handleApplyFilters = (appliedFilters) => {\n setActiveFilters(appliedFilters)\n }\n\n const handleAttachBuilding = async (building: Building) => {\n // Enable editing mode if setEditing is provided\n if (setEditing) {\n setEditing(true)\n }\n // Add to preview list for immediate feedback\n setPreviewBuildings(prev => [...prev, building])\n // Reset search field\n setAttachSearchTerm('')\n // Call the onAttachBuilding prop to update parent state\n if (onAttachBuilding) {\n onAttachBuilding(building)\n }\n }\n\n const handleCreateAndAttach = async (feature: any) => {\n if (!user?.organizationId) {\n toast.error('Organization not found')\n return\n }\n\n setIsCreatingBuilding(true)\n try {\n // Parse the feature data\n const coordinates = feature.geometry?.coordinates || []\n const properties = feature.properties || {}\n\n const buildingData = {\n buildingAddress: properties.label || attachSearchTerm,\n buildingLongitude: coordinates[0],\n buildingLatitude: coordinates[1],\n buildingStreetName: properties.street,\n buildingCountrySubdivision: properties.region_a || properties.region,\n buildingMunicipality: properties.locality || properties.county,\n buildingPostalCode: properties.postalcode,\n }\n\n // Create the building\n const result = await createBuilding({\n buildingData,\n organizationId: user?.organizationId ? String(user.organizationId) : null,\n })\n // Auto-attach the newly created building\n if (result) {\n if (setEditing) {\n setEditing(true)\n }\n setPreviewBuildings(prev => {\n const updated = [...prev, result]\n return updated\n })\n if (onAttachBuilding) {\n onAttachBuilding(result)\n }\n toast.success(t('createAttachToastSuccess'))\n }\n setAttachSearchTerm('')\n setGeocodedSuggestions([])\n } catch (error) {\n console.error('Create and attach building failed:', error)\n toast.error(t('createAttachToastError'))\n } finally {\n setIsCreatingBuilding(false)\n }\n }\n\n return (\n <div className=\"flex flex-col\">\n <div className=\"flex flex-row justify-between\">\n {/* search & filters */}\n <div className=\"flex flex-row gap-12 sm:gap-2 justify-between sm:justify-start w-full\">\n <div className=\"pb-4\">\n <Input\n placeholder={t('searchPlaceholder1')}\n value={searchTerm}\n onChange={e => setSearchTerm(e.target.value)}\n />\n </div>\n <FiltersDialog\n data={displayBuildings}\n isBuilding={true}\n filters={filters}\n activeFilters={activeFilters}\n setFilters={setFilters}\n setActiveFilters={setActiveFilters}\n onApplyFilters={handleApplyFilters}\n />\n </div>\n\n {/* attach building dropdown */}\n <DropdownMenu>\n <DropdownMenuTrigger asChild>\n <Button variant=\"secondary\">{t('attachTrigger')}</Button>\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\" className=\"w-[300px]\">\n {suggestedBuildings.length > 0 && (\n <>\n <DropdownMenuItem\n onClick={() => setShowSuggestDialog(true)}\n className=\"font-medium\"\n >\n <LR.MapPin className=\"h-4 w-4\" />\n {tf('suggestInside', `Review ${suggestedBuildings.length} building(s) inside the boundary`, { count: suggestedBuildings.length })}\n </DropdownMenuItem>\n <DropdownMenuSeparator />\n </>\n )}\n <div className=\"relative\">\n <LR.Search className=\"absolute left-3 top-2.5 h-4 w-4 text-muted-foreground\" />\n <Input\n placeholder={t('searchPlaceholder2')}\n className=\"pl-8\"\n value={attachSearchTerm}\n autoFocus\n onChange={e => setAttachSearchTerm(e.target.value)}\n onKeyDown={e => e.stopPropagation()}\n />\n </div>\n\n {isLoading || isLoadingGeocoded ? (\n <DropdownMenuItem disabled>\n <LoadingSpinner />\n </DropdownMenuItem>\n ) : attachSearchTerm.trim() === '' ? (\n <DropdownMenuItem disabled>\n Type to search for buildings\n </DropdownMenuItem>\n ) : (\n <>\n {/* Existing Buildings Section */}\n {filteredAttachableBuildings.length > 0 && (\n <>\n <DropdownMenuLabel>Existing Buildings</DropdownMenuLabel>\n {filteredAttachableBuildings.map(building => (\n <DropdownMenuItem\n key={building.id}\n onClick={() => { void handleAttachBuilding(building) }}\n >\n <div className=\"flex flex-col\">\n <span className=\"flex items-center\">\n {building.buildingName || 'Unnamed Building'}\n </span>\n {building.buildingAddress && (\n <span className=\"text-muted-foreground text-sm\">\n {building.buildingAddress}\n </span>\n )}\n </div>\n </DropdownMenuItem>\n ))}\n </>\n )}\n\n {/* Separator if both sections have content */}\n {filteredAttachableBuildings.length > 0 && filteredGeocodedSuggestions.length > 0 && (\n <DropdownMenuSeparator />\n )}\n\n {/* Geocoded Addresses Section */}\n {filteredGeocodedSuggestions.length > 0 && (\n <>\n <DropdownMenuLabel>Create New Building</DropdownMenuLabel>\n {filteredGeocodedSuggestions.map((feature) => {\n const location = parseLocation(feature)\n const uniqueKey = feature.properties?.gid\n || `${feature.properties?.name}-${feature.geometry?.coordinates?.[0]}-${feature.geometry?.coordinates?.[1]}`\n\n return (\n <DropdownMenuItem\n key={uniqueKey}\n onClick={() => { void handleCreateAndAttach(feature) }}\n disabled={isCreatingBuilding}\n >\n <div className=\"flex items-center gap-2 w-full\">\n <LR.Plus className=\"h-4 w-4 flex-shrink-0\" />\n <div className=\"flex flex-col flex-1 min-w-0\">\n <span className=\"font-medium truncate\">{location.name}</span>\n <span className=\"text-muted-foreground text-sm truncate\">\n {location.region}\n </span>\n </div>\n </div>\n </DropdownMenuItem>\n )\n })}\n </>\n )}\n\n {/* No results at all */}\n {filteredAttachableBuildings.length === 0 && filteredGeocodedSuggestions.length === 0 && (\n <DropdownMenuItem disabled>\n No buildings or addresses found\n </DropdownMenuItem>\n )}\n </>\n )}\n </DropdownMenuContent>\n </DropdownMenu>\n </div>\n\n {previewBuildings.length > 0 && editing && (\n <div className=\"mb-4 p-3 bg-muted rounded-md border border-border\">\n <p className=\"text-sm text-foreground\">\n <strong>{previewBuildings.length}</strong>\n {' '}\n {t('msg1')}\n {previewBuildings.length > 1 ? 's' : ''}\n {' '}\n {t('msg2')}\n </p>\n </div>\n )}\n\n <div className=\"py-4\">\n <DataTable\n columns={useAssociatedBuildingsColumns()}\n data={filteredBuildings || []}\n onRowClick={onRowClick}\n trailingCell={editing\n ? (({ row }: any) => (\n <button\n type=\"button\"\n title={tf('detachTitle', 'Detach building')}\n onClick={(e) => { e.stopPropagation(); handleDetach(row.original as Building) }}\n className=\"hover:opacity-70 p-1\"\n >\n <LR.X className=\"h-4 w-4\" />\n </button>\n ))\n : undefined}\n className=\"\"\n showPagination={true}\n />\n </div>\n\n {showSuggestDialog && siteId && (\n <AssociateBuildingsDialog\n siteId={siteId}\n siteName={siteName ?? ''}\n buildings={suggestedBuildings}\n onClose={() => setShowSuggestDialog(false)}\n onAssociated={(associated) => {\n // The dialog already persisted the association via updateSite; just\n // reflect it in the visible list (previewBuildings feeds the table).\n setPreviewBuildings(prev => [\n ...prev,\n ...associated.filter(b => !prev.some(p => p.id === b.id)),\n ])\n }}\n />\n )}\n </div>\n )\n}\n\nexport default AssociatedBuildingsTable"],"mappings":";;;;;;;;;;;;;;;;;AAiVQ,SA0BM,UAxBF,KAFJ;AAnUR,YAAY,QAAQ;AACpB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,YAAY,WAAW;AACvB,SAAS,aAAa;AAEtB,SAAS,WAAW,OAAO,QAAQ,sBAAsB;AACzD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,yBAAyB;AAChD,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB,6BAAwC;AACrE,SAAS,gCAAgC;AACzC,SAAS,kBAAkB,qBAAqB;AAChD,OAAO,mBAAmB;AAC1B,SAAS,qCAAqC;AAC9C,SAAS,oBAAoB;AAgB7B,MAAM,2BAAoE,CAAC;AAAA,EACzE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AA9DN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,YAC1C,SAAS,CAAC,MAAM;AAAE,gBAAE,gBAAgB;AAAG,2BAAa,IAAI,QAAoB;AAAA,YAAE;AAAA,YAC9E,WAAU;AAAA,YAEV,8BAAC,GAAG,GAAH,EAAK,WAAU,WAAU;AAAA;AAAA,QAC5B,KAEA;AAAA,QACJ,WAAU;AAAA,QACV,gBAAgB;AAAA;AAAA,IAClB,GACF;AAAA,IAEC,qBAAqB,UACpB;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,UAAU,8BAAY;AAAA,QACtB,WAAW;AAAA,QACX,SAAS,MAAM,qBAAqB,KAAK;AAAA,QACzC,cAAc,CAAC,eAAe;AAG5B,8BAAoB,UAAQ;AAAA,YAC1B,GAAG;AAAA,YACH,GAAG,WAAW,OAAO,OAAK,CAAC,KAAK,KAAK,OAAK,EAAE,OAAO,EAAE,EAAE,CAAC;AAAA,UAC1D,CAAC;AAAA,QACH;AAAA;AAAA,IACF;AAAA,KAEJ;AAEJ;AAEA,IAAO,8BAAQ;","names":["_a"]}
|
|
@@ -2,13 +2,13 @@ import * as React from 'react';
|
|
|
2
2
|
import type { Organization } from '../../types/dbTypes';
|
|
3
3
|
interface ViewerProps {
|
|
4
4
|
organization: Organization;
|
|
5
|
-
|
|
5
|
+
storageBaseUrl?: string;
|
|
6
6
|
martinBaseUrl?: string;
|
|
7
7
|
pointcloudApiUrl?: string;
|
|
8
8
|
maptilerKey?: string;
|
|
9
9
|
geocodeEarthApiKey?: string;
|
|
10
10
|
geocoderUrl?: string;
|
|
11
11
|
}
|
|
12
|
-
export declare function Viewer({ organization,
|
|
12
|
+
export declare function Viewer({ organization, storageBaseUrl, martinBaseUrl, pointcloudApiUrl, maptilerKey, geocodeEarthApiKey, geocoderUrl }: ViewerProps): React.JSX.Element;
|
|
13
13
|
export {};
|
|
14
14
|
//# sourceMappingURL=Viewer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Viewer.d.ts","sourceRoot":"","sources":["../../../../src/core/components/viewers/Viewer.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAiB9B,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,qBAAqB,CAAA;AAsDlE,UAAU,WAAW;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,
|
|
1
|
+
{"version":3,"file":"Viewer.d.ts","sourceRoot":"","sources":["../../../../src/core/components/viewers/Viewer.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAiB9B,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,qBAAqB,CAAA;AAsDlE,UAAU,WAAW;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,wBAAgB,MAAM,CAAC,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,WAAW,EAAE,kBAAkB,EAAE,WAAW,EAAE,EAAE,WAAW,qBA6IlJ"}
|
|
@@ -49,7 +49,7 @@ function useKeptAlive(shown) {
|
|
|
49
49
|
}
|
|
50
50
|
const hiddenInPlace = (visible) => visible ? { width: "100%", height: "100%" } : { position: "absolute", inset: 0, visibility: "hidden", pointerEvents: "none" };
|
|
51
51
|
const shownWhen = (visible) => ({ display: visible ? "block" : "none", width: "100%", height: "100%" });
|
|
52
|
-
function Viewer({ organization,
|
|
52
|
+
function Viewer({ organization, storageBaseUrl, martinBaseUrl, pointcloudApiUrl, maptilerKey, geocodeEarthApiKey, geocoderUrl }) {
|
|
53
53
|
const searchParams = useSearchParams();
|
|
54
54
|
const viewer = searchParams.get("viewer") || ViewerNames.map;
|
|
55
55
|
const { dispatch: menusDispatch, state: menusState } = React.useContext(MenusContext);
|
|
@@ -122,13 +122,13 @@ function Viewer({ organization, minioBaseUrl, martinBaseUrl, pointcloudApiUrl, m
|
|
|
122
122
|
keptBim && /* @__PURE__ */ jsx("div", { style: hiddenInPlace(builtInViewer === ViewerNames.bim), "aria-hidden": builtInViewer !== ViewerNames.bim, children: /* @__PURE__ */ jsx(BimViewer, { pointcloudApiUrl }) }),
|
|
123
123
|
builtInViewer !== null && [ViewerNames.buildings, ViewerNames.sites, ViewerNames.files, ViewerNames.land, ViewerNames.infrastructure, ViewerNames.users].includes(builtInViewer) && /* @__PURE__ */ jsx(DataMenu, { currentViewer: builtInViewer, organization, geocodeEarthApiKey, geocoderUrl }),
|
|
124
124
|
builtInViewer === ViewerNames.plugins && /* @__PURE__ */ jsx("div", { className: "h-full w-full overflow-y-auto", children: /* @__PURE__ */ jsx(PluginsManager, {}) }),
|
|
125
|
-
builtInViewer === ViewerNames.settings && /* @__PURE__ */ jsx(UserSettings, {
|
|
125
|
+
builtInViewer === ViewerNames.settings && /* @__PURE__ */ jsx(UserSettings, { storageBaseUrl }),
|
|
126
126
|
keptPluginPages.map((page) => /* @__PURE__ */ jsx("div", { className: "h-full w-full overflow-y-auto", style: { display: page === validViewer ? "block" : "none" }, children: /* @__PURE__ */ jsx(PluginDataPageHost, { viewer: page }) }, page))
|
|
127
127
|
] })
|
|
128
128
|
] });
|
|
129
129
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
130
130
|
selectedViewer,
|
|
131
|
-
/* @__PURE__ */ jsx(Toolbar, { viewer: validViewer,
|
|
131
|
+
/* @__PURE__ */ jsx(Toolbar, { viewer: validViewer, storageBaseUrl, martinBaseUrl, organization, geocodeEarthApiKey, geocoderUrl }),
|
|
132
132
|
/* @__PURE__ */ jsx(UploadProgressToasts, {})
|
|
133
133
|
] });
|
|
134
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/components/viewers/Viewer.tsx"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\n// Dependencies\nimport { Loader2 } from 'lucide-react'\nimport dynamic from 'next/dynamic'\nimport { useSearchParams, useRouter, usePathname } from 'next/navigation'\nimport * as React from 'react'\n\nimport { parsePluginViewerKey } from '../../plugins/host/pluginViewerKey'\nimport { BuildingsContext, MenusContext } from '../../store'\nimport { ViewerNames } from '../../types'\n\n// Deep import, not the ui barrel: the barrel drags heavy modules into the eager map bundle.\nimport { switchLanguage } from '../../utils/utils'\nimport { UserSettings } from '../settings'\nimport { Toolbar } from '../Toolbar'\nimport { UploadProgressToasts } from '../ui/FilesManager/src/UploadProgressBar'\nimport { SidebarTrigger } from '../ui/Sidebar'\n\nimport { withBuildingId } from './bim/src/lib/buildingLocationParams'\nimport { MapViewer } from './map/MapViewer'\nimport { isViewerAllowed } from './viewerAccess'\n\nimport type { Organization, ViewerKey } from '../../types/dbTypes'\n\n// Code-split: map-only sessions must not pay for @thatopen or the Potree stack.\nconst BimViewer = dynamic(\n () => import('./bim/BimViewer').then(m => ({ default: m.BimViewer })),\n { ssr: false, loading: () => <ViewerLoadingFallback label=\"Loading BIM viewer…\" /> },\n)\n\n// DataMenu reaches BimViewer through FilePreview, so a static import undoes the split above.\nconst PluginsManager = dynamic(\n () => import('./plugins/PluginsManager').then(m => ({ default: m.PluginsManager })),\n { ssr: false, loading: () => <ViewerLoadingFallback label=\"Loading plugins…\" /> },\n)\n\nconst DataMenu = dynamic(\n () => import('./Data/DataMenu').then(m => ({ default: m.DataMenu })),\n { ssr: false, loading: () => <ViewerLoadingFallback label=\"Loading data…\" /> },\n)\n\n// Lazy too, or every plugin's page code lands in the eager bundle for every user.\nconst PluginDataPageHost = dynamic(\n () => import('../../plugins/host/PluginDataPageHost').then(m => ({ default: m.PluginDataPageHost })),\n { ssr: false, loading: () => <ViewerLoadingFallback label=\"Loading page…\" /> },\n)\n\n// Matches BimLoadingState using only Tailwind tokens, so the eager bundle stays light.\nfunction ViewerLoadingFallback({ label }: { label: string }) {\n return (\n <div className=\"absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-[1px]\">\n <div className=\"flex items-center gap-3 rounded-md border border-border bg-card px-5 py-4 shadow-sm\">\n <Loader2 className=\"h-5 w-5 animate-spin text-muted-foreground\" />\n <span className=\"text-foreground text-base font-medium font-['Inter'] leading-7\">{label}</span>\n </div>\n </div>\n )\n}\n\n// Once shown, a view stays mounted and is only hidden, so its camera, open plan and loaded models survive a page switch.\nfunction useKeptAlive<T>(shown: T | null): T[] {\n const [kept, setKept] = React.useState<T[]>([])\n if (shown !== null && !kept.includes(shown)) {\n setKept([...kept, shown])\n return [...kept, shown]\n }\n return kept\n}\n\n// Hidden without `display: none`: a 0×0 container makes OBC resize its camera to a NaN aspect it never recovers from.\nconst hiddenInPlace = (visible: boolean): React.CSSProperties => (visible\n ? { width: '100%', height: '100%' }\n : { position: 'absolute', inset: 0, visibility: 'hidden', pointerEvents: 'none' })\n\nconst shownWhen = (visible: boolean): React.CSSProperties => ({ display: visible ? 'block' : 'none', width: '100%', height: '100%' })\n\ninterface ViewerProps {\n organization: Organization\n minioBaseUrl?: string\n martinBaseUrl?: string\n pointcloudApiUrl?: string\n maptilerKey?: string\n geocodeEarthApiKey?: string\n geocoderUrl?: string\n}\n\nexport function Viewer({ organization, minioBaseUrl, martinBaseUrl, pointcloudApiUrl, maptilerKey, geocodeEarthApiKey, geocoderUrl }: ViewerProps) {\n\n const searchParams = useSearchParams()\n const viewer = (searchParams.get('viewer') as ViewerKey) || ViewerNames.map\n\n const { dispatch: menusDispatch, state: menusState } = React.useContext(MenusContext)\n const { state: buildingState } = React.useContext(BuildingsContext)\n // const { dispatch: appConfigDispatch } = React.useContext(AppConfigContext)\n const { building } = buildingState.buildings\n const { currentViewer } = menusState.menus\n const router = useRouter()\n const pathname = usePathname()\n const [isMounted, setIsMounted] = React.useState(false)\n\n // Use a ref to track if we're currently updating -> prevent circular updates\n const isUpdatingRef = React.useRef(false)\n\n const { appContent } = organization\n\n const pluginPage = parsePluginViewerKey(viewer)\n const isViewerValid = isViewerAllowed(viewer, appContent)\n\n // Use default viewer (map) if current viewer is not valid\n const validViewer = isViewerValid ? viewer : ViewerNames.map\n\n // Update URL if viewer was not available for the organization\n React.useEffect(() => {\n if (isMounted && !isViewerValid && viewer !== ViewerNames.map) {\n const current = new URLSearchParams(searchParams.toString())\n current.delete('viewer')\n const newSearchParams = building?.id ? withBuildingId(current, building.id) : current\n router.replace(`${pathname}?${newSearchParams.toString()}`, { scroll: false })\n }\n }, [isMounted, isViewerValid, viewer, searchParams, pathname, router, building?.id])\n\n // On first mount, respond to URL\n React.useEffect(() => {\n if (!isMounted) {\n menusDispatch({\n type: 'SET_VIEWER',\n payload: { currentViewer: validViewer },\n })\n setIsMounted(true)\n }\n }, [isMounted, validViewer, menusDispatch])\n\n React.useEffect(() => {\n if (!organization) return\n const defaultLanguage = organization.languages?.[0] || 'En'\n if (defaultLanguage) void switchLanguage(defaultLanguage)\n }, [organization])\n\n // Handle context changes (from sidebar, HeaderButtons, etc.)\n React.useEffect(() => {\n if (!isMounted || !currentViewer || currentViewer === validViewer || isUpdatingRef.current) {\n return\n }\n\n isUpdatingRef.current = true\n\n // Create URLSearchParams to preserve existing search params\n\n const current = new URLSearchParams(searchParams.toString())\n current.set('viewer', currentViewer)\n const newSearchParams = building?.id ? withBuildingId(current, building.id) : current\n\n\n router.replace(`${pathname}?${newSearchParams.toString()}`, { scroll: false })\n\n // Reset the flag after a brief delay to allow the navigation to complete\n setTimeout(() => {\n isUpdatingRef.current = false\n }, 100)\n }, [currentViewer, isMounted, pathname, router, viewer, searchParams])\n\n // Handle URL changes (direct navigation)\n React.useEffect(() => {\n if (isMounted && currentViewer !== validViewer && !isUpdatingRef.current) {\n isUpdatingRef.current = true\n\n menusDispatch({\n type: 'SET_VIEWER',\n payload: { currentViewer: validViewer },\n })\n\n // Reset the flag after a brief delay\n setTimeout(() => {\n isUpdatingRef.current = false\n }, 100)\n }\n }, [validViewer, menusDispatch, isMounted, currentViewer])\n\n // Null while a plugin page shows, so the branches below stay exhaustive over ViewerNames.\n const builtInViewer = pluginPage ? null : (validViewer as ViewerNames)\n const keptBim = useKeptAlive(builtInViewer === ViewerNames.bim ? ViewerNames.bim : null).length > 0\n const keptPluginPages = useKeptAlive(pluginPage ? validViewer : null)\n\n const selectedViewer = (\n <>\n {builtInViewer !== null\n && [ViewerNames.map, ViewerNames.bim].includes(builtInViewer)\n && <SidebarTrigger />}\n <div style={{ height: '100%', width: '100%', position: 'relative' }}>\n <div style={shownWhen(builtInViewer === ViewerNames.map)}>\n <MapViewer organization={organization} maptilerKey={maptilerKey} />\n </div>\n {keptBim && (\n <div style={hiddenInPlace(builtInViewer === ViewerNames.bim)} aria-hidden={builtInViewer !== ViewerNames.bim}>\n <BimViewer pointcloudApiUrl={pointcloudApiUrl} />\n </div>\n )}\n {builtInViewer !== null\n && [ViewerNames.buildings, ViewerNames.sites, ViewerNames.files, ViewerNames.land, ViewerNames.infrastructure, ViewerNames.users].includes(builtInViewer) && (\n <DataMenu currentViewer={builtInViewer} organization={organization} geocodeEarthApiKey={geocodeEarthApiKey} geocoderUrl={geocoderUrl} />\n )}\n {/* `plugins` used to route through DataMenu, which rendered nothing:\n VIEWER_CONFIG gives it no dataType. It has its own page now. */}\n {builtInViewer === ViewerNames.plugins && (\n <div className=\"h-full w-full overflow-y-auto\">\n <PluginsManager />\n </div>\n )}\n {builtInViewer === ViewerNames.settings && (\n <UserSettings minioBaseUrl={minioBaseUrl} />\n )}\n {keptPluginPages.map(page => (\n <div key={page} className=\"h-full w-full overflow-y-auto\" style={{ display: page === validViewer ? 'block' : 'none' }}>\n <PluginDataPageHost viewer={page} />\n </div>\n ))}\n </div>\n </>\n )\n\n return (\n <>\n {selectedViewer}\n <Toolbar viewer={validViewer} minioBaseUrl={minioBaseUrl} martinBaseUrl={martinBaseUrl} organization={organization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CACb,8BAAC,kBAAe,GAClB;AAAA,MAED,kBAAkB,YAAY,YAC7B,oBAAC,gBAAa,cAA4B;AAAA,MAE3C,gBAAgB,IAAI,UACnB,oBAAC,SAAe,WAAU,iCAAgC,OAAO,EAAE,SAAS,SAAS,cAAc,UAAU,OAAO,GAClH,8BAAC,sBAAmB,QAAQ,MAAM,KAD1B,IAEV,CACD;AAAA,OACH;AAAA,KACF;AAGF,SACE,iCACG;AAAA;AAAA,IACD,oBAAC,WAAQ,QAAQ,aAAa,cAA4B,eAA8B,cAA4B,oBAAwC,aAA0B;AAAA,IACtL,oBAAC,wBAAqB;AAAA,KACxB;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/components/viewers/Viewer.tsx"],"sourcesContent":["'use client'\n\n// SPDX-License-Identifier: AGPL-3.0-or-later\n// Copyright (C) 2025 Collab Digital Twins\n\n// Dependencies\nimport { Loader2 } from 'lucide-react'\nimport dynamic from 'next/dynamic'\nimport { useSearchParams, useRouter, usePathname } from 'next/navigation'\nimport * as React from 'react'\n\nimport { parsePluginViewerKey } from '../../plugins/host/pluginViewerKey'\nimport { BuildingsContext, MenusContext } from '../../store'\nimport { ViewerNames } from '../../types'\n\n// Deep import, not the ui barrel: the barrel drags heavy modules into the eager map bundle.\nimport { switchLanguage } from '../../utils/utils'\nimport { UserSettings } from '../settings'\nimport { Toolbar } from '../Toolbar'\nimport { UploadProgressToasts } from '../ui/FilesManager/src/UploadProgressBar'\nimport { SidebarTrigger } from '../ui/Sidebar'\n\nimport { withBuildingId } from './bim/src/lib/buildingLocationParams'\nimport { MapViewer } from './map/MapViewer'\nimport { isViewerAllowed } from './viewerAccess'\n\nimport type { Organization, ViewerKey } from '../../types/dbTypes'\n\n// Code-split: map-only sessions must not pay for @thatopen or the Potree stack.\nconst BimViewer = dynamic(\n () => import('./bim/BimViewer').then(m => ({ default: m.BimViewer })),\n { ssr: false, loading: () => <ViewerLoadingFallback label=\"Loading BIM viewer…\" /> },\n)\n\n// DataMenu reaches BimViewer through FilePreview, so a static import undoes the split above.\nconst PluginsManager = dynamic(\n () => import('./plugins/PluginsManager').then(m => ({ default: m.PluginsManager })),\n { ssr: false, loading: () => <ViewerLoadingFallback label=\"Loading plugins…\" /> },\n)\n\nconst DataMenu = dynamic(\n () => import('./Data/DataMenu').then(m => ({ default: m.DataMenu })),\n { ssr: false, loading: () => <ViewerLoadingFallback label=\"Loading data…\" /> },\n)\n\n// Lazy too, or every plugin's page code lands in the eager bundle for every user.\nconst PluginDataPageHost = dynamic(\n () => import('../../plugins/host/PluginDataPageHost').then(m => ({ default: m.PluginDataPageHost })),\n { ssr: false, loading: () => <ViewerLoadingFallback label=\"Loading page…\" /> },\n)\n\n// Matches BimLoadingState using only Tailwind tokens, so the eager bundle stays light.\nfunction ViewerLoadingFallback({ label }: { label: string }) {\n return (\n <div className=\"absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-[1px]\">\n <div className=\"flex items-center gap-3 rounded-md border border-border bg-card px-5 py-4 shadow-sm\">\n <Loader2 className=\"h-5 w-5 animate-spin text-muted-foreground\" />\n <span className=\"text-foreground text-base font-medium font-['Inter'] leading-7\">{label}</span>\n </div>\n </div>\n )\n}\n\n// Once shown, a view stays mounted and is only hidden, so its camera, open plan and loaded models survive a page switch.\nfunction useKeptAlive<T>(shown: T | null): T[] {\n const [kept, setKept] = React.useState<T[]>([])\n if (shown !== null && !kept.includes(shown)) {\n setKept([...kept, shown])\n return [...kept, shown]\n }\n return kept\n}\n\n// Hidden without `display: none`: a 0×0 container makes OBC resize its camera to a NaN aspect it never recovers from.\nconst hiddenInPlace = (visible: boolean): React.CSSProperties => (visible\n ? { width: '100%', height: '100%' }\n : { position: 'absolute', inset: 0, visibility: 'hidden', pointerEvents: 'none' })\n\nconst shownWhen = (visible: boolean): React.CSSProperties => ({ display: visible ? 'block' : 'none', width: '100%', height: '100%' })\n\ninterface ViewerProps {\n organization: Organization\n storageBaseUrl?: string\n martinBaseUrl?: string\n pointcloudApiUrl?: string\n maptilerKey?: string\n geocodeEarthApiKey?: string\n geocoderUrl?: string\n}\n\nexport function Viewer({ organization, storageBaseUrl, martinBaseUrl, pointcloudApiUrl, maptilerKey, geocodeEarthApiKey, geocoderUrl }: ViewerProps) {\n\n const searchParams = useSearchParams()\n const viewer = (searchParams.get('viewer') as ViewerKey) || ViewerNames.map\n\n const { dispatch: menusDispatch, state: menusState } = React.useContext(MenusContext)\n const { state: buildingState } = React.useContext(BuildingsContext)\n // const { dispatch: appConfigDispatch } = React.useContext(AppConfigContext)\n const { building } = buildingState.buildings\n const { currentViewer } = menusState.menus\n const router = useRouter()\n const pathname = usePathname()\n const [isMounted, setIsMounted] = React.useState(false)\n\n // Use a ref to track if we're currently updating -> prevent circular updates\n const isUpdatingRef = React.useRef(false)\n\n const { appContent } = organization\n\n const pluginPage = parsePluginViewerKey(viewer)\n const isViewerValid = isViewerAllowed(viewer, appContent)\n\n // Use default viewer (map) if current viewer is not valid\n const validViewer = isViewerValid ? viewer : ViewerNames.map\n\n // Update URL if viewer was not available for the organization\n React.useEffect(() => {\n if (isMounted && !isViewerValid && viewer !== ViewerNames.map) {\n const current = new URLSearchParams(searchParams.toString())\n current.delete('viewer')\n const newSearchParams = building?.id ? withBuildingId(current, building.id) : current\n router.replace(`${pathname}?${newSearchParams.toString()}`, { scroll: false })\n }\n }, [isMounted, isViewerValid, viewer, searchParams, pathname, router, building?.id])\n\n // On first mount, respond to URL\n React.useEffect(() => {\n if (!isMounted) {\n menusDispatch({\n type: 'SET_VIEWER',\n payload: { currentViewer: validViewer },\n })\n setIsMounted(true)\n }\n }, [isMounted, validViewer, menusDispatch])\n\n React.useEffect(() => {\n if (!organization) return\n const defaultLanguage = organization.languages?.[0] || 'En'\n if (defaultLanguage) void switchLanguage(defaultLanguage)\n }, [organization])\n\n // Handle context changes (from sidebar, HeaderButtons, etc.)\n React.useEffect(() => {\n if (!isMounted || !currentViewer || currentViewer === validViewer || isUpdatingRef.current) {\n return\n }\n\n isUpdatingRef.current = true\n\n // Create URLSearchParams to preserve existing search params\n\n const current = new URLSearchParams(searchParams.toString())\n current.set('viewer', currentViewer)\n const newSearchParams = building?.id ? withBuildingId(current, building.id) : current\n\n\n router.replace(`${pathname}?${newSearchParams.toString()}`, { scroll: false })\n\n // Reset the flag after a brief delay to allow the navigation to complete\n setTimeout(() => {\n isUpdatingRef.current = false\n }, 100)\n }, [currentViewer, isMounted, pathname, router, viewer, searchParams])\n\n // Handle URL changes (direct navigation)\n React.useEffect(() => {\n if (isMounted && currentViewer !== validViewer && !isUpdatingRef.current) {\n isUpdatingRef.current = true\n\n menusDispatch({\n type: 'SET_VIEWER',\n payload: { currentViewer: validViewer },\n })\n\n // Reset the flag after a brief delay\n setTimeout(() => {\n isUpdatingRef.current = false\n }, 100)\n }\n }, [validViewer, menusDispatch, isMounted, currentViewer])\n\n // Null while a plugin page shows, so the branches below stay exhaustive over ViewerNames.\n const builtInViewer = pluginPage ? null : (validViewer as ViewerNames)\n const keptBim = useKeptAlive(builtInViewer === ViewerNames.bim ? ViewerNames.bim : null).length > 0\n const keptPluginPages = useKeptAlive(pluginPage ? validViewer : null)\n\n const selectedViewer = (\n <>\n {builtInViewer !== null\n && [ViewerNames.map, ViewerNames.bim].includes(builtInViewer)\n && <SidebarTrigger />}\n <div style={{ height: '100%', width: '100%', position: 'relative' }}>\n <div style={shownWhen(builtInViewer === ViewerNames.map)}>\n <MapViewer organization={organization} maptilerKey={maptilerKey} />\n </div>\n {keptBim && (\n <div style={hiddenInPlace(builtInViewer === ViewerNames.bim)} aria-hidden={builtInViewer !== ViewerNames.bim}>\n <BimViewer pointcloudApiUrl={pointcloudApiUrl} />\n </div>\n )}\n {builtInViewer !== null\n && [ViewerNames.buildings, ViewerNames.sites, ViewerNames.files, ViewerNames.land, ViewerNames.infrastructure, ViewerNames.users].includes(builtInViewer) && (\n <DataMenu currentViewer={builtInViewer} organization={organization} geocodeEarthApiKey={geocodeEarthApiKey} geocoderUrl={geocoderUrl} />\n )}\n {/* `plugins` used to route through DataMenu, which rendered nothing:\n VIEWER_CONFIG gives it no dataType. It has its own page now. */}\n {builtInViewer === ViewerNames.plugins && (\n <div className=\"h-full w-full overflow-y-auto\">\n <PluginsManager />\n </div>\n )}\n {builtInViewer === ViewerNames.settings && (\n <UserSettings storageBaseUrl={storageBaseUrl} />\n )}\n {keptPluginPages.map(page => (\n <div key={page} className=\"h-full w-full overflow-y-auto\" style={{ display: page === validViewer ? 'block' : 'none' }}>\n <PluginDataPageHost viewer={page} />\n </div>\n ))}\n </div>\n </>\n )\n\n return (\n <>\n {selectedViewer}\n <Toolbar viewer={validViewer} storageBaseUrl={storageBaseUrl} martinBaseUrl={martinBaseUrl} organization={organization} geocodeEarthApiKey={geocodeEarthApiKey} geocoderUrl={geocoderUrl} />\n <UploadProgressToasts />\n </>\n )\n}"],"mappings":";AA+B+B,SA6J3B,UA7J2B,KAwBzB,YAxByB;AAzB/B,SAAS,eAAe;AACxB,OAAO,aAAa;AACpB,SAAS,iBAAiB,WAAW,mBAAmB;AACxD,YAAY,WAAW;AAEvB,SAAS,4BAA4B;AACrC,SAAS,kBAAkB,oBAAoB;AAC/C,SAAS,mBAAmB;AAG5B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,eAAe;AACxB,SAAS,4BAA4B;AACrC,SAAS,sBAAsB;AAE/B,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAKhC,MAAM,YAAY;AAAA,EAChB,MAAM,OAAO,iBAAiB,EAAE,KAAK,QAAM,EAAE,SAAS,EAAE,UAAU,EAAE;AAAA,EACpE,EAAE,KAAK,OAAO,SAAS,MAAM,oBAAC,yBAAsB,OAAM,4BAAsB,EAAG;AACrF;AAGA,MAAM,iBAAiB;AAAA,EACrB,MAAM,OAAO,0BAA0B,EAAE,KAAK,QAAM,EAAE,SAAS,EAAE,eAAe,EAAE;AAAA,EAClF,EAAE,KAAK,OAAO,SAAS,M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AChE;AAAA,0BAAC,SAAI,OAAO,UAAU,kBAAkB,YAAY,GAAG,GACrD,8BAAC,aAAU,cAA4B,aAA0B,GACnE;AAAA,MACC,WACC,oBAAC,SAAI,OAAO,cAAc,kBAAkB,YAAY,GAAG,GAAG,eAAa,kBAAkB,YAAY,KACvG,8BAAC,aAAU,kBAAoC,GACjD;AAAA,MAED,kBAAkB,QACd,CAAC,YAAY,WAAW,YAAY,OAAO,YAAY,OAAO,YAAY,MAAM,YAAY,gBAAgB,YAAY,KAAK,EAAE,SAAS,aAAa,KACxJ,oBAAC,YAAS,eAAe,eAAe,cAA4B,oBAAwC,aAA0B;AAAA,MAIvI,kBAAkB,YAAY,WAC7B,oBAAC,SAAI,WAAU,iCACb,8BAAC,kBAAe,GAClB;AAAA,MAED,kBAAkB,YAAY,YAC7B,oBAAC,gBAAa,gBAAgC;AAAA,MAE/C,gBAAgB,IAAI,UACnB,oBAAC,SAAe,WAAU,iCAAgC,OAAO,EAAE,SAAS,SAAS,cAAc,UAAU,OAAO,GAClH,8BAAC,sBAAmB,QAAQ,MAAM,KAD1B,IAEV,CACD;AAAA,OACH;AAAA,KACF;AAGF,SACE,iCACG;AAAA;AAAA,IACD,oBAAC,WAAQ,QAAQ,aAAa,gBAAgC,eAA8B,cAA4B,oBAAwC,aAA0B;AAAA,IAC1L,oBAAC,wBAAqB;AAAA,KACxB;AAEJ;","names":[]}
|
|
@@ -58,8 +58,8 @@ function RowActions({
|
|
|
58
58
|
};
|
|
59
59
|
const [publishing, setPublishing] = React.useState(false);
|
|
60
60
|
const [published, setPublished] = React.useState(false);
|
|
61
|
-
const
|
|
62
|
-
const fileId =
|
|
61
|
+
const isOrgFile = typeof dataset.id === "string" && dataset.id.startsWith("org-minio-");
|
|
62
|
+
const fileId = isOrgFile ? Number(String(dataset.id).slice("org-minio-".length)) : null;
|
|
63
63
|
const tiledMatch = typeof dataset.id === "string" ? /^org_(\d+)_file_(\d+)$/.exec(dataset.id) : null;
|
|
64
64
|
const tiledFileId = tiledMatch ? Number(tiledMatch[2]) : typeof dataset.publishedFileId === "number" ? dataset.publishedFileId : null;
|
|
65
65
|
const [unpublishing, setUnpublishing] = React.useState(false);
|
|
@@ -88,7 +88,7 @@ function RowActions({
|
|
|
88
88
|
setUnpublishing(false);
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
|
-
const orgFileId =
|
|
91
|
+
const orgFileId = isOrgFile ? fileId : tiledMatch ? Number(tiledMatch[2]) : null;
|
|
92
92
|
const canDelete = orgFileId != null && !Number.isNaN(orgFileId) && ability.can("delete", "File");
|
|
93
93
|
const [confirmingDelete, setConfirmingDelete] = React.useState(false);
|
|
94
94
|
const [deleting, setDeleting] = React.useState(false);
|
|
@@ -138,7 +138,7 @@ function RowActions({
|
|
|
138
138
|
const result = await res.json();
|
|
139
139
|
setPublished(true);
|
|
140
140
|
const tileBaseUrl = (martinBaseUrl != null ? martinBaseUrl : "").replace(/\/+$/, "");
|
|
141
|
-
const
|
|
141
|
+
const orgFileDatasetId = `org-minio-${fileId}`;
|
|
142
142
|
const [optimistic] = buildPublishedTileDatasets(
|
|
143
143
|
[{
|
|
144
144
|
name: dataset.name,
|
|
@@ -149,10 +149,10 @@ function RowActions({
|
|
|
149
149
|
);
|
|
150
150
|
if (optimistic) {
|
|
151
151
|
const current = orgDatasets != null ? orgDatasets : [];
|
|
152
|
-
const swapped = current.some((d) => d.id ===
|
|
152
|
+
const swapped = current.some((d) => d.id === orgFileDatasetId) ? current.map((d) => d.id === orgFileDatasetId ? optimistic : d) : [...current, optimistic];
|
|
153
153
|
datasetsDispatch({ type: "SET_DATASETS", payload: { datasets: swapped } });
|
|
154
|
-
if (addedDatasets.some((d) => d.id ===
|
|
155
|
-
datasetsDispatch({ type: "REMOVE_DATASET_FROM_MAP", payload: { datasetId:
|
|
154
|
+
if (addedDatasets.some((d) => d.id === orgFileDatasetId)) {
|
|
155
|
+
datasetsDispatch({ type: "REMOVE_DATASET_FROM_MAP", payload: { datasetId: orgFileDatasetId } });
|
|
156
156
|
datasetsDispatch({ type: "ADD_DATASET_TO_MAP", payload: { dataset: optimistic } });
|
|
157
157
|
}
|
|
158
158
|
}
|
|
@@ -166,7 +166,7 @@ function RowActions({
|
|
|
166
166
|
setPublishing(false);
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
|
-
const isCatalogGeoJson = !
|
|
169
|
+
const isCatalogGeoJson = !isOrgFile && tiledFileId == null && dataset.datasetType === "GeoJSON" && !!dataset.portal && dataset.id != null;
|
|
170
170
|
const [publishingCatalog, setPublishingCatalog] = React.useState(false);
|
|
171
171
|
const [publishedCatalog, setPublishedCatalog] = React.useState(false);
|
|
172
172
|
const onPublishCatalog = async () => {
|
|
@@ -229,7 +229,7 @@ function RowActions({
|
|
|
229
229
|
)
|
|
230
230
|
}
|
|
231
231
|
),
|
|
232
|
-
|
|
232
|
+
isOrgFile && /* @__PURE__ */ jsx(
|
|
233
233
|
Button,
|
|
234
234
|
{
|
|
235
235
|
variant: "ghost",
|