Skip to content

Commit

Permalink
chore: remove usage of edit mode on the wizard (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-silva authored Feb 14, 2025
1 parent a00ecba commit 0b8c150
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const DatabaseFormBody = ({
<form style={{ flexGrow: 1 }} onSubmit={onSubmit}>
<Box>
{(mode === 'new' ||
((mode === 'edit' || mode === 'restoreFromBackup') &&
(mode === 'restoreFromBackup' &&
dbClusterRequestStatus === 'success')) &&
React.createElement(steps[activeStep], {
loadingDefaultsForEdition,
Expand All @@ -57,7 +57,6 @@ const DatabaseFormBody = ({
disableSubmit={isSubmitting || hasErrors}
disableCancel={isSubmitting}
showSubmit={activeStep === steps.length - 1}
editMode={mode === 'edit'}
onPreviousClick={handlePreviousStep}
onNextClick={handleNextStep}
onCancel={onCancel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const DatabaseFormStepControllers = ({
disableSubmit,
disableCancel,
showSubmit,
editMode,
onPreviousClick,
onNextClick,
onCancel,
Expand Down Expand Up @@ -59,7 +58,7 @@ const DatabaseFormStepControllers = ({
disabled={disableSubmit}
data-testid="db-wizard-submit-button"
>
{editMode ? Messages.editDatabase : Messages.createDatabase}
{Messages.createDatabase}
</Button>
) : (
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,5 @@ export const Messages = {
},
disableShardingTooltip:
'Sharding cannot be enabled unless the PSMDB operator version is 1.17.0 or higher',
disableShardingInEditMode:
'Sharding cannot be enabled/disabled after the database is created',
noEnginesAvailable: 'No engines available for any namespace',
};
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ export const FirstStep = ({ loadingDefaultsForEdition }: StepProps) => {
) {
return;
}
if (
((mode === 'edit' || mode === 'restoreFromBackup') && !dbVersion) ||
mode === 'new'
) {
if ((mode === 'restoreFromBackup' && !dbVersion) || mode === 'new') {
const recommendedVersion = dbEngineData.availableVersions.engine.find(
(version) => version.status === DbEngineToolStatus.RECOMMENDED
);
Expand Down Expand Up @@ -243,11 +240,7 @@ export const FirstStep = ({ loadingDefaultsForEdition }: StepProps) => {
label={Messages.labels.k8sNamespace}
loading={isFetching}
options={filteredNamespaces}
disabled={
mode === 'edit' ||
mode === 'restoreFromBackup' ||
loadingDefaultsForEdition
}
disabled={mode === 'restoreFromBackup' || loadingDefaultsForEdition}
onChange={onNamespaceChange}
autoCompleteProps={{
disableClearable: true,
Expand All @@ -260,7 +253,7 @@ export const FirstStep = ({ loadingDefaultsForEdition }: StepProps) => {
label={Messages.labels.dbName}
textFieldProps={{
placeholder: Messages.placeholders.dbName,
disabled: mode === 'edit' || loadingDefaultsForEdition,
disabled: loadingDefaultsForEdition,
}}
/>
<DbVersion
Expand All @@ -276,7 +269,7 @@ export const FirstStep = ({ loadingDefaultsForEdition }: StepProps) => {
options={clusterInfo?.storageClassNames || []}
autoCompleteProps={{
disableClearable: true,
disabled: mode === 'edit' || loadingDefaultsForEdition,
disabled: loadingDefaultsForEdition,
}}
/>
{dbType === DbType.Mongo && (
Expand Down Expand Up @@ -304,19 +297,9 @@ export const FirstStep = ({ loadingDefaultsForEdition }: StepProps) => {
},
}}
/>
{notSupportedMongoOperatorVersionForSharding &&
mode !== 'edit' && (
<Tooltip
title={Messages.disableShardingTooltip}
arrow
placement="right"
>
<InfoOutlinedIcon color="primary" />
</Tooltip>
)}
{mode === 'edit' && (
{notSupportedMongoOperatorVersionForSharding && (
<Tooltip
title={Messages.disableShardingInEditMode}
title={Messages.disableShardingTooltip}
arrow
placement="right"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const Monitoring = () => {
}
}
if (
(mode === 'edit' || mode === 'restoreFromBackup') &&
mode === 'restoreFromBackup' &&
availableMonitoringInstances?.length &&
!selectedInstance
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ export const ResourcesStep = () => {
/>
<ResourcesForm
dbType={dbType}
pairProxiesWithNodes={mode !== 'edit'}
disableDiskInput={mode === 'edit'}
allowDiskInputUpdate={mode !== 'edit'}
pairProxiesWithNodes
allowDiskInputUpdate
showSharding={dbType === DbType.Mongo}
hideProxies={dbType === DbType.Mongo && !shardingEnabled}
disableShardingInput={mode === 'restoreFromBackup'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export type DatabaseFormStepControllersProps = {
disableSubmit: boolean;
disableCancel: boolean;
showSubmit: boolean;
editMode: boolean;
onPreviousClick: () => void;
onNextClick: () => void;
onCancel: () => void;
Expand Down
2 changes: 1 addition & 1 deletion ui/apps/everest/src/pages/database-form/database-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export const DatabasePage = () => {
return;
}

if (mode === 'edit' || mode === 'restoreFromBackup') {
if (mode === 'restoreFromBackup') {
reset(defaultValues);
}
}, [defaultValues, isDirty, reset, mode]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

export type DbWizardMode = 'edit' | 'new' | 'restoreFromBackup';
export type DbWizardMode = 'new' | 'restoreFromBackup';

export type StepProps = {
loadingDefaultsForEdition: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const DbClusterPayloadToFormValues = (
? (backup?.schedules || []).length > 0
: backup?.pitr?.enabled || false,
[DbWizardFormFields.pitrStorageLocation]:
(backup?.pitr?.enabled && mode === 'new') || mode === 'edit'
backup?.pitr?.enabled && mode === 'new'
? backup?.pitr?.backupStorageName || null
: DB_WIZARD_DEFAULTS[DbWizardFormFields.pitrStorageLocation],
[DbWizardFormFields.schedules]: backup?.schedules || [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { previewSections } from './sections/constants';
import { Messages } from './database.preview.messages';
import { PreviewSection } from './preview-section';
import { DbWizardType } from '../database-form-schema.ts';
import { useDatabasePageMode } from '../useDatabasePageMode.ts';

export const DatabasePreview = ({
activeStep,
Expand All @@ -20,7 +19,6 @@ export const DatabasePreview = ({
getValues,
formState: { errors },
} = useFormContext<DbWizardType>();
const mode = useDatabasePageMode();

// Under normal circumstances, useWatch should return the right values
// But the initial setValue are not taking effect
Expand All @@ -38,7 +36,7 @@ export const DatabasePreview = ({
<PreviewSection
order={idx + 1}
title={Messages.preview[idx]}
hasBeenReached={longestAchievedStep >= idx || mode === 'edit'}
hasBeenReached={longestAchievedStep >= idx}
active={activeStep === idx}
disabled={disabled || Object.values(errors).length != 0}
onEditClick={() => onSectionEdit(idx + 1)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export const useDatabasePageDefaultValues = (
} => {
const { state } = useLocation();
const shouldRetrieveDbClusterData =
(mode === 'edit' || mode === 'restoreFromBackup') &&
!!state?.selectedDbCluster;
mode === 'restoreFromBackup' && !!state?.selectedDbCluster;
const namespace = shouldRetrieveDbClusterData ? state?.namespace : null;
const {
data: dbCluster,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import { DbWizardMode } from './database-form.types';

export const useDatabasePageMode = (): DbWizardMode => {
const { state } = useLocation();
if (state?.selectedDbCluster) {
if (state?.backupName) {
return 'restoreFromBackup';
}
return 'edit';
if (state?.selectedDbCluster && state?.backupName) {
return 'restoreFromBackup';
}
return 'new';
};

0 comments on commit 0b8c150

Please sign in to comment.