Develop #16
@@ -26,11 +26,11 @@ type WorkspaceTreeProps = {
|
|||||||
// 唯一标识此 group(通常 `__group__<owner_user_id>`),让多个 owner 的 group 各自独立展开。
|
// 唯一标识此 group(通常 `__group__<owner_user_id>`),让多个 owner 的 group 各自独立展开。
|
||||||
groupKey: string;
|
groupKey: string;
|
||||||
expandedPaths: Set<string>;
|
expandedPaths: Set<string>;
|
||||||
onToggle: (path: string) => void;
|
onToggle: (path: string, loadPath?: string) => void;
|
||||||
loadingChildrenPaths: Set<string>;
|
loadingChildrenPaths: Set<string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type WorkspaceTreeItemsProps = Omit<WorkspaceTreeProps, "title" | "readOnly" | "groupKey"> & {
|
type WorkspaceTreeItemsProps = Omit<WorkspaceTreeProps, "title" | "readOnly"> & {
|
||||||
path: string;
|
path: string;
|
||||||
depth: number;
|
depth: number;
|
||||||
};
|
};
|
||||||
@@ -100,6 +100,7 @@ export function WorkspaceTreeGroup({
|
|||||||
{open && (
|
{open && (
|
||||||
<div className="tree-group__items">
|
<div className="tree-group__items">
|
||||||
<WorkspaceTreeItems
|
<WorkspaceTreeItems
|
||||||
|
groupKey={groupKey}
|
||||||
path=""
|
path=""
|
||||||
depth={0}
|
depth={0}
|
||||||
scripts={scripts}
|
scripts={scripts}
|
||||||
@@ -123,6 +124,7 @@ export function WorkspaceTreeGroup({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function WorkspaceTreeItems({
|
function WorkspaceTreeItems({
|
||||||
|
groupKey,
|
||||||
path,
|
path,
|
||||||
depth,
|
depth,
|
||||||
scripts,
|
scripts,
|
||||||
@@ -145,6 +147,7 @@ function WorkspaceTreeItems({
|
|||||||
{childDirectories.map((directory) => (
|
{childDirectories.map((directory) => (
|
||||||
<DirectoryBranch
|
<DirectoryBranch
|
||||||
key={directory.path}
|
key={directory.path}
|
||||||
|
groupKey={groupKey}
|
||||||
directory={directory}
|
directory={directory}
|
||||||
depth={depth}
|
depth={depth}
|
||||||
scripts={scripts}
|
scripts={scripts}
|
||||||
@@ -196,6 +199,7 @@ function WorkspaceTreeItems({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function DirectoryBranch({
|
function DirectoryBranch({
|
||||||
|
groupKey,
|
||||||
directory,
|
directory,
|
||||||
depth,
|
depth,
|
||||||
scripts,
|
scripts,
|
||||||
@@ -209,7 +213,8 @@ function DirectoryBranch({
|
|||||||
}: Omit<WorkspaceTreeItemsProps, "path"> & {
|
}: Omit<WorkspaceTreeItemsProps, "path"> & {
|
||||||
directory: WorkspaceDirectory;
|
directory: WorkspaceDirectory;
|
||||||
}) {
|
}) {
|
||||||
const open = expandedPaths.has(directory.path);
|
const expandKey = `${groupKey}/${directory.path}`;
|
||||||
|
const open = expandedPaths.has(expandKey);
|
||||||
const childrenLoading = loadingChildrenPaths.has(directory.path);
|
const childrenLoading = loadingChildrenPaths.has(directory.path);
|
||||||
return (
|
return (
|
||||||
<div className="directory-branch">
|
<div className="directory-branch">
|
||||||
@@ -217,7 +222,7 @@ function DirectoryBranch({
|
|||||||
className="directory-row"
|
className="directory-row"
|
||||||
style={{ paddingLeft: 10 + depth * 16 }}
|
style={{ paddingLeft: 10 + depth * 16 }}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => onToggle(directory.path)}
|
onClick={() => onToggle(expandKey, directory.path)}
|
||||||
onContextMenu={onContextMenu
|
onContextMenu={onContextMenu
|
||||||
? (event) => onContextMenu(event, {
|
? (event) => onContextMenu(event, {
|
||||||
kind: "directory",
|
kind: "directory",
|
||||||
@@ -234,6 +239,7 @@ function DirectoryBranch({
|
|||||||
</button>
|
</button>
|
||||||
{open && (
|
{open && (
|
||||||
<WorkspaceTreeItems
|
<WorkspaceTreeItems
|
||||||
|
groupKey={groupKey}
|
||||||
path={directory.path}
|
path={directory.path}
|
||||||
depth={depth + 1}
|
depth={depth + 1}
|
||||||
scripts={scripts}
|
scripts={scripts}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ type State = {
|
|||||||
createFolder: (name: string, parentPath: string) => Promise<void>;
|
createFolder: (name: string, parentPath: string) => Promise<void>;
|
||||||
deleteScript: (script: ScriptItem) => Promise<void>;
|
deleteScript: (script: ScriptItem) => Promise<void>;
|
||||||
deleteDirectory: (path: string) => Promise<void>;
|
deleteDirectory: (path: string) => Promise<void>;
|
||||||
toggleExpanded: (path: string) => Promise<void>;
|
toggleExpanded: (path: string, loadPath?: string) => Promise<void>;
|
||||||
loadChildren: (parentPath: string) => Promise<void>;
|
loadChildren: (parentPath: string) => Promise<void>;
|
||||||
toggleScriptLock: (script: ScriptItem) => Promise<void>;
|
toggleScriptLock: (script: ScriptItem) => Promise<void>;
|
||||||
openPublishDialog: (script: ScriptItem) => void;
|
openPublishDialog: (script: ScriptItem) => void;
|
||||||
@@ -292,7 +292,7 @@ export const useScriptWorkspaceStore = create<State>((set, get) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleExpanded: async (path) => {
|
toggleExpanded: async (path, loadPath) => {
|
||||||
const state = get();
|
const state = get();
|
||||||
const isOpen = state.expandedPaths.has(path);
|
const isOpen = state.expandedPaths.has(path);
|
||||||
const next = new Set(state.expandedPaths);
|
const next = new Set(state.expandedPaths);
|
||||||
@@ -301,8 +301,9 @@ export const useScriptWorkspaceStore = create<State>((set, get) => {
|
|||||||
} else {
|
} else {
|
||||||
next.add(path);
|
next.add(path);
|
||||||
// group key (`__group__<owner_id>`) 不是 workspace 路径,不调 loadChildren
|
// group key (`__group__<owner_id>`) 不是 workspace 路径,不调 loadChildren
|
||||||
if (!path.startsWith("__group__") && !state.loadedChildPaths.has(path)) {
|
const actualLoadPath = loadPath ?? path;
|
||||||
void get().loadChildren(path);
|
if (!actualLoadPath.startsWith("__group__") && !state.loadedChildPaths.has(actualLoadPath)) {
|
||||||
|
void get().loadChildren(actualLoadPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set({ expandedPaths: next });
|
set({ expandedPaths: next });
|
||||||
|
|||||||
Reference in New Issue
Block a user