Skip to content

Commit 70fb05e

Browse files
wolfibDevtools-frontend LUCI CQ
authored andcommitted
[Patch agent] Preselect automatic workspace even if not connected
Bug: 399560823 Change-Id: Ie9ebc904cc49d0fd24cc6d3492ad948125be72f2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6440431 Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Wolfgang Beyer <[email protected]>
1 parent 6519994 commit 70fb05e

File tree

7 files changed

+101
-24
lines changed

7 files changed

+101
-24
lines changed

config/gni/devtools_grd_files.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ grd_files_release_sources = [
148148
"front_end/Images/flex-wrap.svg",
149149
"front_end/Images/flow.svg",
150150
"front_end/Images/fold-more.svg",
151+
"front_end/Images/folder-asterisk.svg",
152+
"front_end/Images/folder-off.svg",
151153
"front_end/Images/folder.svg",
152154
"front_end/Images/frame-crossed.svg",
153155
"front_end/Images/frame-icon.svg",

config/gni/devtools_image_files.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ devtools_svg_sources = [
150150
"flex-wrap.svg",
151151
"flow.svg",
152152
"fold-more.svg",
153+
"folder-asterisk.svg",
154+
"folder-off.svg",
153155
"folder.svg",
154156
"frame-crossed.svg",
155157
"frame-icon.svg",
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

front_end/panels/ai_assistance/PatchWidget.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ Files:
204204
},
205205
});
206206
const {view} = await createPatchWidget();
207-
assert.isUndefined(view.input.projectName);
207+
assert.strictEqual(view.input.projectName, '');
208208
});
209209

210210
it('does not select a workspace project if setting does not exist', async () => {
211211
const {view} = await createPatchWidget();
212-
assert.isUndefined(view.input.projectName);
212+
assert.strictEqual(view.input.projectName, '');
213213
});
214214

215215
it('selects a workspace project matching the setting', async () => {
@@ -225,7 +225,7 @@ Files:
225225

226226
Workspace.Workspace.WorkspaceImpl.instance().removeProject(project);
227227
const input = await view.nextInput;
228-
assert.isUndefined(input.projectName);
228+
assert.strictEqual(input.projectName, '');
229229
});
230230

