Migrated admin and core modules to use nql-filter-expansions

refs https://github.com/TryGhost/Arch/issues/46

- Reused posts expansions from nql-filter-expansions module
This commit is contained in:
Naz 2023-07-24 21:28:41 +08:00 committed by naz
parent 9f979917e3
commit 8fa36916d7
5 changed files with 8 additions and 67 deletions

View File

@ -6,6 +6,7 @@ import UnpublishPostsModal from './modals/unpublish-posts';
import nql from '@tryghost/nql';
import {action} from '@ember/object';
import {capitalizeFirstLetter} from 'ghost-admin/helpers/capitalize-first-letter';
import {posts as postExpansions} from '@tryghost/nql-filter-expansions';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
@ -257,29 +258,7 @@ export default class PostsContextMenu extends Component {
const updatedModels = this.selectionList.availableModels;
const filter = this.selectionList.allFilter;
const filterNql = nql(filter, {
expansions: [
{
key: 'primary_tag',
replacement: 'tags.slug',
expansion: 'posts_tags.sort_order:0+tags.visibility:public'
}, {
key: 'primary_author',
replacement: 'authors.slug',
expansion: 'posts_authors.sort_order:0+authors.visibility:public'
}, {
key: 'authors',
replacement: 'authors.slug'
}, {
key: 'author',
replacement: 'authors.slug'
}, {
key: 'tag',
replacement: 'tags.slug'
}, {
key: 'tags',
replacement: 'tags.slug'
}
]
expansions: postExpansions
});
const remainingModels = this.selectionList.infinityModel.content.filter((model) => {

View File

@ -52,6 +52,7 @@
"@tryghost/members-csv": "0.0.0",
"@tryghost/mobiledoc-kit": "0.12.5-ghost.2",
"@tryghost/nql": "0.11.0",
"@tryghost/nql-filter-expansions": "0.0.0",
"@tryghost/nql-lang": "0.5.0",
"@tryghost/string": "0.2.4",
"@tryghost/timezone-data": "0.3.0",

View File

@ -7,6 +7,7 @@ const tpl = require('@tryghost/tpl');
const errors = require('@tryghost/errors');
const nql = require('@tryghost/nql');
const htmlToPlaintext = require('@tryghost/html-to-plaintext');
const {posts: postExpansions} = require('@tryghost/nql-filter-expansions');
const ghostBookshelf = require('./base');
const config = require('../../shared/config');
const settingsCache = require('../../shared/settings-cache');
@ -290,28 +291,6 @@ Post = ghostBookshelf.Model.extend({
filterExpansions: function filterExpansions() {
const postsMetaKeys = _.without(ghostBookshelf.model('PostsMeta').prototype.orderAttributes(), 'posts_meta.id', 'posts_meta.post_id');
const expansions = [{
key: 'primary_tag',
replacement: 'tags.slug',
expansion: 'posts_tags.sort_order:0+tags.visibility:public'
}, {
key: 'primary_author',
replacement: 'authors.slug',
expansion: 'posts_authors.sort_order:0+authors.visibility:public'
}, {
key: 'authors',
replacement: 'authors.slug'
}, {
key: 'author',
replacement: 'authors.slug'
}, {
key: 'tag',
replacement: 'tags.slug'
}, {
key: 'tags',
replacement: 'tags.slug'
}];
const postMetaKeyExpansions = postsMetaKeys.map((pmk) => {
return {
key: pmk.split('.')[1],
@ -319,7 +298,7 @@ Post = ghostBookshelf.Model.extend({
};
});
return expansions.concat(postMetaKeyExpansions);
return postExpansions.concat(postMetaKeyExpansions);
},
filterRelations: function filterRelations() {

View File

@ -3,26 +3,7 @@ const nql = require('@tryghost/nql');
const debug = require('@tryghost/debug')('services:url:generator');
const localUtils = require('../../../shared/url-utils');
// @TODO: merge with filter plugin
const EXPANSIONS = [{
key: 'author',
replacement: 'authors.slug'
}, {
key: 'tags',
replacement: 'tags.slug'
}, {
key: 'tag',
replacement: 'tags.slug'
}, {
key: 'authors',
replacement: 'authors.slug'
}, {
key: 'primary_tag',
replacement: 'primary_tag.slug'
}, {
key: 'primary_author',
replacement: 'primary_author.slug'
}];
const {posts: postExpansions} = require('@tryghost/nql-filter-expansions');
/**
* The UrlGenerator class is responsible to generate urls based on a router's conditions.
@ -57,7 +38,7 @@ class UrlGenerator {
if (filter) {
this.filter = filter;
this.nql = nql(this.filter, {
expansions: EXPANSIONS,
expansions: postExpansions,
transformer: nql.utils.mapKeyValues({
key: {
from: 'page',

View File

@ -135,6 +135,7 @@
"@tryghost/mw-vhost": "0.0.0",
"@tryghost/nodemailer": "0.3.35",
"@tryghost/nql": "0.11.0",
"@tryghost/nql-filter-expansions": "0.0.0",
"@tryghost/oembed-service": "0.0.0",
"@tryghost/package-json": "0.0.0",
"@tryghost/post-revisions": "0.0.0",