Skip to content

Commit b090f20

Browse files
authored
feat: Embed widget loading workspace settings (#2068)
Fixes #1964. Also removed a bunch of unnecessary code in `AppInit` where we were using the redux `connect` API with a functional component instead of just using the redux hooks Note that even though this moves a bunch of files to `app-utils`, I don't consider it breaking since they are being moved out of `code-studio`. They wouldn't be consumed by anything else since `code-studio` is published as a bundle. Due to local storage requiring a port match, this can only be tested w/ the local server in 2 steps (this should be fine in prod since the app and embed-widget run on the same port there). 1. Start the dev server and go to the app 2. Run some code to create a table. 3. Change user formatting settings (e.g. show timezones and have a timestamp column) 4. Stop the dev server. 5. Run `PORT=4000 npm run start:embed-widget`. This will let us access the saved workspace from the app 6. Go to `localhost:4000/?name=<your-variable-name>` 7. The formatting settings should be applied
1 parent c804b15 commit b090f20

20 files changed

Lines changed: 183 additions & 207 deletions

package-lock.json

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/app-utils/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@deephaven/console": "file:../console",
3636
"@deephaven/dashboard": "file:../dashboard",
3737
"@deephaven/dashboard-core-plugins": "file:../dashboard-core-plugins",
38+
"@deephaven/file-explorer": "file:../file-explorer",
3839
"@deephaven/golden-layout": "file:../golden-layout",
3940
"@deephaven/icons": "file:../icons",
4041
"@deephaven/iris-grid": "file:../iris-grid",
@@ -46,12 +47,15 @@
4647
"@deephaven/plugin": "file:../plugin",
4748
"@deephaven/react-hooks": "file:../react-hooks",
4849
"@deephaven/redux": "file:../redux",
50+
"@deephaven/storage": "file:../storage",
4951
"@deephaven/utils": "file:../utils",
5052
"@fontsource/fira-mono": "5.0.13",
5153
"@fontsource/fira-sans": "5.0.20",
5254
"@paciolan/remote-component": "2.13.0",
5355
"@paciolan/remote-module-loader": "^3.0.2",
54-
"classnames": "^2.5.1"
56+
"classnames": "^2.5.1",
57+
"lodash.debounce": "^4.0.8",
58+
"lodash.throttle": "^4.1.1"
5559
},
5660
"peerDependencies": {
5761
"react": ">=16.8.0",

packages/app-utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './components';
22
export * from './plugins';
3+
export * from './storage';
34
export * from './utils';
File renamed without changes.

packages/code-studio/src/storage/LocalWorkspaceStorage.ts renamed to packages/app-utils/src/storage/LocalWorkspaceStorage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
DecimalColumnFormatter,
1313
IntegerColumnFormatter,
1414
} from '@deephaven/jsapi-utils';
15-
import UserLayoutUtils from '../main/UserLayoutUtils';
15+
import UserLayoutUtils from './UserLayoutUtils';
1616
import LayoutStorage from './LayoutStorage';
1717

1818
const log = Log.module('LocalWorkspaceStorage');

packages/code-studio/src/main/UserLayoutUtils.test.ts renamed to packages/app-utils/src/storage/UserLayoutUtils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import LayoutStorage, {
44
ExportedLayout,
55
ExportedLayoutV1,
66
ExportedLayoutV2,
7-
} from '../storage/LayoutStorage';
7+
} from './LayoutStorage';
88
import UserLayoutUtils, {
99
DEFAULT_LAYOUT_CONFIG,
1010
DEFAULT_LAYOUT_CONFIG_NO_CONSOLE,

packages/code-studio/src/main/UserLayoutUtils.ts renamed to packages/app-utils/src/storage/UserLayoutUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import LayoutStorage, {
1111
ExportedLayoutV2,
1212
isLayoutV1,
1313
isLayoutV2,
14-
} from '../storage/LayoutStorage';
14+
} from './LayoutStorage';
1515

1616
const log = Log.module('UserLayoutUtils');
1717

