feat: quickEdit 支持配置 reload 可以实现不自动刷新的功能 (#5260)

This commit is contained in:
liaoxuezhi 2022-09-01 19:23:00 +08:00 committed by GitHub
parent 1583e64df6
commit 4b89a1416b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 115 additions and 43 deletions

View File

@ -1198,7 +1198,10 @@ export default class CRUD extends React.Component<CRUDProps, any> {
indexes: Array<string>,
unModifiedItems?: Array<any>,
rowsOrigin?: Array<object> | object,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) {
const {
store,
@ -1239,8 +1242,10 @@ export default class CRUD extends React.Component<CRUDProps, any> {
errorMessage: messages && messages.saveSuccess
})
.then(() => {
reload && this.reloadTarget(reload, data);
this.search(undefined, undefined, true, true);
const finalReload = options?.reload ?? reload;
finalReload
? this.reloadTarget(finalReload, data)
: this.search(undefined, undefined, true, true);
})
.catch(() => {});
} else {
@ -1259,11 +1264,13 @@ export default class CRUD extends React.Component<CRUDProps, any> {
store
.saveRemote(quickSaveItemApi, sendData)
.then(() => {
reload && this.reloadTarget(reload, data);
this.search(undefined, undefined, true, true);
const finalReload = options?.reload ?? reload;
finalReload
? this.reloadTarget(finalReload, data)
: this.search(undefined, undefined, true, true);
})
.catch(() => {
resetOnFailed && this.control.reset();
options?.resetOnFailed && this.control.reset();
});
}
}

View File

@ -602,7 +602,10 @@ export default class CRUD2 extends React.Component<CRUD2Props, any> {
indexes: Array<string>,
unModifiedItems?: Array<any>,
rowsOrigin?: Array<object> | object,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) {
const {
store,
@ -667,7 +670,7 @@ export default class CRUD2 extends React.Component<CRUD2Props, any> {
this.getData(undefined, undefined, true, true);
})
.catch(() => {
resetOnFailed && this.control.reset();
options?.resetOnFailed && this.control.reset();
});
}
}

View File

