Sync BIM attachment versions from viewer storage

This commit is contained in:
DCCONSTRUCTIONS
2026-06-23 11:32:49 +03:00
parent 4ed460ae45
commit df4767a085
4 changed files with 105 additions and 8 deletions
@@ -28,10 +28,12 @@ import {
buildBeamViewerUrl,
dispatchBeamViewerOpenEvent,
fetchBeamConversionStatus,
fetchBeamModelVersions,
getBeamModelVersionRecords,
getBeamVersionViewerUrl,
getBeamViewerAttachment,
isBeamModelFile,
mergeBeamModelVersionRecordLists,
syncCurrentBeamVersionRecord,
type TBeamModelVersionRecord,
type TBeamViewerAttachment,
@@ -85,7 +87,8 @@ const withBeamViewerSettingsSrc = (
url: string | null | undefined,
settingsSrc: string | undefined
): string | undefined => {
if (!url || !settingsSrc) return url;
if (!url) return undefined;
if (!settingsSrc) return url;
try {
const parsedUrl = new URL(url, "http://localhost");
if (!parsedUrl.searchParams.has("settingsSrc")) parsedUrl.searchParams.set("settingsSrc", settingsSrc);
@@ -241,9 +244,14 @@ export const IssueAttachmentsListItem = observer(function IssueAttachmentsListIt
const [deletingVersionKey, setDeletingVersionKey] = useState<string | null>(null);
const [isVersionUploading, setIsVersionUploading] = useState(false);
const [isThumbnailError, setIsThumbnailError] = useState(false);
const [liveBeamVersions, setLiveBeamVersions] = useState<TBeamModelVersionRecord[]>([]);
const versionUploadInputRef = useRef<HTMLInputElement>(null);
const beamVersions = useMemo(() => getBeamModelVersionRecords(beamViewer, attachment), [attachment, beamViewer]);
const rawVersion = beamViewer?.version ?? attachment?.attributes.version;
const localBeamVersions = useMemo(() => getBeamModelVersionRecords(beamViewer, attachment), [attachment, beamViewer]);
const beamVersions = useMemo(
() => mergeBeamModelVersionRecordLists(localBeamVersions, liveBeamVersions),
[localBeamVersions, liveBeamVersions]
);
const rawVersion = beamViewer?.version ?? (attachment?.attributes as { version?: number | string } | undefined)?.version;
const versionLabel =
typeof rawVersion === "number"
? `v${rawVersion}`
@@ -414,6 +422,29 @@ export const IssueAttachmentsListItem = observer(function IssueAttachmentsListIt
/>
) : null;
useEffect(() => {
if (!beamViewer?.src) {
setLiveBeamVersions([]);
return;
}
let isMounted = true;
fetchBeamModelVersions(beamViewer)
.then((history) => {
if (!isMounted) return;
setLiveBeamVersions(Array.isArray(history.versions) ? history.versions : []);
})
.catch((error) => {
if (!isMounted) return;
console.warn("BIM version history unavailable:", error);
setLiveBeamVersions([]);
});
return () => {
isMounted = false;
};
}, [beamViewer?.assetId, beamViewer?.projectId, beamViewer?.src, beamViewer?.versionId]);
useEffect(() => {
if (!beamViewer || !beamViewer.src) return;
if (beamViewer.conversion?.status === "ready" && storedModelViewerUrl) return;
@@ -973,8 +1004,8 @@ const BeamVersionHistoryModal = (props: TBeamVersionHistoryModal) => {
<div>Статус</div>
<div className="text-right">Действия</div>
</div>
{versions
.toSorted((first, second) => second.version - first.version)
{[...versions]
.sort((first, second) => second.version - first.version)
.map((version) => {
const viewerUrl = getBeamVersionViewerUrl(version);
const isCurrent = currentVersionId
@@ -148,6 +148,7 @@ export class IssueAttachmentService extends APIService {
{
...nextBeamViewer,
assetId,
projectId: nextBeamViewer.projectId || previousBeamViewer.projectId,
previewAvailable: nextBeamViewer.previewAvailable,
uploadedBy,
version: nextVersion,