forked from deephaven/web-client-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore.ts
More file actions
181 lines (155 loc) · 4.74 KB
/
store.ts
File metadata and controls
181 lines (155 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { applyMiddleware, createStore, compose, combineReducers } from 'redux';
import type { FileStorage } from '@deephaven/file-explorer';
import type { ValidKeyState } from '@deephaven/components';
import type { dh as DhType } from '@deephaven/jsapi-types';
import type { FormattingRule } from '@deephaven/jsapi-utils';
import type { PayloadAction } from './actions';
import rootMiddleware from './middleware';
import reducers from './reducers';
import reducerRegistry from './reducerRegistry';
export interface UserPermissions {
canUsePanels: boolean;
canCopy: boolean;
canDownloadCsv: boolean;
canLogout: boolean;
}
export interface User {
permissions: UserPermissions;
name: string;
operateAs?: string;
groups: string[];
displayName?: string;
fullName?: string;
image?: string;
}
export type ServerConfigValues = Map<string, string>;
export interface Storage {
commandHistoryStorage: unknown;
fileStorage: FileStorage;
workspaceStorage: WorkspaceStorage;
}
export interface WorkspaceSettings {
defaultDateTimeFormat: string;
defaultDecimalFormatOptions: {
defaultFormatString?: string;
};
defaultIntegerFormatOptions: {
defaultFormatString?: string;
};
formatter: FormattingRule[];
timeZone: string;
showTimeZone: boolean;
showTSeparator: boolean;
truncateNumbersWithPound: boolean;
showEmptyStrings: boolean;
showNullStrings: boolean;
showExtraGroupColumn: boolean;
disableMoveConfirmation: boolean;
shortcutOverrides?: {
windows?: { [id: string]: ValidKeyState };
mac?: { [id: string]: ValidKeyState };
};
notebookSettings: {
isMinimapEnabled?: boolean;
formatOnSave?: boolean;
python?: {
linter?: {
isEnabled?: boolean;
config?: Record<string, unknown>;
};
};
};
webgl: boolean;
webglEditable: boolean;
gridDensity: 'compact' | 'regular' | 'spacious';
}
export interface WorkspaceData {
settings: WorkspaceSettings;
// TODO: #1746 The rest of these options should not be stored with workspace data, we should have a separate DashboardStorage
closed: unknown[];
filterSets: unknown[];
layoutConfig: unknown[];
links: unknown;
pluginDataMap: PluginDataMap;
}
export interface CustomizableWorkspaceData
extends Omit<WorkspaceData, 'settings'> {
settings: Partial<WorkspaceData['settings']>;
}
export interface CustomizableWorkspace {
data: CustomizableWorkspaceData;
}
export interface Workspace {
data: WorkspaceData;
}
export type PluginData = unknown;
export type PluginDataMap<TData = PluginData> = Record<string, TData>;
// These are mostly copied from @deephaven/plugin so we can avoid a circular dependency
export type PluginModule =
| {
name: string;
type:
| 'AuthPlugin'
| 'DashboardPlugin'
| 'WidgetPlugin'
| 'TablePlugin'
| 'ThemePlugin'
| 'ElementPlugin'
| 'MultiPlugin';
}
| {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
DashboardPlugin: any;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| { AuthPlugin: any }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| { TablePlugin: any };
export type VersionedPluginModule = PluginModule & { version?: string };
export type PluginModuleMap = Map<string, VersionedPluginModule>;
export type DashboardData<TPluginData = PluginData> = Record<
string,
unknown
> & {
title?: string;
closed?: unknown[];
filterSets?: unknown[];
pluginDataMap?: PluginDataMap<TPluginData>;
};
export type WorkspaceStorageLoadOptions = {
isConsoleAvailable: boolean;
};
export interface WorkspaceStorage {
load: (
options?: WorkspaceStorageLoadOptions
) => Promise<CustomizableWorkspace>;
save: (workspace: CustomizableWorkspace) => Promise<CustomizableWorkspace>;
}
export type RootState = {
api: typeof DhType;
activeTool: string;
plugins: PluginModuleMap;
storage: Storage;
user: User;
workspace: CustomizableWorkspace;
defaultWorkspaceSettings: WorkspaceSettings;
dashboardData: { [id: string]: DashboardData };
layoutStorage: unknown;
serverConfigValues: ServerConfigValues;
};
Object.entries(reducers).map(([name, reducer]) =>
reducerRegistry.register(name, reducer)
);
const composeEnhancers: typeof compose =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?? compose;
const store = createStore<RootState, PayloadAction, unknown, unknown>(
combineReducers(reducerRegistry.reducers),
composeEnhancers(applyMiddleware(...rootMiddleware))
);
reducerRegistry.setListener(newReducers => {
store.replaceReducer(combineReducers(newReducers));
});
export type AppStore = typeof store;
export type RootDispatch = typeof store.dispatch;
export default store;