Skip to content

feat: optional variables — omit empty values instead of zero-filling (#51) - #52

Merged
HahaSula merged 1 commit into
mainfrom
feat/optional-variables
Jul 16, 2026
Merged

feat: optional variables — omit empty values instead of zero-filling (#51)#52
HahaSula merged 1 commit into
mainfrom
feat/optional-variables

Conversation

@HahaSula

@HahaSula HahaSula commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Implements the Phase-1 scope of #51: an empty cell on a non-required variable is represented by key absence in values.yaml, instead of being backfilled with a zero value.

Changes

  • src/utils/valueUtils.js (new)
    • pruneEmptyValues(rows, vars) — strips '' / null / undefined keys for non-required vars on save; required vars and keys not described by the schema are never pruned
    • pruneAllValues(values, schema) — applies it per alert group; _common and unknown groups pass through unchanged
    • buildNewRow(vars, commonValues) — extracted from AlertTable.handleAdd; optional vars without a default start with no key at all (required vars and booleans keep today's zero-value backfill)
  • AlertUserViewhandleSave / handleOverviewSave prune before POST
  • templateGenerator
    • non-required selector labels are wrapped in {{- if hasKey $row "x" }} guards (hasKey, not truthiness — stays correct for numeric enum selectors where 0 is legitimate); required selectors render unguarded
    • summary annotation prefers a required selector; with only optional selectors it uses an inline guard; with no selectors it drops the on-clause instead of referencing a phantom .namespace (which rendered <no value> before)
  • docs/chart-authoring.md (new) — the contract for hand-written charts: empty = key absent, never write explicit null (Helm delete-key coalesce), hasKey guard convention, _common fallback semantics, promtool safety-net limits

Why key absence (not null)

JSON Schema type only validates keys that are present, so CD-side helm template validation passes unchanged with the declared types untouched. Explicit null is a Helm delete-key instruction during coalesce and never reliably reaches templates. See #51 for the full discussion.

Testing

  • 13 new unit tests for valueUtils, 7 new for templateGenerator guards/summary; existing schemaUtils / templateGenerator suites unaffected
  • npm run lint clean
  • 11 pre-existing failures in render-api / chartDiscovery / helmUnittest (environment-dependent: helm/promtool binaries, env vars) were verified to fail identically without this change
  • The E2E checklist in feat: optional variables - omit empty values instead of zero-filling #51 is not covered here — needs the full minikube environment; follow-up on this branch or a separate PR

Closes nothing on its own — #51 stays open for the E2E checklist and Future work (required enforcement, server-side ajv validation).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Optional empty values are now omitted when deployments are saved, while required values and meaningful zero/false values are preserved.
    • New alert rows now receive consistent defaults and avoid duplicating shared values.
    • Generated Prometheus rules safely handle optional selectors and common variables.
  • Bug Fixes

    • Improved alert summaries and selector labels when optional or required selectors are present.
  • Documentation

    • Added guidance for chart authors on empty values, shared-value inheritance, template guards, and preview validation.

…51)

- pruneEmptyValues/pruneAllValues strip empty non-required keys on save;
  required vars and unknown keys are never pruned
- buildNewRow no longer backfills zero values for optional vars without a
  default (booleans and required vars keep today's behavior)
- templateGenerator wraps non-required selector labels in hasKey guards and
  picks a required selector for the summary annotation (guarded fallback,
  no more phantom .namespace reference when a chart has no selectors)
- docs/chart-authoring.md documents the empty-equals-key-absent contract
  and the guard convention for hand-written charts

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@rophy

rophy commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

PR Preview Bot

Preview environment torn down.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1d8e536a-95bb-4544-bc7b-daa677a94de5

📥 Commits

Reviewing files that changed from the base of the PR and between 6a37b6e and 7ee9620.

📒 Files selected for processing (7)
  • docs/chart-authoring.md
  • src/components/AlertTable.jsx
  • src/pages/AlertUserView.jsx
  • src/utils/__tests__/templateGenerator.test.js
  • src/utils/__tests__/valueUtils.test.js
  • src/utils/templateGenerator.js
  • src/utils/valueUtils.js

📝 Walkthrough

Walkthrough

Optional variable handling now omits empty optional values during persistence, centralizes new-row construction, guards optional selectors in generated templates, and documents the chart-authoring and validation contract.

Changes

Optional variable contract

Layer / File(s) Summary
Value pruning and row construction
src/utils/valueUtils.js, src/components/AlertTable.jsx, src/pages/AlertUserView.jsx, src/utils/__tests__/valueUtils.test.js
Optional empty values are pruned before saves, new rows use shared schema-aware defaults, and the behaviors are tested.
Selector guard generation
src/utils/templateGenerator.js, src/utils/__tests__/templateGenerator.test.js
Generated rules distinguish required and optional selectors, guard optional references, and select summary clauses accordingly.
Chart authoring contract
docs/chart-authoring.md
Documentation describes omitted optional keys, hasKey guards, common-value merging, and Preview validation behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AlertUserView
  participant pruneAllValues
  participant saveDeployment
  AlertUserView->>pruneAllValues: deployment values and schema
  pruneAllValues->>pruneAllValues: remove empty optional keys
  pruneAllValues-->>AlertUserView: pruned values
  AlertUserView->>saveDeployment: persist pruned values
Loading

Possibly related issues

  • Issue 51 — Covers the same optional-variable design across row creation, persistence pruning, template guards, documentation, and tests.

Possibly related PRs

Suggested reviewers: rophy

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% 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 accurately summarizes the main change: optional variables now omit empty values instead of being zero-filled.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/optional-variables

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.

@HahaSula

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@HahaSula

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@HahaSula
HahaSula requested a review from rophy July 16, 2026 00:58
@HahaSula
HahaSula merged commit 51d027a into main Jul 16, 2026
4 checks passed
@HahaSula
HahaSula deleted the feat/optional-variables branch July 16, 2026 04:02
HahaSula added a commit that referenced this pull request Jul 16, 2026
Bump version from 1.4.0 to 1.5.0 to trigger a new image build and
GitHub Release via CI. Since 1.4.0: optional variables — omit empty
values instead of zero-filling (#51, #52), a minor bump per this
project's convention (feat commits warrant minor, not patch).

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
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