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
a521faee7b
commit
97186d72ce
@ -20,12 +20,14 @@ import {
|
||||
FlowModelRenderer,
|
||||
SingleRecordResource,
|
||||
} from '@nocobase/flow-engine';
|
||||
import { InputRef, Skeleton } from 'antd';
|
||||
import { Button, InputRef, Skeleton } from 'antd';
|
||||
import _ from 'lodash';
|
||||
import React, { createRef } from 'react';
|
||||
import { DataBlockModel } from '../../base/BlockModel';
|
||||
|
||||
export class QuickEditForm extends DataBlockModel {
|
||||
form: Form;
|
||||
fieldPath: string;
|
||||
declare resource: SingleRecordResource;
|
||||
declare collection: Collection;
|
||||
|
||||
@ -56,7 +58,7 @@ export class QuickEditForm extends DataBlockModel {
|
||||
|
||||
async open({ target, filterByTk }: { target: any; filterByTk: string }) {
|
||||
await this.applyFlow('initial', { filterByTk });
|
||||
return new Promise((resolve) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const inputRef = createRef<InputRef>();
|
||||
const popover = this.ctx.globals.popover.open({
|
||||
target,
|
||||
@ -67,7 +69,12 @@ export class QuickEditForm extends DataBlockModel {
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
await this.form.submit();
|
||||
await this.resource.save(this.form.values);
|
||||
await this.resource.save(
|
||||
{
|
||||
[this.fieldPath]: this.form.values[this.fieldPath],
|
||||
},
|
||||
{ refresh: false },
|
||||
);
|
||||
popover.destroy();
|
||||
resolve(this.form.values);
|
||||
}}
|
||||
@ -85,17 +92,18 @@ export class QuickEditForm extends DataBlockModel {
|
||||
);
|
||||
})}
|
||||
</FormLayout>
|
||||
<FormButtonGroup>
|
||||
<Submit
|
||||
htmlType="submit"
|
||||
onClick={async () => {
|
||||
await this.resource.save(this.form.values);
|
||||
<FormButtonGroup align="right">
|
||||
<Button
|
||||
onClick={() => {
|
||||
popover.destroy();
|
||||
resolve(this.form.values); // 在 close 之后 resolve
|
||||
reject(null); // 在 close 之后 resolve
|
||||
}}
|
||||
>
|
||||
{this.ctx.globals.flowEngine.translate('Submit')}
|
||||
</Submit>
|
||||
{this.translate('Cancel')}
|
||||
</Button>
|
||||
<Button type="primary" htmlType="submit">
|
||||
{this.translate('Submit')}
|
||||
</Button>
|
||||
</FormButtonGroup>
|
||||
</FormProvider>
|
||||
</FlowEngineProvider>
|
||||
@ -126,6 +134,7 @@ QuickEditForm.registerFlow({
|
||||
if (!dataSourceKey || !collectionName || !fieldPath) {
|
||||
throw new Error('dataSourceKey, collectionName and fieldPath are required parameters');
|
||||
}
|
||||
ctx.model.fieldPath = fieldPath;
|
||||
ctx.model.collection = ctx.globals.dataSourceManager.getCollection(dataSourceKey, collectionName);
|
||||
ctx.model.form = createForm();
|
||||
const resource = new SingleRecordResource();
|
||||
|
@ -156,6 +156,7 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
|
||||
<EditOutlined
|
||||
className="edit-icon"
|
||||
onClick={async (e) => {
|
||||
try {
|
||||
await QuickEditForm.open({
|
||||
target: ref.current,
|
||||
flowEngine: this.flowEngine,
|
||||
@ -165,6 +166,9 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
|
||||
filterByTk: record.id,
|
||||
});
|
||||
await this.resource.refresh();
|
||||
} catch (error) {
|
||||
// console.error('Error stopping event propagation:', error);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
|
@ -15,7 +15,7 @@ export class SingleRecordResource<TData = any> extends BaseRecordResource<TData>
|
||||
return this;
|
||||
}
|
||||
|
||||
async save(data: TData): Promise<void> {
|
||||
async save(data: TData, config: { refresh?: boolean } = {}): Promise<void> {
|
||||
const options: any = {
|
||||
headers: this.request.headers,
|
||||
params: {},
|
||||
@ -29,7 +29,7 @@ export class SingleRecordResource<TData = any> extends BaseRecordResource<TData>
|
||||
...options,
|
||||
data,
|
||||
});
|
||||
if (this.request.params.filterByTk) {
|
||||
if (config.refresh !== false && this.request.params.filterByTk) {
|
||||
await this.refresh();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user