@@ -7,13 +7,13 @@ import type { LDAPConfig } from '../models/index.ts'
77
88import { loadState } from '@nextcloud/initial-state'
99import { defineStore } from 'pinia'
10- import Vue , { computed , ref } from 'vue'
10+ import { computed , ref } from 'vue'
1111import { copyConfig , createConfig , deleteConfig , getConfig , updateConfig } from '../services/ldapConfigService.ts'
1212
1313export const useLDAPConfigsStore = defineStore ( 'ldap-configs' , ( ) => {
1414 const ldapConfigs = ref ( loadState ( 'user_ldap' , 'ldapConfigs' ) as Record < string , LDAPConfig > )
15- const selectedConfigId = ref < string > ( Object . keys ( ldapConfigs . value ) [ 0 ] )
16- const selectedConfig = computed ( ( ) => ldapConfigs . value [ selectedConfigId . value ] )
15+ const selectedConfigId = ref < string | undefined > ( Object . keys ( ldapConfigs . value ) [ 0 ] )
16+ const selectedConfig = computed ( ( ) => selectedConfigId . value === undefined ? undefined : ldapConfigs . value [ selectedConfigId . value ] )
1717 const updatingConfig = ref ( 0 )
1818
1919 /**
@@ -22,6 +22,10 @@ export const useLDAPConfigsStore = defineStore('ldap-configs', () => {
2222 * @param postSetHooks
2323 */
2424 function getConfigProxy < J > ( configId : string , postSetHooks : Partial < Record < keyof LDAPConfig , ( value : J ) => void > > = { } ) {
25+ if ( ldapConfigs . value [ configId ] === undefined ) {
26+ throw new Error ( `Config with id ${ configId } does not exist` )
27+ }
28+
2529 return new Proxy ( ldapConfigs . value [ configId ] , {
2630 get ( target , property ) {
2731 return target [ property ]
@@ -49,7 +53,7 @@ export const useLDAPConfigsStore = defineStore('ldap-configs', () => {
4953 */
5054 async function create ( ) {
5155 const configId = await createConfig ( )
52- Vue . set ( ldapConfigs . value , configId , await getConfig ( configId ) )
56+ ldapConfigs . value [ configId ] = await getConfig ( configId )
5357 selectedConfigId . value = configId
5458 return configId
5559 }
@@ -59,8 +63,13 @@ export const useLDAPConfigsStore = defineStore('ldap-configs', () => {
5963 * @param fromConfigId
6064 */
6165 async function _copyConfig ( fromConfigId : string ) {
66+ if ( ldapConfigs . value [ fromConfigId ] === undefined ) {
67+ throw new Error ( `Config with id ${ fromConfigId } does not exist` )
68+ }
69+
6270 const configId = await copyConfig ( fromConfigId )
63- Vue . set ( ldapConfigs . value , configId , { ...ldapConfigs . value [ fromConfigId ] } )
71+
72+ ldapConfigs . value [ configId ] = { ...ldapConfigs . value [ fromConfigId ] }
6473 selectedConfigId . value = configId
6574 return configId
6675 }
@@ -72,7 +81,7 @@ export const useLDAPConfigsStore = defineStore('ldap-configs', () => {
7281 async function removeConfig ( configId : string ) {
7382 const result = await deleteConfig ( configId )
7483 if ( result === true ) {
75- Vue . delete ( ldapConfigs . value , configId )
84+ delete ldapConfigs . value [ configId ]
7685 }
7786
7887 selectedConfigId . value = Object . keys ( ldapConfigs . value ) [ 0 ] ?? await create ( )
0 commit comments