show default copy job name (#2266)

This commit is contained in:
BChoudhury-ms
2025-11-27 10:34:08 +05:30
committed by GitHub
parent a33429fd85
commit bb0bbd8a6e
4 changed files with 50 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
import { DatabaseAccount } from "Contracts/DataModels"; import { DatabaseAccount } from "Contracts/DataModels";
import { CopyJobErrorType } from "./Types/CopyJobTypes"; import { CopyJobErrorType, CopyJobType } from "./Types/CopyJobTypes";
const azurePortalMpacEndpoint = "https://ms.portal.azure.com/"; const azurePortalMpacEndpoint = "https://ms.portal.azure.com/";
@@ -124,3 +124,40 @@ export function isIntraAccountCopy(sourceAccountId: string | undefined, targetAc
sourceAccountDetails?.accountName === targetAccountDetails?.accountName sourceAccountDetails?.accountName === targetAccountDetails?.accountName
); );
} }
export function isEqual(prevJobs: CopyJobType[], newJobs: CopyJobType[]): boolean {
if (prevJobs.length !== newJobs.length) {
return false;
}
return prevJobs.every((prevJob: CopyJobType) => {
const newJob = newJobs.find((job) => job.Name === prevJob.Name);
if (!newJob) {
return false;
}
return prevJob.Status === newJob.Status;
});
}
const truncateLength = 5;
const truncateName = (name: string, length: number = truncateLength): string => {
return name.length <= length ? name : name.slice(0, length);
};
export function getDefaultJobName(
selectedDatabaseAndContainers: {
sourceDatabaseName?: string;
sourceContainerName?: string;
targetDatabaseName?: string;
targetContainerName?: string;
}[],
): string {
if (selectedDatabaseAndContainers.length === 1) {
const { sourceDatabaseName, sourceContainerName, targetDatabaseName, targetContainerName } =
selectedDatabaseAndContainers[0];
const timestamp = new Date().getTime().toString();
const sourcePart = `${truncateName(sourceDatabaseName)}.${truncateName(sourceContainerName)}`;
const targetPart = `${truncateName(targetDatabaseName)}.${truncateName(targetContainerName)}`;
return `${sourcePart}_${targetPart}_${timestamp}`;
}
return "";
}

View File

@@ -1,8 +1,9 @@
import { DetailsList, DetailsListLayoutMode, Stack, Text, TextField } from "@fluentui/react"; import { DetailsList, DetailsListLayoutMode, Stack, Text, TextField } from "@fluentui/react";
import FieldRow from "Explorer/ContainerCopy/CreateCopyJob/Screens/Components/FieldRow"; import React, { useEffect } from "react";
import React from "react";
import ContainerCopyMessages from "../../../ContainerCopyMessages"; import ContainerCopyMessages from "../../../ContainerCopyMessages";
import { useCopyJobContext } from "../../../Context/CopyJobContext"; import { useCopyJobContext } from "../../../Context/CopyJobContext";
import { getDefaultJobName } from "../../../CopyJobUtils";
import FieldRow from "../Components/FieldRow";
import { getPreviewCopyJobDetailsListColumns } from "./Utils/PreviewCopyJobUtils"; import { getPreviewCopyJobDetailsListColumns } from "./Utils/PreviewCopyJobUtils";
const PreviewCopyJob: React.FC = () => { const PreviewCopyJob: React.FC = () => {
@@ -16,6 +17,11 @@ const PreviewCopyJob: React.FC = () => {
targetContainerName: copyJobState.target?.containerId, targetContainerName: copyJobState.target?.containerId,
}, },
]; ];
useEffect(() => {
onJobNameChange(undefined, getDefaultJobName(selectedDatabaseAndContainers));
}, []);
const jobName = copyJobState.jobName; const jobName = copyJobState.jobName;
const onJobNameChange = (_ev?: React.FormEvent, newValue?: string) => { const onJobNameChange = (_ev?: React.FormEvent, newValue?: string) => {

View File

@@ -56,7 +56,7 @@ function useCreateCopyJobScreensList() {
validations: [ validations: [
{ {
validate: (state: CopyJobContextState) => validate: (state: CopyJobContextState) =>
!!(typeof state?.jobName === "string" && state?.jobName && /^[a-zA-Z0-9-.]+$/.test(state?.jobName)), !!(typeof state?.jobName === "string" && state?.jobName && /^[a-zA-Z0-9-._]+$/.test(state?.jobName)),
message: "Please enter a job name to proceed", message: "Please enter a job name to proceed",
}, },
], ],

View File

@@ -118,8 +118,9 @@
.jobNameLink { .jobNameLink {
color: @LinkColor; color: @LinkColor;
text-decoration: underline; text-overflow: ellipsis;
cursor: pointer; white-space: nowrap;
overflow: hidden;
} }
} }
} }