Skip to content

Commit

Permalink
resolves #855 calcule bibPreview au niveau de GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Jun 28, 2023
1 parent d0b2b6c commit 828e4b8
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions front/src/components/Article.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export default function Article ({ article, onArticleUpdated, onArticleDeleted,

const isArticleOwner = activeUser._id === article.owner._id

console.log({article})

useEffect(() => {
if (contributorsError) {
setToast({
Expand Down
1 change: 1 addition & 0 deletions front/src/components/Export.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ Export.propTypes = {
articleVersionId: PropTypes.string,
articleId: PropTypes.string,
name: PropTypes.string.isRequired,
bib: PropTypes.string,
}
9 changes: 9 additions & 0 deletions front/src/styles/general.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,12 @@
list-style: none;
}
}

/* clears the ‘X’ from Internet Explorer */
input[type=search]::-ms-clear { display: none; width : 0; height: 0; }
input[type=search]::-ms-reveal { display: none; width : 0; height: 0; }
/* clears the ‘X’ from Chrome */
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration { display: none; }
5 changes: 0 additions & 5 deletions graphql/models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const mongoose = require('mongoose')
const Schema = mongoose.Schema

const { computeMajorVersion, computeMinorVersion } = require('../helpers/versions.js')
const { previewEntries } = require('../helpers/bibliography.js')
const { prefixRulesWith, sanitizeTemplate } = require('../helpers/preview.js')

const ArticleContributorSchema = new Schema({
Expand Down Expand Up @@ -68,10 +67,6 @@ const articleSchema = new Schema({
}
}, { timestamps: true })

articleSchema.virtual('workingVersion.bibPreview').get(function () {
return previewEntries(this.workingVersion.bib)
})


/**
* Returns a single article for a given user
Expand Down
5 changes: 0 additions & 5 deletions graphql/models/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const { deriveToc } = require('../helpers/markdown.js')
const { previewEntries } = require('../helpers/bibliography.js')

const versionSchema = new Schema({
owner:{
Expand Down Expand Up @@ -43,9 +42,5 @@ const versionSchema = new Schema({
},
}, {timestamps:true});

versionSchema.virtual('bibPreview').get(function () {
return previewEntries(this.bib)
})

module.exports = mongoose.model('Version', versionSchema);
module.exports.schema = versionSchema
5 changes: 4 additions & 1 deletion graphql/resolvers/articleResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const isUser = require('../policies/isUser')
const { ApiError } = require('../helpers/errors')
const { reformat } = require('../helpers/metadata.js')
const { computeMajorVersion, computeMinorVersion } = require('../helpers/versions')
const { previewEntries } = require('../helpers/bibliography')


async function getUser (userId) {
Expand Down Expand Up @@ -248,7 +249,6 @@ module.exports = {
async versions (article, _args, context) {
const versions = await Promise.all(article.versions.map(async (versionId) => await context.loaders.versions.load(versionId)))
versions.sort((a, b) => b.createdAt - a.createdAt)
console.log('Article.versions', {versions})
return versions
},

Expand Down Expand Up @@ -337,6 +337,9 @@ module.exports = {
},

WorkingVersion: {
bibPreview({ bib }) {
return previewEntries(bib)
},
yaml ({ yaml }, { options }) {
return options?.strip_markdown
? reformat(yaml, { replaceBibliography: false })
Expand Down
5 changes: 5 additions & 0 deletions graphql/resolvers/versionResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const mongoose = require('mongoose')

const { ApiError } = require('../helpers/errors')
const { reformat } = require('../helpers/metadata.js')
const { previewEntries } = require('../helpers/bibliography')

module.exports = {
Query: {
Expand Down Expand Up @@ -34,6 +35,10 @@ module.exports = {
return result === version
},

bibPreview({ bib }) {
return previewEntries(bib)
},

yaml ({ yaml }, { options }) {
return options?.strip_markdown
? reformat(yaml, { replaceBibliography: false })
Expand Down

0 comments on commit 828e4b8

Please sign in to comment.