Skip to content

Conversation

@dionlow
Copy link
Contributor

@dionlow dionlow commented Oct 20, 2025

Summary

  • Add useInstallationValidation hook that exposes clear validation states
  • Update mutation hooks to expose canCreate, canUpdate, canDelete flags
  • Provide detailed validationErrors object for better developer experience

Changes

  • New hook: useInstallationValidation - centralized validation logic

    • Returns canCreate, canUpdate, canDelete boolean flags
    • Returns validationErrors object with detailed error states
    • Returns current installation and integrationObj for convenience
  • Updated hooks:

    • useCreateInstallation - now exports canCreate and validationErrors
    • useUpdateInstallation - now exports canUpdate and validationErrors
    • useDeleteInstallation - now exports canDelete and validationErrors

Why

Previously, developers had to call mutation functions to discover validation errors. Now validation state is exposed upfront, allowing:

  • UI to disable buttons when operations aren't valid
  • Display helpful messages about what's missing
  • Check prerequisites before attempting mutations
  • Better developer experience with clearer error states

Example Usage

const { createInstallation, canCreate, validationErrors } = useCreateInstallation();

// Check if creation is possible
if (!canCreate) {
  if (validationErrors.installationExists) {
    console.log("Installation already exists");
  }
  if (validationErrors.noIntegration) {
    console.log("No integration found");
  }
}

// Disable button in UI
<button disabled={!canCreate} onClick={handleCreate}>Create</button>

…mutations

Add useInstallationValidation hook that exposes validation state (canCreate, canUpdate, canDelete) and detailed error information. This makes it clear to developers when prerequisites are missing before attempting mutations.

Changes:
- Created useInstallationValidation hook with canCreate/canUpdate/canDelete flags
- Updated useCreateInstallation to expose canCreate and validationErrors
- Updated useUpdateInstallation to expose canUpdate and validationErrors
- Updated useDeleteInstallation to expose canDelete and validationErrors
- Exported useInstallationValidation from headless index

Benefits:
- Developers can check validation state before calling mutations
- Clearer error messaging about what's missing (no integration, no installation, etc.)
- Enables UI to disable buttons or show warnings proactively

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings October 20, 2025 23:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds upfront validation capabilities to installation mutation hooks, allowing developers to check prerequisites before attempting operations. Previously, validation errors were only discoverable after calling mutation functions.

Key Changes:

  • Introduced useInstallationValidation hook for centralized validation logic
  • Enhanced mutation hooks (useCreateInstallation, useUpdateInstallation, useDeleteInstallation) to expose validation state
  • Added public export of the new validation hook

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/headless/installation/useInstallationValidation.ts New hook providing validation flags and detailed error states for installation operations
src/headless/installation/useCreateInstallation.ts Enhanced to expose canCreate and validationErrors from validation hook
src/headless/installation/useUpdateInstallation.ts Enhanced to expose canUpdate and validationErrors from validation hook
src/headless/installation/useDeleteInstallation.ts Enhanced to expose canDelete and validationErrors from validation hook
src/headless/index.ts Added public export for useInstallationValidation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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 { 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 { 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants