-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathnextStepFooter.tsx
More file actions
203 lines (188 loc) · 6.48 KB
/
nextStepFooter.tsx
File metadata and controls
203 lines (188 loc) · 6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { Trans } from "@lingui/macro";
import { useMemo } from "react";
import { useDisclosure } from "components/Modal/useDisclosure";
import { FooterStatus } from "components/status/footer";
import { IStatusAndButton } from "components/status/statusAndButton";
import {
AbortModal,
ConfirmModal,
ScheduleUpgradeModal,
} from "plugins/lime-plugin-mesh-wide-upgrade/src/components/modals";
import { useMeshUpgrade } from "plugins/lime-plugin-mesh-wide-upgrade/src/hooks/meshWideUpgradeProvider";
import { useParallelScheduleUpgrade } from "plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradeQueries";
import { StepperState } from "plugins/lime-plugin-mesh-wide-upgrade/src/meshUpgradeTypes";
export type ShowFooterStepperState = Extract<
StepperState,
| "UPDATE_AVAILABLE"
| "DOWNLOADED_MAIN"
| "TRANSACTION_STARTED"
| "UPGRADE_SCHEDULED"
| "CONFIRMATION_PENDING"
| "ERROR"
>;
export function isShowFooterStepperState(
value: string
): value is ShowFooterStepperState {
return [
"UPDATE_AVAILABLE",
"DOWNLOADED_MAIN",
"TRANSACTION_STARTED",
"UPGRADE_SCHEDULED",
"CONFIRMATION_PENDING",
"ERROR",
].includes(value);
}
function isShowAbortButtonState(
value: string
): value is ShowFooterStepperState {
return [
"TRANSACTION_STARTED",
"UPGRADE_SCHEDULED",
"CONFIRMATION_PENDING",
"ERROR",
].includes(value);
}
const NextStepFooter = () => {
const {
stepperState,
becomeMainNode,
startFwUpgradeTransaction,
allNodesReadyForUpgrade,
abort,
} = useMeshUpgrade();
const { errors: scheduleErrors } = useParallelScheduleUpgrade();
const {
open: showScheduleModal,
onOpen: openScheduleModal,
onClose: closeScheduleModal,
} = useDisclosure();
const {
open: showConfirmationModal,
onOpen: openConfirmationModal,
onClose: closeConfirmationModal,
} = useDisclosure();
const {
open: showAbort,
onOpen: openAbort,
onClose: closeAbort,
} = useDisclosure();
const showFooter = isShowFooterStepperState(stepperState);
const step: IStatusAndButton | null = useMemo(() => {
if (!showFooter) return null;
let step: IStatusAndButton;
switch (stepperState as ShowFooterStepperState) {
case "UPDATE_AVAILABLE":
step = {
status: "success",
onClick: () => becomeMainNode(),
children: (
<Trans>
Download remote firmware
<br />
to start mesh upgrade
</Trans>
),
btn: <Trans>Start mesh upgrade</Trans>,
};
break;
case "DOWNLOADED_MAIN":
step = {
status: "success",
onClick: startFwUpgradeTransaction,
children: <Trans>Ready to start mesh wide upgrade</Trans>,
btn: <Trans>Start</Trans>,
};
break;
case "TRANSACTION_STARTED":
step = {
status: allNodesReadyForUpgrade ? "success" : "warning",
onClick: openScheduleModal,
children: allNodesReadyForUpgrade ? (
<Trans>Ready to start mesh wide upgrade</Trans>
) : (
<Trans>
Some nodes are not ready for upgrade <br />
Check node details for more info
</Trans>
),
btn: <Trans>Schedule upgrade</Trans>,
};
break;
case "UPGRADE_SCHEDULED": {
const data: Omit<IStatusAndButton, "status" | "children"> = {
onClick: openScheduleModal,
btn: <Trans>Schedule again</Trans>,
};
if (scheduleErrors?.length) {
step = {
...data,
status: "warning",
children: <Trans>Some nodes have errors</Trans>,
};
}
step = {
...data,
status: "success",
children: <Trans>All nodes scheduled successful</Trans>,
};
break;
}
case "CONFIRMATION_PENDING":
step = {
status: "success",
onClick: openConfirmationModal,
children: <Trans>Confirm upgrade on all nodes</Trans>,
btn: <Trans>Confirm</Trans>,
};
break;
case "ERROR":
default:
step = {
status: "warning",
children: <Trans>Abort current upgrade process</Trans>,
};
}
if (isShowAbortButtonState(stepperState)) {
const showAbort: Pick<
IStatusAndButton,
"btnCancel" | "onClickCancel"
> = {
btnCancel: <Trans>Abort</Trans>,
onClickCancel: openAbort,
};
step = { ...step, ...showAbort };
}
return step;
}, [
abort,
allNodesReadyForUpgrade,
becomeMainNode,
scheduleErrors?.length,
showConfirmationModal,
showFooter,
showScheduleModal,
startFwUpgradeTransaction,
stepperState,
]);
return (
<>
{showFooter && (
<>
<FooterStatus {...step} fixed={false} />
<ScheduleUpgradeModal
isSuccess={allNodesReadyForUpgrade}
isOpen={showScheduleModal}
onClose={closeScheduleModal}
/>
<ConfirmModal
isOpen={showConfirmationModal}
onClose={closeConfirmationModal}
isSuccess // Ideally we have to implement some kind of state before run the upgrade to check if all nodes are up again.
/>
<AbortModal isOpen={showAbort} onClose={closeAbort} />
</>
)}
</>
);
};
export default NextStepFooter;