feat(custom-fields) : autocomplete des noms + corrections formule de référence auto #3
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
import { ref, type Ref } from 'vue'
|
import { ref, type Ref } from 'vue'
|
||||||
import { useToast } from './useToast'
|
import { useToast } from './useToast'
|
||||||
|
import { useCustomFieldNameSuggestions } from './useCustomFieldNameSuggestions'
|
||||||
import { humanizeError } from '~/shared/utils/errorMessages'
|
import { humanizeError } from '~/shared/utils/errorMessages'
|
||||||
import {
|
import {
|
||||||
listModelTypes,
|
listModelTypes,
|
||||||
@@ -79,6 +80,7 @@ export function invalidateEntityTypeCache(category: ModelCategory) {
|
|||||||
export function useEntityTypes(config: EntityTypeConfig) {
|
export function useEntityTypes(config: EntityTypeConfig) {
|
||||||
const { category, label } = config
|
const { category, label } = config
|
||||||
const { showSuccess, showError } = useToast()
|
const { showSuccess, showError } = useToast()
|
||||||
|
const { invalidate: invalidateCustomFieldNames } = useCustomFieldNameSuggestions()
|
||||||
const state = getOrCreateState(category)
|
const state = getOrCreateState(category)
|
||||||
|
|
||||||
const normalizeItem = (item: ModelType): EntityType => ({
|
const normalizeItem = (item: ModelType): EntityType => ({
|
||||||
@@ -124,6 +126,7 @@ export function useEntityTypes(config: EntityTypeConfig) {
|
|||||||
})
|
})
|
||||||
const normalized = normalizeItem(data)
|
const normalized = normalizeItem(data)
|
||||||
state.types.value.push(normalized)
|
state.types.value.push(normalized)
|
||||||
|
invalidateCustomFieldNames()
|
||||||
showSuccess(`Type de ${label} "${data.name}" créé`)
|
showSuccess(`Type de ${label} "${data.name}" créé`)
|
||||||
return { success: true, data: normalized }
|
return { success: true, data: normalized }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -150,6 +153,7 @@ export function useEntityTypes(config: EntityTypeConfig) {
|
|||||||
const normalized = normalizeItem(data)
|
const normalized = normalizeItem(data)
|
||||||
const index = state.types.value.findIndex((t) => t.id === id)
|
const index = state.types.value.findIndex((t) => t.id === id)
|
||||||
if (index !== -1) state.types.value[index] = normalized
|
if (index !== -1) state.types.value[index] = normalized
|
||||||
|
invalidateCustomFieldNames()
|
||||||
showSuccess(`Type de ${label} "${data.name}" mis à jour`)
|
showSuccess(`Type de ${label} "${data.name}" mis à jour`)
|
||||||
return { success: true, data: normalized }
|
return { success: true, data: normalized }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { reactive, ref } from 'vue'
|
import { reactive, ref } from 'vue'
|
||||||
import { useApi } from '~/composables/useApi'
|
import { useApi } from '~/composables/useApi'
|
||||||
|
import { useCustomFieldNameSuggestions } from '~/composables/useCustomFieldNameSuggestions'
|
||||||
import { useToast } from '~/composables/useToast'
|
import { useToast } from '~/composables/useToast'
|
||||||
|
|
||||||
// --- Types ---
|
// --- Types ---
|
||||||
@@ -88,6 +89,7 @@ const parseOptions = (optionsText: string): string[] =>
|
|||||||
export function useMachineCustomFieldDefs(deps: Deps) {
|
export function useMachineCustomFieldDefs(deps: Deps) {
|
||||||
const { apiCall } = useApi()
|
const { apiCall } = useApi()
|
||||||
const { showSuccess, showError } = useToast()
|
const { showSuccess, showError } = useToast()
|
||||||
|
const { invalidate: invalidateCustomFieldNames } = useCustomFieldNameSuggestions()
|
||||||
|
|
||||||
// --- State ---
|
// --- State ---
|
||||||
|
|
||||||
@@ -294,6 +296,7 @@ export function useMachineCustomFieldDefs(deps: Deps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showSuccess('Champs personnalisés sauvegardés avec succès')
|
showSuccess('Champs personnalisés sauvegardés avec succès')
|
||||||
|
invalidateCustomFieldNames()
|
||||||
await deps.onSaved()
|
await deps.onSaved()
|
||||||
} catch {
|
} catch {
|
||||||
showError('Erreur inattendue lors de la sauvegarde des champs personnalisés')
|
showError('Erreur inattendue lors de la sauvegarde des champs personnalisés')
|
||||||
|
|||||||
Reference in New Issue
Block a user