| import type * as d3 from 'd3'; |
|
|
| |
| |
| |
| |
| |
| export type SyncDraftCommittedButtonPairOptions = { |
| primaryBtn: d3.Selection<any, unknown, any, any>; |
| forceRetryBtn: d3.Selection<any, unknown, any, any>; |
| inFlight: boolean; |
| |
| primaryInFlightMode: 'freeze' | 'stop'; |
| |
| primaryInFlightLabel?: string; |
| primaryIdleLabel: string; |
| |
| idleInputsReady: boolean; |
| hasUncommittedDraft: boolean; |
| }; |
|
|
| export function syncDraftCommittedButtonPair(opts: SyncDraftCommittedButtonPairOptions): void { |
| const { |
| primaryBtn, |
| forceRetryBtn, |
| inFlight, |
| primaryInFlightMode, |
| primaryInFlightLabel, |
| primaryIdleLabel, |
| idleInputsReady, |
| hasUncommittedDraft, |
| } = opts; |
|
|
| if (inFlight && primaryInFlightMode === 'stop') { |
| if (primaryInFlightLabel === undefined) { |
| throw new Error( |
| 'syncDraftCommittedButtonPair: primaryInFlightLabel is required when primaryInFlightMode is stop' |
| ); |
| } |
| primaryBtn.text(primaryInFlightLabel); |
| primaryBtn.property('disabled', false); |
| primaryBtn.classed('inactive', false); |
| forceRetryBtn.property('disabled', true); |
| forceRetryBtn.classed('inactive', true); |
| return; |
| } |
|
|
| if (inFlight && primaryInFlightMode === 'freeze') { |
| primaryBtn.property('disabled', true); |
| primaryBtn.classed('inactive', true); |
| forceRetryBtn.property('disabled', true); |
| forceRetryBtn.classed('inactive', true); |
| return; |
| } |
|
|
| primaryBtn.text(primaryIdleLabel); |
| if (!idleInputsReady) { |
| primaryBtn.property('disabled', true); |
| primaryBtn.classed('inactive', true); |
| forceRetryBtn.property('disabled', true); |
| forceRetryBtn.classed('inactive', true); |
| return; |
| } |
|
|
| const enablePrimary = hasUncommittedDraft; |
| const enableForceRetry = true; |
|
|
| primaryBtn.property('disabled', !enablePrimary); |
| primaryBtn.classed('inactive', !enablePrimary); |
| forceRetryBtn.property('disabled', !enableForceRetry); |
| forceRetryBtn.classed('inactive', !enableForceRetry); |
| } |
|
|