refactor(wecom): carry the failed result in the page presentation
The presentation keeps the failed operation result itself instead of a flag, and the section labels non-step phases from the shared `status.*` copy.
This commit is contained in:
1 parent
1c869dabef
commit
d930c4daf4
2 files changed
+7
-8
No files matched your search
@@ -13,9 +13,8 @@ export function WecomConnectionSection(props: FaceProps): ReactNode {
|
||||
const { useWecomConnection, check, connect, cancel, openAuthorization, retry, t } = props
|
||||
const snapshot = useWecomConnection(value => value)
|
||||
const shown = presentConnection(snapshot)
|
||||
const failed = 'failed' in shown && shown.failed ? snapshot.view?.result : undefined
|
||||
const actions: CliAccountAction[] = []
|
||||
let status = t(`status.${shown.phase === 'connecting' ? 'checking' : shown.phase}`)
|
||||
let status: string | undefined
|
||||
let detail: string | undefined
|
||||
switch (shown.phase) {
|
||||
case 'disconnected': actions.push({ label: t('action.connect'), onClick: connect, variant: 'primary' }); detail = t('detail.disconnected'); break
|
||||
@@ -34,7 +33,7 @@ export function WecomConnectionSection(props: FaceProps): ReactNode {
|
||||
}
|
||||
return (
|
||||
<CliAccountSection t={t} packageName={WECOM_PACKAGE} phase={shown.phase} status={status} busy={snapshot.busy} linked={snapshot.linked}
|
||||
actions={actions} detail={detail} failure={failed === undefined ? undefined : { text: t('failed'), command: failed.failure }} />
|
||||
actions={actions} detail={detail} failure={'failed' in shown && shown.failed !== undefined ? { text: t('failed'), command: shown.failed.failure } : undefined} />
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ export type WecomNotice = 'connected'
|
||||
export type ConnectionSnapshot = CliAccountSnapshot<WecomState, WecomNotice>
|
||||
|
||||
export type ConnectionPresentation =
|
||||
| { readonly phase: Exclude<CliAccountPhase, 'connecting'>; readonly failed: boolean }
|
||||
| { readonly phase: Exclude<CliAccountPhase, 'connecting'>; readonly failed: WecomState['result'] }
|
||||
| { readonly phase: 'connecting'; readonly step: 'authorizing' | 'connecting'; readonly url: string | undefined; readonly cancellable: boolean }
|
||||
|
||||
export interface ConnectionFace {
|
||||
@@ -26,9 +26,9 @@ export interface ConnectionFace {
|
||||
}
|
||||
|
||||
export function presentConnection({ view, stopped }: Pick<ConnectionSnapshot, 'view' | 'stopped'>): ConnectionPresentation {
|
||||
if (stopped) return { phase: 'stopped', failed: false }
|
||||
if (stopped) return { phase: 'stopped', failed: undefined }
|
||||
const operation = view?.operation
|
||||
if (view === undefined || operation?.kind === 'check') return { phase: 'checking', failed: false }
|
||||
if (view === undefined || operation?.kind === 'check') return { phase: 'checking', failed: undefined }
|
||||
if (operation !== undefined) {
|
||||
return {
|
||||
phase: 'connecting',
|
||||
@@ -37,9 +37,9 @@ export function presentConnection({ view, stopped }: Pick<ConnectionSnapshot, 'v
|
||||
cancellable: operation.cancellable,
|
||||
}
|
||||
}
|
||||
const failed = view.result?.outcome === 'failed'
|
||||
const failed = view.result?.outcome === 'failed' ? view.result : undefined
|
||||
switch (view.account.state) {
|
||||
case 'unchecked': return { phase: failed ? 'unavailable' : 'checking', failed }
|
||||
case 'unchecked': return { phase: failed === undefined ? 'checking' : 'unavailable', failed }
|
||||
case 'unauthorized': return { phase: 'disconnected', failed }
|
||||
case 'authorized': return { phase: 'connected', failed }
|
||||
/* v8 ignore next -- closed account state union */
|
||||
|
||||
Reference in new issue
Block a user