integerated asset group create api
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import ToggleHeader from "../../ui/inputs/ToggleHeader";
|
import ToggleHeader from "../../ui/inputs/ToggleHeader";
|
||||||
// import Outline from "./Outline";
|
|
||||||
import Header from "./Header";
|
import Header from "./Header";
|
||||||
import { useToggleStore } from "../../../store/ui/useUIToggleStore";
|
import { useToggleStore } from "../../../store/ui/useUIToggleStore";
|
||||||
import Assets from "./assetList/Assets";
|
import Assets from "./assetList/Assets";
|
||||||
@@ -9,7 +8,7 @@ import Widgets from "./visualization/widgets/Widgets";
|
|||||||
import Templates from "../../../modules/visualization/template/Templates";
|
import Templates from "../../../modules/visualization/template/Templates";
|
||||||
import Search from "../../ui/inputs/Search";
|
import Search from "../../ui/inputs/Search";
|
||||||
import { useIsComparing } from "../../../store/builder/store";
|
import { useIsComparing } from "../../../store/builder/store";
|
||||||
import { Outline } from "../../../modules/builder/testUi/outline";
|
import { AssetOutline } from "../../ui/list/OutlineList/AssetOutline";
|
||||||
|
|
||||||
const SideBarLeft: React.FC = () => {
|
const SideBarLeft: React.FC = () => {
|
||||||
const [activeOption, setActiveOption] = useState("Widgets");
|
const [activeOption, setActiveOption] = useState("Widgets");
|
||||||
@@ -54,7 +53,7 @@ const SideBarLeft: React.FC = () => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ToggleHeader options={["Outline", "Assets"]} activeOption={activeOption} handleClick={handleToggleClick} />
|
<ToggleHeader options={["Outline", "Assets"]} activeOption={activeOption} handleClick={handleToggleClick} />
|
||||||
<div className="sidebar-left-content-container">{activeOption === "Outline" ? <Outline /> : <Assets />}</div>
|
<div className="sidebar-left-content-container">{activeOption === "Outline" ? <AssetOutline /> : <Assets />}</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -63,7 +62,7 @@ const SideBarLeft: React.FC = () => {
|
|||||||
{!isComparing && (
|
{!isComparing && (
|
||||||
<>
|
<>
|
||||||
<ToggleHeader options={["Outline"]} activeOption={activeOption} handleClick={handleToggleClick} />
|
<ToggleHeader options={["Outline"]} activeOption={activeOption} handleClick={handleToggleClick} />
|
||||||
<div className="sidebar-left-content-container">{activeOption === "Outline" ? <Outline /> : <Assets />}</div>
|
<div className="sidebar-left-content-container">{activeOption === "Outline" ? <AssetOutline /> : <Assets />}</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
@@ -78,4 +77,4 @@ const SideBarLeft: React.FC = () => {
|
|||||||
|
|
||||||
export default SideBarLeft;
|
export default SideBarLeft;
|
||||||
|
|
||||||
// sidebar-left-container opemn close sidebar-left-container smoothly
|
// sidebar-left-container open close sidebar-left-container smoothly
|
||||||
|
|||||||
@@ -1,25 +1,15 @@
|
|||||||
import { useState, useRef, DragEvent, useCallback } from "react";
|
import { useState, useRef, DragEvent, useCallback } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import {
|
import { EyeIcon, LockIcon, FolderIcon, ChevronIcon, CubeIcon, AddIcon, KebebIcon, CollapseAllIcon, FocusIcon } from "../../../icons/ExportCommonIcons";
|
||||||
EyeIcon,
|
import RenameInput from "../../inputs/RenameInput";
|
||||||
LockIcon,
|
import { useSceneContext } from "../../../../modules/scene/sceneContext";
|
||||||
FolderIcon,
|
import { useSocketStore } from "../../../../store/socket/useSocketStore";
|
||||||
ChevronIcon,
|
import useAssetResponseHandler from "../../../../modules/collaboration/responseHandler/useAssetResponseHandler";
|
||||||
CubeIcon,
|
|
||||||
AddIcon,
|
|
||||||
KebebIcon,
|
|
||||||
CollapseAllIcon,
|
|
||||||
FocusIcon,
|
|
||||||
} from "../../../components/icons/ExportCommonIcons";
|
|
||||||
import RenameInput from "../../../components/ui/inputs/RenameInput";
|
|
||||||
import { useSceneContext } from "../../scene/sceneContext";
|
|
||||||
import { useSocketStore } from "../../../store/socket/useSocketStore";
|
|
||||||
import useAssetResponseHandler from "../../collaboration/responseHandler/useAssetResponseHandler";
|
|
||||||
|
|
||||||
import { getUserData } from "../../../functions/getUserData";
|
import { getUserData } from "../../../../functions/getUserData";
|
||||||
import { setAssetsApi } from "../../../services/factoryBuilder/asset/floorAsset/setAssetsApi";
|
import { setAssetsApi } from "../../../../services/factoryBuilder/asset/floorAsset/setAssetsApi";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { useContextActionStore } from "../../../store/builder/store";
|
import { useContextActionStore } from "../../../../store/builder/store";
|
||||||
|
|
||||||
interface DragState {
|
interface DragState {
|
||||||
draggedItem: AssetGroupChild | null;
|
draggedItem: AssetGroupChild | null;
|
||||||
@@ -63,8 +53,7 @@ const TreeNode = ({
|
|||||||
const isLocked = item.isLocked;
|
const isLocked = item.isLocked;
|
||||||
const isExpanded = isGroupNode ? item.isExpanded : false;
|
const isExpanded = isGroupNode ? item.isExpanded : false;
|
||||||
const isSelected = !isGroupNode ? hasSelectedAsset(item.modelUuid) : false;
|
const isSelected = !isGroupNode ? hasSelectedAsset(item.modelUuid) : false;
|
||||||
const isMultiSelected =
|
const isMultiSelected = !isGroupNode && selectedAssets.length > 1 && hasSelectedAsset(item.modelUuid);
|
||||||
!isGroupNode && selectedAssets.length > 1 && hasSelectedAsset(item.modelUuid);
|
|
||||||
|
|
||||||
// Determine the parent group of this item
|
// Determine the parent group of this item
|
||||||
const getParentGroup = useCallback(
|
const getParentGroup = useCallback(
|
||||||
@@ -123,10 +112,7 @@ const TreeNode = ({
|
|||||||
const shouldShowHighlight = isDropTarget();
|
const shouldShowHighlight = isDropTarget();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div key={itemId} className={`tree-node ${shouldShowHighlight ? "drop-target-highlight" : ""}`}>
|
||||||
key={itemId}
|
|
||||||
className={`tree-node ${shouldShowHighlight ? "drop-target-highlight" : ""}`}
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
className={clsx("tree-node-content", {
|
className={clsx("tree-node-content", {
|
||||||
locked: isLocked,
|
locked: isLocked,
|
||||||
@@ -144,17 +130,12 @@ const TreeNode = ({
|
|||||||
onClick={handleNodeClick}
|
onClick={handleNodeClick}
|
||||||
>
|
>
|
||||||
{isGroupNode && (
|
{isGroupNode && (
|
||||||
<button
|
<button className="expand-button" onClick={() => onToggleExpand(item.groupUuid, !isExpanded)}>
|
||||||
className="expand-button"
|
|
||||||
onClick={() => onToggleExpand(item.groupUuid, !isExpanded)}
|
|
||||||
>
|
|
||||||
<ChevronIcon isOpen={isExpanded} />
|
<ChevronIcon isOpen={isExpanded} />
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="node-icon">
|
<div className="node-icon">{isGroupNode ? <FolderIcon isOpen={isExpanded} /> : <CubeIcon />}</div>
|
||||||
{isGroupNode ? <FolderIcon isOpen={isExpanded} /> : <CubeIcon />}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<RenameInput value={itemName} onRename={() => {}} canEdit={true} />
|
<RenameInput value={itemName} onRename={() => {}} canEdit={true} />
|
||||||
|
|
||||||
@@ -230,7 +211,7 @@ const TreeNode = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Main Component
|
// Main Component
|
||||||
export const Outline = () => {
|
export const AssetOutline = () => {
|
||||||
const [isOpen, setIsOpen] = useState(true);
|
const [isOpen, setIsOpen] = useState(true);
|
||||||
const { setContextAction } = useContextActionStore();
|
const { setContextAction } = useContextActionStore();
|
||||||
const lastSelectedRef = useRef<{ item: AssetGroupChild; index: number } | null>(null);
|
const lastSelectedRef = useRef<{ item: AssetGroupChild; index: number } | null>(null);
|
||||||
@@ -242,25 +223,8 @@ export const Outline = () => {
|
|||||||
});
|
});
|
||||||
const [_, forceUpdate] = useState({});
|
const [_, forceUpdate] = useState({});
|
||||||
const { scene, assetGroupStore, assetStore, versionStore, undoRedo3DStore } = useSceneContext();
|
const { scene, assetGroupStore, assetStore, versionStore, undoRedo3DStore } = useSceneContext();
|
||||||
const {
|
const { addSelectedAsset, clearSelectedAssets, getAssetById, peekToggleVisibility, peekToggleLock, toggleSelectedAsset, selectedAssets } = assetStore();
|
||||||
addSelectedAsset,
|
const { groupHierarchy, isGroup, getGroupsContainingAsset, getFlatGroupChildren, setGroupExpanded, addChildToGroup, removeChildFromGroup, getGroupsContainingGroup } = assetGroupStore();
|
||||||
clearSelectedAssets,
|
|
||||||
getAssetById,
|
|
||||||
peekToggleVisibility,
|
|
||||||
peekToggleLock,
|
|
||||||
toggleSelectedAsset,
|
|
||||||
selectedAssets,
|
|
||||||
} = assetStore();
|
|
||||||
const {
|
|
||||||
groupHierarchy,
|
|
||||||
isGroup,
|
|
||||||
getGroupsContainingAsset,
|
|
||||||
getFlatGroupChildren,
|
|
||||||
setGroupExpanded,
|
|
||||||
addChildToGroup,
|
|
||||||
removeChildFromGroup,
|
|
||||||
getGroupsContainingGroup,
|
|
||||||
} = assetGroupStore();
|
|
||||||
const { projectId } = useParams();
|
const { projectId } = useParams();
|
||||||
const { push3D } = undoRedo3DStore();
|
const { push3D } = undoRedo3DStore();
|
||||||
const { builderSocket } = useSocketStore();
|
const { builderSocket } = useSocketStore();
|
||||||
@@ -304,11 +268,7 @@ export const Outline = () => {
|
|||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data.message || !data.data) {
|
if (!data.message || !data.data) {
|
||||||
echo.error(
|
echo.error(`Error ${asset.isVisible ? "hiding" : "unhiding"} asset: ${asset.modelName}`);
|
||||||
`Error ${asset.isVisible ? "hiding" : "unhiding"} asset: ${
|
|
||||||
asset.modelName
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.message === "Model updated successfully" && data.data) {
|
if (data.message === "Model updated successfully" && data.data) {
|
||||||
@@ -327,22 +287,14 @@ export const Outline = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
updateAssetInScene(model, () => {
|
updateAssetInScene(model, () => {
|
||||||
echo.info(
|
echo.info(`${asset.isVisible ? "Hid" : "Unhid"} asset: ${model.modelName}`);
|
||||||
`${asset.isVisible ? "Hid" : "Unhid"} asset: ${model.modelName}`
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
echo.error(
|
echo.error(`Error ${asset.isVisible ? "hiding" : "unhiding"} asset: ${asset.modelName}`);
|
||||||
`Error ${asset.isVisible ? "hiding" : "unhiding"} asset: ${
|
|
||||||
asset.modelName
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
echo.error(
|
echo.error(`Error ${asset.isVisible ? "hiding" : "unhiding"} asset: ${asset.modelName}`);
|
||||||
`Error ${asset.isVisible ? "hiding" : "unhiding"} asset: ${asset.modelName}`
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const data = {
|
const data = {
|
||||||
@@ -387,11 +339,7 @@ export const Outline = () => {
|
|||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (!data.message || !data.data) {
|
if (!data.message || !data.data) {
|
||||||
echo.error(
|
echo.error(`Error ${asset.isVisible ? "locking" : "unlocking"} asset: ${asset.modelName}`);
|
||||||
`Error ${asset.isVisible ? "locking" : "unlocking"} asset: ${
|
|
||||||
asset.modelName
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (data.message === "Model updated successfully" && data.data) {
|
if (data.message === "Model updated successfully" && data.data) {
|
||||||
@@ -410,26 +358,14 @@ export const Outline = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
updateAssetInScene(model, () => {
|
updateAssetInScene(model, () => {
|
||||||
echo.info(
|
echo.info(`${asset.isVisible ? "Locked" : "Unlocked"} asset: ${model.modelName}`);
|
||||||
`${asset.isVisible ? "Locked" : "Unlocked"} asset: ${
|
|
||||||
model.modelName
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
echo.error(
|
echo.error(`Error ${asset.isVisible ? "locking" : "unlocking"} asset: ${asset.modelName}`);
|
||||||
`Error ${asset.isVisible ? "locking" : "unlocking"} asset: ${
|
|
||||||
asset.modelName
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
echo.error(
|
echo.error(`Error ${asset.isVisible ? "locking" : "unlocking"} asset: ${asset.modelName}`);
|
||||||
`Error ${asset.isVisible ? "locking" : "unlocking"} asset: ${
|
|
||||||
asset.modelName
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const data = {
|
const data = {
|
||||||
@@ -461,16 +397,13 @@ export const Outline = () => {
|
|||||||
[setGroupExpanded]
|
[setGroupExpanded]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleDragStart = useCallback(
|
const handleDragStart = useCallback((e: DragEvent, item: AssetGroupChild, parentGroupUuid: string | null) => {
|
||||||
(e: DragEvent, item: AssetGroupChild, parentGroupUuid: string | null) => {
|
dragStateRef.current.draggedItem = item;
|
||||||
dragStateRef.current.draggedItem = item;
|
dragStateRef.current.draggedItemParentGroupUuid = parentGroupUuid;
|
||||||
dragStateRef.current.draggedItemParentGroupUuid = parentGroupUuid;
|
|
||||||
|
|
||||||
e.dataTransfer.effectAllowed = "move";
|
e.dataTransfer.effectAllowed = "move";
|
||||||
forceUpdate({});
|
forceUpdate({});
|
||||||
},
|
}, []);
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleDragOver = useCallback(
|
const handleDragOver = useCallback(
|
||||||
(e: DragEvent, targetItem: AssetGroupChild) => {
|
(e: DragEvent, targetItem: AssetGroupChild) => {
|
||||||
@@ -540,10 +473,7 @@ export const Outline = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update target group
|
// Update target group
|
||||||
if (
|
if (dragStateRef.current.targetGroupUuid !== targetGroupUuid || dragStateRef.current.isRootTarget !== false) {
|
||||||
dragStateRef.current.targetGroupUuid !== targetGroupUuid ||
|
|
||||||
dragStateRef.current.isRootTarget !== false
|
|
||||||
) {
|
|
||||||
dragStateRef.current.targetGroupUuid = targetGroupUuid;
|
dragStateRef.current.targetGroupUuid = targetGroupUuid;
|
||||||
dragStateRef.current.isRootTarget = false;
|
dragStateRef.current.isRootTarget = false;
|
||||||
forceUpdate({});
|
forceUpdate({});
|
||||||
@@ -657,9 +587,7 @@ export const Outline = () => {
|
|||||||
|
|
||||||
// Update last selected reference
|
// Update last selected reference
|
||||||
const flattened = getFlattenedHierarchy();
|
const flattened = getFlattenedHierarchy();
|
||||||
const index = flattened.findIndex(
|
const index = flattened.findIndex((flatItem) => getItemId(flatItem) === getItemId(item));
|
||||||
(flatItem) => getItemId(flatItem) === getItemId(item)
|
|
||||||
);
|
|
||||||
lastSelectedRef.current = { item, index };
|
lastSelectedRef.current = { item, index };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -673,9 +601,7 @@ export const Outline = () => {
|
|||||||
|
|
||||||
// Update last selected reference
|
// Update last selected reference
|
||||||
const flattened = getFlattenedHierarchy();
|
const flattened = getFlattenedHierarchy();
|
||||||
const index = flattened.findIndex(
|
const index = flattened.findIndex((flatItem) => getItemId(flatItem) === getItemId(item));
|
||||||
(flatItem) => getItemId(flatItem) === getItemId(item)
|
|
||||||
);
|
|
||||||
lastSelectedRef.current = { item, index };
|
lastSelectedRef.current = { item, index };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -683,9 +609,7 @@ export const Outline = () => {
|
|||||||
// Shift+Click - range selection
|
// Shift+Click - range selection
|
||||||
else if (isShiftClick) {
|
else if (isShiftClick) {
|
||||||
const flattened = getFlattenedHierarchy();
|
const flattened = getFlattenedHierarchy();
|
||||||
const clickedIndex = flattened.findIndex(
|
const clickedIndex = flattened.findIndex((flatItem) => getItemId(flatItem) === getItemId(item));
|
||||||
(flatItem) => getItemId(flatItem) === getItemId(item)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (clickedIndex === -1) return;
|
if (clickedIndex === -1) return;
|
||||||
|
|
||||||
@@ -731,14 +655,7 @@ export const Outline = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[
|
[scene, isGroup, clearSelectedAssets, addSelectedAsset, getFlattenedHierarchy, toggleSelectedAsset]
|
||||||
scene,
|
|
||||||
isGroup,
|
|
||||||
clearSelectedAssets,
|
|
||||||
addSelectedAsset,
|
|
||||||
getFlattenedHierarchy,
|
|
||||||
toggleSelectedAsset,
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleOptionClick = useCallback(
|
const handleOptionClick = useCallback(
|
||||||
@@ -860,11 +777,8 @@ export const Outline = () => {
|
|||||||
className="toolbar-button"
|
className="toolbar-button"
|
||||||
title="Expand All"
|
title="Expand All"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const { assetGroups, setGroupExpanded } =
|
const { assetGroups, setGroupExpanded } = assetGroupStore.getState();
|
||||||
assetGroupStore.getState();
|
assetGroups.forEach((group) => setGroupExpanded(group.groupUuid, true));
|
||||||
assetGroups.forEach((group) =>
|
|
||||||
setGroupExpanded(group.groupUuid, true)
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CollapseAllIcon />
|
<CollapseAllIcon />
|
||||||
@@ -876,13 +790,7 @@ export const Outline = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{isOpen && (
|
{isOpen && (
|
||||||
<div
|
<div className={`outline-content ${dragStateRef.current.isRootTarget ? "root-drop-target" : ""}`} onDragOver={handleRootDragOver} onDrop={handleDrop}>
|
||||||
className={`outline-content ${
|
|
||||||
dragStateRef.current.isRootTarget ? "root-drop-target" : ""
|
|
||||||
}`}
|
|
||||||
onDragOver={handleRootDragOver}
|
|
||||||
onDrop={handleDrop}
|
|
||||||
>
|
|
||||||
{groupHierarchy.map((item) => (
|
{groupHierarchy.map((item) => (
|
||||||
<TreeNode
|
<TreeNode
|
||||||
key={isGroup(item) ? item.groupUuid : item.modelUuid}
|
key={isGroup(item) ? item.groupUuid : item.modelUuid}
|
||||||
@@ -902,12 +810,8 @@ export const Outline = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="outline-footer">
|
<div className="outline-footer">
|
||||||
<span
|
<span className={`footer-stats ${selectedAssets.length > 1 ? "multi-selection" : ""}`}>
|
||||||
className={`footer-stats ${selectedAssets.length > 1 ? "multi-selection" : ""}`}
|
{selectedAssets.length > 1 ? `${selectedAssets.length} items selected` : `${groupHierarchy.length} root items`}
|
||||||
>
|
|
||||||
{selectedAssets.length > 1
|
|
||||||
? `${selectedAssets.length} items selected`
|
|
||||||
: `${groupHierarchy.length} root items`}
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
@@ -61,7 +61,7 @@ function WallCreator() {
|
|||||||
|
|
||||||
const addWallToBackend = (wall: Wall) => {
|
const addWallToBackend = (wall: Wall) => {
|
||||||
if (projectId) {
|
if (projectId) {
|
||||||
if (!builderSocket?.connected) {
|
if (builderSocket?.connected) {
|
||||||
// API
|
// API
|
||||||
|
|
||||||
upsertWallApi(projectId, selectedVersion?.versionId || "", wall)
|
upsertWallApi(projectId, selectedVersion?.versionId || "", wall)
|
||||||
@@ -104,7 +104,7 @@ function WallCreator() {
|
|||||||
organization: organization,
|
organization: organization,
|
||||||
};
|
};
|
||||||
|
|
||||||
builderSocket.emit("v1:model-Wall:add", data);
|
// builderSocket.emit("v1:model-Wall:add", data);
|
||||||
|
|
||||||
setTempPoints([]);
|
setTempPoints([]);
|
||||||
setIsCreating(false);
|
setIsCreating(false);
|
||||||
|
|||||||
@@ -11,14 +11,15 @@ import useCallBackOnKey from "../../../../utils/hooks/useCallBackOnKey";
|
|||||||
import generateUniqueAssetGroupName from "../../../builder/asset/functions/generateUniqueAssetGroupName";
|
import generateUniqueAssetGroupName from "../../../builder/asset/functions/generateUniqueAssetGroupName";
|
||||||
import { setAssetsApi } from "../../../../services/factoryBuilder/asset/floorAsset/setAssetsApi";
|
import { setAssetsApi } from "../../../../services/factoryBuilder/asset/floorAsset/setAssetsApi";
|
||||||
import { getAssetGroupsApi } from "../../../../services/factoryBuilder/group/assetGroup/getAssetGroupsApi";
|
import { getAssetGroupsApi } from "../../../../services/factoryBuilder/group/assetGroup/getAssetGroupsApi";
|
||||||
|
import { createAssetGroupApi } from "../../../../services/factoryBuilder/group/assetGroup/createAssetGroupApi";
|
||||||
|
|
||||||
function GroupControls() {
|
function GroupControls() {
|
||||||
const { projectId } = useParams();
|
const { projectId } = useParams();
|
||||||
const { builderSocket } = useSocketStore();
|
const { builderSocket } = useSocketStore();
|
||||||
const { assetStore, undoRedo3DStore, versionStore, assetGroupStore } = useSceneContext();
|
const { assetStore, undoRedo3DStore, versionStore, assetGroupStore } = useSceneContext();
|
||||||
const { assetGroups, addGroup, buildHierarchy } = assetGroupStore();
|
const { assetGroups, addGroup, setGroups, buildHierarchy } = assetGroupStore();
|
||||||
const { push3D } = undoRedo3DStore();
|
const { push3D } = undoRedo3DStore();
|
||||||
const { assets, selectedAssets, pastedObjects, duplicatedObjects, movedObjects, rotatedObjects } = assetStore();
|
const { assets, selectedAssets, pastedObjects, duplicatedObjects, movedObjects, rotatedObjects, getSelectedAssetUuids } = assetStore();
|
||||||
const { updateAssetInScene, removeAssetFromScene } = useAssetResponseHandler();
|
const { updateAssetInScene, removeAssetFromScene } = useAssetResponseHandler();
|
||||||
const { contextAction, setContextAction } = useContextActionStore();
|
const { contextAction, setContextAction } = useContextActionStore();
|
||||||
const { selectedVersion } = versionStore();
|
const { selectedVersion } = versionStore();
|
||||||
@@ -29,6 +30,9 @@ function GroupControls() {
|
|||||||
|
|
||||||
getAssetGroupsApi(projectId, selectedVersion.versionId).then((data) => {
|
getAssetGroupsApi(projectId, selectedVersion.versionId).then((data) => {
|
||||||
console.log("data: ", data);
|
console.log("data: ", data);
|
||||||
|
if (data && data.length > 0) {
|
||||||
|
setGroups(data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}, [projectId, selectedVersion]);
|
}, [projectId, selectedVersion]);
|
||||||
|
|
||||||
@@ -43,18 +47,12 @@ function GroupControls() {
|
|||||||
setContextAction(null);
|
setContextAction(null);
|
||||||
groupSelection();
|
groupSelection();
|
||||||
}
|
}
|
||||||
}, [contextAction]);
|
}, [contextAction, projectId, selectedVersion]);
|
||||||
|
|
||||||
const groupSelection = () => {
|
const groupSelection = () => {
|
||||||
const assetUuids: string[] = [];
|
const assetUuids: string[] = getSelectedAssetUuids();
|
||||||
|
|
||||||
selectedAssets.forEach((selectedAsset) => {
|
if (assetUuids.length > 0 && projectId && selectedVersion) {
|
||||||
if (selectedAsset.userData.modelUuid) {
|
|
||||||
assetUuids.push(selectedAsset.userData.modelUuid);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (assetUuids.length > 0) {
|
|
||||||
const groupName = generateUniqueAssetGroupName({ baseName: "Group", existingGroups: assetGroups });
|
const groupName = generateUniqueAssetGroupName({ baseName: "Group", existingGroups: assetGroups });
|
||||||
|
|
||||||
const assetGroup: AssetGroup = {
|
const assetGroup: AssetGroup = {
|
||||||
@@ -67,7 +65,21 @@ function GroupControls() {
|
|||||||
return { type: "Asset", childrenUuid: assetUuid };
|
return { type: "Asset", childrenUuid: assetUuid };
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
addGroup(assetGroup);
|
console.log("assetGroup: ", assetGroup);
|
||||||
|
// addGroup(assetGroup);
|
||||||
|
|
||||||
|
createAssetGroupApi({
|
||||||
|
projectId,
|
||||||
|
versionId: selectedVersion.versionId,
|
||||||
|
groupUuid: assetGroup.groupUuid,
|
||||||
|
groupName: assetGroup.groupName,
|
||||||
|
isVisible: assetGroup.isVisible,
|
||||||
|
isExpanded: assetGroup.isExpanded,
|
||||||
|
isLocked: assetGroup.isLocked,
|
||||||
|
childrens: assetGroup.childrens,
|
||||||
|
}).then((data) => {
|
||||||
|
console.log("data: ", data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,6 +93,8 @@ function GroupControls() {
|
|||||||
{ dependencies: [pastedObjects, duplicatedObjects, movedObjects, rotatedObjects, selectedAssets, selectedVersion, builderSocket, projectId, userId, organization], noRepeat: true }
|
{ dependencies: [pastedObjects, duplicatedObjects, movedObjects, rotatedObjects, selectedAssets, selectedVersion, builderSocket, projectId, userId, organization], noRepeat: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useCallBackOnKey(() => {}, "Alt+G", { dependencies: [], noRepeat: true });
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +1,44 @@
|
|||||||
const url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
|
const url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
|
||||||
|
|
||||||
interface Props {
|
export const createAssetGroupApi = async ({
|
||||||
|
projectId,
|
||||||
|
versionId,
|
||||||
|
groupUuid,
|
||||||
|
groupName,
|
||||||
|
isVisible,
|
||||||
|
isExpanded,
|
||||||
|
isLocked,
|
||||||
|
childrens,
|
||||||
|
}: {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
versionId: string;
|
versionId: string;
|
||||||
groupUuid: string;
|
groupUuid: string;
|
||||||
groupName: string;
|
groupName: string;
|
||||||
isVisible: string;
|
isVisible: boolean;
|
||||||
isExpanded: string;
|
isExpanded: boolean;
|
||||||
isLocked: string;
|
isLocked: boolean;
|
||||||
childrens: {
|
childrens: {
|
||||||
type: "Asset" | "Group";
|
type: "Asset" | "Group";
|
||||||
childrenUuid: string;
|
childrenUuid: string;
|
||||||
}[];
|
}[];
|
||||||
}
|
}) => {
|
||||||
|
|
||||||
export const createAssetGroupApi = async (props: Props) => {
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${url_Backend_dwinzo}/api/V1/assetgroup/${props.projectId}/${props.versionId}`, {
|
const response = await fetch(`${url_Backend_dwinzo}/api/V1/assetgroup/${projectId}/${versionId}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Bearer ${localStorage.getItem("token") || ""}`,
|
Authorization: `Bearer ${localStorage.getItem("token") || ""}`,
|
||||||
token: localStorage.getItem("token") || "",
|
token: localStorage.getItem("token") || "",
|
||||||
refresh_token: localStorage.getItem("refreshToken") || "",
|
refresh_token: localStorage.getItem("refreshToken") || "",
|
||||||
body: JSON.stringify({
|
|
||||||
groupUuid: props.groupUuid,
|
|
||||||
groupName: props.groupName,
|
|
||||||
isVisible: props.isVisible,
|
|
||||||
isExpanded: props.isExpanded,
|
|
||||||
isLocked: props.isLocked,
|
|
||||||
childrens: props.childrens,
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
groupUuid: groupUuid,
|
||||||
|
groupName: groupName,
|
||||||
|
isVisible: isVisible,
|
||||||
|
isExpanded: isExpanded,
|
||||||
|
isLocked: isLocked,
|
||||||
|
childrens: childrens,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const newAccessToken = response.headers.get("x-access-token");
|
const newAccessToken = response.headers.get("x-access-token");
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_UR
|
|||||||
|
|
||||||
export const getAssetGroupsApi = async (projectId: string, versionId: string) => {
|
export const getAssetGroupsApi = async (projectId: string, versionId: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${url_Backend_dwinzo}/api/V1/assetGroups/${projectId}/${versionId}`, {
|
const response = await fetch(`${url_Backend_dwinzo}/api/V1/assetgroups/${projectId}/${versionId}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer <access_token>",
|
Authorization: "Bearer <access_token>",
|
||||||
|
|||||||
Reference in New Issue
Block a user