diff --git a/components/nav/Group.vue b/components/nav/Group.vue index a4d3add11b..f7de5948f5 100644 --- a/components/nav/Group.vue +++ b/components/nav/Group.vue @@ -141,9 +141,18 @@ export default { if (this.isExpanded && !skipAutoClose) { const items = this.group[this.childrenKey]; - // Navigate to the first item in the group + // Navigate to one of the child items (by default the first child) if (items && items.length > 0) { - const route = items[0].route; + let index = 0; + + // If there is a default type, use it + if (this.group.defaultType) { + const found = items.findIndex(i => i.name === this.group.defaultType); + + index = (found === -1) ? 0 : found; + } + + const route = items[index].route; this.$router.replace(route); } diff --git a/config/product/explorer.js b/config/product/explorer.js index 93d97db908..d2c1dfe913 100644 --- a/config/product/explorer.js +++ b/config/product/explorer.js @@ -35,6 +35,7 @@ export function init(store) { virtualType, componentForType, configureType, + setGroupDefaultType, } = DSL(store, NAME); product({ @@ -134,6 +135,8 @@ export function init(store) { configureType(PVC, { isEditable: false }); configureType(MANAGEMENT.CLUSTER_ROLE_TEMPLATE_BINDING, { isEditable: false }); + setGroupDefaultType('serviceDiscovery', SERVICE); + configureType('workload', { displayName: 'Workload', location: { diff --git a/store/type-map.js b/store/type-map.js index df3e35ff63..79339fce8d 100644 --- a/store/type-map.js +++ b/store/type-map.js @@ -97,6 +97,10 @@ // groupOrArrayOfGroups, -- see weightType... // weight // ) +// setGroupDefaultType( Set the default child type to show when the group is expanded +// groupOrArrayOfGroups, -- see setGroupDefaultType... +// defaultType +// ) // mapGroup( Remap a group name to a display name // matchRegexOrString, -- see mapType... // replacementString, @@ -222,6 +226,14 @@ export function DSL(store, product, module = 'type-map') { } }, + setGroupDefaultType(input, defaultType) { + if ( isArray(input) ) { + store.commit(`${ module }/setGroupDefaultType`, { groups: input, defaultType }); + } else { + store.commit(`${ module }/setGroupDefaultType`, { group: input, defaultType }); + } + }, + weightType(input, weight, forBasic) { if ( isArray(input) ) { store.commit(`${ module }/weightType`, { @@ -291,6 +303,7 @@ export const state = function() { basicTypes: {}, groupIgnore: [], groupWeights: {}, + groupDefaultTypes: {}, basicGroupWeights: { [ROOT]: 1000 }, groupMappings: [], typeIgnore: [], @@ -446,6 +459,14 @@ export const getters = { }; }, + groupDefaultTypeFor(state) { + return (group) => { + group = group.toLowerCase(); + + return state.groupDefaultTypes[group]; + }; + }, + getTree(state, getters, rootState, rootGetters) { return (productId, mode, allTypes, clusterId, namespaceMode, namespaces, currentType, search) => { // modes: basic, used, all, favorite @@ -594,7 +615,8 @@ export const getters = { group = { name, label, - weight: getters.groupWeightFor(name, forBasic), + weight: getters.groupWeightFor(name, forBasic), + defaultType: getters.groupDefaultTypeFor(name), }; tree.children.push(group); @@ -1246,6 +1268,24 @@ export const mutations = { } }, + // setGroupDefaultType({group: 'core', defaultType: 'name'}); + // By default when a group is clicked, the first item is selected - this allows + // this behvaiour to be changed and a named child type can be chosen + // These operate on group names *after* mapping but *before* translation + setGroupDefaultType(state, { group, groups, defaultType }) { + if ( !groups ) { + groups = []; + } + + if ( group ) { + groups.push(group); + } + + for ( const g of groups ) { + state.groupDefaultTypes[g.toLowerCase()] = defaultType; + } + }, + // weightType('Cluster' 99); -- higher groups are shown first // These operate on *schema* type names, before mapping weightType(state, {