Skip to content

Commit cd732bc

Browse files
authored
Open view via the Command Palette (#93)
1 parent 3aa12be commit cd732bc

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/views/manage-components-packs/components-packs-actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ s */
300300
});
301301
};
302302

303-
componentTree.classes.forEach(cclass => {
303+
componentTree.classes?.forEach(cclass => {
304304
cclass.bundles?.forEach(bundle => {
305305
bundle.cgroups?.forEach(group => {
306306
processLayerPaths(group.aggregates);

src/views/manage-components-packs/components-packs-webview-main.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,21 @@ describe('ComponentsPacksWebviewMain', () => {
188188
});
189189

190190

191-
it('does not call openWebview when node is undefined', async () => {
191+
it('calls openWebview with valid project when node is undefined', async () => {
192+
jest.spyOn(componentsPacksWebviewMain as any, 'getValidProjectId').mockReturnValue(projectPath);
193+
await (componentsPacksWebviewMain as any).handleWebviewCommand(undefined);
194+
195+
expect((componentsPacksWebviewMain as any).openWebview).toHaveBeenCalledTimes(1);
196+
expect((componentsPacksWebviewMain as any).openWebview).toHaveBeenCalledWith(projectPath, undefined);
197+
});
198+
199+
it('shows warning when node is undefined and no valid project exists', async () => {
200+
jest.spyOn(componentsPacksWebviewMain as any, 'getValidProjectId').mockReturnValue(undefined);
201+
192202
await (componentsPacksWebviewMain as any).handleWebviewCommand(undefined);
193203

194204
expect((componentsPacksWebviewMain as any).openWebview).not.toHaveBeenCalled();
205+
expect(messageProvider.showWarningMessage).toHaveBeenCalledWith('No valid project found in the active solution.');
195206
});
196207
});
197208

src/views/manage-components-packs/components-packs-webview-main.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,16 @@ export class ComponentsPacksWebviewMain {
113113
private async handleWebviewCommand(treeNode: COutlineItem | undefined) {
114114
if (treeNode) {
115115
await this.openWebview(treeNode.cprojectPath, treeNode.clayerPath);
116+
return;
117+
}
118+
119+
const projectId = this.getValidProjectId();
120+
if (!projectId) {
121+
this.messageProvider.showWarningMessage('No valid project found in the active solution.');
122+
return;
116123
}
124+
125+
await this.openWebview(projectId, undefined);
117126
}
118127

119128
private projectFromPath(path: string | undefined): string {
@@ -131,7 +140,8 @@ export class ComponentsPacksWebviewMain {
131140
return; // nothing to show
132141
}
133142

134-
const reload = this.projectFromPath(this.currentProject?.project.projectId) !== this.projectFromPath(cprojectPath);
143+
const reload = this.currentProject === undefined ||
144+
this.projectFromPath(this.currentProject.project.projectId) !== this.projectFromPath(cprojectPath);
135145
const csolution = this.solutionManager.getCsolution();
136146
if (csolution) {
137147
this.currentProject = { solutionPath: csolution.solutionPath, project: createProject(cprojectPath) };
@@ -217,7 +227,7 @@ export class ComponentsPacksWebviewMain {
217227
}
218228

219229
const latestUsedItems = usedItems ?? await this.csolutionService.getUsedItems({ context: actx });
220-
if (this.usedItems?.packs.length !== latestUsedItems.packs.length || this.usedItems?.components.length !== latestUsedItems.components.length) {
230+
if (this.usedItems?.packs?.length !== latestUsedItems.packs?.length || this.usedItems?.components?.length !== latestUsedItems.components?.length) {
221231
return true;
222232
}
223233

@@ -228,8 +238,8 @@ export class ComponentsPacksWebviewMain {
228238
packs: [...(this.usedItems?.packs ?? [])].sort((a, b) => a.pack.localeCompare(b.pack)).map(packMapper),
229239
};
230240
const usedItemsSorted = {
231-
components: [...latestUsedItems.components].sort((a, b) => a.id.localeCompare(b.id)).map(componentMapper),
232-
packs: [...latestUsedItems.packs].sort((a, b) => a.pack.localeCompare(b.pack)).map(packMapper),
241+
components: [...(latestUsedItems.components ?? [])].sort((a, b) => a.id.localeCompare(b.id)).map(componentMapper),
242+
packs: [...(latestUsedItems.packs ?? [])].sort((a, b) => a.pack.localeCompare(b.pack)).map(packMapper),
233243
};
234244
const usedItemsChanged = !isDeepStrictEqual(localUsedItemsSorted, usedItemsSorted);
235245
return usedItemsChanged;

0 commit comments

Comments
 (0)