Skip to content

fix(backup): several fixes around backup-pages#11

Open
androndo wants to merge 1 commit into
mainfrom
fix/backup-pages
Open

fix(backup): several fixes around backup-pages#11
androndo wants to merge 1 commit into
mainfrom
fix/backup-pages

Conversation

@androndo
Copy link
Copy Markdown

@androndo androndo commented May 15, 2026

  • form about BackupJob creation now correctly fills backupClass
  • enhanced UX selection of targetApplicationRef with pre-filled values for apps.cozystack.io
  • ResotreJob options input great again

Summary by CodeRabbit

  • New Features

    • Added a Backup Job creation page with schema-driven forms, resource validation, and error handling.
  • Bug Fixes

    • Improved application reference filtering in backup forms based on API group selection.
    • Enhanced enum handling for backup class and application fields to prevent widget conflicts.
  • Refactor

    • Consolidated backup creation page implementations for better maintainability.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Warning

Rate limit exceeded

@androndo has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 46 minutes and 43 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 85527279-688d-4350-87af-4391908a111b

📥 Commits

Reviewing files that changed from the base of the PR and between 361fd3c and 5bbda8f.

📒 Files selected for processing (9)
  • apps/console/src/components/BackupClassWidget.tsx
  • apps/console/src/components/SchemaForm.tsx
  • apps/console/src/routes/BackupJobCreatePage.tsx
  • apps/console/src/routes/BackupPlanCreatePage.tsx
  • apps/console/src/routes/BackupResourceCreatePage.tsx
  • apps/console/src/routes/BackupResourceCreatePageWithData.tsx
  • apps/console/src/routes/BackupRestoreJobCreatePage.tsx
  • apps/console/src/routes/ConsolePage.tsx
  • apps/console/src/routes/backup-schemas.ts
📝 Walkthrough

Walkthrough

This PR refactors backup creation pages to add API group awareness and introduces a dedicated BackupJobCreatePage to replace a generic resource creator. The changes improve SchemaForm enum handling, add conditional resource filtering by API group across backup plan and restore job creation flows, and establish new routing for the specialized backup job creator.

Changes

Backup Creation Pages with API Group Support

Layer / File(s) Summary
SchemaForm Foundation Improvements
apps/console/src/components/SchemaForm.tsx
Schema form guards against attaching BackupClassWidget when a native enum is already defined, and switches default emission to use current formData instead of an initial snapshot, enabling correct behavior during async schema recomputation.
New BackupJobCreatePage Component
apps/console/src/routes/BackupJobCreatePage.tsx
Complete new page component that fetches the backup job CRD schema, loads related Kubernetes resources (backupclasses, plans, application instances), enriches the schema with enum values and default apiGroup, validates and creates BackupJob manifests on submit, and displays loading/error UI with pending state handling.
BackupPlanCreatePage API Group Filtering
apps/console/src/routes/BackupPlanCreatePage.tsx
Derives selectedApiGroup from form state and conditionally enables instance fetching and enum population only when apiGroup is "apps.cozystack.io", preventing resource mismatches across API groups.
BackupRestoreJobCreatePage API Group Support
apps/console/src/routes/BackupRestoreJobCreatePage.tsx
Switches from targetRef to targetApplicationRef with apiGroup extraction, conditionally populates kind and instance name enums based on apiGroup match, strips unwanted CRD defaults, restructures spec.options for editor support, and updates validation to require the new field paths.
Console Routing Update
apps/console/src/routes/ConsolePage.tsx, removed BackupResourceCreatePageWithData.tsx
Routes the backup job creation path to the new BackupJobCreatePage, replacing the generic BackupResourceCreatePageWithData; related imports are updated accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops through backup flows so bright,
With apiGroups now keeping things just right,
New JobCreator pages, enums that gleam,
Schema forms guard against widget extremes,
The warren's backup system dreams!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references 'several fixes around backup-pages' which broadly describes multiple bug fixes across backup-related components, matching the changeset that includes fixes to SchemaForm, BackupJobCreatePage, BackupPlanCreatePage, BackupRestoreJobCreatePage, and related routing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/backup-pages

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a dedicated BackupJobCreatePage and refactors existing backup-related creation pages to handle API groups more robustly, specifically filtering application kinds and instances when the API group is apps.cozystack.io. It also improves SchemaForm to preserve user input during async schema updates and fixes UI issues where defaults interfered with selection widgets. Feedback includes suggestions to wrap JSON.parse calls in try-catch blocks for safety, replace alert() calls with better UX patterns like toast notifications, and improve accessibility by adding id and htmlFor attributes to form labels and inputs.

