feat: new nav UI (wip)

This commit is contained in:
NGPixel
2020-02-02 16:26:44 -05:00
committed by Nicolas Giard
parent 53ceea74f1
commit 3ca72ccc1e
8 changed files with 404 additions and 180 deletions

View File

@@ -11,7 +11,7 @@ module.exports = {
},
NavigationQuery: {
async tree(obj, args, context, info) {
return WIKI.models.navigation.getTree()
return WIKI.models.navigation.getTree({ cache: false, locale: 'all' })
}
},
NavigationMutation: {

View File

@@ -15,7 +15,7 @@ extend type Mutation {
# -----------------------------------------------
type NavigationQuery {
tree: [NavigationItem]!
tree: [NavigationTree]!
}
# -----------------------------------------------
@@ -24,7 +24,7 @@ type NavigationQuery {
type NavigationMutation {
updateTree(
tree: [NavigationItemInput]!
tree: [NavigationTreeInput]!
): DefaultResponse @auth(requires: ["manage:navigation", "manage:system"])
}
@@ -32,6 +32,16 @@ type NavigationMutation {
# TYPES
# -----------------------------------------------
type NavigationTree {
locale: String!
items: [NavigationItem]!
}
input NavigationTreeInput {
locale: String!
items: [NavigationItemInput]!
}
type NavigationItem {
id: String!
kind: String!

View File

@@ -1,4 +1,5 @@
const Model = require('objection').Model
const _ = require('lodash')
/* global WIKI */
@@ -21,19 +22,29 @@ module.exports = class Navigation extends Model {
}
}
static async getTree({ cache = false } = {}) {
static async getTree({ cache = false, locale = 'en' } = {}) {
if (cache) {
const navTreeCached = await WIKI.cache.get('nav:sidebar')
const navTreeCached = await WIKI.cache.get(`nav:sidebar:${locale}`)
if (navTreeCached) {
return navTreeCached
}
}
const navTree = await WIKI.models.navigation.query().findOne('key', 'site')
if (navTree) {
if (cache) {
await WIKI.cache.set('nav:sidebar', navTree.config, 300)
// Check for pre-2.1 format
if (_.has(navTree.config[0], 'kind')) {
navTree.config = [{
locale: 'en',
items: navTree.config
}]
}
return navTree.config
for (const tree of navTree.config) {
if (cache) {
await WIKI.cache.set(`nav:sidebar:${tree.locale}`, tree.items, 300)
}
}
return locale === 'all' ? navTree.config : WIKI.cache.get(`nav:sidebar:${locale}`)
} else {
WIKI.logger.warn('Site Navigation is missing or corrupted.')
return []