Skip to content

Commit ade4936

Browse files
Copilotnturinski
andcommitted
Implement dynamic icon for app setting visibility toggle using contextValue monkey-patching
Co-authored-by: nturinski <[email protected]>
1 parent c24a7c7 commit ade4936

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

package.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,18 @@
367367
"category": "Azure Functions",
368368
"icon": "$(eye)"
369369
},
370+
{
371+
"command": "azureFunctions.showAppSettingValue",
372+
"title": "Show App Setting Value",
373+
"category": "Azure Functions",
374+
"icon": "$(eye)"
375+
},
376+
{
377+
"command": "azureFunctions.hideAppSettingValue",
378+
"title": "Hide App Setting Value",
379+
"category": "Azure Functions",
380+
"icon": "$(eye-closed)"
381+
},
370382
{
371383
"command": "azureFunctions.uninstallFuncCoreTools",
372384
"title": "%azureFunctions.uninstallFuncCoreTools%",
@@ -717,8 +729,13 @@
717729
"group": "1@4"
718730
},
719731
{
720-
"command": "azureFunctions.toggleAppSettingVisibility",
721-
"when": "view =~ /(azureResourceGroups|azureFocusView|azureWorkspace)/ && viewItem =~ /applicationSettingItem.*(azFunc|localSettings)/",
732+
"command": "azureFunctions.showAppSettingValue",
733+
"when": "view =~ /(azureResourceGroups|azureFocusView|azureWorkspace)/ && viewItem =~ /applicationSettingItem.*(azFunc|localSettings).*hidden/",
734+
"group": "inline"
735+
},
736+
{
737+
"command": "azureFunctions.hideAppSettingValue",
738+
"when": "view =~ /(azureResourceGroups|azureFocusView|azureWorkspace)/ && viewItem =~ /applicationSettingItem.*(azFunc|localSettings).*visible/",
722739
"group": "inline"
723740
},
724741
{

src/commands/registerCommands.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,46 @@ export function registerCommands(
171171
registerCommandWithTreeNodeUnwrapping('azureFunctions.stopFunctionApp', stopFunctionApp);
172172
registerCommandWithTreeNodeUnwrapping('azureFunctions.stopStreamingLogs', stopStreamingLogs);
173173
registerCommandWithTreeNodeUnwrapping('azureFunctions.swapSlot', swapSlot);
174+
// Monkey-patch AppSettingTreeItem to include visibility state in contextValue
175+
const originalContextValueGetter = Object.getOwnPropertyDescriptor(AppSettingTreeItem.prototype, 'contextValue')?.get;
176+
if (originalContextValueGetter) {
177+
Object.defineProperty(AppSettingTreeItem.prototype, 'contextValue', {
178+
get: function () {
179+
const originalValue = originalContextValueGetter.call(this);
180+
const isHidden = this.label.includes('Hidden value');
181+
return isHidden ? `${originalValue};hidden` : `${originalValue};visible`;
182+
},
183+
configurable: true
184+
});
185+
}
186+
174187
registerCommandWithTreeNodeUnwrapping(
175188
'azureFunctions.toggleAppSettingVisibility',
176189
async (context: IActionContext, node: AppSettingTreeItem) => {
177190
await node.toggleValueVisibility(context);
178191
},
179192
250,
180193
);
194+
registerCommandWithTreeNodeUnwrapping(
195+
'azureFunctions.showAppSettingValue',
196+
async (context: IActionContext, node: AppSettingTreeItem) => {
197+
// Only show if currently hidden
198+
if (node.label.includes('Hidden value')) {
199+
await node.toggleValueVisibility(context);
200+
}
201+
},
202+
250,
203+
);
204+
registerCommandWithTreeNodeUnwrapping(
205+
'azureFunctions.hideAppSettingValue',
206+
async (context: IActionContext, node: AppSettingTreeItem) => {
207+
// Only hide if currently shown
208+
if (!node.label.includes('Hidden value')) {
209+
await node.toggleValueVisibility(context);
210+
}
211+
},
212+
250,
213+
);
181214
registerCommandWithTreeNodeUnwrapping('azureFunctions.uninstallFuncCoreTools', uninstallFuncCoreTools);
182215
registerCommandWithTreeNodeUnwrapping('azureFunctions.viewCommitInGitHub', viewCommitInGitHub);
183216
registerSiteCommand('azureFunctions.viewDeploymentLogs', unwrapTreeNodeCommandCallback(viewDeploymentLogs));

0 commit comments

Comments
 (0)