Skip to content

Commit e90d116

Browse files
szuendDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
[persistence] Use property instead of constructor for EditFileSystemView
This CL prepares `EditFileSystemView` for use in a lit template in it's parent. Instead of passing the file system path via constructor, we use a setter and pass the file system directly. This way, we loose the dependency on the global singleton. R=dsv@chromium.org Bug: 407735766 Change-Id: I86dc70e2099f91d349c11860eec9ede580c40480 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6562902 Commit-Queue: Simon Zünd <szuend@chromium.org> Reviewed-by: Danil Somsikov <dsv@chromium.org>
1 parent 3c32542 commit e90d116

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

front_end/models/persistence/EditFileSystemView.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ describeWithEnvironment('EditFileSystemView view', () => {
5959
describeWithEnvironment('EditFileSystemView widget', () => {
6060
async function setup(initialExcludedFolders: Set<string>) {
6161
const view = createViewFunctionStub(EditFileSystemView);
62-
const widget = new EditFileSystemView(urlString`file:///home/user`, view);
62+
const widget = new EditFileSystemView(view);
6363
const fileSystem = sinon.createStubInstance(Persistence.IsolatedFileSystem.IsolatedFileSystem);
64-
sinon.stub(Persistence.IsolatedFileSystemManager.IsolatedFileSystemManager.instance(), 'fileSystem')
65-
.returns(fileSystem);
64+
fileSystem.path.returns(urlString`file:///home/user`);
6665
fileSystem.excludedFolders.returns(initialExcludedFolders as Set<Platform.DevToolsPath.EncodedPathString>);
66+
widget.fileSystem = fileSystem;
6767

6868
const container = document.createElement('div');
6969
renderElementIntoDOM(container);

front_end/models/persistence/EditFileSystemView.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131
import '../../ui/legacy/components/data_grid/data_grid.js';
3232

3333
import * as i18n from '../../core/i18n/i18n.js';
34-
import type * as Platform from '../../core/platform/platform.js';
34+
import * as Platform from '../../core/platform/platform.js';
3535
import * as UI from '../../ui/legacy/legacy.js';
3636
import {Directives, html, render} from '../../ui/lit/lit.js';
3737

3838
import editFileSystemViewStyles from './editFileSystemView.css.js';
39-
import {IsolatedFileSystemManager} from './IsolatedFileSystemManager.js';
4039
import type {PlatformFileSystem} from './PlatformFileSystem.js';
4140

4241
const {styleMap} = Directives;
@@ -132,28 +131,37 @@ export const DEFAULT_VIEW: View = (input, _output, target) => {
132131
};
133132

134133
export class EditFileSystemView extends UI.Widget.VBox {
135-
readonly #fileSystemPath: Platform.DevToolsPath.UrlString;
134+
#fileSystem?: PlatformFileSystem;
136135
#excludedFolderPaths: PathWithStatus[] = [];
137136
readonly #view: View;
138137

139-
constructor(fileSystemPath: Platform.DevToolsPath.UrlString, view: View = DEFAULT_VIEW) {
138+
constructor(view: View = DEFAULT_VIEW) {
140139
super();
141-
this.#fileSystemPath = fileSystemPath;
142140
this.#view = view;
143141
}
144142

143+
set fileSystem(fileSystem: PlatformFileSystem) {
144+
this.#fileSystem = fileSystem;
145+
this.#resyncExcludedFolderPaths();
146+
this.requestUpdate();
147+
}
148+
145149
override wasShown(): void {
146-
this.#excludedFolderPaths = this.#getFileSystem()
147-
.excludedFolders()
150+
this.#resyncExcludedFolderPaths();
151+
this.requestUpdate();
152+
}
153+
154+
#resyncExcludedFolderPaths(): void {
155+
this.#excludedFolderPaths = this.#fileSystem?.excludedFolders()
148156
.values()
149157
.map(path => ({path, status: ExcludedFolderStatus.VALID}))
150-
.toArray();
151-
this.requestUpdate();
158+
.toArray() ??
159+
[];
152160
}
153161

154162
override performUpdate(): void {
155163
const input: EditFileSystemViewInput = {
156-
fileSystemPath: this.#fileSystemPath,
164+
fileSystemPath: this.#fileSystem?.path() ?? Platform.DevToolsPath.urlString``,
157165
excludedFolderPaths: this.#excludedFolderPaths,
158166
onCreate: e => this.#onCreate(e.detail.url),
159167
onEdit: e => this.#onEdit(e.detail.node.dataset.index ?? '-1', e.detail.valueBeforeEditing, e.detail.newText),
@@ -172,7 +180,7 @@ export class EditFileSystemView extends UI.Widget.VBox {
172180
const pathWithStatus = this.#validateFolder(url);
173181
this.#excludedFolderPaths.push(pathWithStatus);
174182
if (pathWithStatus.status === ExcludedFolderStatus.VALID) {
175-
this.#getFileSystem().addExcludedFolder(pathWithStatus.path);
183+
this.#fileSystem?.addExcludedFolder(pathWithStatus.path);
176184
}
177185

178186
this.requestUpdate();
@@ -189,11 +197,11 @@ export class EditFileSystemView extends UI.Widget.VBox {
189197
this.#excludedFolderPaths[index] = pathWithStatus;
190198

191199
if (oldPathWithStatus.status === ExcludedFolderStatus.VALID) {
192-
this.#getFileSystem().removeExcludedFolder(valueBeforeEditing as Platform.DevToolsPath.EncodedPathString);
200+
this.#fileSystem?.removeExcludedFolder(valueBeforeEditing as Platform.DevToolsPath.EncodedPathString);
193201
}
194202

195203
if (pathWithStatus.status === ExcludedFolderStatus.VALID) {
196-
this.#getFileSystem().addExcludedFolder(pathWithStatus.path);
204+
this.#fileSystem?.addExcludedFolder(pathWithStatus.path);
197205
}
198206

199207
this.requestUpdate();
@@ -205,7 +213,7 @@ export class EditFileSystemView extends UI.Widget.VBox {
205213
return;
206214
}
207215

208-
this.#getFileSystem().removeExcludedFolder(this.#excludedFolderPaths[index].path);
216+
this.#fileSystem?.removeExcludedFolder(this.#excludedFolderPaths[index].path);
209217
this.#excludedFolderPaths.splice(index, 1);
210218

211219
this.requestUpdate();
@@ -230,8 +238,4 @@ export class EditFileSystemView extends UI.Widget.VBox {
230238
}
231239
return prefix + (prefix[prefix.length - 1] === '/' ? '' : '/');
232240
}
233-
234-
#getFileSystem(): PlatformFileSystem {
235-
return IsolatedFileSystemManager.instance().fileSystem(this.#fileSystemPath) as PlatformFileSystem;
236-
}
237241
}

front_end/models/persistence/WorkspaceSettingsTab.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ export class WorkspaceSettingsTab extends UI.Widget.VBox {
141141
fileSystemExcludeCard.heading = filename;
142142
fileSystemExcludeCard.append(folderIcon, removeButton, mappingViewContainer);
143143
this.containerElement.insertBefore(fileSystemExcludeCard, this.#addButtonContainer);
144-
const mappingView = new EditFileSystemView(fileSystem.path());
144+
const mappingView = new EditFileSystemView();
145+
mappingView.fileSystem = fileSystem;
145146
this.mappingViewByPath.set(fileSystem.path(), mappingView);
146147
mappingView.element.classList.add('file-system-mapping-view');
147148

0 commit comments

Comments
 (0)