From 2b9569ff5154e8392a7c88fbac16bdb06e6d9385 Mon Sep 17 00:00:00 2001 From: balibabu Date: Mon, 13 Jul 2026 14:48:02 +0800 Subject: [PATCH] Feat: Added support for session graph and session essence templates. (#16851) ### Summary Feat: Added support for session graph and session essence templates. --- .../components/artifact-force-graph/index.tsx | 11 + web/src/hooks/use-chunk-request.ts | 2 +- .../use-compilation-template-group-request.ts | 11 +- .../database/compilation-template.ts | 1 + .../request/compilation-template.ts | 1 + web/src/lib/editor/plugins/toolbar-plugin.tsx | 1 + web/src/locales/en.ts | 12 +- web/src/locales/zh.ts | 12 +- .../pages/dataset/compilation/empty-state.tsx | 12 +- web/src/pages/dataset/compilation/index.tsx | 6 +- .../dataset/generate-button/constants.ts | 7 - .../components/add-field-modal.tsx | 12 +- .../components/blueprints-step.tsx | 50 +++- .../components/section-field-grid.tsx | 4 +- .../components/template-configuration.tsx | 10 +- .../components/template-sidebar.tsx | 8 +- .../components/tree-template-fields.tsx | 0 .../create-next/hooks/use-add-field-form.ts | 2 +- .../hooks/use-available-kind-options.ts | 2 +- .../create-next/hooks/use-builtin-template.ts | 2 +- .../use-compilation-template-group-form.ts | 0 .../use-compilation-template-group-submit.ts | 0 ...-create-next-compilation-template-group.ts | 17 +- .../hooks/use-field-array-handlers.ts | 2 +- .../hooks/use-template-add-button.ts | 2 +- .../hooks/use-template-kind-change.ts | 0 .../hooks/use-template-preview-sheets.ts | 2 +- .../hooks/use-template-section-data.ts | 2 +- .../create-next/index.tsx | 4 +- .../{edit-template => create-next}/schema.ts | 17 +- .../{edit-template => create-next}/utils.ts | 67 +++++- .../components/fields-section.tsx | 174 -------------- .../components/template-card.tsx | 213 ------------------ .../use-compilation-template-group-data.ts | 49 ---- .../use-edit-compilation-template-group.ts | 51 ----- .../hooks/use-field-type-change.ts | 66 ------ .../edit-template/index.tsx | 183 --------------- .../compilation-templates/template-card.tsx | 7 +- web/src/routes.tsx | 7 - web/src/utils/compilation-template-util.ts | 10 + 40 files changed, 212 insertions(+), 827 deletions(-) rename web/src/pages/user-setting/compilation-templates/{edit-template => create-next}/components/tree-template-fields.tsx (100%) rename web/src/pages/user-setting/compilation-templates/{edit-template => create-next}/hooks/use-compilation-template-group-form.ts (100%) rename web/src/pages/user-setting/compilation-templates/{edit-template => create-next}/hooks/use-compilation-template-group-submit.ts (100%) rename web/src/pages/user-setting/compilation-templates/{edit-template => create-next}/hooks/use-template-kind-change.ts (100%) rename web/src/pages/user-setting/compilation-templates/{edit-template => create-next}/schema.ts (77%) rename web/src/pages/user-setting/compilation-templates/{edit-template => create-next}/utils.ts (75%) delete mode 100644 web/src/pages/user-setting/compilation-templates/edit-template/components/fields-section.tsx delete mode 100644 web/src/pages/user-setting/compilation-templates/edit-template/components/template-card.tsx delete mode 100644 web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-compilation-template-group-data.ts delete mode 100644 web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-edit-compilation-template-group.ts delete mode 100644 web/src/pages/user-setting/compilation-templates/edit-template/hooks/use-field-type-change.ts delete mode 100644 web/src/pages/user-setting/compilation-templates/edit-template/index.tsx create mode 100644 web/src/utils/compilation-template-util.ts diff --git a/web/src/components/artifact-force-graph/index.tsx b/web/src/components/artifact-force-graph/index.tsx index 3c0b9d4275..8304ed4ed2 100644 --- a/web/src/components/artifact-force-graph/index.tsx +++ b/web/src/components/artifact-force-graph/index.tsx @@ -59,6 +59,16 @@ function ArtifactForceGraph({ [onNodeClick, mapNodeToValue], ); + const getLinkColor = useCallback(() => { + if (typeof window === 'undefined' || !containerRef.current) { + return '#b2b5b7'; + } + return window + .getComputedStyle(containerRef.current) + .getPropertyValue('--text-disabled') + .trim(); + }, []); + return (
({ onNodeClick={handleNodeClick} nodeCanvasObject={renderNodeLabel} nodeCanvasObjectMode={() => 'after'} + linkColor={getLinkColor} /> )}
diff --git a/web/src/hooks/use-chunk-request.ts b/web/src/hooks/use-chunk-request.ts index b8698dbd8d..1de0d3b7ae 100644 --- a/web/src/hooks/use-chunk-request.ts +++ b/web/src/hooks/use-chunk-request.ts @@ -20,7 +20,7 @@ export interface IChunkListResult { searchString?: string; handleInputChange?: React.ChangeEventHandler; pagination: PaginationProps; - setPagination?: (pagination: { page: number; pageSize: number }) => void; + setPagination?: (pagination: { page: number; pageSize?: number }) => void; available: number | undefined; handleSetAvailable: (available: number | undefined) => void; dataUpdatedAt?: number; // Timestamp when data was last updated - useful for cache busting diff --git a/web/src/hooks/use-compilation-template-group-request.ts b/web/src/hooks/use-compilation-template-group-request.ts index b07068e4b9..2721432db3 100644 --- a/web/src/hooks/use-compilation-template-group-request.ts +++ b/web/src/hooks/use-compilation-template-group-request.ts @@ -12,9 +12,11 @@ import { getCompilationTemplateGroup, updateCompilationTemplateGroup, } from '@/services/compilation-template-group-service'; +import { isCreateCompilationTemplateGroup } from '@/utils/compilation-template-util'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { useDebounce } from 'ahooks'; import { useCallback, useMemo } from 'react'; +import { useParams } from 'react-router'; import { useGetPaginationWithRouter, @@ -98,15 +100,18 @@ export const useFetchCompilationTemplateGroupsByPage = () => { }; }; -export const useFetchCompilationTemplateGroup = (id?: string) => { +export const useFetchCompilationTemplateGroup = () => { + const { id } = useParams<{ id: string }>(); + const isCreate = isCreateCompilationTemplateGroup(id); + const { data, isFetching: loading } = useQuery< ICompilationTemplateGroup | undefined >({ queryKey: CompilationTemplateGroupKeys.detail(id), - enabled: !!id && id !== 'create', + enabled: !isCreate, gcTime: 0, queryFn: async () => { - if (!id || id === 'create') return undefined; + if (isCreate) return undefined; const { data } = await getCompilationTemplateGroup(id); return data?.data as ICompilationTemplateGroup | undefined; }, diff --git a/web/src/interfaces/database/compilation-template.ts b/web/src/interfaces/database/compilation-template.ts index d68461a1f2..564611c3e6 100644 --- a/web/src/interfaces/database/compilation-template.ts +++ b/web/src/interfaces/database/compilation-template.ts @@ -27,6 +27,7 @@ export interface ICompilationTemplateConfig { [section: string]: | ICompilationTemplateSection | ICompilationTemplateRaptorConfig + | Record | string | boolean | undefined; diff --git a/web/src/interfaces/request/compilation-template.ts b/web/src/interfaces/request/compilation-template.ts index fe64c8ecd0..81058f246a 100644 --- a/web/src/interfaces/request/compilation-template.ts +++ b/web/src/interfaces/request/compilation-template.ts @@ -27,6 +27,7 @@ export interface ICompilationTemplateConfigRequest { [section: string]: | ICompilationTemplateSectionRequest | ICompilationTemplateRaptorConfigRequest + | Record | string | boolean | undefined; diff --git a/web/src/lib/editor/plugins/toolbar-plugin.tsx b/web/src/lib/editor/plugins/toolbar-plugin.tsx index e96ac43699..9c9ca7bf51 100644 --- a/web/src/lib/editor/plugins/toolbar-plugin.tsx +++ b/web/src/lib/editor/plugins/toolbar-plugin.tsx @@ -103,6 +103,7 @@ export default function ToolbarPlugin({ onToggleSource, showSource }: Props) { Source - diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/blueprints-step.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/blueprints-step.tsx index ff6d5f9a9a..f6b6857b7b 100644 --- a/web/src/pages/user-setting/compilation-templates/create-next/components/blueprints-step.tsx +++ b/web/src/pages/user-setting/compilation-templates/create-next/components/blueprints-step.tsx @@ -5,12 +5,13 @@ import { Textarea } from '@/components/ui/textarea'; import { TreeDataItem, TreeView } from '@/components/ui/tree-view'; import { useFetchWikiPresets } from '@/hooks/use-compilation-template-request'; import { IWikiPreset } from '@/interfaces/database/compilation-template'; +import { FormSchemaType } from '@/pages/user-setting/compilation-templates/create-next/schema'; import { groupBy } from 'lodash'; import { useCallback, useMemo, useState } from 'react'; import { UseFormReturn, useWatch } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; -import { FormSchemaType } from '@/pages/user-setting/compilation-templates/edit-template/schema'; +import { Checkbox } from '@/components/ui/checkbox'; type WikiPresetTreeItem = TreeDataItem & { _preset?: IWikiPreset; @@ -73,12 +74,34 @@ export function BlueprintsStep({ `templates.${selectedTemplateIndex}.config.instruction` as const; const pageExamplePath = `templates.${selectedTemplateIndex}.config.page_example` as const; + const useBlueprintPath = + `templates.${selectedTemplateIndex}.config.use_blueprint` as const; const pageExample = useWatch({ control: form.control, name: pageExamplePath, }); + const instruction = useWatch({ + control: form.control, + name: instructionPath, + }); + + const useBlueprint = useWatch({ + control: form.control, + name: useBlueprintPath, + }); + + const selectedTemplateName = useMemo(() => { + if (!selectedItemId) return ''; + const selectedItem = treeData + .flatMap((node) => node.children ?? []) + .find((child) => child.id === selectedItemId); + return selectedItem?.name ?? ''; + }, [treeData, selectedItemId]); + + const hasTemplateData = Boolean(selectedItemId || instruction || pageExample); + const handleSelect = useCallback( (item?: TreeDataItem) => { if (!item || item.children) return; @@ -97,6 +120,14 @@ export function BlueprintsStep({ [form, instructionPath, pageExamplePath], ); + const handleToggleBlueprint = useCallback( + (checked: boolean | 'indeterminate') => { + if (checked === 'indeterminate') return; + form.setValue(useBlueprintPath, checked, { shouldValidate: false }); + }, + [form, useBlueprintPath], + ); + const handlePageExampleChange = useCallback( (value: string) => { form.setValue(pageExamplePath, value, { shouldValidate: false }); @@ -120,7 +151,20 @@ export function BlueprintsStep({
- {selectedItemId ? ( + {hasTemplateData && ( +
+ {selectedTemplateName} +
+ + {t('setting.useBlueprint')} +
+
+ )} + {hasTemplateData ? (
)} -
+
diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/section-field-grid.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/section-field-grid.tsx index ee4f5f49b4..3fc7100bc4 100644 --- a/web/src/pages/user-setting/compilation-templates/create-next/components/section-field-grid.tsx +++ b/web/src/pages/user-setting/compilation-templates/create-next/components/section-field-grid.tsx @@ -11,8 +11,8 @@ import { } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; -import { FormSchemaType } from '@/pages/user-setting/compilation-templates/edit-template/schema'; -import { getTypeOptionsFromBuiltinSection } from '@/pages/user-setting/compilation-templates/edit-template/utils'; +import { FormSchemaType } from '@/pages/user-setting/compilation-templates/create-next/schema'; +import { getTypeOptionsFromBuiltinSection } from '@/pages/user-setting/compilation-templates/create-next/utils'; import { FieldCard } from './field-card'; diff --git a/web/src/pages/user-setting/compilation-templates/create-next/components/template-configuration.tsx b/web/src/pages/user-setting/compilation-templates/create-next/components/template-configuration.tsx index c3cb2b0b88..9ce473974a 100644 --- a/web/src/pages/user-setting/compilation-templates/create-next/components/template-configuration.tsx +++ b/web/src/pages/user-setting/compilation-templates/create-next/components/template-configuration.tsx @@ -12,10 +12,10 @@ import { UseFormReturn, useWatch } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { CompilationTemplateKind } from '@/constants/compilation'; -import { TreeTemplateFields } from '@/pages/user-setting/compilation-templates/edit-template/components/tree-template-fields'; -import { useTemplateKindChange } from '@/pages/user-setting/compilation-templates/edit-template/hooks/use-template-kind-change'; -import { FormSchemaType } from '@/pages/user-setting/compilation-templates/edit-template/schema'; -import { SectionTitleKeyMap } from '@/pages/user-setting/compilation-templates/edit-template/utils'; +import { TreeTemplateFields } from '@/pages/user-setting/compilation-templates/create-next/components/tree-template-fields'; +import { useTemplateKindChange } from '@/pages/user-setting/compilation-templates/create-next/hooks/use-template-kind-change'; +import { FormSchemaType } from '@/pages/user-setting/compilation-templates/create-next/schema'; +import { SectionTitleKeyMap } from '@/pages/user-setting/compilation-templates/create-next/utils'; import { useActiveSectionTab } from '../hooks/use-active-section-tab'; import { useAvailableKindOptions } from '../hooks/use-available-kind-options'; @@ -233,7 +233,7 @@ export function TemplateConfiguration({
-