mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-29 13:51:49 +00:00
Refactor Container Copy Jobs for Intra-account copy and Online operations (#2258)
* fix: for intra-account copy, validation screen should not visible * fix: handle online operations using a button instead manual CLI commands * reset validation cache on leaving of permission screen * update same account logic * fix: update job action menu list and permission screen messages * uplift error handling to context level * use of logError instead of console.error
This commit is contained in:
@@ -2,6 +2,7 @@ import { useCallback, useMemo, useReducer, useState } from "react";
|
||||
import { useSidePanel } from "../../../../hooks/useSidePanel";
|
||||
import { submitCreateCopyJob } from "../../Actions/CopyJobActions";
|
||||
import { useCopyJobContext } from "../../Context/CopyJobContext";
|
||||
import { isIntraAccountCopy } from "../../CopyJobUtils";
|
||||
import { CopyJobMigrationType } from "../../Enums/CopyJobEnums";
|
||||
import { useCopyJobPrerequisitesCache } from "./useCopyJobPrerequisitesCache";
|
||||
import { SCREEN_KEYS, useCreateCopyJobScreensList } from "./useCreateCopyJobScreensList";
|
||||
@@ -33,8 +34,7 @@ function navigationReducer(state: NavigationState, action: Action): NavigationSt
|
||||
|
||||
export function useCopyJobNavigation() {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const { copyJobState, resetCopyJobState } = useCopyJobContext();
|
||||
const { copyJobState, resetCopyJobState, setContextError } = useCopyJobContext();
|
||||
const screens = useCreateCopyJobScreensList();
|
||||
const { validationCache: cache } = useCopyJobPrerequisitesCache();
|
||||
const [state, dispatch] = useReducer(navigationReducer, { screenHistory: [SCREEN_KEYS.SelectAccount] });
|
||||
@@ -71,18 +71,13 @@ export function useCopyJobNavigation() {
|
||||
containerId: container?.containerId || "",
|
||||
});
|
||||
|
||||
const isSameAccount = (
|
||||
sourceIds: ReturnType<typeof getContainerIdentifiers>,
|
||||
targetIds: ReturnType<typeof getContainerIdentifiers>,
|
||||
) => sourceIds.accountId === targetIds.accountId;
|
||||
|
||||
const areContainersIdentical = () => {
|
||||
const { source, target } = copyJobState;
|
||||
const sourceIds = getContainerIdentifiers(source);
|
||||
const targetIds = getContainerIdentifiers(target);
|
||||
|
||||
return (
|
||||
isSameAccount(sourceIds, targetIds) &&
|
||||
isIntraAccountCopy(sourceIds.accountId, targetIds.accountId) &&
|
||||
sourceIds.databaseId === targetIds.databaseId &&
|
||||
sourceIds.containerId === targetIds.containerId
|
||||
);
|
||||
@@ -90,9 +85,10 @@ export function useCopyJobNavigation() {
|
||||
|
||||
const shouldNotShowPermissionScreen = () => {
|
||||
const { source, target, migrationType } = copyJobState;
|
||||
const sourceIds = getContainerIdentifiers(source);
|
||||
const targetIds = getContainerIdentifiers(target);
|
||||
return (
|
||||
migrationType === CopyJobMigrationType.Offline &&
|
||||
isSameAccount(getContainerIdentifiers(source), getContainerIdentifiers(target))
|
||||
migrationType === CopyJobMigrationType.Offline && isIntraAccountCopy(sourceIds.accountId, targetIds.accountId)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -105,7 +101,7 @@ export function useCopyJobNavigation() {
|
||||
error instanceof Error
|
||||
? error.message || "Failed to create copy job. Please try again later."
|
||||
: "Failed to create copy job. Please try again later.";
|
||||
setError(errorMessage);
|
||||
setContextError(errorMessage);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
@@ -113,11 +109,13 @@ export function useCopyJobNavigation() {
|
||||
|
||||
const handlePrimary = useCallback(() => {
|
||||
if (currentScreenKey === SCREEN_KEYS.SelectSourceAndTargetContainers && areContainersIdentical()) {
|
||||
setError("Source and destination containers cannot be the same. Please select different containers to proceed.");
|
||||
setContextError(
|
||||
"Source and destination containers cannot be the same. Please select different containers to proceed.",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setError(null);
|
||||
setContextError(null);
|
||||
const transitions = {
|
||||
[SCREEN_KEYS.SelectAccount]: shouldNotShowPermissionScreen()
|
||||
? SCREEN_KEYS.SelectSourceAndTargetContainers
|
||||
@@ -146,7 +144,5 @@ export function useCopyJobNavigation() {
|
||||
handlePrevious,
|
||||
handleCancel,
|
||||
primaryBtnText,
|
||||
error,
|
||||
setError,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user