forked from openshift-assisted/assisted-installer-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClusterWizardFooter.tsx
126 lines (114 loc) · 3.91 KB
/
ClusterWizardFooter.tsx
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
import React from 'react';
import { useNavigate } from 'react-router-dom-v5-compat';
import { Alert, AlertGroup, AlertVariant } from '@patternfly/react-core';
import {
WizardFooter,
WizardFooterGenericProps,
Alerts,
useAlerts,
clusterFieldLabels,
selectClusterValidationsInfo,
} from '../../../common';
import { wizardStepsValidationsMap } from './wizardTransition';
import { useClusterWizardContext } from './ClusterWizardContext';
import ClusterWizardStepValidationsAlert from '../../../common/components/clusterWizard/ClusterWizardStepValidationsAlert';
import { useTranslation } from '../../../common/hooks/use-translation-wrapper';
import { onFetchEvents } from '../fetching/fetchEvents';
import { Cluster } from '@openshift-assisted/types/assisted-installer-service';
import { useFeature } from '../../hooks/use-feature';
import { useModalDialogsContext } from '../hosts/ModalDialogsContext';
type ClusterValidationSectionProps = {
cluster?: Cluster;
errorFields?: string[];
alertTitle?: string;
alertContent?: string | null;
};
const defaultAlertTitle = 'Provided cluster configuration is not valid';
const ValidationSection = ({
cluster,
errorFields = [],
alertTitle,
alertContent,
}: ClusterValidationSectionProps) => {
const { currentStepId } = useClusterWizardContext();
const validationsInfo = cluster && selectClusterValidationsInfo(cluster);
const { uiSettings } = useClusterWizardContext();
const { t } = useTranslation();
let _alertContent = alertContent;
if (_alertContent === undefined) {
_alertContent = `The following fields are invalid or missing:
${errorFields.map((field: string) => clusterFieldLabels(t)[field] || field).join(', ')}.`;
}
return (
<AlertGroup>
{!!errorFields.length && (
<Alert variant={AlertVariant.danger} title={alertTitle || defaultAlertTitle} isInline>
{_alertContent}
</Alert>
)}
{cluster && (
<ClusterWizardStepValidationsAlert
currentStepId={currentStepId}
clusterStatus={cluster.status}
hosts={cluster?.hosts || []}
validationsInfo={validationsInfo}
wizardStepsValidationsMap={wizardStepsValidationsMap}
lastInstallationPreparation={cluster['last-installation-preparation']}
uiSettings={uiSettings}
/>
)}
</AlertGroup>
);
};
type ClusterWizardFooterProps = WizardFooterGenericProps & {
cluster?: Cluster;
additionalActions?: React.ReactNode;
errorFields?: string[];
alertTitle?: string;
alertContent?: string | null;
};
const ClusterWizardFooter = ({
cluster,
additionalActions,
errorFields,
alertTitle,
alertContent,
onCancel,
...rest
}: ClusterWizardFooterProps) => {
const { alerts } = useAlerts();
const navigate = useNavigate();
const isSingleClusterFeatureEnabled = useFeature('ASSISTED_INSTALLER_SINGLE_CLUSTER_FEATURE');
const { currentStepId } = useClusterWizardContext();
const { resetSingleClusterDialog } = useModalDialogsContext();
const handleCancel = React.useCallback(() => navigate('/cluster-list'), [navigate]);
const handleReset = React.useCallback(() => {
resetSingleClusterDialog.open({ cluster });
}, [resetSingleClusterDialog, cluster]);
const alertsSection = alerts.length ? <Alerts /> : undefined;
const errorsSection = (
<ValidationSection
cluster={cluster}
errorFields={errorFields}
alertTitle={alertTitle}
alertContent={alertContent}
/>
);
return (
<WizardFooter
alerts={alertsSection}
errors={errorsSection}
onCancel={isSingleClusterFeatureEnabled ? undefined : onCancel || handleCancel}
onReset={
isSingleClusterFeatureEnabled && currentStepId !== 'cluster-details'
? handleReset
: undefined
}
leftExtraActions={additionalActions}
cluster={cluster}
onFetchEvents={onFetchEvents}
{...rest}
/>
);
};
export default ClusterWizardFooter;