Skip to content

feat(ui): Implement CRUD interface for repository management #104

Closed

Description

@integry

Task Description

This issue is part of the epic to improve repository management in the web UI. It focuses on replacing the current <textarea>-based input with a proper CRUD interface for adding, removing, and disabling monitored repositories.

This task depends on the completion of the backend changes in Issue #103.

Implementation Steps

  1. Update RepositoriesPage.jsx:

    • Fetch the list of repository objects from the /api/config/repos endpoint.
    • Display the repositories in a list or table format. Each row should show:
      • The repository name (owner/repo).
      • An "Enabled" toggle switch.
      • A "Remove" button.
  2. Implement "Add Repository" Functionality:

    • Create a form for adding new repositories.
    • This form should include:
      • A dropdown to select from a list of available GitHub repositories (fetched from a new API endpoint).
      • A text input to manually enter a custom repository in owner/repo format.
      • An "Add Repository" button.
    • When a repository is added, it should be appended to the list with enabled: true by default.
  3. Implement "Remove Repository" Functionality:

    • When the "Remove" button is clicked, show a confirmation dialog (e.g., window.confirm or a modal) asking the user to confirm the deletion.
    • If confirmed, remove the repository from the local state.
  4. Implement "Disable/Enable" Functionality:

    • The toggle switch for each repository should update the enabled property of the corresponding repository object in the state.
  5. Implement "Save Changes":

    • A "Save Changes" button should be present. When clicked, it should send the entire (modified) list of repository objects to the POST /api/config/repos endpoint.
    • Provide feedback to the user on success or failure.
  6. Create New API Endpoint for Available Repos:

    • In packages/dashboard/server.js, add a new authenticated endpoint (e.g., /api/github/repos) that uses the authenticated user's token to fetch a list of repositories they have access to from the GitHub API. This will populate the "Add Repository" dropdown.

