oakCommit去掉了之前假设是在singlenode的约束

This commit is contained in:
Xu Chang 2024-03-28 22:40:24 +08:00
parent 0d1e6bf7be
commit ddccbd6e9e
5 changed files with 15 additions and 29 deletions

View File

@ -3,7 +3,7 @@ import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity';
import { ReactComponentProps } from 'oak-frontend-base/lib/types/Page';
import { ButtonProps } from 'antd';
import { ButtonProps as AmButtonProps } from 'antd-mobile';
type AfterCommit = ((id?: string) => void) | undefined;
type AfterCommit = (() => void) | undefined;
type BeforeCommit = (() => boolean | undefined | Promise<boolean | undefined>) | undefined;
declare const _default: <ED2 extends EntityDict & BaseEntityDict, T2 extends keyof ED2>(props: ReactComponentProps<ED2, T2, true, {
action?: string | undefined;
@ -12,7 +12,7 @@ declare const _default: <ED2 extends EntityDict & BaseEntityDict, T2 extends key
type?: ButtonProps['type'] | AmButtonProps['type'];
executeText?: string | undefined;
buttonProps?: (ButtonProps & {
color?: "default" | "success" | "warning" | "primary" | "danger" | undefined;
color?: "default" | "success" | "primary" | "warning" | "danger" | undefined;
fill?: "none" | "solid" | "outline" | undefined;
size?: "small" | "middle" | "large" | "mini" | undefined;
block?: boolean | undefined;
@ -21,10 +21,10 @@ declare const _default: <ED2 extends EntityDict & BaseEntityDict, T2 extends key
loadingIcon?: import("react").ReactNode;
disabled?: boolean | undefined;
onClick?: ((event: import("react").MouseEvent<HTMLButtonElement, MouseEvent>) => unknown) | undefined;
type?: "button" | "reset" | "submit" | undefined;
type?: "button" | "submit" | "reset" | undefined;
shape?: "default" | "rounded" | "rectangular" | undefined;
children?: import("react").ReactNode;
} & Pick<import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement>, "id" | "onMouseDown" | "onMouseUp" | "onTouchEnd" | "onTouchStart"> & {
} & Pick<import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement>, "id" | "onMouseDown" | "onMouseUp" | "onTouchStart" | "onTouchEnd"> & {
className?: string | undefined;
style?: (import("react").CSSProperties & Partial<Record<"--text-color" | "--background-color" | "--border-radius" | "--border-width" | "--border-style" | "--border-color", string>>) | undefined;
tabIndex?: number | undefined;

View File

@ -39,7 +39,6 @@ export default OakComponent({
},
data: {
failureIds: undefined,
currentId: undefined,
},
lifetimes: {
ready() {
@ -130,42 +129,36 @@ export default OakComponent({
return;
}
}
const id = this.getId();
await this.execute(undefined, messageProps);
const failureIds = await this.upload(ids);
if (failureIds && failureIds.length > 0) {
this.setState({
failureIds,
currentId: id,
});
return;
}
this.setState({
failureIds: undefined,
currentId: undefined,
});
if (afterCommit) {
afterCommit(id);
afterCommit();
}
}
else {
const { failureIds, currentId } = this.state;
const id2 = currentId;
const { failureIds } = this.state;
assert(failureIds && failureIds.length > 0);
const failureIds2 = await this.upload(failureIds);
if (failureIds2 && failureIds2.length > 0) {
this.setState({
failureIds: failureIds2,
currentId: id2,
});
return;
}
this.setState({
failureIds: undefined,
currentId: undefined,
});
if (afterCommit) {
afterCommit(id2);
afterCommit();
}
}
},

View File

@ -3,9 +3,9 @@ import { Button } from 'antd-mobile';
export default function render(props) {
const { state, oakExecutable, oakExecuting, oakDirty, size, block, type, executeText, failureIds, buttonProps, } = props.data;
const { t, onSubmit } = props.methods;
const disabled = oakExecuting ||
const disabled = (oakExecuting ||
['uploading'].includes(state) ||
oakExecutable !== true && !failureIds;
(oakExecutable !== true && ['uploaded'].includes(state))) && !failureIds;
let text = executeText || t('common::submit');
if (oakExecuting) {
text = t('executing', { text });

View File

@ -1,6 +1,6 @@
import { EntityDict } from '../../../oak-app-domain';
declare const _default: (props: import("oak-frontend-base").ReactComponentProps<EntityDict, keyof EntityDict, false, {
type: "login" | "bind";
type: "bind" | "login";
url: string;
}>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
export default _default;

View File

@ -7,7 +7,7 @@ import { MessageProps } from 'oak-frontend-base/lib/types/Message';
import { ButtonProps } from 'antd';
import { ButtonProps as AmButtonProps } from 'antd-mobile';
type AfterCommit = ((id?: string) => void) | undefined;
type AfterCommit = (() => void) | undefined;
type BeforeCommit =
| (() => boolean | undefined | Promise<boolean | undefined>)
| undefined;
@ -51,7 +51,6 @@ export default OakComponent({
},
data: {
failureIds: undefined as string[] | undefined,
currentId: undefined as string | undefined,
},
lifetimes: {
ready() {
@ -166,42 +165,36 @@ export default OakComponent({
return;
}
}
const id = this.getId();
await this.execute(undefined, messageProps);
const failureIds = await this.upload(ids);
if (failureIds && failureIds.length > 0) {
this.setState({
failureIds,
currentId: id,
});
return;
}
this.setState({
failureIds: undefined,
currentId: undefined,
});
if (afterCommit) {
afterCommit(id);
afterCommit();
}
} else {
const { failureIds, currentId } = this.state;
const id2 = currentId;
const { failureIds } = this.state;
assert(failureIds && failureIds.length > 0);
const failureIds2 = await this.upload(failureIds);
if (failureIds2 && failureIds2.length > 0) {
this.setState({
failureIds: failureIds2,
currentId: id2,
});
return;
}
this.setState({
failureIds: undefined,
currentId: undefined,
});
if (afterCommit) {
afterCommit(id2);
afterCommit();
}
}
},