Skip to content

Commit 85f3ea4

Browse files
danilsomsikovDevtools-frontend LUCI CQ
authored andcommitted
Make SharedStorageItemsView a subclass of KeyValueStorageItemsView
Bug: 394287937 Change-Id: I016e90540a68900b9f52ab5d826863b3a7c38ba8 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6264607 Reviewed-by: Benedikt Meurer <[email protected]> Auto-Submit: Danil Somsikov <[email protected]> Commit-Queue: Benedikt Meurer <[email protected]>
1 parent 379b414 commit 85f3ea4

File tree

6 files changed

+192
-548
lines changed

6 files changed

+192
-548
lines changed

front_end/panels/application/ApplicationPanelSidebar.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ describeWithMockConnection('ApplicationPanelSidebar', () => {
291291
addEventListener: () => {},
292292
securityOrigin: 'https://example.com',
293293
databaseId: new Application.IndexedDBModel.DatabaseId({storageKey: ''}, ''),
294+
getEntries: () => Promise.resolve([]),
294295
};
295296

296297
const testUiUpdate = <Events, T extends keyof Events>(

front_end/panels/application/KeyValueStorageItemsView.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import * as UI from '../../ui/legacy/legacy.js';
3333
import {Directives as LitDirectives, html, nothing, render} from '../../ui/lit/lit.js';
3434
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
3535

36+
import type * as ApplicationComponents from './components/components.js';
3637
import {StorageItemsView} from './StorageItemsView.js';
3738

3839
const {ARIAUtils} = UI;
@@ -101,7 +102,9 @@ export abstract class KeyValueStorageItemsView extends StorageItemsView {
101102
#isSortOrderAscending = true;
102103
#editable: boolean;
103104

104-
constructor(title: string, id: string, editable: boolean, view?: View) {
105+
constructor(
106+
title: string, id: string, editable: boolean, view?: View,
107+
metadataView?: ApplicationComponents.StorageMetadataView.StorageMetadataView) {
105108
if (!view) {
106109
view = (input: ViewInput, output: ViewOutput, target: HTMLElement) => {
107110
// clang-format off
@@ -152,7 +155,7 @@ export abstract class KeyValueStorageItemsView extends StorageItemsView {
152155
target, {host: input});
153156
};
154157
}
155-
super(title, id);
158+
super(title, id, metadataView);
156159
this.#editable = editable;
157160
this.#view = view;
158161
this.performUpdate();
@@ -267,18 +270,28 @@ export abstract class KeyValueStorageItemsView extends StorageItemsView {
267270
#createCallback(key: string, value: string): void {
268271
this.setItem(key, value);
269272
this.#removeDupes(key, value);
273+
void this.#previewEntry({key, value});
274+
}
275+
276+
protected isEditAllowed(_columnIdentifier: string, _oldText: string, _newText: string): boolean {
277+
return true;
270278
}
271279

272280
#editingCallback(editingNode: HTMLElement, columnIdentifier: string, oldText: string, newText: string): void {
281+
if (!this.isEditAllowed(columnIdentifier, oldText, newText)) {
282+
return;
283+
}
273284
if (columnIdentifier === 'key') {
274285
if (typeof oldText === 'string') {
275286
this.removeItem(oldText);
276287
}
277288
this.setItem(newText, editingNode.dataset.value || '');
278289
this.#removeDupes(newText, editingNode.dataset.value || '');
279290
editingNode.dataset.key = newText;
291+
void this.#previewEntry({key: newText, value: editingNode.dataset.value || ''});
280292
} else {
281293
this.setItem(editingNode.dataset.key || '', newText);
294+
void this.#previewEntry({key: editingNode.dataset.key || '', value: newText});
282295
}
283296
}
284297

@@ -330,6 +343,10 @@ export abstract class KeyValueStorageItemsView extends StorageItemsView {
330343
this.performUpdate();
331344
}
332345

346+
protected keys(): string[] {
347+
return this.#items.map(item => item.key);
348+
}
349+
333350
protected abstract setItem(key: string, value: string): void;
334351
protected abstract removeItem(key: string): void;
335352
protected abstract createPreview(key: string, value: string): Promise<Widget|null>;

0 commit comments

Comments
 (0)