Activity

  1. integry commented on Oct 7, 2025

    @integry
    OwnerAuthor

    Implementation Suggestions

    Here are some code suggestions for the frontend implementation in gitfix-ui/src/pages/RepositoriesPage.jsx.

    --- a/gitfix-ui/src/pages/RepositoriesPage.jsx
    +++ b/gitfix-ui/src/pages/RepositoriesPage.jsx
    @@ -1,23 +1,38 @@
     import React, { useState, useEffect } from 'react';
    -import { getRepoConfig, updateRepoConfig } from '../api/gitfixApi';
    +import { getRepoConfig, updateRepoConfig, getAvailableGithubRepos } from '../api/gitfixApi'; // Assume getAvailableGithubRepos is added to api
     
     const RepositoriesPage = () => {
    -  const [repos, setRepos] = useState('');
    +  const [repos, setRepos] = useState([]);
       const [loading, setLoading] = useState(true);
       const [saving, setSaving] = useState(false);
       const [error, setError] = useState(null);
       const [success, setSuccess] = useState(null);
    +  const [newRepo, setNewRepo] = useState('');
    +  const [availableRepos, setAvailableRepos] = useState([]);
     
       useEffect(() => {
         loadRepos();
    +    loadAvailableRepos();
       }, []);
     
       const loadRepos = async () => {
         try {
           setLoading(true);
           setError(null);
           const data = await getRepoConfig();
    -      setRepos(data.repos_to_monitor.join('\n'));
    +      setRepos(data.repos_to_monitor || []);
         } catch (err) {
           setError(err.message || 'Failed to load repositories');
         } finally {
    @@ -25,16 +40,51 @@
         }
       };
     
    +  const loadAvailableRepos = async () => {
    +    try {
    +      const data = await getAvailableGithubRepos();
    +      setAvailableRepos(data.repos || []);
    +    } catch (err) {
    +      // Non-critical, so just log it
    +      console.error('Failed to load available GitHub repos:', err);
    +    }
    +  };
    +
    +  const handleAddRepo = () => {
    +    if (newRepo && !repos.some(r => r.name === newRepo)) {
    +      setRepos([...repos, { name: newRepo, enabled: true }]);
    +      setNewRepo('');
    +    }
    +  };
    +
    +  const handleRemoveRepo = (repoNameToRemove) => {
    +    if (window.confirm(`Are you sure you want to remove the repository "${repoNameToRemove}"?`)) {
    +      setRepos(repos.filter(repo => repo.name !== repoNameToRemove));
    +    }
    +  };
    +
    +  const handleToggleRepo = (repoNameToToggle) => {
    +    setRepos(
    +      repos.map(repo =>
    +        repo.name === repoNameToToggle ? { ...repo, enabled: !repo.enabled } : repo
    +      )
    +    );
    +  };
    +
       const handleSave = async () => {
         setError(null);
         setSuccess(null);
         setSaving(true);
         
    -    const repoList = repos.split('\n').map(r => r.trim()).filter(Boolean);
    -    
         try {
    -      await updateRepoConfig(repoList);
    -      setSuccess('Repository list updated successfully! Changes will be picked up within 5 minutes.');
    +      // Validate repo format before saving
    +      for (const repo of repos) {
    +        if (!/^[a-zA-Z0-9\-_]+\/[a-zA-Z0-9\-_]+$/.test(repo.name)) {
    +          throw new Error(`Invalid repository format: "${repo.name}"`);
    +        }
    +      }
    +      await updateRepoConfig(repos);
    +      setSuccess('Repository list updated successfully! The daemon will pick up changes within 5 minutes.');
         } catch (err) {
           setError(err.message || 'Failed to update repository list');
         } finally {
    @@ -54,23 +104,82 @@
             Enter one repository per line (e.g., 'owner/repo'). Changes will be automatically picked up by the daemon within 5 minutes.
           </p>
           
    -      <textarea
    -        value={repos}
    -        onChange={(e) => setRepos(e.target.value)}
    -        rows={15}
    -        style={{
    -          width: '100%',
    -          fontFamily: 'monospace',
    -          fontSize: '0.9rem',
    -          padding: '0.75rem',
    -          backgroundColor: '#1f2937',
    -          color: '#fff',
    -          border: '1px solid #374151',
    -          borderRadius: '0.375rem',
    -          marginBottom: '1rem',
    -          resize: 'vertical'
    -        }}
    -        disabled={saving}
    -        placeholder="owner/repo1&#10;owner/repo2&#10;owner/repo3"
    -      />
    +      {/* Add Repo Form */}
    +      <div style={{ display: 'flex', gap: '1rem', marginBottom: '1.5rem' }}>
    +        <input
    +          list="available-repos"
    +          value={newRepo}
    +          onChange={(e) => setNewRepo(e.target.value)}
    +          placeholder="owner/repo or select from list"
    +          style={{ flex: 1, padding: '0.5rem', backgroundColor: '#1f2937', color: '#fff', border: '1px solid #374151', borderRadius: '0.375rem' }}
    +        />
    +        <datalist id="available-repos">
    +          {availableRepos.map(repo => <option key={repo} value={repo} />)}
    +        </datalist>
    +        <button onClick={handleAddRepo} style={{ backgroundColor: '#10B981' }}>Add Repository</button>
    +      </div>
    +
    +      {/* Repo List */}
    +      <div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
    +        {repos.map(repo => (
    +          <div
    +            key={repo.name}
    +            style={{
    +              display: 'flex',
    +              alignItems: 'center',
    +              justifyContent: 'space-between',
    +              padding: '0.75rem 1rem',
    +              backgroundColor: '#374151',
    +              borderRadius: '0.375rem',
    +            }}
    +          >
    +            <span style={{ fontFamily: 'monospace', color: '#fff' }}>{repo.name}</span>
    +            <div style={{ display: 'flex', alignItems: 'center', gap: '1rem' }}>
    +              <label style={{ display: 'flex', alignItems: 'center', cursor: 'pointer', color: '#9ca3af' }}>
    +                <input
    +                  type="checkbox"
    +                  checked={repo.enabled}
    +                  onChange={() => handleToggleRepo(repo.name)}
    +                  style={{ marginRight: '0.5rem', height: '1rem', width: '1rem' }}
    +                />
    +                Enabled
    +              </label>
    +              <button
    +                onClick={() => handleRemoveRepo(repo.name)}
    +                style={{ backgroundColor: '#EF4444', fontSize: '0.75rem', padding: '0.25rem 0.75rem' }}
    +              >
    +                Remove
    +              </button>
    +            </div>
    +          </div>
    +        ))}
    +        {repos.length === 0 && <p style={{ color: '#9ca3af', textAlign: 'center' }}>No repositories configured.</p>}
    +      </div>
           
           <button
    +        onClick={handleSave}
    +        disabled={saving || repos.length === 0}
    +        style={{
    +          marginTop: '1.5rem',
    +          padding: '0.75rem 1.5rem',
    +          backgroundColor: saving ? '#6b7280' : '#3b82f6',
    +          color: '#fff',
    +          border: 'none',
    +          borderRadius: '0.375rem',
    +          cursor: saving || repos.length === 0 ? 'not-allowed' : 'pointer',
    +          fontSize: '1rem',
    +          fontWeight: 'bold'
    +        }}
    +      >
    +        {saving ? 'Saving...' : 'Save All Changes'}
    +      </button>
    +
           <button
             onClick={handleSave}
             disabled={saving}
    

    And the corresponding changes in gitfix-ui/src/api/gitfixApi.js.

    // In gitfixApi.js
    
    // ... other functions
    
    export const getAvailableGithubRepos = async () => {
      const response = await fetch(`${API_BASE_URL}/api/github/repos`, {
        credentials: 'include'
      });
      await handleApiResponse(response);
      return response.json();
    };
    
    export const updateRepoConfig = async (repos) => {
      const response = await fetch(`${API_BASE_URL}/api/config/repos`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ repos_to_monitor: repos }), // Send the array of objects
        credentials: 'include'
      });
      await handleApiResponse(response);
      return response.json();
    };
  2. propr-dev commented on Oct 7, 2025

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using claude-sonnet-4-5-20250929 model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Model: claude-sonnet-4-5-20250929
    • Branch: ai-fix/104-feat-ui-implement-crud-in-20251007-1420-claude-sonnet-4-5-20250929-nh0
    • Base Branch: main
    • Worktree: issue-104-20251007-1420-claude-sonnet-4-5-20250929-nh0
  3. added a commit that references this issue on Oct 7, 2025
  4. added a commit that references this issue on Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions