feat: re-check role config after menu item insert adjacent
This commit is contained in:
		
							parent
							
								
									6843bad133
								
							
						
					
					
						commit
						8b5ddf4501
					
				@ -1,6 +1,5 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "@nocobase/api",
 | 
			
		||||
  "private": true,
 | 
			
		||||
  "version": "0.6.0-alpha.0",
 | 
			
		||||
  "description": "",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "@nocobase/app",
 | 
			
		||||
  "version": "0.6.0-alpha.0",
 | 
			
		||||
  "private": true,
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "start": "umi dev",
 | 
			
		||||
    "build": "umi build",
 | 
			
		||||
 | 
			
		||||
@ -46,6 +46,21 @@ export const ACLRolesCheckProvider = (props) => {
 | 
			
		||||
  return <ACLContext.Provider value={result}>{props.children}</ACLContext.Provider>;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const useRoleRecheck = () => {
 | 
			
		||||
  const ctx = useContext(ACLContext);
 | 
			
		||||
  const { allowAll, allowConfigure } = useACLRoleContext();
 | 
			
		||||
  return () => {
 | 
			
		||||
    if (allowAll) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    ctx.refresh();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const useACLContext = () => {
 | 
			
		||||
  return useContext(ACLContext);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export const useACLRoleContext = () => {
 | 
			
		||||
  const ctx = useContext(ACLContext);
 | 
			
		||||
  const data = ctx.data?.data;
 | 
			
		||||
 | 
			
		||||
@ -3,16 +3,21 @@ import { SchemaOptionsContext } from '@formily/react';
 | 
			
		||||
import React, { useContext } from 'react';
 | 
			
		||||
import { useTranslation } from 'react-i18next';
 | 
			
		||||
import { SchemaComponent, SchemaComponentOptions } from '../../..';
 | 
			
		||||
import { useRoleRecheck } from '../../../../acl';
 | 
			
		||||
import { SchemaInitializer } from '../../../../schema-initializer';
 | 
			
		||||
 | 
			
		||||
export const MenuItemInitializers = (props: any) => {
 | 
			
		||||
  const { t } = useTranslation();
 | 
			
		||||
  const recheck = useRoleRecheck();
 | 
			
		||||
  return (
 | 
			
		||||
    <SchemaInitializer.Button
 | 
			
		||||
      insertPosition={'beforeEnd'}
 | 
			
		||||
      icon={'PlusOutlined'}
 | 
			
		||||
      insert={props.insert}
 | 
			
		||||
      style={props.style}
 | 
			
		||||
      onSuccess={() => {
 | 
			
		||||
        recheck?.();
 | 
			
		||||
      }}
 | 
			
		||||
      {...props}
 | 
			
		||||
      items={[
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
@ -306,7 +306,7 @@ export class Designable {
 | 
			
		||||
    if (!Schema.isSchemaInstance(this.current)) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    const opts = {};
 | 
			
		||||
    const opts = { onSuccess: options.onSuccess };
 | 
			
		||||
    const { wrap = defaultWrap, breakRemoveOn, removeParentsIfNoChildren } = options;
 | 
			
		||||
    if (Schema.isSchemaInstance(schema)) {
 | 
			
		||||
      if (this.parentsIn(schema)) {
 | 
			
		||||
@ -363,7 +363,7 @@ export class Designable {
 | 
			
		||||
    if (!Schema.isSchemaInstance(this.current)) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    const opts = {};
 | 
			
		||||
    const opts = { onSuccess: options.onSuccess };
 | 
			
		||||
    const { wrap = defaultWrap, breakRemoveOn, removeParentsIfNoChildren } = options;
 | 
			
		||||
    if (Schema.isSchemaInstance(schema)) {
 | 
			
		||||
      if (this.parentsIn(schema)) {
 | 
			
		||||
@ -411,7 +411,7 @@ export class Designable {
 | 
			
		||||
    if (!Schema.isSchemaInstance(this.current)) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    const opts = {};
 | 
			
		||||
    const opts = { onSuccess: options.onSuccess };
 | 
			
		||||
    const { wrap = defaultWrap, breakRemoveOn, removeParentsIfNoChildren } = options;
 | 
			
		||||
    if (Schema.isSchemaInstance(schema)) {
 | 
			
		||||
      if (this.parentsIn(schema)) {
 | 
			
		||||
 | 
			
		||||
@ -29,6 +29,7 @@ SchemaInitializer.Button = observer((props: SchemaInitializerButtonProps) => {
 | 
			
		||||
    component,
 | 
			
		||||
    style,
 | 
			
		||||
    icon,
 | 
			
		||||
    onSuccess,
 | 
			
		||||
    ...others
 | 
			
		||||
  } = props;
 | 
			
		||||
  const compile = useCompile();
 | 
			
		||||
@ -38,7 +39,7 @@ SchemaInitializer.Button = observer((props: SchemaInitializerButtonProps) => {
 | 
			
		||||
    if (props.insert) {
 | 
			
		||||
      props.insert(wrap(schema));
 | 
			
		||||
    } else {
 | 
			
		||||
      insertAdjacent(insertPosition, wrap(schema));
 | 
			
		||||
      insertAdjacent(insertPosition, wrap(schema), { onSuccess });
 | 
			
		||||
    }
 | 
			
		||||
  };
 | 
			
		||||
  const renderItems = (items: any) => {
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@ export interface SchemaInitializerButtonProps extends ButtonProps {
 | 
			
		||||
  dropdown?: DropDownProps;
 | 
			
		||||
  component?: any;
 | 
			
		||||
  designable?: boolean;
 | 
			
		||||
  onSuccess?: any;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export type SchemaInitializerItemOptions = ItemGroupOptions | SubMenuOptions | ItemOptions | DividerOptions;
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "@nocobase/database",
 | 
			
		||||
  "version": "0.6.0-alpha.0",
 | 
			
		||||
  "private": true,
 | 
			
		||||
  "description": "",
 | 
			
		||||
  "main": "./lib/index.js",
 | 
			
		||||
  "types": "./lib/index.d.ts",
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,6 @@
 | 
			
		||||
  "name": "@nocobase/plugin-workflow",
 | 
			
		||||
  "version": "0.6.0-alpha.0",
 | 
			
		||||
  "main": "lib/index.js",
 | 
			
		||||
  "private": true,
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm",
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user