MCPcopy Create free account
hub / github.com/DTStack/molecule / SidebarService

Class SidebarService

src/services/workbench/sidebarService.ts:48–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46
47@singleton()
48export class SidebarService
49 extends Component<ISidebar>
50 implements ISidebarService
51{
52 protected state: ISidebar;
53
54 constructor() {
55 super();
56 this.state = container.resolve(SidebarModel);
57 }
58
59 private getPane(id: UniqueId) {
60 const { panes } = this.state;
61 const target = panes.find(searchById(id));
62 return target;
63 }
64
65 public get(id: UniqueId) {
66 const pane = this.getPane(id);
67 return pane ? cloneDeep(pane) : undefined;
68 }
69
70 public add(data: ISidebarPane, isActive = false) {
71 const pane = this.getPane(data.id);
72 if (pane) {
73 logger.error(
74 `There already has a pane which id is ${data.id}, if you want to modify it, please use the update method`
75 );
76 return;
77 }
78
79 const oldPanes = this.state.panes.concat();
80 oldPanes.push(cloneDeep(data));
81 if (isActive) {
82 this.setState({
83 current: data.id,
84 });
85 }
86 this.setState({
87 panes: oldPanes,
88 });
89 }
90
91 public update(pane: ISidebarPane) {
92 const { panes } = this.state;
93 const targetPane = this.getPane(pane.id);
94 if (!targetPane) {
95 logger.error(`There is no pane found via the ${pane.id} id`);
96 return;
97 }
98
99 Object.assign(targetPane, pane);
100 this.setState({
101 panes: cloneDeep(panes),
102 });
103 }
104
105 public remove(id: UniqueId) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected