Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[UI][RFC] SelectiveView #471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions 32 apps/ui/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1294,10 +1294,24 @@ function PodTreeItem({ id, node2children }) {
);
}

function dfs(node, node2children, visited) {
if (!visited.has(node)) {
visited.add(node);
const children = node2children.get(node);
children.forEach((n) => {
dfs(n, node2children, visited);
});
}
}

function TableofPods() {
const store = useContext(RepoContext);
if (!store) throw new Error("Missing BearContext.Provider in the tree");
const nodesMap = useStore(store, (state) => state.getNodesMap());
const selectedToc = useStore(store, (state) => state.selectedToc);
const setSelectedToc = useStore(store, (state) => state.setSelectedToc);
const setSelectiveView = useStore(store, (state) => state.setSelectiveView);
const clearSelectedToc = useStore(store, (state) => state.clearSelectedToc);
let node2children = new Map<string, string[]>();
let keys = new Set(nodesMap.keys());

Expand All @@ -1323,6 +1337,23 @@ function TableofPods() {
}
}

const handleSelect = (event, nodeIds: string[]) => {
if (nodeIds.length > 1) {
const selectedItems = new Set<string>();
//select all descendants of a node
nodeIds.forEach((n) => {
dfs(n, node2children, selectedItems);
});

if (selectedItems !== selectedToc) {
setSelectedToc(selectedItems);
}
setSelectiveView(true);
} else {
clearSelectedToc();
setSelectiveView(false);
}
};
return (
<TreeView
aria-label="multi-select"
Expand All @@ -1331,6 +1362,7 @@ function TableofPods() {
defaultExpanded={Array.from(node2children.keys()).filter(
(key) => node2children!.get(key!)!.length > 0
)}
onNodeSelect={handleSelect}
multiSelect
>
{node2children.size > 0 &&
Expand Down
98 changes: 80 additions & 18 deletions 98 apps/ui/src/lib/store/canvasSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ export interface CanvasSlice {
centerSelection: boolean;
setCenterSelection: (b: boolean) => void;

isSelectiveView: boolean;
setSelectiveView: (b: boolean) => void;
selectedToc: Set<string>;
clearSelectedToc: () => void;
setSelectedToc: (selectedItems: Set<string>) => void;

handlePaste(event: ClipboardEvent, position: XYPosition): void;
handleCopy(event: ClipboardEvent): void;

Expand Down Expand Up @@ -382,6 +388,23 @@ export const createCanvasSlice: StateCreator<MyState, [], [], CanvasSlice> = (
set({ centerSelection: b });
},

isSelectiveView: false,
setSelectiveView: (b: boolean) => set({ isSelectiveView: b }),
selectedToc: new Set(),
setSelectedToc(selectedItems) {
set(
produce((state: MyState) => {
state.selectedToc = selectedItems;
})
);
},
clearSelectedToc: () => {
set(
produce((state: MyState) => {
state.selectedToc.clear();
})
);
},
focusedEditor: undefined,
setFocusedEditor: (id?: string) =>
set(
Expand All @@ -408,29 +431,68 @@ export const createCanvasSlice: StateCreator<MyState, [], [], CanvasSlice> = (
* This function handles the real updates to the reactflow nodes to render.
*/
updateView: () => {
let nodes: Node[] = [];
const nodesMap = get().getNodesMap();
let selectedPods = get().selectedPods;
let nodes = Array.from<Node>(nodesMap.values());
nodes = nodes
.sort((a: Node, b: Node) => a.data.level - b.data.level)
.map((node) => ({
...node,
style: {
...node.style,
backgroundColor:
node.type === "SCOPE" ? level2color[node.data.level] : undefined,
},
selected: selectedPods.has(node.id),
// className: get().dragHighlight === node.id ? "active" : "",
className: match(node.id)
.with(get().dragHighlight || "", () => "active")
.otherwise(() => undefined),
}));
if (!get().isSelectiveView) {
let selectedPods = get().selectedPods;
nodes = Array.from<Node>(nodesMap.values());
nodes = nodes
.sort((a: Node, b: Node) => a.data.level - b.data.level)
.map((node) => ({
...node,
style: {
...node.style,
backgroundColor:
node.type === "SCOPE" ? level2color[node.data.level] : undefined,
},
selected: selectedPods.has(node.id),
// className: get().dragHighlight === node.id ? "active" : "",
className: match(node.id)
.with(get().dragHighlight || "", () => "active")
.otherwise(() => undefined),
}));
} else {
nodes = Array.from(
[...get().selectedToc].map((id): Node => {
return nodesMap.get(id)!;
})
);
nodes = nodes
.sort((a: Node, b: Node) => a.data.level - b.data.level)
.map((node) => ({
...node,
style: {
...node.style,
backgroundColor:
node.type === "SCOPE" ? level2color[node.data.level] : undefined,
},
parentNode:
node.parentNode === undefined ||
get().selectedToc.has(node.parentNode)
? node.parentNode
: undefined,
position:
node.parentNode === undefined ||
get().selectedToc.has(node.parentNode)
? node.position
: getAbsPos(node, nodesMap),
selected: get().selectedToc.has(node.id),
// className: get().dragHighlight === node.id ? "active" : "",
className: match(node.id)
.with(get().dragHighlight || "", () => "active")
.otherwise(() => undefined),
}));
}

set({ nodes });
// edges view
const edgesMap = get().getEdgesMap();
set({ edges: Array.from<Edge>(edgesMap.values()).filter((e) => e) });
const nodeSet = new Set<Node>(Array.from(nodes));
set({
edges: Array.from<Edge>(edgesMap.values()).filter(
(e) => nodeSet.has(e.sourceNode!) && nodeSet.has(e.targetNode!)
),
});
},

addNode: (type, position, parent) => {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.