Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to update the target guid for a deployment at any time (from the ... menu) #2576

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
9 changes: 9 additions & 0 deletions extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
"title": "Select Active Configuration For Deployment",
"category": "Posit Publisher"
},
{
"command": "posit.publisher.homeView.showAssociateDeployment",
"title": "Associate with a Different Deployment on Connect",
"category": "Posit Publisher"
},
{
"command": "posit.publisher.homeView.createConfigForDeployment",
"title": "Create New Configuration For Destination",
Expand Down Expand Up @@ -325,6 +330,10 @@
"command": "posit.publisher.homeView.showSelectConfigForDeployment",
"when": "webviewId == 'posit.publisher.homeView' && webviewSection == 'even-easier-deploy-more-menu-matching-configs'"
},
{
"command": "posit.publisher.homeView.showAssociateDeployment",
"when": "webviewId == 'posit.publisher.homeView' && webviewSection == 'even-easier-deploy-more-menu-matching-configs' && posit.publish.selection.haveCredentialMatch == 'true'"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows the context menu option while a pre-deployment shows the association link.

We could try to hide it using message passing or we could generalize the label to remove the "with a Different Deployment". 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following you. Can you provide a screenshot? I'm looking at
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that screenshot shows what I'm talking about. We have both "update that previous deployment" available as a link, and the "Associate with a Different Deployment on Connect". The wording is just strange since it isn't associated with any deployment yet. That may be too in the weeds with how this is working though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added another context state within the extension, which indicates if the actively selected content record is a PreContentRecord or not. This allows the menu item to now be shown only when it has been deployed, which should address the confusion you identified here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing that, it is a small thing, but it should make it easier to understand for users.

},
{
"command": "posit.publisher.homeView.createConfigForDeployment",
"when": "webviewId == 'posit.publisher.homeView' && webviewSection == 'even-easier-deploy-more-menu-no-matching-configs'"
Expand Down
7 changes: 6 additions & 1 deletion extensions/vscode/src/actions/showAssociateGUID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ export async function showAssociateGUID(state: PublisherState) {
}
await showProgress("Updating Content Record", Views.HomeView, async () => {
const api = await useApi();
await api.contentRecords.patch(
const result = await api.contentRecords.patch(
targetContentRecord.deploymentName,
targetContentRecord.projectDir,
{
guid,
},
);
if (result.status === 200) {
window.showInformationMessage(
`Deployment is now associated with Content GUID ${guid} as requested. An error will be displayed if this deployment cannot update this deployment on the Connect Server.`,
);
}
});
}
1 change: 1 addition & 0 deletions extensions/vscode/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const homeViewCommands = {
Refresh: "posit.publisher.homeView.refresh",
ShowSelectConfigForDeployment:
"posit.publisher.homeView.showSelectConfigForDeployment",
ShowAssociateDeployment: "posit.publisher.homeView.showAssociateDeployment",
CreateConfigForDeployment:
"posit.publisher.homeView.createConfigForDeployment",
SelectDeployment: "posit.publisher.homeView.selectDeployment",
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;
}
>;
19 changes: 19 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 Expand Up @@ -1782,6 +1796,11 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable {
this.showSelectOrCreateConfigForDeployment,
this,
),
commands.registerCommand(
Commands.HomeView.ShowAssociateDeployment,
() => showAssociateGUID(this.state),
this,
),
commands.registerCommand(
Commands.HomeView.CreateConfigForDeployment,
this.showSelectOrCreateConfigForDeployment,
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",
},
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always sending back true. Looks like it might be a missing .value on serverCredential.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the purpose of the message sending however. This is checking if the current deployment has a credential, but if we are associating with a different piece of content we could be pointing to an entirely different server. What is this supposed to be catching?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose is to enable or disable the ability to associate, within the ... menu. I've seen it work, so I'm surprised there is an error there, but I'll check it out. What it implements is that when we do not have a credential for the server, so we couldn't contact the server to patch the deployment file, so it would fail always. So the option isn't offered.

I'll check the logic, like I mentioned, I'm not sure with this how I was seeing the vscode context set correctly per the state, as shown in the screen shots.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to examine the reference's value rather than the reference itself. Thanks for catching this. The message stayed in place, as my explanation of its purpose above still stands.

};

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

const updateParentViewSelectionState = () => {
Expand Down