Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(header) ensure instance name is unique and ot matched against previous name #805

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/components/RenameHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ 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,
name: name,
isRenaming: !formik.values.isRenaming,
});
};

Expand Down Expand Up @@ -82,9 +83,7 @@ const RenameHeader: FC<Props> = ({
<Button
appearance="base"
className="cancel"
onClick={() =>
void formik.setFieldValue("isRenaming", false)
}
onClick={toggleRename}
>
Cancel
</Button>
Expand All @@ -101,7 +100,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
Loading