diff --git a/src/store/flow/flow.ts b/src/store/flow/flow.ts index 7e50e38c6..3d70a85a9 100644 --- a/src/store/flow/flow.ts +++ b/src/store/flow/flow.ts @@ -34,7 +34,7 @@ export const getters: GetterTree = { } } }, - blockUuidsOnActiveFlow: (state, getters): IBlock['uuid'][] => getters.activeFlow?.blocks, + blocksOnActiveFlow: (state, getters): IBlock[] => getters.activeFlow?.blocks, isActiveFlowValid: (state, getters, rootState) => { const flowValidationResult = get(rootState.validation.validationStatuses, `flow/${getters.activeFlow.uuid}`) if (flowValidationResult && !flowValidationResult.isValid) { diff --git a/src/store/flow/resource.ts b/src/store/flow/resource.ts index ab66a64f0..192365435 100644 --- a/src/store/flow/resource.ts +++ b/src/store/flow/resource.ts @@ -32,6 +32,8 @@ export const getters: GetterTree = { resourcesByUuidOnActiveFlow: (_state, getters) => keyBy(getters.activeFlow.resources, 'uuid'), resourceUuidsOnActiveFlow: (_state, getters) => compact(map(getters.activeFlow.resources, (res) => res.uuid)), + + resourcesOnActiveFlow: (_state, getters) => getters.activeFlow.resources, } export const mutations: MutationTree = { diff --git a/src/store/validation/index.ts b/src/store/validation/index.ts index c827724ed..0d1afadb7 100644 --- a/src/store/validation/index.ts +++ b/src/store/validation/index.ts @@ -1,5 +1,5 @@ import Vue from 'vue' -import {ActionTree, GetterTree, Module, MutationTree} from 'vuex' +import {ActionTree, GetterTree, Module, MutationTree, Store} from 'vuex' import {IRootState} from '@/store' import {ErrorObject} from 'ajv' import { @@ -7,13 +7,11 @@ import { IContainer, IFlow, ILanguage, - getFlowStructureErrors, IResource, SupportedContentType, SupportedMode, - } from '@floip/flow-runner' -import {cloneDeep, each, filter, get, forIn, includes, intersection, isEmpty, map, uniqBy} from 'lodash' +import {cloneDeep, each, filter, get, forIn, includes, intersection, isEmpty, map, uniqBy, debounce} from 'lodash' import { debugValidationStatus, flatValidationStatuses, @@ -298,6 +296,50 @@ export const actions: ActionTree = { }, } +export function registerWatchers(store: Store): void { + const DEBOUNCE_VALIDATION_TIMER_MS = 300 + + store.watch( + (_, getters) => getters['flow/activeFlow'], + newFlow => debounce( + async () => { + console.debug('watch/activeFlow:', 'active flow has changed', 'Validating ...') + await store.dispatch('validate_flow', {flow: newFlow}) + }, + DEBOUNCE_VALIDATION_TIMER_MS, + ), + {deep: true, immediate: true}, + ) + + store.watch( + (_, getters) => getters['flow/blocksOnActiveFlow'], + () => debounce( + async () => { + console.debug('watch/activeFlow.blocks:', 'blocks inside active flow have changed', 'Validating ...') + await store.dispatch('validate_allBlocksWithinFlow') + }, + DEBOUNCE_VALIDATION_TIMER_MS, + ), + {deep: true, immediate: true}, + ) + + store.watch( + (_, getters) => getters['flow/resourcesOnActiveFlow'], + newResources => debounce( + async () => { + console.debug('watch/activeFlow.resources:', 'resources inside active flow have changed', 'Validating ...') + await store.dispatch('validate_resourcesOnSupportedValues', { + resources: newResources, + supportedModes: this.activeFlow.supported_modes, + supportedLanguages: this.activeFlow.languages, + }) + }, + DEBOUNCE_VALIDATION_TIMER_MS, + ), + {deep: true, immediate: true}, + ) +} + export const store: Module = { namespaced: true, state: stateFactory, diff --git a/src/views/InteractionDesigner.vue b/src/views/InteractionDesigner.vue index 9dd156f5b..2c81c4093 100644 --- a/src/views/InteractionDesigner.vue +++ b/src/views/InteractionDesigner.vue @@ -48,20 +48,20 @@