Skip to content

Commit

Permalink
contextually hide or show associate guid if we have credentials to co…
Browse files Browse the repository at this point in the history
…ntact server or not.
  • Loading branch information
sagerb committed Jan 30, 2025
1 parent 9ec3b19 commit c9b2057
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
},
{
"command": "posit.publisher.homeView.showAssociateDeployment",
"when": "webviewId == 'posit.publisher.homeView' && webviewSection == 'even-easier-deploy-more-menu-matching-configs'"
"when": "webviewId == 'posit.publisher.homeView' && webviewSection == 'even-easier-deploy-more-menu-matching-configs' && posit.publish.selection.haveCredentialMatch == 'true'"
},
{
"command": "posit.publisher.homeView.createConfigForDeployment",
Expand Down
17 changes: 17 additions & 0 deletions extensions/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ enum InitializationInProgress {
false = "false",
}

const SELECTION_HAS_CREDENTIAL_MATCH_CONTEXT =
"posit.publish.selection.haveCredentialMatch";
export enum SelectionCredentialMatch {
true = "true",
false = "false",
}

// Once the extension is activate, hang on to the service so that we can stop it on deactivation.
let service: Service;

Expand All @@ -42,6 +49,16 @@ function setInitializationInProgressContext(context: InitializationInProgress) {
commands.executeCommand("setContext", INITIALIZING_CONTEXT, context);
}

export function setSelectionHasCredentialMatch(
context: SelectionCredentialMatch,
) {
commands.executeCommand(
"setContext",
SELECTION_HAS_CREDENTIAL_MATCH_CONTEXT,
context,
);
}

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export async function activate(context: ExtensionContext) {
Expand Down
14 changes: 12 additions & 2 deletions extensions/vscode/src/types/messages/webviewToHostMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum WebviewToHostMessageType {
NEW_CREDENTIAL = "newCredential",
VIEW_PUBLISHING_LOG = "viewPublishingLog",
SHOW_ASSOCIATE_GUID = "ShowAssociateGUID",
UPDATE_SELECTION_CREDENTIAL_STATE = "UpdateSelectionCredentialStateMsg",
}

export type AnyWebviewToHostMessage<
Expand Down Expand Up @@ -62,7 +63,8 @@ export type WebviewToHostMessage =
| NewCredentialForDeploymentMsg
| NewCredentialMsg
| ViewPublishingLog
| ShowAssociateGUIDMsg;
| ShowAssociateGUIDMsg
| UpdateSelectionCredentialStateMsg;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isWebviewToHostMessage(msg: any): msg is WebviewToHostMessage {
Expand All @@ -89,7 +91,8 @@ export function isWebviewToHostMessage(msg: any): msg is WebviewToHostMessage {
msg.kind === WebviewToHostMessageType.NEW_CREDENTIAL_FOR_DEPLOYMENT ||
msg.kind === WebviewToHostMessageType.NEW_CREDENTIAL ||
msg.kind === WebviewToHostMessageType.VIEW_PUBLISHING_LOG ||
msg.kind === WebviewToHostMessageType.SHOW_ASSOCIATE_GUID
msg.kind === WebviewToHostMessageType.SHOW_ASSOCIATE_GUID ||
msg.kind === WebviewToHostMessageType.UPDATE_SELECTION_CREDENTIAL_STATE
);
}

Expand Down Expand Up @@ -210,3 +213,10 @@ export type ViewPublishingLog =

export type ShowAssociateGUIDMsg =
AnyWebviewToHostMessage<WebviewToHostMessageType.SHOW_ASSOCIATE_GUID>;

export type UpdateSelectionCredentialStateMsg = AnyWebviewToHostMessage<
WebviewToHostMessageType.UPDATE_SELECTION_CREDENTIAL_STATE,
{
state: string;
}
>;
14 changes: 14 additions & 0 deletions extensions/vscode/src/views/homeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ import { showAssociateGUID } from "src/actions/showAssociateGUID";
import { extensionSettings } from "src/extension";
import { openFileInEditor } from "src/commands";
import { showImmediateDeploymentFailureMessage } from "./publishFailures";
import {
SelectionCredentialMatch,
setSelectionHasCredentialMatch,
} from "../extension";

enum HomeViewInitialized {
initialized = "initialized",
Expand Down Expand Up @@ -174,6 +178,8 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable {
return this.showPublishingLog();
case WebviewToHostMessageType.SHOW_ASSOCIATE_GUID:
return showAssociateGUID(this.state);
case WebviewToHostMessageType.UPDATE_SELECTION_CREDENTIAL_STATE:
return this.updateSelectionCredentialState(msg.content.state);
default:
window.showErrorMessage(
`Internal Error: onConduitMessage unhandled msg: ${JSON.stringify(msg)}`,
Expand All @@ -189,6 +195,14 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable {
);
}

private async updateSelectionCredentialState(state: string) {
const match =
state === SelectionCredentialMatch.true
? SelectionCredentialMatch.true
: SelectionCredentialMatch.false;
return await setSelectionHasCredentialMatch(match);
}

private async initiateDeployment(
deploymentName: string,
credentialName: string,
Expand Down
12 changes: 12 additions & 0 deletions extensions/vscode/webviews/homeView/src/stores/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ export const useHomeStore = defineStore("home", () => {
selectedContentRecord.value = contentRecord;
}

watch([serverCredential], () => updateSelectionCredentialStatus());

const updateSelectionCredentialStatus = () => {
const hostConduit = useHostConduitService();
hostConduit.sendMsg({
kind: WebviewToHostMessageType.UPDATE_SELECTION_CREDENTIAL_STATE,
content: {
state: serverCredential !== undefined ? "true" : "false",
},
});
};

watch([selectedConfiguration], () => updateParentViewSelectionState());

const updateParentViewSelectionState = () => {
Expand Down

0 comments on commit c9b2057

Please sign in to comment.