@sqlrooms/room-shell 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/README.md +722 -0
- package/dist/RoomBuilder.d.ts +3 -0
- package/dist/RoomBuilder.d.ts.map +1 -0
- package/dist/RoomBuilder.js +28 -0
- package/dist/RoomBuilder.js.map +1 -0
- package/dist/RoomShell.d.ts +38 -0
- package/dist/RoomShell.d.ts.map +1 -0
- package/dist/RoomShell.js +47 -0
- package/dist/RoomShell.js.map +1 -0
- package/dist/RoomShellSidebarButtons.d.ts +19 -0
- package/dist/RoomShellSidebarButtons.d.ts.map +1 -0
- package/dist/RoomShellSidebarButtons.js +31 -0
- package/dist/RoomShellSidebarButtons.js.map +1 -0
- package/dist/RoomShellStore.d.ts +91 -0
- package/dist/RoomShellStore.d.ts.map +1 -0
- package/dist/RoomShellStore.js +461 -0
- package/dist/RoomShellStore.js.map +1 -0
- package/dist/data-sources/FileDataSourceCard.d.ts +9 -0
- package/dist/data-sources/FileDataSourceCard.d.ts.map +1 -0
- package/dist/data-sources/FileDataSourceCard.js +29 -0
- package/dist/data-sources/FileDataSourceCard.js.map +1 -0
- package/dist/data-sources/FileDataSourcesPanel.d.ts +6 -0
- package/dist/data-sources/FileDataSourcesPanel.d.ts.map +1 -0
- package/dist/data-sources/FileDataSourcesPanel.js +10 -0
- package/dist/data-sources/FileDataSourcesPanel.js.map +1 -0
- package/dist/data-sources/TableCard.d.ts +20 -0
- package/dist/data-sources/TableCard.d.ts.map +1 -0
- package/dist/data-sources/TableCard.js +12 -0
- package/dist/data-sources/TableCard.js.map +1 -0
- package/dist/data-sources/TablesListPanel.d.ts +7 -0
- package/dist/data-sources/TablesListPanel.d.ts.map +1 -0
- package/dist/data-sources/TablesListPanel.js +26 -0
- package/dist/data-sources/TablesListPanel.js.map +1 -0
- package/dist/data-sources/index.d.ts +5 -0
- package/dist/data-sources/index.d.ts.map +1 -0
- package/dist/data-sources/index.js +5 -0
- package/dist/data-sources/index.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/panels/RoomHeaderButton.d.ts +9 -0
- package/dist/panels/RoomHeaderButton.d.ts.map +1 -0
- package/dist/panels/RoomHeaderButton.js +8 -0
- package/dist/panels/RoomHeaderButton.js.map +1 -0
- package/dist/panels/RoomPanel.d.ts +8 -0
- package/dist/panels/RoomPanel.d.ts.map +1 -0
- package/dist/panels/RoomPanel.js +8 -0
- package/dist/panels/RoomPanel.js.map +1 -0
- package/dist/panels/RoomPanelHeader.d.ts +8 -0
- package/dist/panels/RoomPanelHeader.d.ts.map +1 -0
- package/dist/panels/RoomPanelHeader.js +17 -0
- package/dist/panels/RoomPanelHeader.js.map +1 -0
- package/dist/panels/index.d.ts +4 -0
- package/dist/panels/index.d.ts.map +1 -0
- package/dist/panels/index.js +4 -0
- package/dist/panels/index.js.map +1 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +46 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025 Ilya Boyandin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,722 @@
|
|
|
1
|
+
A powerful framework for building and managing data rooms in SQLRooms. This package provides components and utilities for creating, configuring, and managing data rooms with an intuitive user interface.
|
|
2
|
+
|
|
3
|
+
## Features
|
|
4
|
+
|
|
5
|
+
- 🏗️ **Room Structure**: Tools for defining and managing room structure
|
|
6
|
+
- 📊 **Data Sources**: Components for connecting to and managing data sources
|
|
7
|
+
- 🧩 **Panel System**: Flexible panel-based UI for room components
|
|
8
|
+
- 🔄 **State Management**: Robust state management using Zustand
|
|
9
|
+
- 📁 **File Handling**: Utilities for processing and managing room files
|
|
10
|
+
- 🧰 **Extensible Architecture**: Easily extend with custom components and panels
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @sqlrooms/room-shell
|
|
16
|
+
# or
|
|
17
|
+
yarn add @sqlrooms/room-shell
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Basic Usage
|
|
21
|
+
|
|
22
|
+
### Creating a Room Builder
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import {RoomShell} from '@sqlrooms/room-shell';
|
|
26
|
+
|
|
27
|
+
function MyApp() {
|
|
28
|
+
return (
|
|
29
|
+
<RoomShell className="h-screen" roomStore={roomStore}>
|
|
30
|
+
<RoomShell.Sidebar />
|
|
31
|
+
<RoomShell.LayoutComposer />
|
|
32
|
+
<RoomShell.LoadingProgress />
|
|
33
|
+
</RoomShell>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Working with Room State
|
|
39
|
+
|
|
40
|
+
The room-shell package uses Zustand for state management. You can create a custom store with room-specific state and actions.
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import {
|
|
44
|
+
createRoomSlice,
|
|
45
|
+
createRoomStore,
|
|
46
|
+
RoomState,
|
|
47
|
+
BaseRoomConfig,
|
|
48
|
+
} from '@sqlrooms/room-shell';
|
|
49
|
+
import {z} from 'zod';
|
|
50
|
+
|
|
51
|
+
// Define your custom config schema (optional)
|
|
52
|
+
const MyRoomConfig = BaseRoomConfig.extend({
|
|
53
|
+
myCustomSetting: z.string().default('default value'),
|
|
54
|
+
});
|
|
55
|
+
type MyRoomConfig = z.infer<typeof MyRoomConfig>;
|
|
56
|
+
|
|
57
|
+
// Define your custom app state
|
|
58
|
+
type MyRoomState = RoomState<MyRoomConfig> & {
|
|
59
|
+
myFeatureData: any[];
|
|
60
|
+
addItem: (item: any) => void;
|
|
61
|
+
removeItem: (id: string) => void;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Create a room store with custom state
|
|
65
|
+
export const {roomStore, useRoomStore} = createRoomStore<
|
|
66
|
+
MyRoomConfig,
|
|
67
|
+
MyRoomState
|
|
68
|
+
>((set, get, store) => ({
|
|
69
|
+
// Base room slice with initial configuration
|
|
70
|
+
...createRoomSlice<MyRoomConfig>({
|
|
71
|
+
config: {
|
|
72
|
+
title: 'My Room',
|
|
73
|
+
layout: {
|
|
74
|
+
/* layout configuration */
|
|
75
|
+
},
|
|
76
|
+
dataSources: [],
|
|
77
|
+
myCustomSetting: 'custom value',
|
|
78
|
+
},
|
|
79
|
+
room: {
|
|
80
|
+
panels: {
|
|
81
|
+
/* panel definitions */
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
})(set, get, store),
|
|
85
|
+
|
|
86
|
+
// Custom state and actions
|
|
87
|
+
myFeatureData: [],
|
|
88
|
+
addItem: (item) =>
|
|
89
|
+
set((state) => ({
|
|
90
|
+
myFeatureData: [...state.myFeatureData, item],
|
|
91
|
+
})),
|
|
92
|
+
removeItem: (id) =>
|
|
93
|
+
set((state) => ({
|
|
94
|
+
myFeatureData: state.myFeatureData.filter((item) => item.id !== id),
|
|
95
|
+
})),
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
// Use the store in a component with selector for better performance
|
|
99
|
+
function MyComponent() {
|
|
100
|
+
// Use selectors for better performance
|
|
101
|
+
const myFeatureData = useRoomStore((state) => state.myFeatureData);
|
|
102
|
+
const addItem = useRoomStore((state) => state.addItem);
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div>
|
|
106
|
+
<h2>My Items ({myFeatureData.length})</h2>
|
|
107
|
+
<button onClick={() => addItem({id: Date.now(), name: 'New Item'})}>
|
|
108
|
+
Add Item
|
|
109
|
+
</button>
|
|
110
|
+
{/* Render items */}
|
|
111
|
+
</div>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Persisting Room Configuration
|
|
117
|
+
|
|
118
|
+
The room configuration is designed to be persisted between sessions. You can use Zustand's persist middleware to save the configuration to localStorage or any other storage:
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
import {persist} from 'zustand/middleware';
|
|
122
|
+
import {
|
|
123
|
+
createRoomSlice,
|
|
124
|
+
createRoomStore,
|
|
125
|
+
RoomState,
|
|
126
|
+
BaseRoomConfig,
|
|
127
|
+
} from '@sqlrooms/room-shell';
|
|
128
|
+
import {z} from 'zod';
|
|
129
|
+
|
|
130
|
+
// Define your custom config schema
|
|
131
|
+
const MyRoomConfig = BaseRoomConfig.extend({
|
|
132
|
+
myCustomSetting: z.string().default('default value'),
|
|
133
|
+
});
|
|
134
|
+
type MyRoomConfig = z.infer<typeof MyRoomConfig>;
|
|
135
|
+
|
|
136
|
+
// Define your custom app state
|
|
137
|
+
type MyRoomState = RoomState<MyRoomConfig> & {
|
|
138
|
+
myFeatureData: any[];
|
|
139
|
+
addItem: (item: any) => void;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Create a store with persistence
|
|
143
|
+
export const {roomStore, useRoomStore} = createRoomStore<
|
|
144
|
+
MyRoomConfig,
|
|
145
|
+
MyRoomState
|
|
146
|
+
>(
|
|
147
|
+
persist(
|
|
148
|
+
(set, get, store) => ({
|
|
149
|
+
// Base room slice
|
|
150
|
+
...createRoomSlice<MyRoomConfig>({
|
|
151
|
+
config: {
|
|
152
|
+
title: 'My Room',
|
|
153
|
+
layout: {
|
|
154
|
+
/* layout configuration */
|
|
155
|
+
},
|
|
156
|
+
dataSources: [],
|
|
157
|
+
myCustomSetting: 'custom value',
|
|
158
|
+
},
|
|
159
|
+
room: {
|
|
160
|
+
panels: {
|
|
161
|
+
/* panel definitions */
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
})(set, get, store),
|
|
165
|
+
|
|
166
|
+
// Custom state and actions
|
|
167
|
+
myFeatureData: [],
|
|
168
|
+
addItem: (item) =>
|
|
169
|
+
set((state) => ({
|
|
170
|
+
myFeatureData: [...state.myFeatureData, item],
|
|
171
|
+
})),
|
|
172
|
+
}),
|
|
173
|
+
{
|
|
174
|
+
name: 'my-room-storage',
|
|
175
|
+
partialize: (state) => ({
|
|
176
|
+
// Persist only the config part of the state
|
|
177
|
+
config: state.config,
|
|
178
|
+
}),
|
|
179
|
+
},
|
|
180
|
+
),
|
|
181
|
+
);
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Integrating Multiple Feature Slices
|
|
185
|
+
|
|
186
|
+
For larger applications, you can organize your state into feature slices:
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import {
|
|
190
|
+
createRoomSlice,
|
|
191
|
+
createRoomStore,
|
|
192
|
+
RoomState,
|
|
193
|
+
} from '@sqlrooms/room-shell';
|
|
194
|
+
import {createMyFeatureSlice, MyFeatureState} from './myFeatureSlice';
|
|
195
|
+
import {
|
|
196
|
+
createAnotherFeatureSlice,
|
|
197
|
+
AnotherFeatureState,
|
|
198
|
+
} from './anotherFeatureSlice';
|
|
199
|
+
|
|
200
|
+
// Combined app state type
|
|
201
|
+
type RoomState = RoomState<MyRoomConfig> & MyFeatureState & AnotherFeatureState;
|
|
202
|
+
|
|
203
|
+
// Create a store with multiple slices
|
|
204
|
+
export const {roomStore, useRoomStore} = createRoomStore<
|
|
205
|
+
MyRoomConfig,
|
|
206
|
+
RoomState
|
|
207
|
+
>((set, get, store) => ({
|
|
208
|
+
// Base room slice
|
|
209
|
+
...createRoomSlice<MyRoomConfig>({
|
|
210
|
+
config: {
|
|
211
|
+
/* initial config */
|
|
212
|
+
},
|
|
213
|
+
room: {
|
|
214
|
+
panels: {
|
|
215
|
+
/* panel definitions */
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
})(set, get, store),
|
|
219
|
+
|
|
220
|
+
// Feature slices
|
|
221
|
+
...createMyFeatureSlice()(set, get, store),
|
|
222
|
+
...createAnotherFeatureSlice({
|
|
223
|
+
// Feature-specific options
|
|
224
|
+
customOption: 'value',
|
|
225
|
+
})(set, get, store),
|
|
226
|
+
}));
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Managing Data Sources
|
|
230
|
+
|
|
231
|
+
```tsx
|
|
232
|
+
import {
|
|
233
|
+
FileDataSourcesPanel,
|
|
234
|
+
TablesListPanel,
|
|
235
|
+
DataSourceType,
|
|
236
|
+
} from '@sqlrooms/room-shell';
|
|
237
|
+
|
|
238
|
+
function DataSourcesSection() {
|
|
239
|
+
// Use selectors for better performance
|
|
240
|
+
const addDataSource = useRoomStore((state) => state.room.addDataSource);
|
|
241
|
+
const addRoomFile = useRoomStore((state) => state.room.addRoomFile);
|
|
242
|
+
|
|
243
|
+
const handleFileDrop = async (files) => {
|
|
244
|
+
for (const file of files) {
|
|
245
|
+
await addRoomFile(file);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const handleAddCsvUrl = (url) => {
|
|
250
|
+
addDataSource({
|
|
251
|
+
type: DataSourceType.url,
|
|
252
|
+
url,
|
|
253
|
+
tableName: 'data_from_url',
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const handleAddSqlQuery = (query) => {
|
|
258
|
+
addDataSource({
|
|
259
|
+
type: DataSourceType.sqlQuery,
|
|
260
|
+
query,
|
|
261
|
+
tableName: 'query_results',
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<div className="grid grid-cols-2 gap-4">
|
|
267
|
+
<FileDataSourcesPanel onFileDrop={handleFileDrop} />
|
|
268
|
+
<TablesListPanel />
|
|
269
|
+
<button onClick={() => handleAddCsvUrl('https://example.com/data.csv')}>
|
|
270
|
+
Add CSV from URL
|
|
271
|
+
</button>
|
|
272
|
+
</div>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Creating Custom Panels
|
|
278
|
+
|
|
279
|
+
```tsx
|
|
280
|
+
import {RoomPanel, RoomPanelHeader} from '@sqlrooms/room-shell';
|
|
281
|
+
|
|
282
|
+
function CustomPanel({title, children}) {
|
|
283
|
+
return (
|
|
284
|
+
<RoomPanel>
|
|
285
|
+
<RoomPanelHeader title={title} />
|
|
286
|
+
<div className="p-4">{children}</div>
|
|
287
|
+
</RoomPanel>
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## RoomStore API Reference
|
|
293
|
+
|
|
294
|
+
The RoomStore is the core of the room-shell package. It provides a comprehensive set of properties and methods for managing room state.
|
|
295
|
+
|
|
296
|
+
### State Properties
|
|
297
|
+
|
|
298
|
+
#### `config`
|
|
299
|
+
|
|
300
|
+
The room configuration, which can be persisted between sessions.
|
|
301
|
+
|
|
302
|
+
```tsx
|
|
303
|
+
const config = useRoomStore((state) => state.config);
|
|
304
|
+
console.log(config.title); // Access room title
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
#### `schema`
|
|
308
|
+
|
|
309
|
+
The database schema name used for the room.
|
|
310
|
+
|
|
311
|
+
```tsx
|
|
312
|
+
const schema = useRoomStore((state) => state.room.schema);
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
#### `tasksProgress`
|
|
316
|
+
|
|
317
|
+
A record of task progress information, useful for displaying loading indicators.
|
|
318
|
+
|
|
319
|
+
```tsx
|
|
320
|
+
const tasksProgress = useRoomStore((state) => state.room.tasksProgress);
|
|
321
|
+
// Example: { "init-db": { message: "Initializing database...", progress: 0.5 } }
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
#### `roomId`
|
|
325
|
+
|
|
326
|
+
The unique identifier for the room, undefined for new rooms.
|
|
327
|
+
|
|
328
|
+
```tsx
|
|
329
|
+
const roomId = useRoomStore((state) => state.room.roomId);
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
#### `panels`
|
|
333
|
+
|
|
334
|
+
A record of panel information, including title, icon, component, and placement.
|
|
335
|
+
|
|
336
|
+
```tsx
|
|
337
|
+
const panels = useRoomStore((state) => state.room.panels);
|
|
338
|
+
// Example: { "data-sources": { title: "Data Sources", icon: DatabaseIcon, ... } }
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
#### `isReadOnly`
|
|
342
|
+
|
|
343
|
+
Whether the room is in read-only mode.
|
|
344
|
+
|
|
345
|
+
```tsx
|
|
346
|
+
const isReadOnly = useRoomStore((state) => state.room.isReadOnly);
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
#### `tables`
|
|
350
|
+
|
|
351
|
+
An array of data tables available in the room.
|
|
352
|
+
|
|
353
|
+
```tsx
|
|
354
|
+
const tables = useRoomStore((state) => state.room.tables);
|
|
355
|
+
// Access table schemas and metadata
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
#### `roomFiles`
|
|
359
|
+
|
|
360
|
+
An array of room file information.
|
|
361
|
+
|
|
362
|
+
```tsx
|
|
363
|
+
const roomFiles = useRoomStore((state) => state.room.roomFiles);
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
#### `roomFilesProgress`
|
|
367
|
+
|
|
368
|
+
A record of file processing progress information.
|
|
369
|
+
|
|
370
|
+
```tsx
|
|
371
|
+
const roomFilesProgress = useRoomStore((state) => state.room.roomFilesProgress);
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
#### `lastSavedConfig`
|
|
375
|
+
|
|
376
|
+
The last saved room configuration, used to check for unsaved changes.
|
|
377
|
+
|
|
378
|
+
```tsx
|
|
379
|
+
const lastSavedConfig = useRoomStore((state) => state.room.lastSavedConfig);
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
#### `initialized`
|
|
383
|
+
|
|
384
|
+
Whether the room has been initialized.
|
|
385
|
+
|
|
386
|
+
```tsx
|
|
387
|
+
const initialized = useRoomStore((state) => state.room.initialized);
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
#### `isDataAvailable`
|
|
391
|
+
|
|
392
|
+
Whether the room data has been loaded.
|
|
393
|
+
|
|
394
|
+
```tsx
|
|
395
|
+
const isDataAvailable = useRoomStore((state) => state.room.isDataAvailable);
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
#### `dataSourceStates`
|
|
399
|
+
|
|
400
|
+
A record of data source states by table name.
|
|
401
|
+
|
|
402
|
+
```tsx
|
|
403
|
+
const dataSourceStates = useRoomStore((state) => state.room.dataSourceStates);
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
#### `tableRowCounts`
|
|
407
|
+
|
|
408
|
+
A record of row counts by table name.
|
|
409
|
+
|
|
410
|
+
```tsx
|
|
411
|
+
const tableRowCounts = useRoomStore((state) => state.room.tableRowCounts);
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Methods
|
|
415
|
+
|
|
416
|
+
#### `initialize()`
|
|
417
|
+
|
|
418
|
+
Initialize the room state.
|
|
419
|
+
|
|
420
|
+
```tsx
|
|
421
|
+
const initialize = useRoomStore((state) => state.room.initialize);
|
|
422
|
+
await initialize();
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
#### `setTaskProgress(id, taskProgress)`
|
|
426
|
+
|
|
427
|
+
Set the progress of a task.
|
|
428
|
+
|
|
429
|
+
```tsx
|
|
430
|
+
const setTaskProgress = useRoomStore((state) => state.room.setTaskProgress);
|
|
431
|
+
setTaskProgress('my-task', {message: 'Processing...', progress: 0.5});
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
#### `getLoadingProgress()`
|
|
435
|
+
|
|
436
|
+
Get the current loading progress.
|
|
437
|
+
|
|
438
|
+
```tsx
|
|
439
|
+
const getLoadingProgress = useRoomStore(
|
|
440
|
+
(state) => state.room.getLoadingProgress,
|
|
441
|
+
);
|
|
442
|
+
const progress = getLoadingProgress();
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
#### `setRoomConfig(config)`
|
|
446
|
+
|
|
447
|
+
Set the room configuration.
|
|
448
|
+
|
|
449
|
+
```tsx
|
|
450
|
+
const setRoomConfig = useRoomStore((state) => state.room.setRoomConfig);
|
|
451
|
+
const config = useRoomStore((state) => state.config);
|
|
452
|
+
setRoomConfig({...config, title: 'New Title'});
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
#### `setLastSavedConfig(config)`
|
|
456
|
+
|
|
457
|
+
Set the last saved room configuration.
|
|
458
|
+
|
|
459
|
+
```tsx
|
|
460
|
+
const setLastSavedConfig = useRoomStore(
|
|
461
|
+
(state) => state.room.setLastSavedConfig,
|
|
462
|
+
);
|
|
463
|
+
const config = useRoomStore((state) => state.config);
|
|
464
|
+
setLastSavedConfig(config);
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
#### `hasUnsavedChanges()`
|
|
468
|
+
|
|
469
|
+
Check if the room has unsaved changes.
|
|
470
|
+
|
|
471
|
+
```tsx
|
|
472
|
+
const hasUnsavedChanges = useRoomStore((state) => state.room.hasUnsavedChanges);
|
|
473
|
+
if (hasUnsavedChanges()) {
|
|
474
|
+
// Prompt user to save changes
|
|
475
|
+
}
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
#### `setLayout(layout)`
|
|
479
|
+
|
|
480
|
+
Set the room layout configuration.
|
|
481
|
+
|
|
482
|
+
```tsx
|
|
483
|
+
const setLayout = useRoomStore((state) => state.room.setLayout);
|
|
484
|
+
setLayout(newLayout);
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
#### `togglePanel(panel, show)`
|
|
488
|
+
|
|
489
|
+
Toggle the visibility of a panel.
|
|
490
|
+
|
|
491
|
+
```tsx
|
|
492
|
+
const togglePanel = useRoomStore((state) => state.room.togglePanel);
|
|
493
|
+
togglePanel('data-sources', true); // Show the data sources panel
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
#### `togglePanelPin(panel)`
|
|
497
|
+
|
|
498
|
+
Toggle the pin state of a panel.
|
|
499
|
+
|
|
500
|
+
```tsx
|
|
501
|
+
const togglePanelPin = useRoomStore((state) => state.room.togglePanelPin);
|
|
502
|
+
togglePanelPin('data-sources');
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
#### `addOrUpdateSqlQueryDataSource(tableName, query, oldTableName)`
|
|
506
|
+
|
|
507
|
+
Add or update a SQL query data source.
|
|
508
|
+
|
|
509
|
+
```tsx
|
|
510
|
+
const addOrUpdateSqlQueryDataSource = useRoomStore(
|
|
511
|
+
(state) => state.room.addOrUpdateSqlQueryDataSource,
|
|
512
|
+
);
|
|
513
|
+
await addOrUpdateSqlQueryDataSource(
|
|
514
|
+
'filtered_data',
|
|
515
|
+
'SELECT * FROM data WHERE value > 10',
|
|
516
|
+
);
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
#### `removeSqlQueryDataSource(tableName)`
|
|
520
|
+
|
|
521
|
+
Remove a SQL query data source.
|
|
522
|
+
|
|
523
|
+
```tsx
|
|
524
|
+
const removeSqlQueryDataSource = useRoomStore(
|
|
525
|
+
(state) => state.room.removeSqlQueryDataSource,
|
|
526
|
+
);
|
|
527
|
+
await removeSqlQueryDataSource('filtered_data');
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
#### `addRoomFile(info, desiredTableName)`
|
|
531
|
+
|
|
532
|
+
Add a room file.
|
|
533
|
+
|
|
534
|
+
```tsx
|
|
535
|
+
const addRoomFile = useRoomStore((state) => state.room.addRoomFile);
|
|
536
|
+
const dataTable = await addRoomFile(file, 'my_data');
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
#### `removeRoomFile(pathname)`
|
|
540
|
+
|
|
541
|
+
Remove a room file.
|
|
542
|
+
|
|
543
|
+
```tsx
|
|
544
|
+
const removeRoomFile = useRoomStore((state) => state.room.removeRoomFile);
|
|
545
|
+
removeRoomFile('/path/to/file.csv');
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
#### `maybeDownloadDataSources()`
|
|
549
|
+
|
|
550
|
+
Download data sources if needed.
|
|
551
|
+
|
|
552
|
+
```tsx
|
|
553
|
+
const maybeDownloadDataSources = useRoomStore(
|
|
554
|
+
(state) => state.room.maybeDownloadDataSources,
|
|
555
|
+
);
|
|
556
|
+
await maybeDownloadDataSources();
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
#### `setRoomFiles(info)`
|
|
560
|
+
|
|
561
|
+
Set the room files.
|
|
562
|
+
|
|
563
|
+
```tsx
|
|
564
|
+
const setRoomFiles = useRoomStore((state) => state.room.setRoomFiles);
|
|
565
|
+
setRoomFiles(fileInfoArray);
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
#### `setRoomFileProgress(pathname, fileState)`
|
|
569
|
+
|
|
570
|
+
Set the progress of a room file.
|
|
571
|
+
|
|
572
|
+
```tsx
|
|
573
|
+
const setRoomFileProgress = useRoomStore(
|
|
574
|
+
(state) => state.room.setRoomFileProgress,
|
|
575
|
+
);
|
|
576
|
+
setRoomFileProgress('/path/to/file.csv', {status: 'processing'});
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
#### `addTable(tableName, data)`
|
|
580
|
+
|
|
581
|
+
Add a table to the room.
|
|
582
|
+
|
|
583
|
+
```tsx
|
|
584
|
+
const addTable = useRoomStore((state) => state.room.addTable);
|
|
585
|
+
await addTable('my_table', records);
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
#### `addDataSource(dataSource, status)`
|
|
589
|
+
|
|
590
|
+
Add a data source to the room.
|
|
591
|
+
|
|
592
|
+
```tsx
|
|
593
|
+
const addDataSource = useRoomStore((state) => state.room.addDataSource);
|
|
594
|
+
await addDataSource({
|
|
595
|
+
type: 'url',
|
|
596
|
+
url: 'https://example.com/data.csv',
|
|
597
|
+
tableName: 'external_data',
|
|
598
|
+
});
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
#### `getTable(tableName)`
|
|
602
|
+
|
|
603
|
+
Get a table by name.
|
|
604
|
+
|
|
605
|
+
```tsx
|
|
606
|
+
const getTable = useRoomStore((state) => state.room.getTable);
|
|
607
|
+
const table = getTable('my_table');
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
#### `setTables(dataTable)`
|
|
611
|
+
|
|
612
|
+
Set the room tables.
|
|
613
|
+
|
|
614
|
+
```tsx
|
|
615
|
+
const setTables = useRoomStore((state) => state.room.setTables);
|
|
616
|
+
await setTables(tableArray);
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
#### `setTableRowCount(tableName, rowCount)`
|
|
620
|
+
|
|
621
|
+
Set the row count for a table.
|
|
622
|
+
|
|
623
|
+
```tsx
|
|
624
|
+
const setTableRowCount = useRoomStore((state) => state.room.setTableRowCount);
|
|
625
|
+
setTableRowCount('my_table', 1000);
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
#### `setRoomTitle(title)`
|
|
629
|
+
|
|
630
|
+
Set the room title.
|
|
631
|
+
|
|
632
|
+
```tsx
|
|
633
|
+
const setRoomTitle = useRoomStore((state) => state.room.setRoomTitle);
|
|
634
|
+
setRoomTitle('My Awesome Room');
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
#### `setDescription(description)`
|
|
638
|
+
|
|
639
|
+
Set the room description.
|
|
640
|
+
|
|
641
|
+
```tsx
|
|
642
|
+
const setDescription = useRoomStore((state) => state.room.setDescription);
|
|
643
|
+
setDescription('This is a description of my room');
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
#### `areDatasetsReady()`
|
|
647
|
+
|
|
648
|
+
Check if all datasets are ready.
|
|
649
|
+
|
|
650
|
+
```tsx
|
|
651
|
+
const areDatasetsReady = useRoomStore((state) => state.room.areDatasetsReady);
|
|
652
|
+
if (areDatasetsReady()) {
|
|
653
|
+
// Proceed with data operations
|
|
654
|
+
}
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
#### `findTableByName(tableName)`
|
|
658
|
+
|
|
659
|
+
Find a table by name.
|
|
660
|
+
|
|
661
|
+
```tsx
|
|
662
|
+
const findTableByName = useRoomStore((state) => state.room.findTableByName);
|
|
663
|
+
const table = findTableByName('my_table');
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
#### `updateReadyDataSources()`
|
|
667
|
+
|
|
668
|
+
Update the status of all data sources based on the current tables.
|
|
669
|
+
|
|
670
|
+
```tsx
|
|
671
|
+
const updateReadyDataSources = useRoomStore(
|
|
672
|
+
(state) => state.room.updateReadyDataSources,
|
|
673
|
+
);
|
|
674
|
+
await updateReadyDataSources();
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
#### `onDataUpdated()`
|
|
678
|
+
|
|
679
|
+
Called when data has been updated.
|
|
680
|
+
|
|
681
|
+
```tsx
|
|
682
|
+
const onDataUpdated = useRoomStore((state) => state.room.onDataUpdated);
|
|
683
|
+
await onDataUpdated();
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
#### `areViewsReadyToRender()`
|
|
687
|
+
|
|
688
|
+
Check if views are ready to render.
|
|
689
|
+
|
|
690
|
+
```tsx
|
|
691
|
+
const areViewsReadyToRender = useRoomStore(
|
|
692
|
+
(state) => state.room.areViewsReadyToRender,
|
|
693
|
+
);
|
|
694
|
+
if (areViewsReadyToRender()) {
|
|
695
|
+
// Render views
|
|
696
|
+
}
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
#### `refreshTableSchemas()`
|
|
700
|
+
|
|
701
|
+
Refresh table schemas from the database.
|
|
702
|
+
|
|
703
|
+
```tsx
|
|
704
|
+
const refreshTableSchemas = useRoomStore(
|
|
705
|
+
(state) => state.room.refreshTableSchemas,
|
|
706
|
+
);
|
|
707
|
+
const updatedTables = await refreshTableSchemas();
|
|
708
|
+
```
|
|
709
|
+
|
|
710
|
+
## Advanced Features
|
|
711
|
+
|
|
712
|
+
- **Custom State Slices**: Extend the room state with custom slices
|
|
713
|
+
- **Task Management**: Built-in task progress tracking
|
|
714
|
+
- **Panel Configuration**: Configure and arrange panels dynamically
|
|
715
|
+
- **Data Source Integration**: Connect to various data sources
|
|
716
|
+
- **File Processing**: Process and transform data files
|
|
717
|
+
|
|
718
|
+
For more information, visit the SQLRooms documentation.
|
|
719
|
+
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
```
|