Skip to content

Commit

Permalink
fix(instance) use created instead of launched in notification copy
Browse files Browse the repository at this point in the history
Co-authored-by: Michele Lo Russo <[email protected]>
  • Loading branch information
edlerd and lorumic committed Sep 29, 2023
1 parent 06901ad commit 2ddfa7a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
27 changes: 18 additions & 9 deletions src/pages/instances/CreateInstanceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,18 @@ const CreateInstanceForm: FC = () => {
void queryClient.invalidateQueries({
queryKey: [queryKeys.instances],
});
void queryClient.invalidateQueries({
queryKey: [queryKeys.operations, project],
});
};

const notifyCreatedNowStarting = (instanceLink: ReactNode) => {
notify.info(<>Created instance {instanceLink}, now starting it.</>);
clearCache();
};

const notifyLaunchedAndStarted = (instanceLink: ReactNode) => {
notify.success(<>Launched and started instance {instanceLink}.</>);
const notifyCreatedAndStarted = (instanceLink: ReactNode) => {
notify.success(<>Created and started instance {instanceLink}.</>);
clearCache();
};

Expand All @@ -139,16 +147,16 @@ const CreateInstanceForm: FC = () => {
clearCache();
};

const notifyLaunched = (instanceLink: ReactNode, message?: ReactNode) => {
const notifyCreated = (instanceLink: ReactNode, message?: ReactNode) => {
notify.success(
<>
Launched instance {instanceLink}.{message}
Created instance {instanceLink}.{message}
</>
);
clearCache();
};

const notifyLaunchFailed = (
const notifyCreationFailed = (
e: Error,
formUrl: string,
values: CreateInstanceFormValues
Expand All @@ -175,12 +183,13 @@ const CreateInstanceForm: FC = () => {
);

if (shouldStart) {
notifyCreatedNowStarting(instanceLink);
startInstance({
name: instanceName,
project: project,
} as LxdInstance)
.then(() => {
notifyLaunchedAndStarted(instanceLink);
notifyCreatedAndStarted(instanceLink);
})
.catch((e: Error) => {
notifyCreatedButStartFailed(instanceLink, e);
Expand All @@ -196,7 +205,7 @@ const CreateInstanceForm: FC = () => {
</Button>
</>
);
notifyLaunched(instanceLink, message);
notifyCreated(instanceLink, message);
}
};

Expand All @@ -218,14 +227,14 @@ const CreateInstanceForm: FC = () => {
eventQueue.set(
operation.metadata.id,
() => creationCompletedHandler(instanceName, shouldStart, isIsoImage),
(msg) => notifyLaunchFailed(new Error(msg), formUrl, values)
(msg) => notifyCreationFailed(new Error(msg), formUrl, values)
);
})
.catch((e: Error) => {
if (e.message === "Cancelled") {
return;
}
notifyLaunchFailed(e, formUrl, values);
notifyCreationFailed(e, formUrl, values);
});
};

Expand Down
2 changes: 1 addition & 1 deletion tests/helpers/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const createInstance = async (
.selectOption(type);
await page.getByRole("button", { name: "Create" }).first().click();

await page.waitForSelector(`text=Launched instance ${instance}.`, TIMEOUT);
await page.waitForSelector(`text=Created instance ${instance}.`, TIMEOUT);
};

export const visitInstance = async (page: Page, instance: string) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/iso-volumes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test("use custom iso for instance launch", async ({ page }) => {
await page.locator(".u-align--right > .p-button--positive").click();
await page.getByRole("button", { name: "Create" }).click();

await page.waitForSelector(`text=Launched instance ${instance}.`, TIMEOUT);
await page.waitForSelector(`text=Created instance ${instance}.`, TIMEOUT);

await deleteInstance(page, instance);
await page.goto("/ui/");
Expand Down

0 comments on commit 2ddfa7a

Please sign in to comment.