Skip to content

Commit

Permalink
Merge pull request #1909 from posit-dev/sagerb-add-context-strings-in…
Browse files Browse the repository at this point in the history
…to-WebUX-constants-file

Move VSCode context strings into constants file.
  • Loading branch information
sagerb authored Jul 1, 2024
2 parents b3aa0dd + ab05125 commit 2d59d8f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
31 changes: 30 additions & 1 deletion extensions/vscode/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@ const configurationsCommands = {
Delete: "posit.publisher.configurations.delete",
} as const;

const configurationsContexts = {
TreeItem: "posit.publisher.configurations.tree.item",
} as const;

const credentialsCommands = {
Add: "posit.publisher.credentials.add",
Delete: "posit.publisher.credentials.delete",
Refresh: "posit.publisher.credentials.refresh",
} as const;

const credentialsContexts = {
Keychain: "posit.publisher.credentials.tree.item.keychain",
};

const contentRecordsCommands = {
Edit: "posit.publisher.contentRecords.edit",
Rename: "posit.publisher.contentRecords.rename",
Expand All @@ -46,6 +54,12 @@ const contentRecordsCommands = {
Refresh: "posit.publisher.contentRecords.refresh",
} as const;

const contentRecordsContexts = {
ContentRecord: "posit.publisher.contentRecords.tree.item.contentRecord",
PreContentRecord: "posit.publisher.contentRecords.tree.item.precontentRecord",
DeploymentError: "posit.publisher.contentRecords.tree.item.deploymentError",
} as const;

const filesCommands = {
Refresh: "posit.publisher.files.refresh",
Exclude: "posit.publisher.files.exclude",
Expand Down Expand Up @@ -79,11 +93,19 @@ const homeViewCommands = {
ShowContentLogs: "posit.publisher.homeView.navigateToDeployment.ContentLog",
} as const;

const homeViewContexts = {
Initialized: "posit.publisher.homeView.initialized",
};

const helpAndFeedbackCommands = {
OpenFeedback: "posit.publisher.helpAndFeedback.openFeedback",
OpenGettingStarted: "posit.publisher.helpAndFeedback.gettingStarted",
} as const;

export const LocalState = {
LastSelectionState: "posit.publisher.homeView.lastSelectionState.v2",
};

export const Commands = {
...baseCommands,
Configurations: configurationsCommands,
Expand All @@ -95,7 +117,14 @@ export const Commands = {
RPackages: rPackagesCommands,
HomeView: homeViewCommands,
HelpAndFeedback: helpAndFeedbackCommands,
} as const;
};

export const Contexts = {
Configurations: configurationsContexts,
ContentRecords: contentRecordsContexts,
Credentials: credentialsContexts,
HomeView: homeViewContexts,
};

export const enum Views {
Project = "posit.publisher.project",
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/views/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { ensureSuffix, fileExists, isValidFilename } from "src/utils/files";
import { untitledConfigurationName } from "src/utils/names";
import { newConfig } from "src/multiStepInputs/newConfig";
import { WatcherManager } from "src/watchers";
import { Commands, Views } from "src/constants";
import { Commands, Contexts, Views } from "src/constants";

type ConfigurationEventEmitter = EventEmitter<
ConfigurationTreeItem | undefined | void
Expand Down Expand Up @@ -200,7 +200,7 @@ export class ConfigurationsTreeDataProvider
}

export class ConfigurationTreeItem extends TreeItem {
contextValue = "posit.publisher.configurations.tree.item";
contextValue = Contexts.Configurations.TreeItem;

constructor(
public readonly config: Configuration | ConfigurationError,
Expand Down
11 changes: 4 additions & 7 deletions extensions/vscode/src/views/contentRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { getSummaryStringFromError } from "src/utils/errors";
import { ensureSuffix } from "src/utils/files";
import { contentRecordNameValidator } from "src/utils/names";
import { WatcherManager } from "src/watchers";
import { Commands, Views } from "src/constants";
import { Commands, Contexts, Views } from "src/constants";

type ContentRecordsEventEmitter = EventEmitter<
ContentRecordsTreeItem | undefined | void
Expand Down Expand Up @@ -226,8 +226,7 @@ export class ContentRecordsTreeItem extends TreeItem {
}

private initializeContentRecord(contentRecord: ContentRecord) {
this.contextValue =
"posit.publisher.contentRecords.tree.item.contentRecord";
this.contextValue = Contexts.ContentRecords.ContentRecord;
if (!contentRecord.deploymentError) {
this.tooltip =
`ContentRecord file: ${contentRecord.deploymentPath}\n` +
Expand All @@ -253,8 +252,7 @@ export class ContentRecordsTreeItem extends TreeItem {
}

private initializePreContentRecord(precontentRecord: PreContentRecord) {
this.contextValue =
"posit.publisher.contentRecords.tree.item.precontentRecord";
this.contextValue = Contexts.ContentRecords.PreContentRecord;
this.tooltip =
`Deployment Record file: ${precontentRecord.deploymentPath}\n` +
`\n` +
Expand All @@ -266,8 +264,7 @@ export class ContentRecordsTreeItem extends TreeItem {
}

private initializeContentRecordError(deploymentError: ContentRecordError) {
this.contextValue =
"posit.publisher.contentRecords.tree.item.deploymentError";
this.contextValue = Contexts.ContentRecords.DeploymentError;
this.tooltip =
`Deployment Record file: ${deploymentError.deploymentPath}\n` +
`\n` +
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/views/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useBus } from "src/bus";
import { confirmDelete } from "src/dialogs";
import { getSummaryStringFromError } from "src/utils/errors";
import { newCredential } from "src/multiStepInputs/newCredential";
import { Commands, Views } from "src/constants";
import { Commands, Contexts, Views } from "src/constants";

type CredentialEventEmitter = EventEmitter<
CredentialsTreeItem | undefined | void
Expand Down Expand Up @@ -129,6 +129,6 @@ export class CredentialsTreeItem extends TreeItem {
super(cred.name);
this.iconPath = new ThemeIcon("key");
this.description = `${cred.url}`;
this.contextValue = `posit.publisher.credentials.tree.item.keychain`;
this.contextValue = Contexts.Credentials.Keychain;
}
}
15 changes: 7 additions & 8 deletions extensions/vscode/src/views/homeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,13 @@ import { selectConfig } from "src/multiStepInputs/selectConfig";
import { RPackage, RVersionConfig } from "src/api/types/packages";
import { calculateTitle } from "src/utils/titles";
import { ConfigWatcherManager, WatcherManager } from "src/watchers";
import { Commands, Views } from "src/constants";

const contextIsHomeViewInitialized = "posit.publisher.homeView.initialized";
import { Commands, Contexts, LocalState, Views } from "src/constants";

enum HomeViewInitialized {
initialized = "initialized",
uninitialized = "uninitialized",
}

const lastSelectionState = "posit.publisher.homeView.lastSelectionState.v2";

const fileEventDebounce = 200;

export class HomeViewProvider implements WebviewViewProvider, Disposable {
Expand Down Expand Up @@ -244,7 +240,7 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable {
private setInitializationContext(context: HomeViewInitialized) {
commands.executeCommand(
"setContext",
contextIsHomeViewInitialized,
Contexts.HomeView.Initialized,
context,
);
}
Expand Down Expand Up @@ -431,7 +427,7 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable {

private _getSelectionState(): HomeViewState {
const state = this._context.workspaceState.get<HomeViewState>(
lastSelectionState,
LocalState.LastSelectionState,
{
deploymentName: undefined,
configurationName: undefined,
Expand Down Expand Up @@ -462,7 +458,10 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable {
}

private async _saveSelectionState(state: HomeViewState): Promise<void> {
await this._context.workspaceState.update(lastSelectionState, state);
await this._context.workspaceState.update(
LocalState.LastSelectionState,
state,
);

useBus().trigger(
"activeContentRecordChanged",
Expand Down

0 comments on commit 2d59d8f

Please sign in to comment.