mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 11:56:29 +00:00
fix: custom request role list (#4074)
* fix: custom request role list * fix: custom request body users * fix: support external data sources * fix: record data --------- Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
parent
27962ab283
commit
c9171a7117
@ -23,6 +23,7 @@ export type RemoteSelectProps<P = any> = SelectProps<P, any> & {
|
||||
mapOptions?: (data: any) => RemoteSelectProps['fieldNames'];
|
||||
targetField?: any;
|
||||
service: ResourceActionOptions<P>;
|
||||
dataSource?: string;
|
||||
CustomDropdownRender?: (v: any) => any;
|
||||
optionFilter?: (option: any) => boolean;
|
||||
};
|
||||
@ -41,10 +42,11 @@ const InternalRemoteSelect = connect(
|
||||
targetField: _targetField,
|
||||
CustomDropdownRender,
|
||||
optionFilter,
|
||||
dataSource: propsDataSource,
|
||||
...others
|
||||
} = props;
|
||||
const dataSource = useDataSourceKey();
|
||||
const headers = useDataSourceHeaders(dataSource);
|
||||
const headers = useDataSourceHeaders(propsDataSource || dataSource);
|
||||
const [open, setOpen] = useState(false);
|
||||
const firstRun = useRef(false);
|
||||
const fieldSchema = useFieldSchema();
|
||||
|
@ -17,6 +17,10 @@ export class DataSourceManager {
|
||||
this.middlewares = [];
|
||||
}
|
||||
|
||||
get(dataSourceKey: string) {
|
||||
return this.dataSources.get(dataSourceKey);
|
||||
}
|
||||
|
||||
async add(dataSource: DataSource, options: any = {}) {
|
||||
await dataSource.load(options);
|
||||
this.dataSources.set(dataSource.name, dataSource);
|
||||
|
@ -6,6 +6,7 @@ import {
|
||||
SchemaSettingsActionModalItem,
|
||||
actionSettingsItems,
|
||||
useCollection_deprecated,
|
||||
useDataSourceKey,
|
||||
useRequest,
|
||||
} from '@nocobase/client';
|
||||
import { App } from 'antd';
|
||||
@ -19,6 +20,7 @@ import { CustomRequestACLSchema, CustomRequestConfigurationFieldsSchema } from '
|
||||
export function CustomRequestSettingsItem() {
|
||||
const { t } = useTranslation();
|
||||
const { name } = useCollection_deprecated();
|
||||
const dataSourceKey = useDataSourceKey();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const customRequestsResource = useCustomRequestsResource();
|
||||
const { message } = App.useApp();
|
||||
@ -45,6 +47,7 @@ export function CustomRequestSettingsItem() {
|
||||
options: {
|
||||
...requestSettings,
|
||||
collectionName: name,
|
||||
dataSourceKey,
|
||||
},
|
||||
},
|
||||
filterKeys: ['key'],
|
||||
|
@ -1,4 +1,9 @@
|
||||
import { useCollection_deprecated, useCollectionFilterOptions, useCompile } from '@nocobase/client';
|
||||
import {
|
||||
DEFAULT_DATA_SOURCE_KEY,
|
||||
useCollection_deprecated,
|
||||
useCollectionFilterOptions,
|
||||
useCompile,
|
||||
} from '@nocobase/client';
|
||||
import { useMemo } from 'react';
|
||||
import { useTranslation } from '../locale';
|
||||
|
||||
@ -6,7 +11,7 @@ export const useCustomRequestVariableOptions = () => {
|
||||
const collection = useCollection_deprecated();
|
||||
const { t } = useTranslation();
|
||||
const fieldsOptions = useCollectionFilterOptions(collection);
|
||||
const userFieldOptions = useCollectionFilterOptions('users');
|
||||
const userFieldOptions = useCollectionFilterOptions('users', DEFAULT_DATA_SOURCE_KEY);
|
||||
const compile = useCompile();
|
||||
|
||||
const [fields, userFields] = useMemo(() => {
|
||||
|
@ -1,15 +1,7 @@
|
||||
import { useField, useFieldSchema, useForm } from '@formily/react';
|
||||
import {
|
||||
TableFieldResource,
|
||||
useAPIClient,
|
||||
useActionContext,
|
||||
useBlockRequestContext,
|
||||
useCollection_deprecated,
|
||||
useCompile,
|
||||
useRecord,
|
||||
} from '@nocobase/client';
|
||||
import { App } from 'antd';
|
||||
import { useAPIClient, useActionContext, useCompile, useDataSourceKey, useRecord } from '@nocobase/client';
|
||||
import { isURL } from '@nocobase/utils/client';
|
||||
import { App } from 'antd';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
export const useCustomizeRequestActionProps = () => {
|
||||
@ -18,13 +10,13 @@ export const useCustomizeRequestActionProps = () => {
|
||||
const actionSchema = useFieldSchema();
|
||||
const compile = useCompile();
|
||||
const form = useForm();
|
||||
const { getPrimaryKey } = useCollection_deprecated();
|
||||
const { resource, __parent, service } = useBlockRequestContext();
|
||||
// const { getPrimaryKey } = useCollection_deprecated();
|
||||
const record = useRecord();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const actionField = useField();
|
||||
const { setVisible } = useActionContext();
|
||||
const { modal, message } = App.useApp();
|
||||
const dataSourceKey = useDataSourceKey();
|
||||
return {
|
||||
async onClick(e?, callBack?) {
|
||||
const { skipValidator, onSuccess } = actionSchema?.['x-action-settings'] ?? {};
|
||||
@ -33,7 +25,7 @@ export const useCustomizeRequestActionProps = () => {
|
||||
await form.submit();
|
||||
}
|
||||
|
||||
let formValues = {};
|
||||
let formValues = { ...record };
|
||||
if (xAction === 'customize:form:request') {
|
||||
formValues = form.values;
|
||||
}
|
||||
@ -46,16 +38,14 @@ export const useCustomizeRequestActionProps = () => {
|
||||
method: 'POST',
|
||||
data: {
|
||||
currentRecord: {
|
||||
id: record[getPrimaryKey()],
|
||||
appends: service.params[0]?.appends,
|
||||
// id: record[getPrimaryKey()],
|
||||
// appends: result.params[0]?.appends,
|
||||
dataSourceKey,
|
||||
data: formValues,
|
||||
},
|
||||
},
|
||||
});
|
||||
actionField.data.loading = false;
|
||||
if (!(resource instanceof TableFieldResource)) {
|
||||
__parent?.service?.refresh?.();
|
||||
}
|
||||
// service?.refresh?.();
|
||||
if (callBack) {
|
||||
callBack?.();
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { DEFAULT_DATA_SOURCE_KEY } from '@nocobase/client';
|
||||
import { generateNTemplate } from '../locale';
|
||||
|
||||
export const CustomRequestACLSchema = {
|
||||
@ -14,6 +15,7 @@ export const CustomRequestACLSchema = {
|
||||
'x-component-props': {
|
||||
multiple: true,
|
||||
objectValue: true,
|
||||
dataSource: DEFAULT_DATA_SOURCE_KEY,
|
||||
service: {
|
||||
resource: 'roles',
|
||||
},
|
||||
|
@ -2,6 +2,7 @@ import { Context, Next } from '@nocobase/actions';
|
||||
import { parse } from '@nocobase/utils';
|
||||
|
||||
import { appendArrayColumn } from '@nocobase/evaluators';
|
||||
import Application from '@nocobase/server';
|
||||
import axios from 'axios';
|
||||
import CustomRequestPlugin from '../plugin';
|
||||
|
||||
@ -46,7 +47,8 @@ const getCurrentUserAppends = (str: string, user) => {
|
||||
};
|
||||
|
||||
export async function send(this: CustomRequestPlugin, ctx: Context, next: Next) {
|
||||
const { filterByTk, resourceName, values = {} } = ctx.action.params;
|
||||
const resourceName = ctx.action.resourceName;
|
||||
const { filterByTk, values = {} } = ctx.action.params;
|
||||
const {
|
||||
currentRecord = {
|
||||
id: 0,
|
||||
@ -70,7 +72,6 @@ export async function send(this: CustomRequestPlugin, ctx: Context, next: Next)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const repo = ctx.db.getRepository(resourceName);
|
||||
const requestConfig = await repo.findOne({
|
||||
filter: {
|
||||
@ -84,13 +85,23 @@ export async function send(this: CustomRequestPlugin, ctx: Context, next: Next)
|
||||
|
||||
ctx.withoutDataWrapping = true;
|
||||
|
||||
const { collectionName, url, headers = [], params = [], data = {}, ...options } = requestConfig.options || {};
|
||||
const {
|
||||
dataSourceKey,
|
||||
collectionName,
|
||||
url,
|
||||
headers = [],
|
||||
params = [],
|
||||
data = {},
|
||||
...options
|
||||
} = requestConfig.options || {};
|
||||
if (!url) {
|
||||
return ctx.throw(400, ctx.t('Please configure the request settings first', { ns: 'custom-request' }));
|
||||
}
|
||||
let currentRecordValues = {};
|
||||
if (collectionName && typeof currentRecord.id !== 'undefined') {
|
||||
const recordRepo = ctx.db.getRepository(collectionName);
|
||||
const app = ctx.app as Application;
|
||||
const dataSource = app.dataSourceManager.get(dataSourceKey || currentRecord.dataSourceKey || 'main');
|
||||
const recordRepo = dataSource.collectionManager.getRepository(collectionName);
|
||||
currentRecordValues =
|
||||
(
|
||||
await recordRepo.findOne({
|
||||
|
Loading…
Reference in New Issue
Block a user