Skip to content

Commit

Permalink
createImageWizard: change the default name of bllueprint
Browse files Browse the repository at this point in the history
this commit change the default name to different format
<release>-<arch>-<date>-<time>
  const dateString = `${day}${month}${year}`;
  const timeString = `${hours}`;
  • Loading branch information
mgold1234 authored and regexowl committed Aug 27, 2024
1 parent be8a00d commit 047ae01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
8 changes: 1 addition & 7 deletions src/Components/CreateImageWizard/steps/Details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
selectBlueprintDescription,
selectBlueprintName,
selectDistribution,
selectImageTypes,
} from '../../../../store/wizardSlice';
import { generateDefaultName } from '../../utilities/generateDefaultName';
import { useDetailsValidation } from '../../utilities/useValidation';
Expand All @@ -30,15 +29,10 @@ const DetailsStep = () => {
const blueprintDescription = useAppSelector(selectBlueprintDescription);
const distribution = useAppSelector(selectDistribution);
const arch = useAppSelector(selectArchitecture);
const targetEnvironments = useAppSelector(selectImageTypes);

useEffect(() => {
if (!blueprintName) {
dispatch(
changeBlueprintName(
generateDefaultName(distribution, arch, targetEnvironments)
)
);
dispatch(changeBlueprintName(generateDefaultName(distribution, arch)));
}
// This useEffect hook should run *only* on mount and therefore has an empty
// dependency array. eslint's exhaustive-deps rule does not support this use.
Expand Down
20 changes: 11 additions & 9 deletions src/Components/CreateImageWizard/utilities/generateDefaultName.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { ImageTypes } from '../../../store/imageBuilderApi';
import { Distributions, ImageRequest } from '../../../store/imageBuilderApi';

export const generateDefaultName = (
distribution: string,
arch: string,
targetEnvironments: ImageTypes[]
distribution: Distributions,
arch: ImageRequest['architecture']
) => {
const date = new Date();
const day = date.getDate().toString().padStart(2, '0');
const month = date.toLocaleString('en-US', { month: 'long' });
const year = date.getFullYear();
return `${distribution} ${arch} ${targetEnvironments.join(
' '
)} ${day} ${month} ${year}`;
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const year = date.getFullYear().toString();
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');

const dateTimeString = `${month}${day}${year}-${hours}${minutes}`;

return `${distribution}-${arch}-${dateTimeString}`;
};

0 comments on commit 047ae01

Please sign in to comment.