const schema = useMemo(() => {
if (!baseSchema) return null

const base = JSON.parse(baseSchema)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The JSON.parse(baseSchema) call is unsafe and will crash the component if baseSchema is invalid or empty. Consider wrapping it in a try-catch block to handle parsing errors gracefully, similar to the implementation in SchemaForm.tsx.

Suggested change
const base = JSON.parse(baseSchema)
let base;
try {
base = JSON.parse(baseSchema);
} catch (e) {
console.error("Failed to parse BackupJob schema:", e);
return null;
}

@@ -53,7 +54,12 @@ export function BackupPlanCreatePage() {
if (!baseSchema) return null

const base = JSON.parse(baseSchema)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The JSON.parse(baseSchema) call is unsafe and will crash the component if baseSchema is invalid. Consider wrapping it in a try-catch block to handle potential parsing errors.

Suggested change
const base = JSON.parse(baseSchema)
let base;
try {
base = JSON.parse(baseSchema);
} catch (e) {
console.error("Failed to parse Plan schema:", e);
return null;
}

@@ -55,7 +56,13 @@ export function BackupRestoreJobCreatePage() {

const base = JSON.parse(baseSchema)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The JSON.parse(baseSchema) call is unsafe and will crash the component if baseSchema is invalid. Consider wrapping it in a try-catch block.

    let base;
    try {
      base = JSON.parse(baseSchema);
    } catch (e) {
      console.error("Failed to parse RestoreJob schema:", e);
      return null;
    }

Comment on lines +104 to +137
alert("Tenant namespace is not available. Please refresh.")
return
}

if (!name.trim()) {
alert("Name is required")
return
}

if (!formData.applicationRef?.kind || !formData.applicationRef?.name) {
alert("Application reference is required")
return
}

if (!formData.backupClassName) {
alert("Backup class name is required")
return
}

const resource = {
apiVersion: "backups.cozystack.io/v1alpha1",
kind: "BackupJob",
metadata: {
name: name.trim(),
namespace: tenantNamespace ?? undefined,
},
spec: formData,
}

try {
await createMutation.mutateAsync(resource)
navigate("/console/backups/backupjobs")
} catch (err) {
alert(`Failed to create BackupJob: ${(err as Error).message}`)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using alert() for validation and error reporting is generally discouraged as it provides a poor user experience and blocks the main thread. Consider using a toast notification system or inline validation messages. Additionally, these strings are hardcoded and should be moved to a localization system if the project supports i18n.

Comment on lines +179 to +189
<label className="block text-sm font-medium text-slate-700 mb-1">
Backup Job Name <span className="text-red-500">*</span>
</label>
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="my-backup-job"
className="w-full rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm text-slate-900 outline-none focus:border-blue-400 focus:ring-1 focus:ring-blue-400"
required
/>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The 'Backup Job Name' input field is missing an id, and its label is missing a htmlFor attribute. Adding these improves accessibility for screen readers and allows users to focus the input by clicking the label.

Suggested change
<label className="block text-sm font-medium text-slate-700 mb-1">
Backup Job Name <span className="text-red-500">*</span>
</label>
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="my-backup-job"
className="w-full rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm text-slate-900 outline-none focus:border-blue-400 focus:ring-1 focus:ring-blue-400"
required
/>
<div>
<label htmlFor="backup-job-name" className="block text-sm font-medium text-slate-700 mb-1">
Backup Job Name <span className="text-red-500">*</span>
</label>
<input
id="backup-job-name"
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="my-backup-job"
className="w-full rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm text-slate-900 outline-none focus:border-blue-400 focus:ring-1 focus:ring-blue-400"
required
/>
</div>

Signed-off-by: Andrey Kolkov <androndo@gmail.com>
@androndo androndo force-pushed the fix/backup-pages branch from 361fd3c to 5bbda8f Compare May 15, 2026 15:55
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.

1 participant