Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/refactor store modules #11062

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions shell/pages/diagnostic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export default {
'digitalocean',
'linode',
'targetRoute', // contains circular references, isn't useful (added later to store)
'$router', // also contains a circular reference to $store, not useful for diagnostics
];

const clearListsKeys = [
Expand Down
6 changes: 4 additions & 2 deletions shell/store/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ export const actions = {
}
},

async logout({ dispatch, commit, getters }, options = {}) {
async logout({
dispatch, commit, getters, rootState
}, options = {}) {
// So, we only do this check if auth has been initialized.
//
// It's possible to be logged in and visit auth/logout directly instead
Expand All @@ -362,7 +364,7 @@ export const actions = {
}

// Unload plugins - we will load again on login
await this.$plugin.logout();
await rootState.$plugin.logout();

try {
await dispatch('rancher/request', {
Expand Down
31 changes: 19 additions & 12 deletions shell/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ export const state = () => {
isRancherInHarvester: false,
targetRoute: null,
rootProduct: undefined,
$router: undefined,
$route: undefined,
$plugin: undefined,
};
};

Expand Down Expand Up @@ -722,6 +725,18 @@ export const mutations = {

targetRoute(state, route) {
state.targetRoute = route;
},

setRouter(state, router) {
state.$router = router;
},

setRoute(state, route) {
state.$route = route;
},

setPlugin(state, pluginDefinition) {
state.$plugin = pluginDefinition;
}
};

Expand Down Expand Up @@ -1128,18 +1143,10 @@ export const actions = {
}
},

nuxtServerInit({ dispatch, rootState }, nuxt) {
// Models in SSR server mode have no way to get to the route or router, so hack one in...
Object.defineProperty(rootState, '$router', { value: nuxt.app.router });
Object.defineProperty(rootState, '$route', { value: nuxt.route });
dispatch('prefs/loadCookies');
},

nuxtClientInit({ dispatch, rootState }, nuxt) {
Object.defineProperty(rootState, '$router', { value: nuxt.app.router });
Object.defineProperty(rootState, '$route', { value: nuxt.route });
Object.defineProperty(rootState, '$plugin', { value: nuxt.app.$plugin });
Object.defineProperty(this, '$plugin', { value: nuxt.app.$plugin });
nuxtClientInit({ dispatch, commit, rootState }, nuxt) {
commit('setRouter', nuxt.app.router);
commit('setRoute', nuxt.route);
commit('setPlugin', nuxt.app.$plugin);

dispatch('management/rehydrateSubscribe');
dispatch('cluster/rehydrateSubscribe');
Expand Down
Loading