Improve MigrateStep and PullStep
This commit is contained in:
@@ -5709,9 +5709,6 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "1"],
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "2"]
|
||||
],
|
||||
"public/app/features/provisioning/GettingStarted/BootstrapStep.tsx:5381": [
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"]
|
||||
],
|
||||
"public/app/features/provisioning/GettingStarted/EnhancedFeatures.tsx:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "No untranslated strings in text props. Wrap text with <Trans /> or use t()", "1"],
|
||||
|
||||
@@ -23,48 +23,46 @@ export function MigrateStep({ onStatusChange, onRunningChange, onErrorChange }:
|
||||
const history = watch('migrate.history');
|
||||
const migrateName = migrateQuery.data?.metadata?.name;
|
||||
|
||||
// Handle initial migration
|
||||
useEffect(() => {
|
||||
// Early return conditions
|
||||
if (!repositoryName || hasInitialized.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
let isMounted = true;
|
||||
hasInitialized.current = true;
|
||||
let isMounted = true;
|
||||
|
||||
const handleError = (error: unknown) => {
|
||||
if (!isMounted) {
|
||||
return;
|
||||
}
|
||||
const errorMessage = error instanceof Error ? error.message : 'Failed to start migration operation';
|
||||
onErrorChange(errorMessage);
|
||||
onStatusChange(false);
|
||||
onRunningChange(false);
|
||||
};
|
||||
|
||||
const startMigrate = async () => {
|
||||
try {
|
||||
if (!isMounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
onRunningChange(true);
|
||||
const response = await migrateRepo({
|
||||
name: repositoryName,
|
||||
body: {
|
||||
identifier,
|
||||
history,
|
||||
},
|
||||
body: { identifier, history },
|
||||
}).unwrap();
|
||||
|
||||
if (response?.metadata?.name) {
|
||||
} else {
|
||||
onErrorChange('Invalid response from migration operation');
|
||||
onStatusChange(false);
|
||||
onRunningChange(false);
|
||||
}
|
||||
} catch (error) {
|
||||
if (!isMounted) {
|
||||
return;
|
||||
}
|
||||
onErrorChange(error instanceof Error ? error.message : 'Failed to start migration operation');
|
||||
onStatusChange(false);
|
||||
onRunningChange(false);
|
||||
|
||||
if (!response?.metadata?.name) {
|
||||
handleError(new Error('Invalid response from migration operation'));
|
||||
}
|
||||
} catch (error) {
|
||||
handleError(error);
|
||||
}
|
||||
};
|
||||
|
||||
startMigrate();
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
|
||||
@@ -21,47 +21,46 @@ export function PullStep({ onStatusChange, onRunningChange, onErrorChange }: Pul
|
||||
const repositoryName = watch('repositoryName');
|
||||
const syncName = syncQuery.data?.metadata?.name;
|
||||
|
||||
// Handle initial sync
|
||||
useEffect(() => {
|
||||
// Early return conditions
|
||||
if (!repositoryName || hasInitialized.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
let isMounted = true;
|
||||
hasInitialized.current = true;
|
||||
let isMounted = true;
|
||||
|
||||
const handleError = (error: unknown) => {
|
||||
if (!isMounted) {
|
||||
return;
|
||||
}
|
||||
const errorMessage = error instanceof Error ? error.message : 'Failed to start sync operation';
|
||||
onErrorChange(errorMessage);
|
||||
onStatusChange(false);
|
||||
onRunningChange(false);
|
||||
};
|
||||
|
||||
const startSync = async () => {
|
||||
try {
|
||||
if (!isMounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
onRunningChange(true);
|
||||
const response = await syncRepo({
|
||||
name: repositoryName,
|
||||
body: {
|
||||
incremental: false,
|
||||
},
|
||||
body: { incremental: false },
|
||||
}).unwrap();
|
||||
|
||||
if (response?.metadata?.name) {
|
||||
} else {
|
||||
onErrorChange('Invalid response from sync operation');
|
||||
onStatusChange(false);
|
||||
onRunningChange(false);
|
||||
}
|
||||
} catch (error) {
|
||||
if (!isMounted) {
|
||||
return;
|
||||
}
|
||||
onErrorChange(error instanceof Error ? error.message : 'Failed to start sync operation');
|
||||
onStatusChange(false);
|
||||
onRunningChange(false);
|
||||
|
||||
if (!response?.metadata?.name) {
|
||||
handleError(new Error('Invalid response from sync operation'));
|
||||
}
|
||||
} catch (error) {
|
||||
handleError(error);
|
||||
}
|
||||
};
|
||||
|
||||
startSync();
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user