mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 11:12:20 +08:00
feat: add settingsMenuLevel parameter to control menu hierarchy
This commit is contained in:
parent
a8546e3599
commit
75b4de9b07
@ -75,6 +75,9 @@ interface FlowModelRendererProps {
|
|||||||
|
|
||||||
/** 是否在最外层包装 FlowErrorFallback 组件,默认 false */
|
/** 是否在最外层包装 FlowErrorFallback 组件,默认 false */
|
||||||
showErrorFallback?: boolean; // 默认 false
|
showErrorFallback?: boolean; // 默认 false
|
||||||
|
|
||||||
|
/** 设置菜单层级:1=仅当前模型(默认),2=包含子模型 */
|
||||||
|
settingsMenuLevel?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,6 +92,7 @@ const FlowModelRendererWithAutoFlows: React.FC<{
|
|||||||
sharedContext?: Record<string, any>;
|
sharedContext?: Record<string, any>;
|
||||||
independentAutoFlowExecution?: boolean;
|
independentAutoFlowExecution?: boolean;
|
||||||
showErrorFallback?: boolean;
|
showErrorFallback?: boolean;
|
||||||
|
settingsMenuLevel?: number;
|
||||||
}> = observer(
|
}> = observer(
|
||||||
({
|
({
|
||||||
model,
|
model,
|
||||||
@ -99,6 +103,7 @@ const FlowModelRendererWithAutoFlows: React.FC<{
|
|||||||
sharedContext,
|
sharedContext,
|
||||||
independentAutoFlowExecution,
|
independentAutoFlowExecution,
|
||||||
showErrorFallback,
|
showErrorFallback,
|
||||||
|
settingsMenuLevel,
|
||||||
}) => {
|
}) => {
|
||||||
useApplyAutoFlows(model, extraContext, !independentAutoFlowExecution);
|
useApplyAutoFlows(model, extraContext, !independentAutoFlowExecution);
|
||||||
|
|
||||||
@ -110,6 +115,7 @@ const FlowModelRendererWithAutoFlows: React.FC<{
|
|||||||
flowSettingsVariant={flowSettingsVariant}
|
flowSettingsVariant={flowSettingsVariant}
|
||||||
hideRemoveInSettings={hideRemoveInSettings}
|
hideRemoveInSettings={hideRemoveInSettings}
|
||||||
showErrorFallback={showErrorFallback}
|
showErrorFallback={showErrorFallback}
|
||||||
|
settingsMenuLevel={settingsMenuLevel}
|
||||||
/>
|
/>
|
||||||
</FlowModelProvider>
|
</FlowModelProvider>
|
||||||
);
|
);
|
||||||
@ -126,8 +132,17 @@ const FlowModelRendererWithoutAutoFlows: React.FC<{
|
|||||||
hideRemoveInSettings: boolean;
|
hideRemoveInSettings: boolean;
|
||||||
sharedContext?: Record<string, any>;
|
sharedContext?: Record<string, any>;
|
||||||
showErrorFallback?: boolean;
|
showErrorFallback?: boolean;
|
||||||
|
settingsMenuLevel?: number;
|
||||||
}> = observer(
|
}> = observer(
|
||||||
({ model, showFlowSettings, flowSettingsVariant, hideRemoveInSettings, sharedContext, showErrorFallback }) => {
|
({
|
||||||
|
model,
|
||||||
|
showFlowSettings,
|
||||||
|
flowSettingsVariant,
|
||||||
|
hideRemoveInSettings,
|
||||||
|
sharedContext,
|
||||||
|
showErrorFallback,
|
||||||
|
settingsMenuLevel,
|
||||||
|
}) => {
|
||||||
return (
|
return (
|
||||||
<FlowModelProvider model={model}>
|
<FlowModelProvider model={model}>
|
||||||
<FlowModelRendererCore
|
<FlowModelRendererCore
|
||||||
@ -136,6 +151,7 @@ const FlowModelRendererWithoutAutoFlows: React.FC<{
|
|||||||
flowSettingsVariant={flowSettingsVariant}
|
flowSettingsVariant={flowSettingsVariant}
|
||||||
hideRemoveInSettings={hideRemoveInSettings}
|
hideRemoveInSettings={hideRemoveInSettings}
|
||||||
showErrorFallback={showErrorFallback}
|
showErrorFallback={showErrorFallback}
|
||||||
|
settingsMenuLevel={settingsMenuLevel}
|
||||||
/>
|
/>
|
||||||
</FlowModelProvider>
|
</FlowModelProvider>
|
||||||
);
|
);
|
||||||
@ -151,7 +167,9 @@ const FlowModelRendererCore: React.FC<{
|
|||||||
flowSettingsVariant: string;
|
flowSettingsVariant: string;
|
||||||
hideRemoveInSettings: boolean;
|
hideRemoveInSettings: boolean;
|
||||||
showErrorFallback?: boolean;
|
showErrorFallback?: boolean;
|
||||||
}> = observer(({ model, showFlowSettings, flowSettingsVariant, hideRemoveInSettings, showErrorFallback }) => {
|
settingsMenuLevel?: number;
|
||||||
|
}> = observer(
|
||||||
|
({ model, showFlowSettings, flowSettingsVariant, hideRemoveInSettings, showErrorFallback, settingsMenuLevel }) => {
|
||||||
// 渲染模型内容
|
// 渲染模型内容
|
||||||
const modelContent = model.render();
|
const modelContent = model.render();
|
||||||
|
|
||||||
@ -177,6 +195,7 @@ const FlowModelRendererCore: React.FC<{
|
|||||||
showDeleteButton={!hideRemoveInSettings}
|
showDeleteButton={!hideRemoveInSettings}
|
||||||
showBackground={_.isObject(showFlowSettings) ? showFlowSettings.showBackground : undefined}
|
showBackground={_.isObject(showFlowSettings) ? showFlowSettings.showBackground : undefined}
|
||||||
showBorder={_.isObject(showFlowSettings) ? showFlowSettings.showBorder : undefined}
|
showBorder={_.isObject(showFlowSettings) ? showFlowSettings.showBorder : undefined}
|
||||||
|
settingsMenuLevel={settingsMenuLevel}
|
||||||
>
|
>
|
||||||
{wrapWithErrorBoundary(modelContent)}
|
{wrapWithErrorBoundary(modelContent)}
|
||||||
</FlowsFloatContextMenu>
|
</FlowsFloatContextMenu>
|
||||||
@ -200,19 +219,23 @@ const FlowModelRendererCore: React.FC<{
|
|||||||
return wrapWithErrorBoundary(modelContent);
|
return wrapWithErrorBoundary(modelContent);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.warn(`FlowModelRenderer: Unknown flowSettingsVariant '${flowSettingsVariant}', falling back to dropdown`);
|
console.warn(
|
||||||
|
`FlowModelRenderer: Unknown flowSettingsVariant '${flowSettingsVariant}', falling back to dropdown`,
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<FlowsFloatContextMenu
|
<FlowsFloatContextMenu
|
||||||
model={model}
|
model={model}
|
||||||
showDeleteButton={!hideRemoveInSettings}
|
showDeleteButton={!hideRemoveInSettings}
|
||||||
showBackground={_.isObject(showFlowSettings) ? showFlowSettings.showBackground : undefined}
|
showBackground={_.isObject(showFlowSettings) ? showFlowSettings.showBackground : undefined}
|
||||||
showBorder={_.isObject(showFlowSettings) ? showFlowSettings.showBorder : undefined}
|
showBorder={_.isObject(showFlowSettings) ? showFlowSettings.showBorder : undefined}
|
||||||
|
settingsMenuLevel={settingsMenuLevel}
|
||||||
>
|
>
|
||||||
{wrapWithErrorBoundary(modelContent)}
|
{wrapWithErrorBoundary(modelContent)}
|
||||||
</FlowsFloatContextMenu>
|
</FlowsFloatContextMenu>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A React component responsible for rendering a FlowModel.
|
* A React component responsible for rendering a FlowModel.
|
||||||
@ -228,6 +251,7 @@ const FlowModelRendererCore: React.FC<{
|
|||||||
* @param {any} props.extraContext - Extra context to pass to useApplyAutoFlows when skipApplyAutoFlows is false.
|
* @param {any} props.extraContext - Extra context to pass to useApplyAutoFlows when skipApplyAutoFlows is false.
|
||||||
* @param {any} props.sharedContext - Shared context to pass to the model.
|
* @param {any} props.sharedContext - Shared context to pass to the model.
|
||||||
* @param {boolean} props.independentAutoFlowExecution - Whether each component has independent auto flow execution.
|
* @param {boolean} props.independentAutoFlowExecution - Whether each component has independent auto flow execution.
|
||||||
|
* @param {number} props.settingsMenuLevel - Settings menu levels: 1=current model only (default), 2=include sub-models.
|
||||||
* @returns {React.ReactNode | null} The rendered output of the model, or null if the model or its render method is invalid.
|
* @returns {React.ReactNode | null} The rendered output of the model, or null if the model or its render method is invalid.
|
||||||
*/
|
*/
|
||||||
export const FlowModelRenderer: React.FC<FlowModelRendererProps> = observer(
|
export const FlowModelRenderer: React.FC<FlowModelRendererProps> = observer(
|
||||||
@ -242,6 +266,7 @@ export const FlowModelRenderer: React.FC<FlowModelRendererProps> = observer(
|
|||||||
sharedContext,
|
sharedContext,
|
||||||
independentAutoFlowExecution = false,
|
independentAutoFlowExecution = false,
|
||||||
showErrorFallback = false,
|
showErrorFallback = false,
|
||||||
|
settingsMenuLevel,
|
||||||
}) => {
|
}) => {
|
||||||
if (!model || typeof model.render !== 'function') {
|
if (!model || typeof model.render !== 'function') {
|
||||||
// 可以选择渲染 null 或者一个错误/提示信息
|
// 可以选择渲染 null 或者一个错误/提示信息
|
||||||
@ -264,6 +289,7 @@ export const FlowModelRenderer: React.FC<FlowModelRendererProps> = observer(
|
|||||||
hideRemoveInSettings={hideRemoveInSettings}
|
hideRemoveInSettings={hideRemoveInSettings}
|
||||||
sharedContext={sharedContext}
|
sharedContext={sharedContext}
|
||||||
showErrorFallback={showErrorFallback}
|
showErrorFallback={showErrorFallback}
|
||||||
|
settingsMenuLevel={settingsMenuLevel}
|
||||||
/>
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
);
|
);
|
||||||
@ -279,6 +305,7 @@ export const FlowModelRenderer: React.FC<FlowModelRendererProps> = observer(
|
|||||||
sharedContext={sharedContext}
|
sharedContext={sharedContext}
|
||||||
independentAutoFlowExecution={independentAutoFlowExecution}
|
independentAutoFlowExecution={independentAutoFlowExecution}
|
||||||
showErrorFallback={showErrorFallback}
|
showErrorFallback={showErrorFallback}
|
||||||
|
settingsMenuLevel={settingsMenuLevel}
|
||||||
/>
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
);
|
);
|
||||||
|
@ -40,6 +40,7 @@ const renderToolbarItems = (
|
|||||||
showDeleteButton: boolean,
|
showDeleteButton: boolean,
|
||||||
showCopyUidButton: boolean,
|
showCopyUidButton: boolean,
|
||||||
flowEngine: FlowEngine,
|
flowEngine: FlowEngine,
|
||||||
|
settingsMenuLevel?: number,
|
||||||
) => {
|
) => {
|
||||||
const toolbarItems = flowEngine?.flowSettings?.getToolbarItems?.() || [];
|
const toolbarItems = flowEngine?.flowSettings?.getToolbarItems?.() || [];
|
||||||
|
|
||||||
@ -60,6 +61,7 @@ const renderToolbarItems = (
|
|||||||
model={model}
|
model={model}
|
||||||
showDeleteButton={showDeleteButton}
|
showDeleteButton={showDeleteButton}
|
||||||
showCopyUidButton={showCopyUidButton}
|
showCopyUidButton={showCopyUidButton}
|
||||||
|
menuLevels={settingsMenuLevel}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -144,6 +146,10 @@ interface ModelProvidedProps {
|
|||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
showBackground?: boolean;
|
showBackground?: boolean;
|
||||||
|
/**
|
||||||
|
* Settings menu levels: 1=current model only (default), 2=include sub-models
|
||||||
|
*/
|
||||||
|
settingsMenuLevel?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ModelByIdProps {
|
interface ModelByIdProps {
|
||||||
@ -163,6 +169,10 @@ interface ModelByIdProps {
|
|||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
showBackground?: boolean;
|
showBackground?: boolean;
|
||||||
|
/**
|
||||||
|
* Settings menu levels: 1=current model only (default), 2=include sub-models
|
||||||
|
*/
|
||||||
|
settingsMenuLevel?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
type FlowsFloatContextMenuProps = ModelProvidedProps | ModelByIdProps;
|
type FlowsFloatContextMenuProps = ModelProvidedProps | ModelByIdProps;
|
||||||
@ -193,6 +203,7 @@ const isModelByIdProps = (props: FlowsFloatContextMenuProps): props is ModelById
|
|||||||
* @param props.showCopyUidButton 是否显示复制UID按钮,默认为true
|
* @param props.showCopyUidButton 是否显示复制UID按钮,默认为true
|
||||||
* @param props.containerStyle 容器自定义样式
|
* @param props.containerStyle 容器自定义样式
|
||||||
* @param props.className 容器自定义类名
|
* @param props.className 容器自定义类名
|
||||||
|
* @param props.settingsMenuLevel 设置菜单层级:1=仅当前模型(默认),2=包含子模型
|
||||||
*/
|
*/
|
||||||
const FlowsFloatContextMenu: React.FC<FlowsFloatContextMenuProps> = observer((props) => {
|
const FlowsFloatContextMenu: React.FC<FlowsFloatContextMenuProps> = observer((props) => {
|
||||||
const flowEngine = useFlowEngine();
|
const flowEngine = useFlowEngine();
|
||||||
@ -219,6 +230,7 @@ const FlowsFloatContextMenuWithModel: React.FC<ModelProvidedProps> = observer(
|
|||||||
className,
|
className,
|
||||||
showBackground = true,
|
showBackground = true,
|
||||||
showBorder = true,
|
showBorder = true,
|
||||||
|
settingsMenuLevel,
|
||||||
}: ModelProvidedProps) => {
|
}: ModelProvidedProps) => {
|
||||||
const [hideMenu, setHideMenu] = useState<boolean>(false);
|
const [hideMenu, setHideMenu] = useState<boolean>(false);
|
||||||
const [hasButton, setHasButton] = useState<boolean>(false);
|
const [hasButton, setHasButton] = useState<boolean>(false);
|
||||||
@ -293,7 +305,7 @@ const FlowsFloatContextMenuWithModel: React.FC<ModelProvidedProps> = observer(
|
|||||||
<div className="general-schema-designer">
|
<div className="general-schema-designer">
|
||||||
<div className="general-schema-designer-icons">
|
<div className="general-schema-designer-icons">
|
||||||
<Space size={3} align="center">
|
<Space size={3} align="center">
|
||||||
{renderToolbarItems(model, showDeleteButton, showCopyUidButton, flowEngine)}
|
{renderToolbarItems(model, showDeleteButton, showCopyUidButton, flowEngine, settingsMenuLevel)}
|
||||||
</Space>
|
</Space>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -313,6 +325,7 @@ const FlowsFloatContextMenuWithModelById: React.FC<ModelByIdProps> = observer(
|
|||||||
showCopyUidButton = true,
|
showCopyUidButton = true,
|
||||||
containerStyle,
|
containerStyle,
|
||||||
className,
|
className,
|
||||||
|
settingsMenuLevel,
|
||||||
}) => {
|
}) => {
|
||||||
const model = useFlowModelById(uid, modelClassName);
|
const model = useFlowModelById(uid, modelClassName);
|
||||||
|
|
||||||
@ -328,6 +341,7 @@ const FlowsFloatContextMenuWithModelById: React.FC<ModelByIdProps> = observer(
|
|||||||
showCopyUidButton={showCopyUidButton}
|
showCopyUidButton={showCopyUidButton}
|
||||||
containerStyle={containerStyle}
|
containerStyle={containerStyle}
|
||||||
className={className}
|
className={className}
|
||||||
|
settingsMenuLevel={settingsMenuLevel}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</FlowsFloatContextMenuWithModel>
|
</FlowsFloatContextMenuWithModel>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user