@ -337,11 +337,14 @@ export class CardRenderer extends React.Component<CardProps> {
values: object,
saveImmediately?: boolean,
savePristine?: boolean,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) {
const {onQuickChange, item} = this.props;
onQuickChange &&
onQuickChange(item, values, saveImmediately, savePristine, resetOnFailed);
onQuickChange(item, values, saveImmediately, savePristine, options);
}
renderToolbar() {

View File

@ -163,7 +163,10 @@ export interface GridProps
rowIndexes: Array<number> | number,
unModifiedItems?: Array<object>,
rowOrigins?: Array<object> | object,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) => void;
onSaveOrder?: (moved: Array<object>, items: Array<object>) => void;
onQuery: (values: object) => void;
@ -481,12 +484,15 @@ export default class Cards extends React.Component<GridProps, object> {
item: IItem,
values: object,
saveImmediately?: boolean | any,
saveSilent?: boolean,
resetOnFailed?: boolean
savePristine?: boolean,
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) {
item.change(values, saveSilent);
item.change(values, savePristine);
if (!saveImmediately || saveSilent) {
if (!saveImmediately || savePristine) {
return;
}
@ -495,7 +501,8 @@ export default class Cards extends React.Component<GridProps, object> {
null,
{
actionType: 'ajax',
api: saveImmediately.api
api: saveImmediately.api,
reload: options?.reload
},
values
);
@ -514,7 +521,7 @@ export default class Cards extends React.Component<GridProps, object> {
item.index,
undefined,
item.pristine,
resetOnFailed
options
);
}

View File

@ -69,7 +69,15 @@ export default class StaticControl extends React.Component<StaticProps, any> {
this.handleQuickChange = this.handleQuickChange.bind(this);
}
async handleQuickChange(values: any, saveImmediately: boolean | any) {
async handleQuickChange(
values: any,
saveImmediately: boolean | any,
savePristine?: boolean,
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) {
const {onBulkChange, onAction, data} = this.props;
if (saveImmediately && saveImmediately.api) {
@ -77,7 +85,8 @@ export default class StaticControl extends React.Component<StaticProps, any> {
null,
{
actionType: 'ajax',
api: saveImmediately.api
api: saveImmediately.api,
reload: options?.reload
},
extendObject(data, values),
true

View File

@ -246,7 +246,10 @@ export interface ListProps
rowIndexes: Array<number> | number,
unModifiedItems?: Array<object>,
rowOrigins?: Array<object> | object,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) => void;
onSaveOrder?: (moved: Array<object>, items: Array<object>) => void;
onQuery: (values: object) => void;
@ -492,7 +495,10 @@ export default class List extends React.Component<ListProps, object> {
values: object,
saveImmediately?: boolean | any,
savePristine?: boolean,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) {
item.change(values, savePristine);
@ -505,7 +511,8 @@ export default class List extends React.Component<ListProps, object> {
null,
{
actionType: 'ajax',
api: saveImmediately.api
api: saveImmediately.api,
reload: options?.reload
},
values
);
@ -524,7 +531,7 @@ export default class List extends React.Component<ListProps, object> {
item.index,
undefined,
item.pristine,
resetOnFailed
options
);
}
@ -1101,11 +1108,14 @@ export class ListItem extends React.Component<ListItemProps> {
values: object,
saveImmediately?: boolean,
savePristine?: boolean,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) {
const {onQuickChange, item} = this.props;
onQuickChange &&
onQuickChange(item, values, saveImmediately, savePristine, resetOnFailed);
onQuickChange(item, values, saveImmediately, savePristine, options);
}
renderLeft() {

View File

@ -29,6 +29,12 @@ export type SchemaQuickEditObject =
*/
resetOnFailed?: boolean;
/**
* crud
* "none"
*/
reload?: string;
/**
*
*/
@ -49,6 +55,12 @@ export type SchemaQuickEditObject =
*/
resetOnFailed?: boolean;
/**
* crud
* "none"
*/
reload?: string;
/**
*
*/
@ -62,6 +74,7 @@ export type SchemaQuickEdit = boolean | SchemaQuickEditObject;
export interface QuickEditConfig {
saveImmediately?: boolean;
resetOnFailed?: boolean;
reload?: string;
mode?: 'inline' | 'dialog' | 'popOver' | 'append';
type?: string;
body?: any;
@ -300,7 +313,7 @@ export const HocQuickEdit =
values,
(quickEdit as QuickEditConfig).saveImmediately,
false,
(quickEdit as QuickEditConfig).resetOnFailed
quickEdit as QuickEditConfig
);
return false;
@ -318,7 +331,7 @@ export const HocQuickEdit =
values,
(quickEdit as QuickEditConfig).saveImmediately,
false,
(quickEdit as QuickEditConfig).resetOnFailed
quickEdit as QuickEditConfig
);
}

View File

@ -72,11 +72,14 @@ export class TableRow extends React.Component<TableRowProps> {
values: object,
saveImmediately?: boolean,
savePristine?: boolean,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) {
const {onQuickChange, item} = this.props;
onQuickChange &&
onQuickChange(item, values, saveImmediately, savePristine, resetOnFailed);
onQuickChange(item, values, saveImmediately, savePristine, options);
}
handleChange(

View File

@ -357,7 +357,10 @@ export interface TableProps extends RendererProps {
rowIndexes: Array<string> | string,
unModifiedItems?: Array<object>,
rowOrigins?: Array<object> | object,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) => void;
onSaveOrder?: (moved: Array<object>, items: Array<object>) => void;
onQuery: (values: object) => void;
@ -918,7 +921,10 @@ export default class Table extends React.Component<TableProps, object> {
values: object,
saveImmediately?: boolean | any,
savePristine?: boolean,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) {
if (!isAlive(item)) {
return;
@ -948,7 +954,8 @@ export default class Table extends React.Component<TableProps, object> {
null,
{
actionType: 'ajax',
api: saveImmediately.api
api: saveImmediately.api,
reload: options?.reload
},
values
);
@ -965,7 +972,7 @@ export default class Table extends React.Component<TableProps, object> {
item.path,
undefined,
item.pristine,
resetOnFailed
options
);
}

View File

@ -694,14 +694,17 @@ export default class Table2 extends React.Component<Table2Props, object> {
values: object,
saveImmediately?: boolean,
savePristine?: boolean,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) => {
this.handleQuickChange(
item,
values,
saveImmediately,
savePristine,
resetOnFailed
options
);
},
row: item,
@ -842,7 +845,10 @@ export default class Table2 extends React.Component<Table2Props, object> {
indexes: Array<string>,
unModifiedItems?: Array<any>,
rowsOrigin?: Array<object> | object,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) {
const {
store,
@ -905,7 +911,7 @@ export default class Table2 extends React.Component<Table2Props, object> {
reload && this.reloadTarget(reload, data);
})
.catch(() => {
resetOnFailed && this.control.reset();
options?.resetOnFailed && this.control.reset();
});
}
}
@ -916,7 +922,10 @@ export default class Table2 extends React.Component<Table2Props, object> {
values: object,
saveImmediately?: boolean | any,
savePristine?: boolean,
resetOnFailed?: boolean
options?: {
resetOnFailed?: boolean;
reload?: string;
}
) {
if (!isAlive(item)) {
return;
@ -941,7 +950,8 @@ export default class Table2 extends React.Component<Table2Props, object> {
null,
{
actionType: 'ajax',
api: saveImmediately.api
api: saveImmediately.api,
reload: options?.reload
},
values
);
@ -951,19 +961,19 @@ export default class Table2 extends React.Component<Table2Props, object> {
onSave
? onSave(
item.data,
difference(item.data, item.pristine, ['id', primaryField]),
difference(item.data, item.pristine, ['id', primaryField!]),
item.path,
undefined,
item.pristine,
resetOnFailed
options
)
: this.handleSave(
quickSaveItemApi ? item.data : [item.data],
difference(item.data, item.pristine, ['id', primaryField]),
difference(item.data, item.pristine, ['id', primaryField!]),
[item.path],
undefined,
item.pristine,
resetOnFailed
options
);
}