mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
fix: quick edit
This commit is contained in:
parent
f51a0474ff
commit
64f5f2134e
@ -15,7 +15,7 @@ export class DataBlockModel<T = DefaultStructure> extends BlockModel<T> {
|
||||
resource: APIResource;
|
||||
collection: Collection;
|
||||
|
||||
onInit() {
|
||||
onInit(options) {
|
||||
this.setSharedContext({
|
||||
currentBlockModel: this,
|
||||
});
|
||||
|
@ -11,9 +11,9 @@ import { FormButtonGroup, FormLayout } from '@formily/antd-v5';
|
||||
import { createForm, Form } from '@formily/core';
|
||||
import { FormProvider } from '@formily/react';
|
||||
import { AddActionButton, AddFieldButton, FlowModelRenderer, SingleRecordResource } from '@nocobase/flow-engine';
|
||||
import { tval } from '@nocobase/utils/client';
|
||||
import { Card } from 'antd';
|
||||
import React from 'react';
|
||||
import { tval } from '@nocobase/utils/client';
|
||||
import { DataBlockModel } from '../../base/BlockModel';
|
||||
import { EditableFieldModel } from '../../fields/EditableField/EditableFieldModel';
|
||||
|
||||
@ -52,7 +52,8 @@ export class FormModel extends DataBlockModel {
|
||||
collection={this.collection}
|
||||
subModelBaseClass="EditableFieldModel"
|
||||
onSubModelAdded={async (model: EditableFieldModel) => {
|
||||
this.addAppends(model.fieldPath, true);
|
||||
const params = model.getStepParams('default', 'step1');
|
||||
this.addAppends(params?.fieldPath, true);
|
||||
}}
|
||||
/>
|
||||
<FormButtonGroup style={{ marginTop: 16 }}>
|
||||
@ -113,6 +114,9 @@ FormModel.registerFlow({
|
||||
resource.setResourceName(params.collectionName);
|
||||
resource.setAPIClient(ctx.globals.api);
|
||||
ctx.model.resource = resource;
|
||||
ctx.model.resource.on('refresh', () => {
|
||||
ctx.model.form.setInitialValues(ctx.model.resource.getData());
|
||||
});
|
||||
}
|
||||
await ctx.model.applySubModelsAutoFlows('fields');
|
||||
const filterByTk = ctx.shared?.currentFlow?.extra?.filterByTk;
|
||||
|
@ -22,35 +22,13 @@ import {
|
||||
} from '@nocobase/flow-engine';
|
||||
import { InputRef, Skeleton } from 'antd';
|
||||
import React, { createRef } from 'react';
|
||||
import { DataBlockModel } from '../../base/BlockModel';
|
||||
|
||||
export class QuickEditForm extends FlowModel {
|
||||
export class QuickEditForm extends DataBlockModel {
|
||||
form: Form;
|
||||
declare resource: SingleRecordResource;
|
||||
declare collection: Collection;
|
||||
|
||||
onInit() {
|
||||
this.setSharedContext({
|
||||
currentBlockModel: this,
|
||||
});
|
||||
}
|
||||
|
||||
addAppends(fieldPath: string, refresh = false) {
|
||||
const field = this.ctx.globals.dataSourceManager.getCollectionField(
|
||||
`${this.collection.dataSourceKey}.${this.collection.name}.${fieldPath}`,
|
||||
);
|
||||
if (!field) {
|
||||
throw new Error(
|
||||
`Collection field not found: ${this.collection.dataSourceKey}.${this.collection.name}.${fieldPath}`,
|
||||
);
|
||||
}
|
||||
if (['belongsToMany', 'belongsTo', 'hasMany', 'hasOne'].includes(field.type)) {
|
||||
(this.resource as BaseRecordResource).addAppends(field.name);
|
||||
if (refresh) {
|
||||
this.resource.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async open(options: {
|
||||
target: any;
|
||||
flowEngine: FlowEngine;
|
||||
@ -155,11 +133,6 @@ QuickEditForm.registerFlow({
|
||||
resource.setResourceName(collectionName);
|
||||
resource.setAPIClient(ctx.globals.api);
|
||||
ctx.model.resource = resource;
|
||||
if (ctx.extra.filterByTk) {
|
||||
resource.setFilterByTk(ctx.extra.filterByTk);
|
||||
await resource.refresh();
|
||||
ctx.model.form.setInitialValues(resource.getData());
|
||||
}
|
||||
const collectionField = ctx.model.collection.getField(fieldPath) as CollectionField;
|
||||
if (collectionField) {
|
||||
const use = collectionField.getFirstSubclassNameOf('EditableFieldModel') || 'EditableFieldModel';
|
||||
@ -175,6 +148,12 @@ QuickEditForm.registerFlow({
|
||||
},
|
||||
},
|
||||
});
|
||||
ctx.model.addAppends(fieldPath);
|
||||
}
|
||||
if (ctx.extra.filterByTk) {
|
||||
resource.setFilterByTk(ctx.extra.filterByTk);
|
||||
await resource.refresh();
|
||||
ctx.model.form.setInitialValues(resource.getData());
|
||||
}
|
||||
},
|
||||
},
|
||||
|
@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
import { EditOutlined } from '@ant-design/icons';
|
||||
import { DragEndEvent } from '@dnd-kit/core';
|
||||
import { css } from '@emotion/css';
|
||||
import { observer } from '@formily/reactive-react';
|
||||
import {
|
||||
@ -18,16 +19,15 @@ import {
|
||||
MultiRecordResource,
|
||||
useFlowEngine,
|
||||
} from '@nocobase/flow-engine';
|
||||
import { tval } from '@nocobase/utils/client';
|
||||
import { Card, Space, Spin, Table } from 'antd';
|
||||
import classNames from 'classnames';
|
||||
import _ from 'lodash';
|
||||
import React, { useRef } from 'react';
|
||||
import { tval } from '@nocobase/utils/client';
|
||||
import { ActionModel } from '../../base/ActionModel';
|
||||
import { DataBlockModel } from '../../base/BlockModel';
|
||||
import { QuickEditForm } from '../form/QuickEditForm';
|
||||
import { TableColumnModel } from './TableColumnModel';
|
||||
import { DragEndEvent } from '@dnd-kit/core';
|
||||
|
||||
type TableModelStructure = {
|
||||
subModels: {
|
||||
@ -355,15 +355,15 @@ TableModel.registerFlow({
|
||||
ctx.model.resource.setPageSize(params.pageSize);
|
||||
},
|
||||
},
|
||||
dataScope: {
|
||||
use: 'dataScope',
|
||||
title: tval('Set data scope'),
|
||||
},
|
||||
refresh: {
|
||||
async handler(ctx, params) {
|
||||
await ctx.model.resource.refresh();
|
||||
},
|
||||
},
|
||||
dataScope: {
|
||||
use: 'dataScope',
|
||||
title: tval('Set data scope'),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -117,6 +117,7 @@ export class APIResource<TData = any> extends FlowResource<TData> {
|
||||
...this.getRefreshRequestOptions(),
|
||||
});
|
||||
this.setData(data);
|
||||
this.emit('refresh');
|
||||
}
|
||||
|
||||
protected getRefreshRequestOptions() {
|
||||
|
@ -52,5 +52,6 @@ export class SingleRecordResource<TData = any> extends BaseRecordResource<TData>
|
||||
...this.getRefreshRequestOptions(),
|
||||
});
|
||||
this.setData(data).setMeta(meta);
|
||||
this.emit('refresh');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user