Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/actions/Model/getDocument.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const Archetype = require('archetype');
const getRefFromSchemaType = require('../../helpers/getRefFromSchemaType');
const removeSpecifiedPaths = require('../../helpers/removeSpecifiedPaths');
const authorize = require('../../authorize');

Expand Down Expand Up @@ -37,7 +38,7 @@ module.exports = ({ db }) => async function getDocument(params) {
schemaPaths[path] = {
instance: Model.schema.paths[path].instance,
path,
ref: Model.schema.paths[path].options?.ref,
ref: getRefFromSchemaType(Model.schema.paths[path]),
required: Model.schema.paths[path].options?.required,
enum: Model.schema.paths[path].options?.enum
};
Expand Down
5 changes: 3 additions & 2 deletions backend/actions/Model/getDocuments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Archetype = require('archetype');
const removeSpecifiedPaths = require('../../helpers/removeSpecifiedPaths');
const evaluateFilter = require('../../helpers/evaluateFilter');
const getRefFromSchemaType = require('../../helpers/getRefFromSchemaType');
const authorize = require('../../authorize');

const GetDocumentsParams = new Archetype({
Expand Down Expand Up @@ -77,7 +78,7 @@ module.exports = ({ db }) => async function getDocuments(params) {
schemaPaths[path] = {
instance: schemaType.instance,
path,
ref: schemaType.options?.ref,
ref: getRefFromSchemaType(schemaType),
required: schemaType.options?.required,
enum: schemaType.options?.enum
};
Expand All @@ -87,7 +88,7 @@ module.exports = ({ db }) => async function getDocuments(params) {
schemaPaths[path].schema[subpath] = {
instance: schemaType.schema.paths[subpath].instance,
path: subpath,
ref: schemaType.schema.paths[subpath].options?.ref,
ref: getRefFromSchemaType(schemaType.schema.paths[subpath]),
required: schemaType.schema.paths[subpath].options?.required,
enum: schemaType.schema.paths[subpath].options?.enum
};
Expand Down
5 changes: 3 additions & 2 deletions backend/actions/Model/getDocumentsStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Archetype = require('archetype');
const removeSpecifiedPaths = require('../../helpers/removeSpecifiedPaths');
const evaluateFilter = require('../../helpers/evaluateFilter');
const getRefFromSchemaType = require('../../helpers/getRefFromSchemaType');
const authorize = require('../../authorize');

const GetDocumentsParams = new Archetype({
Expand Down Expand Up @@ -67,7 +68,7 @@ module.exports = ({ db }) => async function* getDocumentsStream(params) {
schemaPaths[path] = {
instance: schemaType.instance,
path,
ref: schemaType.options?.ref,
ref: getRefFromSchemaType(schemaType),
required: schemaType.options?.required,
enum: schemaType.options?.enum
};
Expand All @@ -77,7 +78,7 @@ module.exports = ({ db }) => async function* getDocumentsStream(params) {
schemaPaths[path].schema[subpath] = {
instance: schemaType.schema.paths[subpath].instance,
path: subpath,
ref: schemaType.schema.paths[subpath].options?.ref,
ref: getRefFromSchemaType(schemaType.schema.paths[subpath]),
required: schemaType.schema.paths[subpath].options?.required,
enum: schemaType.schema.paths[subpath].options?.enum
};
Expand Down
5 changes: 5 additions & 0 deletions backend/helpers/getRefFromSchemaType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = function getRefFromSchemaType(schemaType) {
return schemaType?.options?.ref ?? schemaType?.embeddedSchemaType?.options?.ref ?? schemaType?.caster?.options?.ref;
};
2 changes: 1 addition & 1 deletion frontend/src/list-json/json-node.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<a
href="#"
class="ml-1 text-sm text-sky-700 opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity"
@click.stop.prevent="goToReference(value)"
@click.stop.prevent="goToReference()"
>
View Document
</a>
Expand Down
31 changes: 28 additions & 3 deletions frontend/src/list-json/list-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,31 @@ module.exports = app => app.component('list-json', {
return this.references[this.normalizedPath] || null;
},
shouldShowReferenceLink() {
return Boolean(this.referenceModel) && typeof this.value === 'string';
return this.referenceId != null;
},
referenceId() {
if (!this.referenceModel) {
return null;
}
if (this.value == null) {
return null;
}
const type = typeof this.value;
if (type === 'string' || type === 'number' || type === 'bigint') {
return String(this.value);
}
if (type === 'object') {
if (this.value._id != null) {
return String(this.value._id);
}
if (typeof this.value.toString === 'function') {
const stringified = this.value.toString();
if (typeof stringified === 'string' && stringified !== '[object Object]') {
return stringified;
}
}
}
return null;
}
},
methods: {
Expand All @@ -303,8 +327,9 @@ module.exports = app => app.component('list-json', {
this.expandTopLevel();
}
},
goToReference(id) {
if (!this.referenceModel) {
goToReference() {
const id = this.referenceId;
if (!this.referenceModel || id == null) {
return;
}
this.$router.push({ path: `/model/${this.referenceModel}/document/${id}` });
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/models/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module.exports = app => app.component('models', {
this.error = 'No models found and Mongoose is not connected. Check our documentation for more information.';
}
}

await this.initSearchFromUrl();
},
computed: {
Expand Down