Update context transaction states

pull/21833/head
Travis Ralston 2020-07-31 10:00:02 -06:00
parent 16ebcf70c9
commit 7645fe6b23
4 changed files with 14 additions and 14 deletions

View File

@ -56,10 +56,10 @@ export default class ServerOfflineDialog extends React.PureComponent<IProps> {
</div>
);
const entries = c.transactions
.filter(t => t.status === TransactionStatus.DoneError || t.didPreviouslyFail)
.filter(t => t.status === TransactionStatus.Error || t.didPreviouslyFail)
.map((t, j) => {
let button = <Spinner w={19} h={19} />;
if (t.status === TransactionStatus.DoneError) {
if (t.status === TransactionStatus.Error) {
button = (
<AccessibleButton kind="link" onClick={() => t.run()}>{_t("Resend")}</AccessibleButton>
);

View File

@ -38,7 +38,7 @@ export abstract class EchoContext extends Whenable<ContextTransactionState> impl
}
public get firstFailedTime(): Date {
const failedTxn = this.transactions.find(t => t.didPreviouslyFail || t.status === TransactionStatus.DoneError);
const failedTxn = this.transactions.find(t => t.didPreviouslyFail || t.status === TransactionStatus.Error);
if (failedTxn) return failedTxn.startTime;
return null;
}
@ -57,7 +57,7 @@ export abstract class EchoContext extends Whenable<ContextTransactionState> impl
// We have no intent to call the transaction again if it succeeds (in fact, it'll
// be really angry at us if we do), so call that the end of the road for the events.
txn.when(TransactionStatus.DoneSuccess, () => txn.destroy());
txn.when(TransactionStatus.Success, () => txn.destroy());
return txn;
}
@ -65,7 +65,7 @@ export abstract class EchoContext extends Whenable<ContextTransactionState> impl
private checkTransactions = () => {
let status = ContextTransactionState.AllSuccessful;
for (const txn of this.transactions) {
if (txn.status === TransactionStatus.DoneError || txn.didPreviouslyFail) {
if (txn.status === TransactionStatus.Error || txn.didPreviouslyFail) {
status = ContextTransactionState.PendingErrors;
break;
} else if (txn.status === TransactionStatus.Pending) {

View File

@ -20,8 +20,8 @@ export type RunFn = () => Promise<void>;
export enum TransactionStatus {
Pending,
DoneSuccess,
DoneError,
Success,
Error,
}
export class EchoTransaction extends Whenable<TransactionStatus> {
@ -46,25 +46,25 @@ export class EchoTransaction extends Whenable<TransactionStatus> {
}
public run() {
if (this.status === TransactionStatus.DoneSuccess) {
if (this.status === TransactionStatus.Success) {
throw new Error("Cannot re-run a successful echo transaction");
}
this.setStatus(TransactionStatus.Pending);
this.runFn()
.then(() => this.setStatus(TransactionStatus.DoneSuccess))
.catch(() => this.setStatus(TransactionStatus.DoneError));
.then(() => this.setStatus(TransactionStatus.Success))
.catch(() => this.setStatus(TransactionStatus.Error));
}
public cancel() {
// Success basically means "done"
this.setStatus(TransactionStatus.DoneSuccess);
this.setStatus(TransactionStatus.Success);
}
private setStatus(status: TransactionStatus) {
this._status = status;
if (status === TransactionStatus.DoneError) {
if (status === TransactionStatus.Error) {
this.didFail = true;
} else if (status === TransactionStatus.DoneSuccess) {
} else if (status === TransactionStatus.Success) {
this.didFail = false;
}
this.notifyCondition(status);

View File

@ -84,7 +84,7 @@ export abstract class GenericEchoChamber<C extends EchoContext, K, V> extends Ev
this.cacheVal(key, targetVal, txn); // set the cache now as it won't be updated by the .when() ladder below.
txn.when(TransactionStatus.Pending, () => this.cacheVal(key, targetVal, txn))
.when(TransactionStatus.DoneError, () => revertFn());
.when(TransactionStatus.Error, () => revertFn());
txn.run();
}