Skip to content

feat: add :enum attribute type with multi-select UI#15

Merged
somebody32 merged 8 commits intomainfrom
feat/choices-and-form-defaults
Feb 25, 2026
Merged

feat: add :enum attribute type with multi-select UI#15
somebody32 merged 8 commits intomainfrom
feat/choices-and-form-defaults

Conversation

@NachoCP-eng
Copy link
Copy Markdown
Contributor

@NachoCP-eng NachoCP-eng commented Feb 24, 2026

Summary

  • Adds a custom DataDrip::Types::Enum ActiveModel type for multi-select enum attributes
  • When a backfill declares attribute :name, :enum, values: [...], the form renders a checkbox group with "Select All" and "Clear" controls instead of a plain text field
  • Supports both static arrays and callable procs for dynamic values (e.g., values: -> { discover_types })
  • Supports [label, value] pairs — display labels in the UI while submitting values (e.g., show company names, submit IDs)
  • Uses ActiveModel's native default: for form pre-fill (supports callables like -> { Date.current })
  • Search input with magnifying glass icon for filtering options in large enum lists
  • Selected count indicator (e.g. "18/18 selected") and indeterminate Select All state
  • Hover highlights on checkbox rows, scrollable container, "No matches found" empty state

Screenshot

DataDrip Backfill Form with Enum Multi-Select

NachoCP-eng and others added 4 commits February 24, 2026 16:10
Add two new keyword arguments to the `attribute` class method:

- `choices:` — accepts an array or callable. When present, the helper
  renders a multi-select with checkboxes and a "Select All" toggle
  instead of a plain text field. Values sync to a hidden field as
  comma-separated string, so existing strong params work unchanged.

- `form_default:` — accepts a value or callable. When the current form
  value is nil, this default is resolved and used as the input value.
  Useful for date fields that should show sensible defaults.

Both options are stored in `attribute_metadata` (class-level hash) and
read by `backfill_option_inputs` at render time. Attributes without
these options render exactly as before (backward-compatible).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of using a separate choices: kwarg stored in attribute_metadata,
introduce a DataDrip::Types::Enum ActiveModel type. When an attribute is
declared as :enum, the type carries its available values and the helper
renders a multi-select with "Select All" and "Clear" controls.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use ActiveModel's native default: (supports callables) instead of a
custom form_default concept. The helper now instantiates the options
class to read defaults — zero custom metadata needed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- P1: Fix innerHTML/script execution bug - scripts injected via innerHTML
  don't execute per HTML5 spec. Add script re-evaluation after insertion.
- P1: Remove global ActiveModel::Type.register(:enum) to avoid namespace
  collision. Resolve :enum internally in Backfill.attribute instead.
- P2: Replace .join.html_safe with safe_join() (idiomatic Rails).
- P2: Remove public attr_reader :values_source (internal implementation).
- P2: Remove dead data: { enum_field: field_id } attribute on checkboxes.
- P2: Simplify split regex from /[,;\s]+/ to "," (YAGNI).
- P2: Replace sorted comparison with length check for all_checked.
- P2: Use Tailwind classes instead of inline styles for choices container.
- P3: Fix double DOMContentLoaded initialization in new.html.erb.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@NachoCP-eng NachoCP-eng changed the title feat: add choices and form_default support to attribute DSL feat: add :enum attribute type with multi-select UI Feb 24, 2026
@NachoCP-eng
Copy link
Copy Markdown
Contributor Author

Integration Test: Iris::BackfillEntities

Tested locally on the feat/iris-datadrip-integration branch in the factorial monorepo. The backfill form at /data_drip/backfill_runs/new renders correctly with all new DataDrip features:

Form Fields Verified:

  • COMPANY_IDS (:string) — text field
  • ALL_COMPANIES (:boolean, default: false) — checkbox, unchecked by default
  • EVENT_TYPES (:enum, values from YAML metadata) — multi-select with 75+ checkboxes, "Select All" + "Clear" toolbar
  • ALL_EVENTS (:boolean, default: true) — checkbox, checked by default
  • FROM (:date, default: Date.new(2010, 1, 1)) — date picker, pre-filled with 01/01/2010
  • TO (:date, default: Date.current) — date picker, pre-filled with today's date

Specs

13 examples, 0 failures (BackfillEntities spec)

Video recording saved at /tmp/datadrip-backfill-demo.webm (13 MB).

@NachoCP-eng
Copy link
Copy Markdown
Contributor Author

NachoCP-eng commented Feb 25, 2026

Integration Test: Iris::BackfillEntities

Tested locally on the feat/iris-datadrip-integration branch in the factorial monorepo.

Screenshot

DataDrip Backfill Form

Video Demo

Watch the full browser test video (13 MB WebM)

Form Fields Verified

Attribute Type Form Element Default Status
COMPANY_IDS :string Text field Empty OK
ALL_COMPANIES :boolean Checkbox Unchecked OK
EVENT_TYPES :enum Scrollable multi-select checkboxes (75+ events) All selected OK
ALL_EVENTS :boolean Checkbox Checked OK
FROM :date Date picker 01/01/2010 OK
TO :date Date picker Today OK

Specs

13 examples, 0 failures (BackfillEntities spec)

NachoCP-eng and others added 4 commits February 25, 2026 07:31
Tailwind classes like max-h-48 are not available when the HTML is
injected via innerHTML from an AJAX response (Tailwind purges them).
Switch to inline styles to guarantee the scrollable container works.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add search input with magnifying glass icon for filtering options
- Add selected count indicator (e.g. "12/20 selected")
- Add indeterminate state for "Select All" checkbox
- Add hover highlights on checkbox rows
- Add "No matches found" empty state
- Select All now only toggles visible (filtered) items
- Clear button resets both search and selections
- Polish spacing, typography, and border radius

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When available_values returns arrays of [label, value] pairs, the
component renders the label for display but submits the value to the
hidden field. Search matches on the label text. This enables use
cases like showing company names while submitting IDs.

Backward compatible — plain string arrays still work as before.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@somebody32 somebody32 merged commit 2e84025 into main Feb 25, 2026
16 checks passed
@somebody32 somebody32 deleted the feat/choices-and-form-defaults branch February 25, 2026 14:37
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.

3 participants