Skip to content

Commit 2e1c282

Browse files
author
Charles Queiroz
authored
UI: Add central project store and watch functionality (#7900)
Added a new getter 'allProjects' and mutation 'RELOAD_ALL_PROJECTS' to centralize the tracking of available projects in the state. This eliminates direct manipulation of the Project list in separate components and improves data consistency across the application. A watcher in ProjectMenu.vue has been implemented to handle changes to the 'allProjects' getter. The 'RELOAD_ALL_PROJECTS' mutation was also added where necessary to ensure projects list is updated in the state whenever changes occur.
1 parent b37834f commit 2e1c282

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

ui/src/components/header/ProjectMenu.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ export default {
102102
getNextPage()
103103
}
104104
}).finally(() => {
105-
this.projects = _.orderBy(projects, ['displaytext'], ['asc'])
106-
this.projects.unshift({ name: this.$t('label.default.view') })
107105
this.loading = false
106+
this.$store.commit('RELOAD_ALL_PROJECTS', projects)
108107
})
109108
}
110109
getNextPage()
@@ -125,6 +124,17 @@ export default {
125124
filterProject (input, option) {
126125
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
127126
}
127+
},
128+
mounted () {
129+
this.$store.watch(
130+
(state, getters) => getters.allProjects,
131+
(newValue, oldValue) => {
132+
if (oldValue !== newValue && newValue !== undefined) {
133+
this.projects = _.orderBy(newValue, ['displaytext'], ['asc'])
134+
this.projects.unshift({ name: this.$t('label.default.view') })
135+
}
136+
}
137+
)
128138
}
129139
}
130140
</script>

ui/src/store/getters.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ const getters = {
4747
twoFaEnabled: state => state.user.twoFaEnabled,
4848
twoFaProvider: state => state.user.twoFaProvider,
4949
twoFaIssuer: state => state.user.twoFaIssuer,
50-
loginFlag: state => state.user.loginFlag
50+
loginFlag: state => state.user.loginFlag,
51+
allProjects: (state) => state.app.allProjects
5152
}
5253

5354
export default getters

ui/src/store/modules/app.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import {
3030
USE_BROWSER_TIMEZONE,
3131
SERVER_MANAGER,
3232
VUE_VERSION,
33-
CUSTOM_COLUMNS
33+
CUSTOM_COLUMNS,
34+
RELOAD_ALL_PROJECTS
3435
} from '@/store/mutation-types'
3536

3637
const app = {
@@ -50,7 +51,8 @@ const app = {
5051
metrics: false,
5152
listAllProjects: false,
5253
server: '',
53-
vueVersion: ''
54+
vueVersion: '',
55+
allProjects: []
5456
},
5557
mutations: {
5658
SET_SIDEBAR_TYPE: (state, type) => {
@@ -121,6 +123,10 @@ const app = {
121123
SET_CUSTOM_COLUMNS: (state, customColumns) => {
122124
vueProps.$localStorage.set(CUSTOM_COLUMNS, customColumns)
123125
state.customColumns = customColumns
126+
},
127+
RELOAD_ALL_PROJECTS: (state, allProjects = []) => {
128+
vueProps.$localStorage.set(RELOAD_ALL_PROJECTS, allProjects)
129+
state.allProjects = allProjects
124130
}
125131
},
126132
actions: {
@@ -177,6 +183,9 @@ const app = {
177183
},
178184
SetCustomColumns ({ commit }, bool) {
179185
commit('SET_CUSTOM_COLUMNS', bool)
186+
},
187+
ReloadAllProjects ({ commit, allProjects }) {
188+
commit('RELOAD_ALL_PROJECTS', allProjects)
180189
}
181190
}
182191
}

ui/src/views/AutogenView.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,10 @@ export default {
693693
}
694694
api('listProjects', { id: projectId, listall: true, details: 'min' }).then(json => {
695695
if (!json || !json.listprojectsresponse || !json.listprojectsresponse.project) return
696+
const projects = json.listprojectsresponse.project
696697
const project = json.listprojectsresponse.project[0]
697698
this.$store.dispatch('SetProject', project)
699+
this.$store.commit('RELOAD_ALL_PROJECTS', projects)
698700
this.$store.dispatch('ToggleTheme', project.id === undefined ? 'light' : 'dark')
699701
this.$message.success(`${this.$t('message.switch.to')} "${project.name}"`)
700702
const query = Object.assign({}, this.$route.query)
@@ -937,6 +939,7 @@ export default {
937939
}
938940
939941
if (this.apiName === 'listProjects' && this.items.length > 0) {
942+
this.$store.commit('RELOAD_ALL_PROJECTS', this.items)
940943
this.columns.map(col => {
941944
if (col.title === 'Account') {
942945
col.title = this.$t('label.project.owner')
@@ -1808,7 +1811,6 @@ export default {
18081811
this.rules[field.name].push(rule)
18091812
break
18101813
default:
1811-
console.log('hererere')
18121814
rule.required = field.required
18131815
rule.message = this.$t('message.error.required.input')
18141816
this.rules[field.name].push(rule)

0 commit comments

Comments
 (0)