Skip to content
Open
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
1 change: 1 addition & 0 deletions src/headless/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { useConnection } from "./useConnection";

// Installation Hooks
export { useInstallation } from "./installation/useInstallation";
export { useInstallationValidation } from "./installation/useInstallationValidation";
export { useCreateInstallation } from "./installation/useCreateInstallation";
export { useUpdateInstallation } from "./installation/useUpdateInstallation";
export { useDeleteInstallation } from "./installation/useDeleteInstallation";
Expand Down
6 changes: 6 additions & 0 deletions src/headless/installation/useCreateInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import { useInstallationProps } from "../InstallationProvider";
import { useConnection } from "../useConnection";

import { useInstallation } from "./useInstallation";
import { useInstallationValidation } from "./useInstallationValidation";

/**
* create installation hook
* @returns {Object} An object containing:
* - `createInstallation` (function): A function to create the installation.
* - `canCreate` (boolean): Whether a new installation can be created.
* - `validationErrors` (Object): Detailed validation error information.
* - `isIdle` (boolean): Whether the mutation is idle.
* - `isPending` (boolean): Whether the mutation is pending.
* - `error` (Error | null): The error object, if any.
Expand All @@ -29,6 +32,7 @@ export function useCreateInstallation() {
const { data: integrationObj } = useIntegrationQuery(integrationNameOrId);
const { connection } = useConnection();
const { installation } = useInstallation();
const { canCreate, validationErrors } = useInstallationValidation();
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useInstallationValidation hook internally calls useIntegrationQuery and useInstallation, resulting in duplicate hook calls since these are already invoked on lines 32 and 34. This creates redundant queries and state management. Consider refactoring useInstallationValidation to accept integrationObj and installation as parameters to avoid duplicate hook invocations.

Suggested change
const { canCreate, validationErrors } = useInstallationValidation();
const { canCreate, validationErrors } = useInstallationValidation(integrationObj, installation);

Copilot uses AI. Check for mistakes.
const queryClient = useQueryClient();
const {
mutate: createInstallationMutation,
Expand Down Expand Up @@ -86,6 +90,8 @@ export function useCreateInstallation() {

return {
createInstallation,
canCreate,
validationErrors,
isIdle,
isPending,
error,
Expand Down
6 changes: 6 additions & 0 deletions src/headless/installation/useDeleteInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import { useIntegrationQuery } from "src/hooks/query/useIntegrationQuery";
import { useInstallationProps } from "../InstallationProvider";

import { useInstallation } from "./useInstallation";
import { useInstallationValidation } from "./useInstallationValidation";

/**
* delete installation hook
* @returns {Object} An object containing:
* - `deleteInstallation` (function): A function to delete the installation.
* - `canDelete` (boolean): Whether the installation can be deleted.
* - `validationErrors` (Object): Detailed validation error information.
* - `isIdle` (boolean): Whether the mutation is idle.
* - `isPending` (boolean): Whether the mutation is pending.
* - `error` (Error | null): The error object, if any.
Expand All @@ -21,6 +24,7 @@ export function useDeleteInstallation() {
const { integrationNameOrId } = useInstallationProps();
const { data: integrationObj } = useIntegrationQuery(integrationNameOrId);
const { installation } = useInstallation();
const { canDelete, validationErrors } = useInstallationValidation();
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useInstallationValidation hook internally calls useIntegrationQuery and useInstallation, resulting in duplicate hook calls since these are already invoked on lines 25-26. This creates redundant queries and state management. Consider refactoring useInstallationValidation to accept integrationObj and installation as parameters to avoid duplicate hook invocations.

Suggested change
const { canDelete, validationErrors } = useInstallationValidation();
const { canDelete, validationErrors } = useInstallationValidation(integrationObj, installation);

Copilot uses AI. Check for mistakes.
const queryClient = useQueryClient();
const {
mutate: deleteInstallationMutation,
Expand Down Expand Up @@ -74,6 +78,8 @@ export function useDeleteInstallation() {

return {
deleteInstallation,
canDelete,
validationErrors,
isIdle,
isPending,
error,
Expand Down
34 changes: 34 additions & 0 deletions src/headless/installation/useInstallationValidation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useIntegrationQuery } from "src/hooks/query/useIntegrationQuery";

import { useInstallationProps } from "../InstallationProvider";

import { useInstallation } from "./useInstallation";

/**
* Validation hook that checks prerequisites for installation mutations
* @returns {Object} An object containing:
* - `canCreate` (boolean): Whether a new installation can be created
* - `canUpdate` (boolean): Whether an existing installation can be updated
* - `canDelete` (boolean): Whether an existing installation can be deleted
* - `validationErrors` (Object): Detailed validation error information
*/
export function useInstallationValidation() {
const { integrationNameOrId } = useInstallationProps();
const { data: integrationObj } = useIntegrationQuery(integrationNameOrId);
const { installation } = useInstallation();

const validationErrors = {
noIntegration: !integrationObj,
installationExists: !!installation,
noInstallation: !installation,
};

return {
canCreate: !validationErrors.installationExists && !validationErrors.noIntegration,
canUpdate: !validationErrors.noInstallation && !validationErrors.noIntegration,
canDelete: !validationErrors.noInstallation && !validationErrors.noIntegration,
validationErrors,
installation,
integrationObj,
};
}
6 changes: 6 additions & 0 deletions src/headless/installation/useUpdateInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import { toUpdateConfigContent } from "../config/types";
import { useInstallationProps } from "../InstallationProvider";

import { useInstallation } from "./useInstallation";
import { useInstallationValidation } from "./useInstallationValidation";

/**
* update installation hook
* @returns {Object} An object containing:
* - `updateInstallation` (function): A function to update the installation.
* - `canUpdate` (boolean): Whether the installation can be updated.
* - `validationErrors` (Object): Detailed validation error information.
* - `isIdle` (boolean): Whether the mutation is idle.
* - `isPending` (boolean): Whether the mutation is pending.
* - `error` (Error | null): The error object, if any.
Expand All @@ -27,6 +30,7 @@ export function useUpdateInstallation() {
const { integrationNameOrId } = useInstallationProps();
const { data: integrationObj } = useIntegrationQuery(integrationNameOrId);
const { installation } = useInstallation();
const { canUpdate, validationErrors } = useInstallationValidation();
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useInstallationValidation hook internally calls useIntegrationQuery and useInstallation, resulting in duplicate hook calls since these are already invoked on lines 31-32. This creates redundant queries and state management. Consider refactoring useInstallationValidation to accept integrationObj and installation as parameters to avoid duplicate hook invocations.

Suggested change
const { canUpdate, validationErrors } = useInstallationValidation();
const { canUpdate, validationErrors } = useInstallationValidation(integrationObj, installation);

Copilot uses AI. Check for mistakes.
const queryClient = useQueryClient();
const {
mutate: updateInstallationMutation,
Expand Down Expand Up @@ -115,6 +119,8 @@ export function useUpdateInstallation() {

return {
updateInstallation,
canUpdate,
validationErrors,
isIdle,
isPending,
error,
Expand Down