231231
it('selection is triggered by applyToWorkspace click if no workspace is (pre-)selected', async () => {
@@ -237,7 +237,7 @@ Files:
237237
const {view, widget} =
238238
await createPatchWidget({aidaClient: mockAidaClient([[{explanation: 'suggested patch'}]])});
239239
widget.changeSummary = 'body { background-color: red; }';
240-
assert.isUndefined(view.input.projectName);
240+
assert.strictEqual(view.input.projectName, '');
241241

242242
// Simulate clicking the "Apply to workspace" button
243243
view.input.onApplyToWorkspace();

front_end/panels/ai_assistance/PatchWidget.ts

Lines changed: 77 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,34 @@ export enum PatchSuggestionState {
144144
ERROR = 'error',
145145
}
146146

147+
enum SelectedProjectType {
148+
/**
149+
* No project selected
150+
*/
151+
NONE = 'none',
152+
/**
153+
* The selected project is not an automatic workspace project
154+
*/
155+
REGULAR = 'regular',
156+
/**
157+
* The selected project is a disconnected automatic workspace project
158+
*/
159+
AUTOMATIC_DISCONNECTED = 'automaticDisconncted',
160+
/**
161+
* The selected project is a connected automatic workspace project
162+
*/
163+
AUTOMATIC_CONNECTED = 'automaticConnected',
164+
}
165+
147166
export interface ViewInput {
148167
workspaceDiff: WorkspaceDiff.WorkspaceDiff.WorkspaceDiffImpl;
149168
patchSuggestionState: PatchSuggestionState;
150169
changeSummary?: string;
151170
sources?: string;
152-
projectName?: string;
153-
savedToDisk?: boolean;
171+
projectName: string;
154172
projectPath: Platform.DevToolsPath.RawPathString;
173+
projectType: SelectedProjectType;
174+
savedToDisk?: boolean;
155175
applyToWorkspaceTooltipText: Platform.UIString.LocalizedString;
156176
onLearnMoreTooltipClick: () => void;
157177
onApplyToWorkspace: () => void;
@@ -318,12 +338,13 @@ export class PatchWidget extends UI.Widget.Widget {
318338
`;
319339
}
320340

341+
const iconName = input.projectType === SelectedProjectType.AUTOMATIC_DISCONNECTED ? 'folder-off' : input.projectType === SelectedProjectType.AUTOMATIC_CONNECTED ? 'folder-asterisk' : 'folder';
321342
return html`
322343
<div class="footer">
323344
${input.projectName ? html`
324345
<div class="change-workspace">
325346
<div class="selected-folder">
326-
<devtools-icon .name=${'folder'}></devtools-icon> <span class="folder-name" title=${input.projectPath}>${input.projectName}</span>
347+
<devtools-icon .name=${iconName}></devtools-icon> <span class="folder-name" title=${input.projectPath}>${input.projectName}</span>
327348
</div>
328349
${input.onChangeWorkspaceClick ? html`
329350
<devtools-button
@@ -346,7 +367,7 @@ export class PatchWidget extends UI.Widget.Widget {
346367
</span>
347368
</div>
348369
` : html`
349-
<devtools-button
370+
<devtools-button
350371
@click=${input.onApplyToWorkspace}
351372
.jslogContext=${'stage-to-workspace'}
352373
.variant=${Buttons.Button.Variant.OUTLINED}>
@@ -412,22 +433,48 @@ export class PatchWidget extends UI.Widget.Widget {
412433
void UI.ViewManager.ViewManager.instance().showView('chrome-ai');
413434
}
414435

415-
override performUpdate(): void {
416-
const projectName = this.#project ? Common.ParsedURL.ParsedURL.encodedPathToRawPathString(
417-
this.#project.displayName() as Platform.DevToolsPath.EncodedPathString) :
418-
undefined;
419-
const projectPath = this.#project ?
420-
Common.ParsedURL.ParsedURL.urlToRawPathString(
421-
this.#project.id() as Platform.DevToolsPath.UrlString, Host.Platform.isWin()) :
422-
Platform.DevToolsPath.EmptyRawPathString;
436+
#getDisplayedProject(): {projectName: string, projectPath: Platform.DevToolsPath.RawPathString} {
437+
if (this.#project) {
438+
return {
439+
projectName: Common.ParsedURL.ParsedURL.encodedPathToRawPathString(
440+
this.#project.displayName() as Platform.DevToolsPath.EncodedPathString),
441+
projectPath: Common.ParsedURL.ParsedURL.urlToRawPathString(
442+
this.#project.id() as Platform.DevToolsPath.UrlString, Host.Platform.isWin()),
443+
};
444+
}
445+
if (this.#automaticFileSystem) {
446+
return {
447+
projectName: Common.ParsedURL.ParsedURL.extractName(this.#automaticFileSystem.root),
448+
projectPath: this.#automaticFileSystem.root,
449+
};
450+
}
451+
return {
452+
projectName: '',
453+
projectPath: Platform.DevToolsPath.EmptyRawPathString,
454+
};
455+
}
456+
457+
#shouldShowChangeButton(): boolean {
423458
const automaticFileSystemProject =
424459
this.#automaticFileSystem ? this.#workspace.projectForFileSystemRoot(this.#automaticFileSystem.root) : null;
425-
const projects = this.#workspace.projectsForType(Workspace.Workspace.projectTypes.FileSystem)
426-
.filter(
427-
project => project instanceof Persistence.FileSystemWorkspaceBinding.FileSystem &&
428-
project.fileSystem().type() ===
429-
Persistence.PlatformFileSystem.PlatformFileSystemType.WORKSPACE_PROJECT);
430-
const showChangeButton = projects.length > 1 || this.#project !== automaticFileSystemProject;
460+
const regularProjects = this.#workspace.projectsForType(Workspace.Workspace.projectTypes.FileSystem)
461+
.filter(
462+
project => project instanceof Persistence.FileSystemWorkspaceBinding.FileSystem &&
463+
project.fileSystem().type() ===
464+
Persistence.PlatformFileSystem.PlatformFileSystemType.WORKSPACE_PROJECT)
465+
.filter(project => project !== automaticFileSystemProject);
466+
return regularProjects.length > 0;
467+
}
468+
469+
#getSelectedProjectType(projectPath: Platform.DevToolsPath.RawPathString): SelectedProjectType {
470+
if (this.#automaticFileSystem && this.#automaticFileSystem.root === projectPath) {
471+
return this.#project ? SelectedProjectType.AUTOMATIC_CONNECTED : SelectedProjectType.AUTOMATIC_DISCONNECTED;
472+
}
473+
return this.#project ? SelectedProjectType.NONE : SelectedProjectType.REGULAR;
474+
}
475+
476+
override performUpdate(): void {
477+
const {projectName, projectPath} = this.#getDisplayedProject();
431478

432479
this.#view(
433480
{
@@ -437,6 +484,7 @@ export class PatchWidget extends UI.Widget.Widget {
437484
sources: this.#patchSources,
438485
projectName,
439486
projectPath,
487+
projectType: this.#getSelectedProjectType(projectPath),
440488
savedToDisk: this.#savedToDisk,
441489
applyToWorkspaceTooltipText: this.#noLogging ?
442490
lockedString(UIStringsNotTranslate.applyToWorkspaceTooltipNoLogging) :
@@ -448,8 +496,9 @@ export class PatchWidget extends UI.Widget.Widget {
448496
},
449497
onDiscard: this.#onDiscard.bind(this),
450498
onSaveAll: this.#onSaveAll.bind(this),
451-
onChangeWorkspaceClick: showChangeButton ? this.#showSelectWorkspaceDialog.bind(this, {applyPatch: false}) :
452-
undefined,
499+
onChangeWorkspaceClick: this.#shouldShowChangeButton() ?
500+
this.#showSelectWorkspaceDialog.bind(this, {applyPatch: false}) :
501+
undefined,
453502
},
454503
this.#viewOutput, this.contentElement);
455504
}
@@ -459,6 +508,7 @@ export class PatchWidget extends UI.Widget.Widget {
459508
this.#selectDefaultProject();
460509

461510
if (isAiAssistancePatchingEnabled()) {
511+
this.#workspace.addEventListener(Workspace.Workspace.Events.ProjectAdded, this.#onProjectAdded, this);
462512
this.#workspace.addEventListener(Workspace.Workspace.Events.ProjectRemoved, this.#onProjectRemoved, this);
463513

464514
// @ts-expect-error temporary global function for local testing.
@@ -470,6 +520,7 @@ export class PatchWidget extends UI.Widget.Widget {
470520

471521
override willHide(): void {
472522
if (isAiAssistancePatchingEnabled()) {
523+
this.#workspace.removeEventListener(Workspace.Workspace.Events.ProjectAdded, this.#onProjectAdded, this);
473524
this.#workspace.removeEventListener(Workspace.Workspace.Events.ProjectRemoved, this.#onProjectRemoved, this);
474525
}
475526
}
@@ -531,6 +582,12 @@ export class PatchWidget extends UI.Widget.Widget {
531582
this.requestUpdate();
532583
}
533584

585+
#onProjectAdded(): void {
586+
if (this.#project === undefined) {
587+
this.#selectDefaultProject();
588+
}
589+
}
590+
534591
#onProjectRemoved(): void {
535592
if (this.#project && !this.#workspace.project(this.#project.id())) {
536593
this.#projectIdSetting.set('');

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export const knownContextValues = new Set([
1717
'-epub-word-break',
1818
'-epub-writing-mode',
1919
'-moz-box-direction',
20+
'automatic-workspace-folders',
21+
'connect-workspace',
22+
'stage-to-workspace',
2023
'-moz-box-orient',
2124
'-moz-box-sizing',
2225
'-moz-osx-font-smoothing',

0 commit comments

Comments
 (0)