-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into contributor-enhancements
- Loading branch information
Showing
29 changed files
with
460 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { get } from "svelte/store" | ||
import { selectedScreen as selectedScreenStore } from "./screens" | ||
import { findComponentPath } from "@/helpers/components" | ||
import { Screen, Component } from "@budibase/types" | ||
import { BudiStore, PersistenceType } from "@/stores/BudiStore" | ||
|
||
interface OpenNodesState { | ||
[key: string]: boolean | ||
} | ||
|
||
export class ComponentTreeNodesStore extends BudiStore<OpenNodesState> { | ||
constructor() { | ||
super({} as OpenNodesState, { | ||
persistence: { | ||
type: PersistenceType.SESSION, | ||
key: "openNodes", | ||
}, | ||
}) | ||
} | ||
|
||
toggleNode(componentId: string) { | ||
this.update((openNodes: OpenNodesState) => { | ||
openNodes[`nodeOpen-${componentId}`] = | ||
!openNodes[`nodeOpen-${componentId}`] | ||
|
||
return openNodes | ||
}) | ||
} | ||
|
||
expandNodes(componentIds: string[]) { | ||
this.update((openNodes: OpenNodesState) => { | ||
const newNodes = Object.fromEntries( | ||
componentIds.map(id => [`nodeOpen-${id}`, true]) | ||
) | ||
|
||
return { ...openNodes, ...newNodes } | ||
}) | ||
} | ||
|
||
collapseNodes(componentIds: string[]) { | ||
this.update((openNodes: OpenNodesState) => { | ||
const newNodes = Object.fromEntries( | ||
componentIds.map(id => [`nodeOpen-${id}`, false]) | ||
) | ||
|
||
return { ...openNodes, ...newNodes } | ||
}) | ||
} | ||
|
||
// Will ensure all parents of a node are expanded so that it is visible in the tree | ||
makeNodeVisible(componentId: string) { | ||
const selectedScreen: Screen = get(selectedScreenStore) | ||
|
||
const path = findComponentPath(selectedScreen.props, componentId) | ||
|
||
const componentIds = path.map((component: Component) => component._id) | ||
|
||
this.update((openNodes: OpenNodesState) => { | ||
const newNodes = Object.fromEntries( | ||
componentIds.map((id: string) => [`nodeOpen-${id}`, true]) | ||
) | ||
|
||
return { ...openNodes, ...newNodes } | ||
}) | ||
} | ||
|
||
isNodeExpanded(componentId: string): boolean { | ||
const openNodes = get(this) | ||
return !!openNodes[`nodeOpen-${componentId}`] | ||
} | ||
} | ||
|
||
export default new ComponentTreeNodesStore() |
Oops, something went wrong.