Skip to content

Commit

Permalink
fix(instance) ensure instance name is unique and ot matched against p…
Browse files Browse the repository at this point in the history
…revious name on renaming

Signed-off-by: David Edler <[email protected]>
  • Loading branch information
edlerd committed Jun 25, 2024
1 parent 9f9f47d commit 1693d00
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
12 changes: 5 additions & 7 deletions src/components/RenameHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ const RenameHeader: FC<Props> = ({
renameDisabledReason,
}) => {
const canRename = renameDisabledReason === undefined;
const enableRename = () => {
window.dispatchEvent(new Event("resize"));
const toggleRename = () => {
setTimeout(() => window.dispatchEvent(new Event("resize")), 10);
if (!canRename || !formik) {
return;
}
void formik.setValues({
...formik.values,
isRenaming: true,
isRenaming: !formik.values.isRenaming,
});
};

Expand Down Expand Up @@ -82,9 +82,7 @@ const RenameHeader: FC<Props> = ({
<Button
appearance="base"
className="cancel"
onClick={() =>
void formik.setFieldValue("isRenaming", false)
}
onClick={toggleRename}
>
Cancel
</Button>
Expand All @@ -101,7 +99,7 @@ const RenameHeader: FC<Props> = ({
) : (
<li
className="p-heading--4 u-no-margin--bottom name continuous-breadcrumb"
onClick={enableRename}
onClick={toggleRename}
title={`Rename ${name}`}
>
<Tooltip
Expand Down
2 changes: 1 addition & 1 deletion src/pages/instances/InstanceDetailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const InstanceDetailHeader: FC<Props> = ({
const controllerState = useState<AbortController | null>(null);

const RenameSchema = Yup.object().shape({
name: instanceNameValidation(project, controllerState).required(
name: instanceNameValidation(project, controllerState, name).required(
"Instance name is required",
),
});
Expand Down
9 changes: 7 additions & 2 deletions src/util/instances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ export const instanceLinkFromOperation = (args: {
export const instanceNameValidation = (
project: string,
controllerState: AbortControllerState,
oldName?: string,
): Yup.StringSchema =>
Yup.string()
.test("deduplicate", "An instance with this name already exists", (value) =>
checkDuplicateName(value, project, controllerState, "instances"),
.test(
"deduplicate",
"An instance with this name already exists",
(value) =>
oldName === value ||
checkDuplicateName(value, project, controllerState, "instances"),
)
.test(
"size",
Expand Down

0 comments on commit 1693d00

Please sign in to comment.