Skip to content

Commit

Permalink
fix: fix change resource button is not disabled when we need to (#369)
Browse files Browse the repository at this point in the history
Because

- when NEXT_PUBLIC_DISABLE_CREATE_UPDATE_DELETE_RESOURCE=true we need to
disable all related action

This commit

- fix change resource button is not disabled when we need to
  • Loading branch information
EiffelFly committed Mar 7, 2023
1 parent 99776bd commit 53f5472
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/ui/ChangeResourceStateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { UseMutationResult } from "@tanstack/react-query";
import cn from "clsx";
import { AxiosError } from "axios";
import { Operation } from "@/lib/instill/types";
import { useCreateUpdateDeleteResourceGuard } from "@/hooks";

export type ChangeResourceStateButtonProps = {
resource: Nullable<ModelInstance | Pipeline>;
Expand Down Expand Up @@ -36,6 +37,8 @@ export const ChangeResourceStateButton: FC<ChangeResourceStateButtonProps> = ({
setError(null);
}, [resource]);

const enableGuard = useCreateUpdateDeleteResourceGuard();

const changeResourceStateHandler = useCallback(() => {
if (!resource || resource.state === "STATE_UNSPECIFIED") return;

Expand Down Expand Up @@ -89,7 +92,7 @@ export const ChangeResourceStateButton: FC<ChangeResourceStateButtonProps> = ({
? "STATE_LOADING"
: resource?.state || "STATE_UNSPECIFIED"
}
disabled={resource?.state === "STATE_UNSPECIFIED"}
disabled={enableGuard ? true : resource?.state === "STATE_UNSPECIFIED"}
loadingLabelText="Model instance is in the long running operation, please refresh this page to get the new status"
/>
</div>
Expand Down

0 comments on commit 53f5472

Please sign in to comment.