Skip to content

Commit

Permalink
Updates pull request pane to remember expanded preference
Browse files Browse the repository at this point in the history
  • Loading branch information
d13 committed May 12, 2024
1 parent 9c2cddc commit 9728c36
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Expand Up @@ -943,6 +943,7 @@ export type WorkspaceStorage = {
'views:repositories:autoRefresh': boolean;
'views:searchAndCompare:pinned': StoredSearchAndCompareItems;
'views:commitDetails:autolinksExpanded': boolean;
'views:commitDetails:pullRequestExpanded': boolean;
} & { [key in `confirm:ai:tos:${AIProviders}`]: boolean } & {
[key in `connected:${Integration['key']}`]: boolean;
};
Expand Down
21 changes: 17 additions & 4 deletions src/webviews/apps/commitDetails/components/commit-details-app.ts
Expand Up @@ -211,7 +211,12 @@ export class GlCommitDetailsApp extends LitElement {
DOM.on<WebviewPane, WebviewPaneExpandedChangeEventDetail>(
'[data-region="rich-pane"]',
'expanded-change',
e => this.onExpandedChange(e.detail),
e => this.onExpandedChange(e.detail, 'autolinks'),
),
DOM.on<WebviewPane, WebviewPaneExpandedChangeEventDetail>(
'[data-region="pullrequest-pane"]',
'expanded-change',
e => this.onExpandedChange(e.detail, 'pullrequest'),
),
DOM.on('[data-action="explain-commit"]', 'click', e => this.onExplainCommit(e)),
DOM.on('[data-action="switch-ai"]', 'click', e => this.onSwitchAiModel(e)),
Expand Down Expand Up @@ -610,14 +615,22 @@ export class GlCommitDetailsApp extends LitElement {
this._hostIpc.sendCommand(UpdatePreferencesCommand, { files: files });
}

private onExpandedChange(e: WebviewPaneExpandedChangeEventDetail) {
private onExpandedChange(e: WebviewPaneExpandedChangeEventDetail, pane: string) {
let preferenceChange;
if (pane === 'autolinks') {
preferenceChange = { autolinksExpanded: e.expanded };
} else if (pane === 'pullrequest') {
preferenceChange = { pullRequestExpanded: e.expanded };
}
if (preferenceChange == null) return;

this.state = {
...this.state,
preferences: { ...this.state!.preferences, autolinksExpanded: e.expanded },
preferences: { ...this.state!.preferences, ...preferenceChange },
} as any;
// this.attachState();

this._hostIpc.sendCommand(UpdatePreferencesCommand, { autolinksExpanded: e.expanded });
this._hostIpc.sendCommand(UpdatePreferencesCommand, preferenceChange);
}

private onNavigate(direction: 'back' | 'forward') {
Expand Down
6 changes: 5 additions & 1 deletion src/webviews/apps/commitDetails/components/gl-wip-details.ts
Expand Up @@ -247,7 +247,11 @@ export class GlWipDetails extends GlDetailsBase {
if (this.wip?.pullRequest == null) return nothing;

return html`
<webview-pane collapsable expanded>
<webview-pane
collapsable
?expanded=${this.preferences?.pullRequestExpanded ?? true}
data-region="pullrequest-pane"
>
<span slot="title">Pull Request #${this.wip?.pullRequest?.id}</span>
<action-nav slot="actions">
<action-item
Expand Down
14 changes: 14 additions & 0 deletions src/webviews/commitDetails/commitDetailsWebview.ts
Expand Up @@ -872,6 +872,7 @@ export class CommitDetailsWebviewProvider
private getPreferences(): Preferences {
return {
autolinksExpanded: this.container.storage.getWorkspace('views:commitDetails:autolinksExpanded') ?? true,
pullRequestExpanded: this.container.storage.getWorkspace('views:commitDetails:pullRequestExpanded') ?? true,
avatars: configuration.get('views.commitDetails.avatars'),
dateFormat: configuration.get('defaultDateFormat') ?? 'MMMM Do, YYYY h:mma',
dateStyle: configuration.get('defaultDateStyle') ?? 'relative',
Expand Down Expand Up @@ -1491,6 +1492,7 @@ export class CommitDetailsWebviewProvider
private updatePreferences(preferences: UpdateablePreferences) {
if (
this._context.preferences?.autolinksExpanded === preferences.autolinksExpanded &&
this._context.preferences?.pullRequestExpanded === preferences.pullRequestExpanded &&
this._context.preferences?.files?.compact === preferences.files?.compact &&
this._context.preferences?.files?.icon === preferences.files?.icon &&
this._context.preferences?.files?.layout === preferences.files?.layout &&
Expand All @@ -1516,6 +1518,18 @@ export class CommitDetailsWebviewProvider
changes.autolinksExpanded = preferences.autolinksExpanded;
}

if (
preferences.pullRequestExpanded != null &&
this._context.preferences?.pullRequestExpanded !== preferences.pullRequestExpanded
) {
void this.container.storage.storeWorkspace(
'views:commitDetails:pullRequestExpanded',
preferences.pullRequestExpanded,
);

changes.pullRequestExpanded = preferences.pullRequestExpanded;
}

if (preferences.files != null) {
if (this._context.preferences?.files?.compact !== preferences.files?.compact) {
void configuration.updateEffective('views.commitDetails.files.compact', preferences.files?.compact);
Expand Down
3 changes: 2 additions & 1 deletion src/webviews/commitDetails/protocol.ts
Expand Up @@ -39,14 +39,15 @@ export interface CommitDetails extends CommitSummary {

export interface Preferences {
autolinksExpanded: boolean;
pullRequestExpanded: boolean;
avatars: boolean;
dateFormat: DateTimeFormat | string;
dateStyle: DateStyle;
files: Config['views']['commitDetails']['files'];
indent: number | undefined;
indentGuides: 'none' | 'onHover' | 'always';
}
export type UpdateablePreferences = Partial<Pick<Preferences, 'autolinksExpanded' | 'files'>>;
export type UpdateablePreferences = Partial<Pick<Preferences, 'autolinksExpanded' | 'pullRequestExpanded' | 'files'>>;

export interface WipChange {
branchName: string;
Expand Down

0 comments on commit 9728c36

Please sign in to comment.