Skip to content

Commit dfdc8c2

Browse files
authored
showing lock status on component viewer instances (#836)
* showing lock status on component viewer instances * removing redundant behaviour
1 parent bf75e13 commit dfdc8c2

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/views/component-viewer/component-viewer-tree-view.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ export class ComponentViewerTreeDataProvider implements vscode.TreeDataProvider<
3737
: vscode.TreeItemCollapsibleState.None;
3838
// Needs fixing, getGuiValue() for ScvdNode returns 0 when undefined
3939
treeItem.description = element.getGuiValue() ?? '';
40-
const intermediateContextValue = element.isRootInstance ? 'parentInstance' : 'child';
40+
let intermediateContextValue = '';
41+
if (element.isRootInstance) {
42+
intermediateContextValue = 'parentInstance';
43+
if (element.isLocked) {
44+
treeItem.iconPath = new vscode.ThemeIcon('lock');
45+
}
46+
}
47+
4148
treeItem.contextValue = element.isLocked ? `locked.${intermediateContextValue}` : intermediateContextValue;
4249
const guiId = element.getGuiId();
4350
if (guiId !== undefined) {

src/views/component-viewer/test/unit/component-viewer-tree-view.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ jest.mock('vscode', () => {
3030
public event = jest.fn();
3131
}
3232

33+
class ThemeIcon {
34+
public id: string;
35+
36+
constructor(id: string) {
37+
this.id = id;
38+
}
39+
}
3340
class MarkdownString {
3441
public value: string;
3542
public supportHtml = false;
@@ -46,6 +53,7 @@ jest.mock('vscode', () => {
4653
public tooltip: string | MarkdownString | undefined;
4754
public id: string | undefined;
4855
public contextValue: string | undefined;
56+
public iconPath: vscode.ThemeIcon | undefined;
4957

5058
constructor(label: string) {
5159
this.label = label;
@@ -56,6 +64,7 @@ jest.mock('vscode', () => {
5664
EventEmitter,
5765
MarkdownString,
5866
TreeItem,
67+
ThemeIcon,
5968
TreeItemCollapsibleState: {
6069
Collapsed: 1,
6170
None: 0,
@@ -173,7 +182,21 @@ describe('ComponentViewerTreeDataProvider', () => {
173182
expect(rootItem.contextValue).toBe('locked.parentInstance');
174183

175184
const childItem = provider.getTreeItem(childUnlocked);
176-
expect(childItem.contextValue).toBe('child');
185+
expect(childItem.contextValue).toBe('');
186+
});
187+
188+
it('assigns lock icon for locked root nodes', () => {
189+
const provider = new ComponentViewerTreeDataProvider();
190+
const rootLocked = makeGui({ isRootInstance: true, isLocked: true });
191+
const rootUnLocked = makeGui({ isRootInstance: true, isLocked: false });
192+
193+
const rootItem = provider.getTreeItem(rootLocked);
194+
expect(rootItem.iconPath).toBeInstanceOf(vscode.ThemeIcon);
195+
const rootIcon = rootItem.iconPath as { id: string };
196+
expect(rootIcon.id).toBe('lock');
197+
198+
const rootUnLockedItem = provider.getTreeItem(rootUnLocked);
199+
expect(rootUnLockedItem.iconPath).toBeUndefined();
177200
});
178201

179202
it('returns root children when no element is provided', async () => {

tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"noImplicitAny": true,
1616
"noFallthroughCasesInSwitch": true,
1717
"exactOptionalPropertyTypes": true,
18+
"types": [
19+
"jest"
20+
]
1821
},
1922
"include": [
2023
"src"

0 commit comments

Comments
 (0)