diff --git a/client/store/index.js b/client/store/index.js index 4db8b3b07c46ce608a97726b04a422187122da87..bc36da1ca1f0ef7b8905314a05bce736fbfeaa47 100644 --- a/client/store/index.js +++ b/client/store/index.js @@ -2,6 +2,8 @@ // across components. // https://v2.nuxt.com/docs/directory-structure/store +const _ = require('lodash'); + export const state = () => ({ initTables: {} }) @@ -38,24 +40,23 @@ export const mutations = { export const actions = { async fetchTables({ commit }) { - const initTables = {} + const initTables = [] return await this.$axios.$get('/tables') - .then((initTablesList) => { - const initMetaRequests = initTablesList.map(initTableName => { + .then((initTableslist) => { + const initMetaRequests = initTableslist.map(initTableName => { return this.$axios .$post('/initmeta', { initTableName }) .then(initMeta => { - initTables[initTableName] = initMeta + initMeta.tableName = initTableName + initTables.push(initMeta) }) }) return Promise.all(initMetaRequests) }) .then(() => { - // Store the initTables all at once to avoid partial fetching - // if one of the previous requests fail. - commit('setInitTables', initTables) + commit('setInitTables', _.orderBy(initTables, 'name')) }) } }