discourse/app/assets/javascripts/admin/addon/controllers
chapoi 2ca06ba236
DEV: form-kit
This PR introduces FormKit, a component-based form library designed to simplify form creation and management. This library provides a single `Form` component, various field components, controls, validation mechanisms, and customization options. Additionally, it includes helpers to facilitate testing and writing specifications for forms.

1. **Form Component**:
   - The main component that encapsulates form logic and structure.
   - Yields various utilities like `Field`, `Submit`, `Alert`, etc.

   **Example Usage**:
   ```gjs
   import Form from "discourse/form";

   <template>
     <Form as |form|>
       <form.Field
         @name="username"
         @title="Username"
         @validation="required"
         as |field|
       >
         <field.Input />
       </form.Field>

       <form.Field @name="age" @title="Age" as |field|>
         <field.Input @type="number" />
       </form.Field>

       <form.Submit />
     </Form>
   </template>
   ```

2. **Validation**:
   - Built-in validation rules such as `required`, `number`, `length`, and `url`.
   - Custom validation callbacks for more complex validation logic.

   **Example Usage**:
   ```javascript
   validateUsername(name, value, data, { addError }) {
     if (data.bar / 2 === value) {
       addError(name, "That's not how maths work.");
     }
   }
   ```

   ```hbs
   <form.Field @name="username" @validate={{this.validateUsername}} />
   ```

3. **Customization**:
   - Plugin outlets for extending form functionality.
   - Styling capabilities through propagated attributes.
   - Custom controls with properties provided by `form` and `field`.

   **Example Usage**:
   ```hbs
   <Form class="my-form" as |form|>
     <form.Field class="my-field" as |field|>
       <MyCustomControl id={{field.id}} @onChange={{field.set}} />
     </form.Field>
   </Form>
   ```

4. **Helpers for Testing**:
   - Test assertions for form and field validation.

   **Example usage**:
   ```javascript
   assert.form().hasErrors("the form shows errors");
   assert.form().field("foo").hasValue("bar", "user has set the value");
   ```

   - Helper for interacting with he form

   **Example usage**:
   ```javascript
   await formKit().field("foo").fillIn("bar");
   ```

5. **Page Object for System Specs**:
   - Page objects for interacting with forms in system specs.
   - Methods for submitting forms, checking alerts, and interacting with fields.

   **Example Usage**:
   ```ruby
   form = PageObjects::Components::FormKit.new(".my-form")
   form.submit
   expect(form).to have_an_alert("message")
   ```

   **Field Interactions**:
   ```ruby
   field = form.field("foo")
   expect(field).to have_value("bar")
   field.fill_in("bar")
   ```


6. **Collections handling**:
   - A specific component to handle array of objects

   **Example Usage**:
   ```gjs
    <Form @data={{hash foo=(array (hash bar=1) (hash bar=2))}} as |form|>
      <form.Collection @name="foo" as |collection|>
        <collection.Field @name="bar" @title="Bar" as |field|>
          <field.Input />
        </collection.Field>
      </form.Collection>
    </Form>
   ```
2024-07-17 11:59:35 +02:00
..
admin-badges DEV: form-kit 2024-07-17 11:59:35 +02:00
admin-api-keys-index.js DEV: Update admin controllers to native class syntax (#20674) 2023-03-15 09:42:12 +00:00
admin-api-keys-new.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-api-keys-show.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-api-keys.js DEV: Update admin controllers to native class syntax (#20674) 2023-03-15 09:42:12 +00:00
admin-backups-index.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-backups-logs.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-backups.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-badges.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-customize-colors-show.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-customize-colors.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-customize-email-style-edit.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-customize-email-templates-edit.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-customize-email-templates.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-customize-form-templates-index.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-customize-robots-txt.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-customize-themes-edit.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-customize-themes-show.js FIX: Locale mismatch at theme translations picker (#26687) 2024-04-19 14:23:27 -03:00
admin-customize-themes.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-dashboard-general.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-dashboard-moderation.js DEV: Replace period mixin with a component (#25292) 2024-01-18 13:06:42 +01:00
admin-dashboard-new-features.js FEATURE: dedicated admin section for new features (#24292) 2023-11-20 09:59:04 +11:00
admin-dashboard-reports.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-dashboard-tab.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-dashboard.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-email-advanced-test.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-email-bounced.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-email-index.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-email-logs.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-email-preview-digest.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-email-received.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-email-rejected.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-email-sent.js FEAT: add cc addresses and post_id to sent email logs (#25014) 2024-01-03 09:27:25 +08:00
admin-email-skipped.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-embedding.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-emojis.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-logs-screened-emails.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-logs-screened-ip-addresses.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-logs-screened-urls.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-logs-staff-action-logs.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-permalinks.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-plugins-index.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-plugins-show-settings.js FIX: Admin setting search debounce losing characters (#27238) 2024-05-29 15:49:44 +10:00
admin-plugins.js FEATURE: More flexible admin plugin config nav definition (#26254) 2024-03-21 13:42:06 +10:00
admin-reports-show.js DEV: Update admin controllers to native class syntax (#20674) 2023-03-15 09:42:12 +00:00
admin-search-logs-index.js DEV: Rename I18n imports to discourse-i18n (#23915) 2023-10-18 11:07:09 +01:00
admin-search-logs-term.js DEV: Rename I18n imports to discourse-i18n (#23915) 2023-10-18 11:07:09 +01:00
admin-site-settings-category.js DEV: Update admin controllers to native class syntax (#20674) 2023-03-15 09:42:12 +00:00
admin-site-settings.js FEATURE: Allow site settings to be edited throughout admin UI (#26154) 2024-03-18 08:50:39 +10:00
admin-site-text-edit.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-site-text-index.js FEATURE: add Untranslated filter to admin text customization (#27555) 2024-06-24 06:24:06 -03:00
admin-user-badges.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-user-fields.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-user-index.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-user.js DEV: Update admin controllers to native class syntax (#20674) 2023-03-15 09:42:12 +00:00
admin-users-list-show.js DEV: Rename I18n imports to discourse-i18n (#23915) 2023-10-18 11:07:09 +01:00
admin-watched-words-action.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-watched-words.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
admin-web-hooks-edit.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-web-hooks-index.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
admin-web-hooks-show.js FEATURE: Add Filter for Webhook Events by Status (#27332) 2024-06-07 10:26:00 -05:00
admin-web-hooks.js DEV: Update admin controllers to native class syntax (#20674) 2023-03-15 09:42:12 +00:00
admin.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00