@mongoosejs/studio 0.5.8 → 0.5.9

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.
@@ -195,7 +195,7 @@ app.component('app-component', {
195
195
  <div v-else-if="!hasAPIKey || user">
196
196
  <navbar :user="user" :roles="roles" />
197
197
  <div class="view">
198
- <router-view :key="$route.fullPath" :user="user" :roles="roles" :hasAPIKey="hasAPIKey" />
198
+ <router-view :key="$route.meta.preserveStateKey || $route.fullPath" :user="user" :roles="roles" :hasAPIKey="hasAPIKey" />
199
199
  </div>
200
200
  </div>
201
201
  </div>
@@ -146,6 +146,7 @@ module.exports = app => app.component('models', {
146
146
  currentModel: null,
147
147
  modelDocumentCounts: {},
148
148
  documents: [],
149
+ allSchemaPaths: null,
149
150
  schemaPaths: [],
150
151
  filteredPaths: [],
151
152
  selectedPaths: [],
@@ -263,8 +264,9 @@ module.exports = app => app.component('models', {
263
264
  this.query = Object.assign({}, this.$route.query);
264
265
  // Keep UI mode in sync with the URL on remounts.
265
266
  this.isProjectionMenuSelected = this.$route?.query?.[PROJECTION_MODE_QUERY_KEY] === '1';
266
- const { models, readyState } = await api.Model.listModels();
267
+ const { models, modelSchemaPaths, readyState } = await api.Model.listModels();
267
268
  this.models = models;
269
+ this.allSchemaPaths = modelSchemaPaths;
268
270
  await this.loadModelCounts();
269
271
  if (this.currentModel == null && this.models.length > 0) {
270
272
  this.currentModel = this.models[0];
@@ -275,6 +277,29 @@ module.exports = app => app.component('models', {
275
277
  if (readyState === 0) {
276
278
  this.error = 'No models found and Mongoose is not connected. Check our documentation for more information.';
277
279
  }
280
+ } else {
281
+ this._refreshSidebar = setInterval(async() => {
282
+ try {
283
+ const { models, modelSchemaPaths, readyState } = await api.Model.listModels();
284
+ this.models = models;
285
+ this.allSchemaPaths = modelSchemaPaths;
286
+ await this.loadModelCounts();
287
+ if (this.currentModel) {
288
+ const schemaPaths = this.allSchemaPaths?.[this.currentModel] ?? {};
289
+ this.schemaPaths = Object.keys(schemaPaths).sort((k1, k2) => {
290
+ if (k1 === '_id' && k2 !== '_id') {
291
+ return -1;
292
+ }
293
+ if (k1 !== '_id' && k2 === '_id') {
294
+ return 1;
295
+ }
296
+ return 0;
297
+ }).map(key => schemaPaths[key]);
298
+ }
299
+ } catch (e) {
300
+ console.error(e);
301
+ }
302
+ }, 20000);
278
303
  }
279
304
 
280
305
  await this.initSearchFromUrl();
@@ -285,25 +310,33 @@ module.exports = app => app.component('models', {
285
310
  this.$nextTick(() => {
286
311
  const focusIntent = takeModelsRemountFocusIntent();
287
312
  if (focusIntent === 'documentSearch') {
288
- const ds = this.$refs.documentSearch;
289
- if (ds && typeof ds.focusInput === 'function') {
290
- ds.focusInput();
291
- }
313
+ this.$refs.documentSearch?.focusInput();
292
314
  return;
293
315
  }
294
316
  if (focusIntent === 'projection' && this.isProjectionMenuSelected) {
295
- const projectionSearch = this.$refs.projectionSearch;
296
- if (projectionSearch && typeof projectionSearch.focusInput === 'function') {
297
- projectionSearch.focusInput();
298
- }
317
+ this.$refs.projectionSearch?.focusInput();
299
318
  }
300
319
  });
301
320
  },
321
+ unmounted() {
322
+ clearInterval(this._refreshSidebar);
323
+ },
302
324
  watch: {
303
325
  model(newModel) {
304
326
  if (newModel !== this.currentModel) {
305
327
  this.currentModel = newModel;
306
328
  if (this.currentModel != null) {
329
+ this.$refs.documentSearch?.focusInput();
330
+ const schemaPaths = this.allSchemaPaths?.[newModel] ?? {};
331
+ this.schemaPaths = Object.keys(schemaPaths).sort((k1, k2) => {
332
+ if (k1 === '_id' && k2 !== '_id') {
333
+ return -1;
334
+ }
335
+ if (k1 !== '_id' && k2 === '_id') {
336
+ return 1;
337
+ }
338
+ return 0;
339
+ }).map(key => schemaPaths[key]);
307
340
  this.initSearchFromUrl();
308
341
  }
309
342
  }
@@ -747,6 +780,8 @@ module.exports = app => app.component('models', {
747
780
  this.query.sortKey = sortKey;
748
781
  this.query.sortDirection = sortDirection;
749
782
  delete this.query.sort;
783
+ } else {
784
+ this.sortBy = {};
750
785
  }
751
786
  if (this.currentModel != null) {
752
787
  await this.getDocuments();
@@ -762,6 +797,8 @@ module.exports = app => app.component('models', {
762
797
  this.selectedPaths = [...this.filteredPaths];
763
798
  this.syncProjectionInputFromQueryOrPaths();
764
799
  }
800
+ } else {
801
+ this.selectedPaths = [];
765
802
  }
766
803
  this.status = 'loaded';
767
804
 
@@ -1043,7 +1080,6 @@ module.exports = app => app.component('models', {
1043
1080
 
1044
1081
  // Clear previous data
1045
1082
  this.documents = [];
1046
- this.schemaPaths = [];
1047
1083
  this.numDocuments = null;
1048
1084
  this.loadedAllDocs = false;
1049
1085
  this.lastSelectedIndex = null;
@@ -33,7 +33,8 @@ module.exports = {
33
33
  name: 'model',
34
34
  component: 'models',
35
35
  meta: {
36
- authorized: false
36
+ authorized: false,
37
+ preserveStateKey: 'model'
37
38
  }
38
39
  },
39
40
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongoosejs/studio",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "AI-Powered Data Workspace for MongoDB: Turn your MongoDB data into dashboards, maps, and interactive workflows - powered by your Mongoose models and AI.",
5
5
  "homepage": "https://mongoosestudio.app/",
6
6
  "repository": {