feat: re-check role config after menu item insert adjacent

This commit is contained in:
chenos 2022-04-11 09:22:41 +08:00
parent 6843bad133
commit 8b5ddf4501
9 changed files with 26 additions and 8 deletions

View File

@ -1,6 +1,5 @@
{ {
"name": "@nocobase/api", "name": "@nocobase/api",
"private": true,
"version": "0.6.0-alpha.0", "version": "0.6.0-alpha.0",
"description": "", "description": "",
"license": "MIT", "license": "MIT",

View File

@ -1,7 +1,6 @@
{ {
"name": "@nocobase/app", "name": "@nocobase/app",
"version": "0.6.0-alpha.0", "version": "0.6.0-alpha.0",
"private": true,
"scripts": { "scripts": {
"start": "umi dev", "start": "umi dev",
"build": "umi build", "build": "umi build",

View File

@ -46,6 +46,21 @@ export const ACLRolesCheckProvider = (props) => {
return <ACLContext.Provider value={result}>{props.children}</ACLContext.Provider>; 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 = () => { export const useACLRoleContext = () => {
const ctx = useContext(ACLContext); const ctx = useContext(ACLContext);
const data = ctx.data?.data; const data = ctx.data?.data;

View File

@ -3,16 +3,21 @@ import { SchemaOptionsContext } from '@formily/react';
import React, { useContext } from 'react'; import React, { useContext } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { SchemaComponent, SchemaComponentOptions } from '../../..'; import { SchemaComponent, SchemaComponentOptions } from '../../..';
import { useRoleRecheck } from '../../../../acl';
import { SchemaInitializer } from '../../../../schema-initializer'; import { SchemaInitializer } from '../../../../schema-initializer';
export const MenuItemInitializers = (props: any) => { export const MenuItemInitializers = (props: any) => {
const { t } = useTranslation(); const { t } = useTranslation();
const recheck = useRoleRecheck();
return ( return (
<SchemaInitializer.Button <SchemaInitializer.Button
insertPosition={'beforeEnd'} insertPosition={'beforeEnd'}
icon={'PlusOutlined'} icon={'PlusOutlined'}
insert={props.insert} insert={props.insert}
style={props.style} style={props.style}
onSuccess={() => {
recheck?.();
}}
{...props} {...props}
items={[ items={[
{ {

View File

@ -306,7 +306,7 @@ export class Designable {
if (!Schema.isSchemaInstance(this.current)) { if (!Schema.isSchemaInstance(this.current)) {
return; return;
} }
const opts = {}; const opts = { onSuccess: options.onSuccess };
const { wrap = defaultWrap, breakRemoveOn, removeParentsIfNoChildren } = options; const { wrap = defaultWrap, breakRemoveOn, removeParentsIfNoChildren } = options;
if (Schema.isSchemaInstance(schema)) { if (Schema.isSchemaInstance(schema)) {
if (this.parentsIn(schema)) { if (this.parentsIn(schema)) {
@ -363,7 +363,7 @@ export class Designable {
if (!Schema.isSchemaInstance(this.current)) { if (!Schema.isSchemaInstance(this.current)) {
return; return;
} }
const opts = {}; const opts = { onSuccess: options.onSuccess };
const { wrap = defaultWrap, breakRemoveOn, removeParentsIfNoChildren } = options; const { wrap = defaultWrap, breakRemoveOn, removeParentsIfNoChildren } = options;
if (Schema.isSchemaInstance(schema)) { if (Schema.isSchemaInstance(schema)) {
if (this.parentsIn(schema)) { if (this.parentsIn(schema)) {
@ -411,7 +411,7 @@ export class Designable {
if (!Schema.isSchemaInstance(this.current)) { if (!Schema.isSchemaInstance(this.current)) {
return; return;
} }
const opts = {}; const opts = { onSuccess: options.onSuccess };
const { wrap = defaultWrap, breakRemoveOn, removeParentsIfNoChildren } = options; const { wrap = defaultWrap, breakRemoveOn, removeParentsIfNoChildren } = options;
if (Schema.isSchemaInstance(schema)) { if (Schema.isSchemaInstance(schema)) {
if (this.parentsIn(schema)) { if (this.parentsIn(schema)) {

View File

@ -29,6 +29,7 @@ SchemaInitializer.Button = observer((props: SchemaInitializerButtonProps) => {
component, component,
style, style,
icon, icon,
onSuccess,
...others ...others
} = props; } = props;
const compile = useCompile(); const compile = useCompile();
@ -38,7 +39,7 @@ SchemaInitializer.Button = observer((props: SchemaInitializerButtonProps) => {
if (props.insert) { if (props.insert) {
props.insert(wrap(schema)); props.insert(wrap(schema));
} else { } else {
insertAdjacent(insertPosition, wrap(schema)); insertAdjacent(insertPosition, wrap(schema), { onSuccess });
} }
}; };
const renderItems = (items: any) => { const renderItems = (items: any) => {

View File

@ -9,6 +9,7 @@ export interface SchemaInitializerButtonProps extends ButtonProps {
dropdown?: DropDownProps; dropdown?: DropDownProps;
component?: any; component?: any;
designable?: boolean; designable?: boolean;
onSuccess?: any;
} }
export type SchemaInitializerItemOptions = ItemGroupOptions | SubMenuOptions | ItemOptions | DividerOptions; export type SchemaInitializerItemOptions = ItemGroupOptions | SubMenuOptions | ItemOptions | DividerOptions;

View File

@ -1,7 +1,6 @@
{ {
"name": "@nocobase/database", "name": "@nocobase/database",
"version": "0.6.0-alpha.0", "version": "0.6.0-alpha.0",
"private": true,
"description": "", "description": "",
"main": "./lib/index.js", "main": "./lib/index.js",
"types": "./lib/index.d.ts", "types": "./lib/index.d.ts",

View File

@ -2,7 +2,6 @@
"name": "@nocobase/plugin-workflow", "name": "@nocobase/plugin-workflow",
"version": "0.6.0-alpha.0", "version": "0.6.0-alpha.0",
"main": "lib/index.js", "main": "lib/index.js",
"private": true,
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm", "build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm",