/** * This file is part of the NocoBase (R) project. * Copyright (c) 2020-2024 NocoBase Co., Ltd. * Authors: NocoBase Team. * * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. * For more information, please refer to: https://www.nocobase.com/agreement. */ import React from 'react'; import { Alert } from 'antd'; import { useFlowModelById } from '../../../../hooks'; import FlowsSettingsContent from './FlowsSettingsContent'; import { observer } from '../../../../reactive'; // 简单的流程设置组件接口 interface ModelProvidedProps { model: any; expandAll?: boolean; // 是否展开所有Collapse,默认为false children?: React.ReactNode; // 子组件,如果提供则作为wrapper模式 } interface ModelByIdProps { uid: string; modelClassName: string; expandAll?: boolean; // 是否展开所有Collapse,默认为false children?: React.ReactNode; // 子组件,如果提供则作为wrapper模式 } type FlowsSettingsProps = ModelProvidedProps | ModelByIdProps; // 判断是否是通过ID获取模型的props const isModelByIdProps = (props: FlowsSettingsProps): props is ModelByIdProps => { return 'uid' in props && 'modelClassName' in props && Boolean(props.uid) && Boolean(props.modelClassName); }; /** * FlowsSettings组件 - 简单的流程配置界面 * * 功能特性: * - 流程配置界面 * - Wrapper 模式支持 * * 支持两种使用方式: * 1. 直接提供model: * 2. 通过uid和modelClassName获取model: * * 支持两种模式: * 1. 独立设置界面: * 2. Wrapper模式: {children} * * @param props.expandAll 是否展开所有Collapse,默认为false * @param props.children 子组件,如果提供则作为wrapper模式 */ const FlowsSettings: React.FC = (props) => { if (isModelByIdProps(props)) { return ; } else { return ; } }; // 使用传入的model const FlowsSettingsWithModel: React.FC = observer(({ model, expandAll = false, children }) => { if (!model) { return ; } const settingsContent = ; // 如果有children,作为wrapper模式 if (children) { return (
{settingsContent} {children}
); } // 如果没有children,返回设置内容 return settingsContent; }); // 通过useModelById hook获取model const FlowsSettingsWithModelById: React.FC = observer( ({ uid, modelClassName, expandAll = false, children }) => { const model = useFlowModelById(uid, modelClassName); if (!model) { return ; } const settingsContent = ; // 如果有children,作为wrapper模式 if (children) { return (
{settingsContent} {children}
); } // 如果没有children,返回设置内容 return settingsContent; }, ); export { FlowsSettings };