fix: access namespace only if loaded
This commit is contained in:
parent
1964c1352c
commit
e064c3bf96
2 changed files with 19 additions and 20 deletions
|
@ -90,12 +90,7 @@ export default {
|
|||
return null
|
||||
},
|
||||
getNamespaceById: state => namespaceId => {
|
||||
for (const n in state.namespaces) {
|
||||
if (state.namespaces[n].id === namespaceId) {
|
||||
return state.namespaces[n]
|
||||
}
|
||||
}
|
||||
return null
|
||||
return state.namespaces.find(({id}) => id == namespaceId) || null
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
|
|
|
@ -13,26 +13,30 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import NamespaceService from '@/services/namespace'
|
||||
|
||||
export default {
|
||||
name: 'namespace-setting-delete',
|
||||
data() {
|
||||
return {
|
||||
namespaceService: new NamespaceService(),
|
||||
title: '',
|
||||
}
|
||||
computed: {
|
||||
namespace() {
|
||||
return this.$store.getters['namespaces/getNamespaceById'](this.$route.params.id)
|
||||
},
|
||||
title() {
|
||||
if (!this.namespace) {
|
||||
return
|
||||
}
|
||||
return this.$t('namespace.delete.title', {namespace: this.namespace.title})
|
||||
},
|
||||
},
|
||||
created() {
|
||||
const namespace = this.$store.getters['namespaces/getNamespaceById'](this.$route.params.id)
|
||||
this.title = this.$t('namespace.delete.title', {namespace: namespace.title})
|
||||
this.setTitle(this.title)
|
||||
watch: {
|
||||
title: {
|
||||
handler(title) {
|
||||
this.setTitle(title)
|
||||
},
|
||||
immediate: true,
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
deleteNamespace() {
|
||||
const namespace = this.$store.getters['namespaces/getNamespaceById'](this.$route.params.id)
|
||||
|
||||
this.$store.dispatch('namespaces/deleteNamespace', namespace)
|
||||
this.$store.dispatch('namespaces/deleteNamespace', this.namespace)
|
||||
.then(() => {
|
||||
this.$message.success({message: this.$t('namespace.delete.success')})
|
||||
this.$router.push({name: 'home'})
|
||||
|
|
Loading…
Reference in a new issue