Use index.json to load workflow templates (#2803)

This commit is contained in:
bymyself
2025-03-02 13:37:15 -07:00
committed by GitHub
parent e6a583e11b
commit 8d515dc309
5 changed files with 34 additions and 15 deletions

View File

@@ -2,7 +2,6 @@ import { groupBy } from 'lodash'
import { defineStore } from 'pinia'
import { computed, ref, shallowRef } from 'vue'
import { CORE_TEMPLATES } from '@/constants/coreTemplates'
import { api } from '@/scripts/api'
import type {
TemplateGroup,
@@ -13,12 +12,12 @@ export const useWorkflowTemplatesStore = defineStore(
'workflowTemplates',
() => {
const customTemplates = shallowRef<{ [moduleName: string]: string[] }>({})
const coreTemplates = shallowRef<WorkflowTemplates[]>([])
const isLoaded = ref(false)
const defaultTemplate: WorkflowTemplates = CORE_TEMPLATES[0]
const groupedTemplates = computed<TemplateGroup[]>(() => {
const allTemplates = [
...CORE_TEMPLATES,
...coreTemplates.value,
...Object.entries(customTemplates.value).map(
([moduleName, templates]) => ({
moduleName,
@@ -44,6 +43,7 @@ export const useWorkflowTemplatesStore = defineStore(
try {
if (!isLoaded.value) {
customTemplates.value = await api.getWorkflowTemplates()
coreTemplates.value = await api.getCoreWorkflowTemplates()
isLoaded.value = true
}
} catch (error) {
@@ -53,7 +53,6 @@ export const useWorkflowTemplatesStore = defineStore(
return {
groupedTemplates,
defaultTemplate,
isLoaded,
loadWorkflowTemplates
}