mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
chore: rename useFlowModel
This commit is contained in:
parent
b8ab09f68c
commit
8a9131bc8d
@ -1,12 +1,12 @@
|
||||
import React from 'react';
|
||||
import { Application, Plugin } from '@nocobase/client';
|
||||
import { useFlowModel, FlowContext, FlowModel, withFlowModel, FlowsSettings } from '@nocobase/flow-engine';
|
||||
import { useFlowModelById, FlowContext, FlowModel, withFlowModel, FlowsSettings } from '@nocobase/flow-engine';
|
||||
import MarkdownIt from 'markdown-it';
|
||||
import Handlebars from 'handlebars';
|
||||
|
||||
const Demo = () => {
|
||||
const uid = 'markdown-block';
|
||||
const model = useFlowModel<FlowModel>(uid, 'MarkdownModel');
|
||||
const model = useFlowModelById<FlowModel>(uid, 'MarkdownModel');
|
||||
return (
|
||||
<div style={{ padding: 24, background: '#f5f5f5', borderRadius: 8 }}>
|
||||
<MarkdownBlock model={model} />
|
||||
|
@ -7,14 +7,14 @@
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { FlowModelRenderer, useFlowEngine, useFlowModel } from '@nocobase/flow-engine';
|
||||
import { FlowModelRenderer, useFlowEngine, useFlowModelById } from '@nocobase/flow-engine';
|
||||
import { useRequest } from 'ahooks';
|
||||
import { Spin } from 'antd';
|
||||
import React from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
|
||||
function InternalFlowPage({ uid, sharedContext }) {
|
||||
const model = useFlowModel(uid);
|
||||
const model = useFlowModelById(uid);
|
||||
return (
|
||||
<FlowModelRenderer
|
||||
model={model}
|
||||
|
@ -11,7 +11,7 @@ import React, { useCallback } from 'react';
|
||||
import { Button, Space, Dropdown, Alert } from 'antd';
|
||||
import { SettingOutlined, DownOutlined } from '@ant-design/icons';
|
||||
import { FlowModel } from '../../../../models';
|
||||
import { useFlowModel } from '../../../../hooks';
|
||||
import { useFlowModelById } from '../../../../hooks';
|
||||
import { observer } from '@formily/react';
|
||||
import { openStepSettingsDialog } from '../../wrappers/contextual';
|
||||
|
||||
@ -86,21 +86,24 @@ const FlowsDropdownButtonWithModel: React.FC<ModelProvidedProps> = observer(
|
||||
onClick?.();
|
||||
};
|
||||
|
||||
const handleMenuClick = useCallback(({ key }: { key: string }) => {
|
||||
// key格式为 "flowKey:stepKey"
|
||||
const [flowKey, stepKey] = key.split(':');
|
||||
const handleMenuClick = useCallback(
|
||||
({ key }: { key: string }) => {
|
||||
// key格式为 "flowKey:stepKey"
|
||||
const [flowKey, stepKey] = key.split(':');
|
||||
|
||||
try {
|
||||
openStepSettingsDialog({
|
||||
model,
|
||||
flowKey,
|
||||
stepKey,
|
||||
});
|
||||
} catch (error) {
|
||||
// 用户取消或出错
|
||||
console.log('配置弹窗已取消或出错:', error);
|
||||
}
|
||||
}, [model]);
|
||||
try {
|
||||
openStepSettingsDialog({
|
||||
model,
|
||||
flowKey,
|
||||
stepKey,
|
||||
});
|
||||
} catch (error) {
|
||||
// 用户取消或出错
|
||||
console.log('配置弹窗已取消或出错:', error);
|
||||
}
|
||||
},
|
||||
[model],
|
||||
);
|
||||
|
||||
if (!model) {
|
||||
return <Alert message="提供的模型无效" type="error" />;
|
||||
@ -239,7 +242,7 @@ const FlowsDropdownButtonWithModel: React.FC<ModelProvidedProps> = observer(
|
||||
},
|
||||
);
|
||||
|
||||
// 通过useFlowModel hook获取model
|
||||
// 通过useFlowModelById hook获取model
|
||||
const FlowsDropdownButtonWithModelById: React.FC<ModelByIdProps> = observer(
|
||||
({
|
||||
uid,
|
||||
@ -254,7 +257,7 @@ const FlowsDropdownButtonWithModelById: React.FC<ModelByIdProps> = observer(
|
||||
style,
|
||||
className,
|
||||
}) => {
|
||||
const model = useFlowModel(uid, modelClassName);
|
||||
const model = useFlowModelById(uid, modelClassName);
|
||||
|
||||
if (!model) {
|
||||
return <Alert message={`未找到ID为 ${uid} 的模型`} type="error" />;
|
||||
|
@ -14,7 +14,7 @@ import { SettingOutlined, DeleteOutlined, ExclamationCircleOutlined } from '@ant
|
||||
import { observer } from '@formily/react';
|
||||
import { FlowModel } from '../../../../models';
|
||||
import { ActionStepDefinition } from '../../../../types';
|
||||
import { useFlowModel } from '../../../../hooks';
|
||||
import { useFlowModelById } from '../../../../hooks';
|
||||
import { openStepSettingsDialog } from './StepSettingsDialog';
|
||||
|
||||
// 右键菜单组件接口
|
||||
@ -254,7 +254,7 @@ const FlowsContextMenuWithModel: React.FC<ModelProvidedProps> = observer(
|
||||
// 通过useModelById hook获取model
|
||||
const FlowsContextMenuWithModelById: React.FC<ModelByIdProps> = observer(
|
||||
({ uid, modelClassName, children, enabled = true, position = 'right', showDeleteButton = true }) => {
|
||||
const model = useFlowModel(uid, modelClassName);
|
||||
const model = useFlowModelById(uid, modelClassName);
|
||||
|
||||
if (!model) {
|
||||
return <Alert message={`未找到ID为 ${uid} 的模型`} type="error" />;
|
||||
|
@ -21,7 +21,7 @@ import { observer } from '@formily/react';
|
||||
import { css } from '@emotion/css';
|
||||
import { FlowModel } from '../../../../models';
|
||||
import { ActionStepDefinition } from '../../../../types';
|
||||
import { useFlowModel } from '../../../../hooks';
|
||||
import { useFlowModelById } from '../../../../hooks';
|
||||
import { useFlowEngine } from '../../../../provider';
|
||||
import { openStepSettingsDialog } from './StepSettingsDialog';
|
||||
|
||||
@ -472,7 +472,7 @@ const FlowsFloatContextMenuWithModelById: React.FC<ModelByIdProps> = observer(
|
||||
containerStyle,
|
||||
className,
|
||||
}) => {
|
||||
const model = useFlowModel(uid, modelClassName);
|
||||
const model = useFlowModelById(uid, modelClassName);
|
||||
|
||||
if (!model) {
|
||||
return <Alert message={`未找到ID为 ${uid} 的模型`} type="error" />;
|
||||
|
@ -11,7 +11,7 @@ import React, { useCallback, useEffect } from 'react';
|
||||
import { Alert, Input, InputNumber, Select, Switch, Form } from 'antd';
|
||||
// TODO: ISchema may need to be imported from a different package or refactored.
|
||||
import { ActionStepDefinition } from '../../../../types';
|
||||
import { useFlowModel } from '../../../../hooks';
|
||||
import { useFlowModelById } from '../../../../hooks';
|
||||
import { FlowModel } from '../../../../models';
|
||||
import { observer } from '@formily/react';
|
||||
import { resolveDefaultParams } from '../../../../utils';
|
||||
@ -67,7 +67,7 @@ const FlowSettingsWithModel: React.FC<ModelProvidedProps> = observer(({ model, f
|
||||
|
||||
// 通过useModelById hook获取model
|
||||
const FlowSettingsWithModelById: React.FC<ModelByIdProps> = observer(({ uid, flowKey, modelClassName }) => {
|
||||
const model = useFlowModel(uid, modelClassName);
|
||||
const model = useFlowModelById(uid, modelClassName);
|
||||
|
||||
if (!model) {
|
||||
return <Alert message={`未找到ID为 ${uid} 的模型`} type="error" />;
|
||||
|
@ -1,6 +1,15 @@
|
||||
/**
|
||||
* 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 { useFlowModel } from '../../../../hooks';
|
||||
import { useFlowModelById } from '../../../../hooks';
|
||||
import { observer } from '@formily/react';
|
||||
import FlowsSettingsContent from './FlowsSettingsContent';
|
||||
|
||||
@ -76,7 +85,7 @@ const FlowsSettingsWithModel: React.FC<ModelProvidedProps> = observer(({ model,
|
||||
// 通过useModelById hook获取model
|
||||
const FlowsSettingsWithModelById: React.FC<ModelByIdProps> = observer(
|
||||
({ uid, modelClassName, expandAll = false, children }) => {
|
||||
const model = useFlowModel(uid, modelClassName);
|
||||
const model = useFlowModelById(uid, modelClassName);
|
||||
|
||||
if (!model) {
|
||||
return <Alert message={`未找到ID为 ${uid} 的模型`} type="error" />;
|
||||
|
@ -8,6 +8,6 @@
|
||||
*/
|
||||
|
||||
export * from './useFlowExtraContext';
|
||||
export * from './useFlowModel';
|
||||
export * from './useFlowModelById';
|
||||
export * from './useApplyFlow';
|
||||
export * from './useDispatchEvent';
|
||||
|
@ -13,7 +13,7 @@ import { FlowModel } from '../models';
|
||||
import { useFlowEngine } from '../provider';
|
||||
import { StepParams } from '../types';
|
||||
|
||||
export function useFlowModel<T extends FlowModel = FlowModel>(
|
||||
export function useFlowModelById<T extends FlowModel = FlowModel>(
|
||||
uid: string,
|
||||
modelClassName?: string,
|
||||
stepParams?: StepParams,
|
@ -12,7 +12,7 @@ import { observer } from '@formily/react';
|
||||
import { FlowModel } from './models';
|
||||
import { useApplyAutoFlows } from './hooks/useApplyFlow';
|
||||
import { useFlowExtraContext } from './hooks/useFlowExtraContext';
|
||||
import { useFlowModel } from './hooks/useFlowModel';
|
||||
import { useFlowModelById } from './hooks/useFlowModelById';
|
||||
|
||||
// 基础组件props类型
|
||||
type BaseFlowModelRendererProps<P extends React.ComponentProps<any>> = {
|
||||
@ -124,8 +124,8 @@ function WithCreatedModel<P extends object>({
|
||||
} & P) {
|
||||
const extraContext = useFlowExtraContext();
|
||||
|
||||
// 使用 useFlowModel 创建模型
|
||||
const model = useFlowModel(uid, use);
|
||||
// 使用 useFlowModelById 创建模型
|
||||
const model = useFlowModelById(uid, use);
|
||||
|
||||
// 始终应用默认流程
|
||||
useApplyAutoFlows(model, extraContext);
|
||||
|
Loading…
x
Reference in New Issue
Block a user