packages/code-studio/src/storage/grpc/GrpcFileStorage.ts renamed to packages/app-utils/src/storage/grpc/GrpcFileStorage.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable class-methods-use-this */
2-
31
import throttle from 'lodash.throttle';
42
import {
53
FileNotFoundError,
@@ -19,6 +17,8 @@ const log = Log.module('GrpcFileStorage');
1917
export class GrpcFileStorage implements FileStorage {
2018
private static readonly REFRESH_THROTTLE = 150;
2119

20+
private dh: typeof DhType;
21+
2222
private readonly storageService: DhType.storage.StorageService;
2323

2424
private tables = [] as GrpcFileStorageTable[];
@@ -30,7 +30,12 @@ export class GrpcFileStorage implements FileStorage {
3030
* @param storageService Storage service to use
3131
* @param root Root path for this instance. Should not contain trailing slash.
3232
*/
33-
constructor(storageService: DhType.storage.StorageService, root = '') {
33+
constructor(
34+
dh: typeof DhType,
35+
storageService: DhType.storage.StorageService,
36+
root = ''
37+
) {
38+
this.dh = dh;
3439
this.storageService = storageService;
3540
this.root = root;
3641
}
@@ -61,7 +66,7 @@ export class GrpcFileStorage implements FileStorage {
6166
}
6267

6368
async saveFile(file: File): Promise<File> {
64-
const fileContents = dh.storage.FileContents.text(file.content);
69+
const fileContents = this.dh.storage.FileContents.text(file.content);
6570
await this.storageService.saveFile(
6671
this.addRoot(file.filename),
6772
fileContents,

packages/code-studio/src/storage/grpc/GrpcFileStorageTable.test.ts renamed to packages/app-utils/src/storage/grpc/GrpcFileStorageTable.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import { FileUtils } from '@deephaven/file-explorer';
2-
import type { ItemDetails, StorageService } from '@deephaven/jsapi-types';
2+
import type { dh } from '@deephaven/jsapi-types';
33
import GrpcFileStorageTable from './GrpcFileStorageTable';
44

5-
let storageService: StorageService;
5+
let storageService: dh.storage.StorageService;
66
function makeTable(baseRoot = '', root = ''): GrpcFileStorageTable {
77
return new GrpcFileStorageTable(storageService, baseRoot, root);
88
}
99

10-
function makeStorageService(): StorageService {
10+
function makeStorageService(): dh.storage.StorageService {
1111
return {
1212
listItems: jest.fn(async () => []),
1313
loadFile: jest.fn(async () => {
1414
throw new Error('No file loaded');
1515
}),
1616
deleteItem: jest.fn(async () => undefined),
17-
saveFile: jest.fn(async () => undefined),
17+
saveFile: jest.fn(
18+
async () => undefined as unknown as dh.storage.FileContents
19+
),
1820
moveItem: jest.fn(async () => undefined),
1921
createDirectory: jest.fn(async () => undefined),
2022
};
@@ -38,7 +40,7 @@ it('Does not get contents until a viewport is set', () => {
3840
});
3941

4042
describe('directory expansion tests', () => {
41-
function makeFile(name: string, path = ''): ItemDetails {
43+
function makeFile(name: string, path = ''): dh.storage.ItemDetails {
4244
return {
4345
basename: name,
4446
filename: `${path}/${name}`,
@@ -49,7 +51,7 @@ describe('directory expansion tests', () => {
4951
};
5052
}
5153

52-
function makeDirectory(name: string, path = ''): ItemDetails {
54+
function makeDirectory(name: string, path = ''): dh.storage.ItemDetails {
5355
const file = makeFile(name, path);
5456
file.type = 'directory';
5557
return file;
@@ -59,8 +61,8 @@ describe('directory expansion tests', () => {
5961
path = '/',
6062
numDirs = 3,
6163
numFiles = 2
62-
): Array<ItemDetails> {
63-
const results = [] as ItemDetails[];
64+
): Array<dh.storage.ItemDetails> {
65+
const results = [] as dh.storage.ItemDetails[];
6466

6567
for (let i = 0; i < numDirs; i += 1) {
6668
const name = `dir${i}`;
@@ -75,7 +77,7 @@ describe('directory expansion tests', () => {
7577
return results;
7678
}
7779

78-
function expectItem(itemDetails: ItemDetails) {
80+
function expectItem(itemDetails: dh.storage.ItemDetails) {
7981
return expect.objectContaining({
8082
basename: itemDetails.basename,
8183
filename: itemDetails.filename,

packages/code-studio/src/storage/grpc/GrpcFileStorageTable.ts renamed to packages/app-utils/src/storage/grpc/GrpcFileStorageTable.ts

File renamed without changes.

0 commit comments

Comments
 (0)