nitro_kit 2.0.0.beta.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +79 -1
- data/LICENSE +21 -28
- data/README.md +10 -9
- data/STYLE_GUIDE.md +1 -1
- data/app/assets/stylesheets/nitro_kit.css +1706 -1400
- data/app/assets/tailwind/nitro_kit/engine.css +15 -0
- data/app/components/nitro_kit/accordion.rb +1 -13
- data/app/components/nitro_kit/app_navigation.rb +0 -12
- data/app/components/nitro_kit/app_shell.rb +5 -11
- data/app/components/nitro_kit/appearance_picker.rb +1 -7
- data/app/components/nitro_kit/combobox.rb +366 -21
- data/app/components/nitro_kit/command_palette.rb +7 -20
- data/app/components/nitro_kit/details_table.rb +5 -11
- data/app/components/nitro_kit/dropzone.rb +3 -15
- data/app/components/nitro_kit/field.rb +20 -2
- data/app/components/nitro_kit/pagination.rb +2 -8
- data/app/components/nitro_kit/settings_layout.rb +3 -9
- data/app/javascript/controllers/nk/app_shell_controller.js +2 -2
- data/app/javascript/controllers/nk/combobox_controller.js +308 -22
- data/app/javascript/controllers/nk/combobox_remote.js +70 -0
- data/app/javascript/controllers/nk/dropzone_controller.js +2 -2
- data/app/javascript/controllers/nk/tabs_controller.js +2 -2
- data/config/locales/en.yml +3 -0
- data/docs/agent_guide.md +43 -13
- data/docs/browser_support.md +7 -1
- data/docs/component_contracts.md +90 -61
- data/docs/customization.md +205 -47
- data/docs/initialization_prompt.md +4 -5
- data/docs/migration_1_to_2.md +10 -8
- data/docs/patterns/application_foundation.md +5 -0
- data/docs/patterns/composition.md +61 -0
- data/docs/patterns/crud_resource.md +5 -0
- data/docs/patterns/inset_workspace.md +21 -22
- data/docs/patterns/resource_form.md +65 -0
- data/docs/rails_integration.md +217 -3
- data/lib/generators/nitro_kit/install_generator.rb +5 -4
- data/lib/nitro_kit/engine.rb +13 -0
- data/lib/nitro_kit/installation.rb +353 -72
- data/lib/nitro_kit/migration_inventory.rb +18 -3
- data/lib/nitro_kit/version.rb +1 -1
- data/lib/rails/commands/nitro_kit/nitro_kit_command.rb +2 -2
- data/lib/tasks/nitro_kit_tasks.rake +1 -1
- data/patterns/README.md +21 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/account_deletion.rb +72 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/base.rb +44 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/page.rb +57 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/preferences.rb +68 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/profile.rb +86 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/security.rb +69 -0
- data/patterns/account-settings/files/app/components/ui/account_settings/sessions.rb +86 -0
- data/patterns/account-settings/files/app/controllers/settings/account_deletions_controller.rb +35 -0
- data/patterns/account-settings/files/app/controllers/settings/base_controller.rb +12 -0
- data/patterns/account-settings/files/app/controllers/settings/other_sessions_controller.rb +8 -0
- data/patterns/account-settings/files/app/controllers/settings/preferences_controller.rb +27 -0
- data/patterns/account-settings/files/app/controllers/settings/profiles_controller.rb +20 -0
- data/patterns/account-settings/files/app/controllers/settings/securities_controller.rb +37 -0
- data/patterns/account-settings/files/app/controllers/settings/sessions_controller.rb +31 -0
- data/patterns/account-settings/files/app/models/account_settings/account_closure.rb +33 -0
- data/patterns/account-settings/files/app/models/account_settings/password_change.rb +42 -0
- data/patterns/account-settings/files/app/models/account_settings/session_summary.rb +45 -0
- data/patterns/account-settings/files/app/models/concerns/user/account_configurable.rb +18 -0
- data/patterns/account-settings/files/config/routes/account_settings.rb +10 -0
- data/patterns/account-settings/files/db/migrate/20260731020000_add_account_settings.rb +27 -0
- data/patterns/account-settings/files/test/controllers/settings/account_settings_flow_test.rb +84 -0
- data/patterns/account-settings/files/test/models/account_settings/password_change_test.rb +40 -0
- data/patterns/account-settings/files/test/system/account_settings_test.rb +52 -0
- data/patterns/account-settings/item.yml +4 -0
- data/patterns/account-settings/pattern.md +44 -0
- data/patterns/application-shell/files/app/assets/stylesheets/ui/application_shell.css +267 -0
- data/patterns/application-shell/files/app/components/ui/application_shell.rb +184 -0
- data/patterns/application-shell/item.yml +4 -0
- data/patterns/application-shell/pattern.md +110 -0
- data/patterns/authentication/files/app/components/ui/authentication/base.rb +11 -0
- data/patterns/authentication/files/app/components/ui/authentication/page.rb +53 -0
- data/patterns/authentication/files/app/components/ui/email_verifications/show.rb +62 -0
- data/patterns/authentication/files/app/components/ui/password_resets/new.rb +65 -0
- data/patterns/authentication/files/app/components/ui/passwords/edit.rb +72 -0
- data/patterns/authentication/files/app/components/ui/sessions/new.rb +58 -0
- data/patterns/authentication/files/app/components/ui/verification_emails/new.rb +59 -0
- data/patterns/authentication/files/app/controllers/concerns/authentication.rb +66 -0
- data/patterns/authentication/files/app/controllers/concerns/safe_return_navigation.rb +37 -0
- data/patterns/authentication/files/app/controllers/email_verifications_controller.rb +39 -0
- data/patterns/authentication/files/app/controllers/password_resets_controller.rb +33 -0
- data/patterns/authentication/files/app/controllers/passwords_controller.rb +51 -0
- data/patterns/authentication/files/app/controllers/sessions_controller.rb +42 -0
- data/patterns/authentication/files/app/controllers/verification_emails_controller.rb +33 -0
- data/patterns/authentication/files/app/jobs/authentication_delivery_job.rb +17 -0
- data/patterns/authentication/files/app/mailers/authentication_mailer.rb +15 -0
- data/patterns/authentication/files/app/models/authentication/credentials.rb +16 -0
- data/patterns/authentication/files/app/models/authentication/email_request.rb +17 -0
- data/patterns/authentication/files/app/models/concerns/user/email_verifiable.rb +40 -0
- data/patterns/authentication/files/app/models/session.rb +5 -0
- data/patterns/authentication/files/app/views/authentication_mailer/email_verification.html.erb +3 -0
- data/patterns/authentication/files/app/views/authentication_mailer/email_verification.text.erb +5 -0
- data/patterns/authentication/files/app/views/authentication_mailer/password_reset.html.erb +3 -0
- data/patterns/authentication/files/app/views/authentication_mailer/password_reset.text.erb +5 -0
- data/patterns/authentication/files/config/routes/authentication.rb +11 -0
- data/patterns/authentication/files/db/migrate/20260731000000_add_authentication_and_recovery.rb +13 -0
- data/patterns/authentication/files/test/controllers/authentication_flow_test.rb +103 -0
- data/patterns/authentication/files/test/controllers/safe_return_navigation_test.rb +18 -0
- data/patterns/authentication/files/test/mailers/authentication_mailer_test.rb +21 -0
- data/patterns/authentication/files/test/models/user_email_verifiable_test.rb +36 -0
- data/patterns/authentication/files/test/system/authentication_flow_test.rb +23 -0
- data/patterns/authentication/item.yml +12 -0
- data/patterns/authentication/pattern.md +54 -0
- data/patterns/crud-resource/files/app/assets/stylesheets/ui/projects.css +4 -0
- data/patterns/crud-resource/files/app/components/ui/projects/form.rb +89 -0
- data/patterns/crud-resource/files/app/components/ui/projects/index.rb +161 -0
- data/patterns/crud-resource/files/app/components/ui/projects/show.rb +84 -0
- data/patterns/crud-resource/files/app/controllers/projects/archivals_controller.rb +23 -0
- data/patterns/crud-resource/files/app/controllers/projects_controller.rb +70 -0
- data/patterns/crud-resource/files/app/models/project/archival.rb +8 -0
- data/patterns/crud-resource/files/app/models/project/event.rb +12 -0
- data/patterns/crud-resource/files/app/models/project/filter.rb +41 -0
- data/patterns/crud-resource/files/app/models/project.rb +41 -0
- data/patterns/crud-resource/files/app/views/projects/edit.html.erb +19 -0
- data/patterns/crud-resource/files/app/views/projects/index.html.erb +18 -0
- data/patterns/crud-resource/files/app/views/projects/new.html.erb +16 -0
- data/patterns/crud-resource/files/app/views/projects/show.html.erb +28 -0
- data/patterns/crud-resource/files/config/routes/crud_resource.rb +7 -0
- data/patterns/crud-resource/files/db/migrate/20260720000000_create_crud_resource.rb +37 -0
- data/patterns/crud-resource/files/test/controllers/projects_controller_test.rb +64 -0
- data/patterns/crud-resource/files/test/models/project_test.rb +34 -0
- data/patterns/crud-resource/files/test/support/crud_resource_test_helpers.rb +25 -0
- data/patterns/crud-resource/files/test/system/projects_crud_test.rb +87 -0
- data/patterns/crud-resource/item.yml +6 -0
- data/patterns/crud-resource/pattern.md +48 -0
- data/patterns/file-uploads/files/app/assets/stylesheets/ui/uploads.css +133 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/base.rb +30 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/index.rb +188 -0
- data/patterns/file-uploads/files/app/components/ui/uploads/page.rb +33 -0
- data/patterns/file-uploads/files/app/controllers/uploads/base_controller.rb +29 -0
- data/patterns/file-uploads/files/app/controllers/uploads/direct_uploads_controller.rb +55 -0
- data/patterns/file-uploads/files/app/controllers/uploads/retries_controller.rb +14 -0
- data/patterns/file-uploads/files/app/controllers/uploads_controller.rb +40 -0
- data/patterns/file-uploads/files/app/jobs/upload_blob_cleanup_job.rb +9 -0
- data/patterns/file-uploads/files/app/jobs/upload_processing_job.rb +10 -0
- data/patterns/file-uploads/files/app/jobs/upload_repair_job.rb +17 -0
- data/patterns/file-uploads/files/app/models/concerns/team/uploadable.rb +9 -0
- data/patterns/file-uploads/files/app/models/upload.rb +295 -0
- data/patterns/file-uploads/files/config/recurring/uploads.yml +7 -0
- data/patterns/file-uploads/files/config/routes/uploads.rb +5 -0
- data/patterns/file-uploads/files/db/migrate/20260802000000_add_file_uploads.rb +30 -0
- data/patterns/file-uploads/files/test/controllers/uploads_flow_test.rb +77 -0
- data/patterns/file-uploads/files/test/fixtures/files/workspace.png.base64 +1 -0
- data/patterns/file-uploads/files/test/fixtures/uploads.yml +17 -0
- data/patterns/file-uploads/files/test/models/upload_test.rb +55 -0
- data/patterns/file-uploads/files/test/system/file_uploads_test.rb +30 -0
- data/patterns/file-uploads/item.yml +4 -0
- data/patterns/file-uploads/pattern.md +71 -0
- data/patterns/nitro-kit-1-upgrade/files/docs/nitro_kit_1_upgrade.md +57 -0
- data/patterns/nitro-kit-1-upgrade/item.yml +4 -0
- data/patterns/nitro-kit-1-upgrade/pattern.md +30 -0
- data/patterns/onboarding/files/app/assets/stylesheets/ui/onboarding.css +55 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/base.rb +11 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/branch_form.rb +36 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/details_form.rb +67 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/invitation_plan_form.rb +48 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/page.rb +75 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/review.rb +51 -0
- data/patterns/onboarding/files/app/components/ui/onboarding/show.rb +32 -0
- data/patterns/onboarding/files/app/controllers/concerns/requires_finished_onboarding.rb +14 -0
- data/patterns/onboarding/files/app/controllers/onboarding/base_controller.rb +30 -0
- data/patterns/onboarding/files/app/controllers/onboarding/branches_controller.rb +16 -0
- data/patterns/onboarding/files/app/controllers/onboarding/completions_controller.rb +13 -0
- data/patterns/onboarding/files/app/controllers/onboarding/details_controller.rb +16 -0
- data/patterns/onboarding/files/app/controllers/onboarding/invitation_plans_controller.rb +20 -0
- data/patterns/onboarding/files/app/controllers/onboardings_controller.rb +7 -0
- data/patterns/onboarding/files/app/jobs/onboarding_invitation_delivery_job.rb +15 -0
- data/patterns/onboarding/files/app/models/concerns/team/onboardable.rb +23 -0
- data/patterns/onboarding/files/app/models/onboarding/completion.rb +17 -0
- data/patterns/onboarding/files/app/models/onboarding/invitation_delivery.rb +14 -0
- data/patterns/onboarding/files/app/models/onboarding.rb +174 -0
- data/patterns/onboarding/files/config/routes/onboarding.rb +11 -0
- data/patterns/onboarding/files/db/migrate/20260731010000_create_onboarding.rb +60 -0
- data/patterns/onboarding/files/test/controllers/onboarding_flow_test.rb +62 -0
- data/patterns/onboarding/files/test/fixtures/onboarding_completions.yml +3 -0
- data/patterns/onboarding/files/test/fixtures/onboardings.yml +25 -0
- data/patterns/onboarding/files/test/jobs/onboarding_invitation_delivery_job_test.rb +18 -0
- data/patterns/onboarding/files/test/models/onboarding_test.rb +60 -0
- data/patterns/onboarding/files/test/system/onboarding_flow_test.rb +39 -0
- data/patterns/onboarding/item.yml +4 -0
- data/patterns/onboarding/pattern.md +53 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/base.rb +39 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/checkout_result.rb +64 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/page.rb +33 -0
- data/patterns/subscription-billing/files/app/components/ui/billing/show.rb +149 -0
- data/patterns/subscription-billing/files/app/controllers/billing/base_controller.rb +16 -0
- data/patterns/subscription-billing/files/app/controllers/billing/checkouts_controller.rb +65 -0
- data/patterns/subscription-billing/files/app/controllers/billing/portals_controller.rb +18 -0
- data/patterns/subscription-billing/files/app/controllers/billing_controller.rb +17 -0
- data/patterns/subscription-billing/files/app/controllers/webhooks/stripe_events_controller.rb +21 -0
- data/patterns/subscription-billing/files/app/jobs/billing/stripe_event_job.rb +16 -0
- data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_job.rb +16 -0
- data/patterns/subscription-billing/files/app/jobs/billing/subscription_reconciliation_sweep_job.rb +9 -0
- data/patterns/subscription-billing/files/app/models/billing/checkout.rb +58 -0
- data/patterns/subscription-billing/files/app/models/billing/plan.rb +19 -0
- data/patterns/subscription-billing/files/app/models/billing/stripe_event.rb +73 -0
- data/patterns/subscription-billing/files/app/models/billing/subscription.rb +106 -0
- data/patterns/subscription-billing/files/app/models/concerns/team/billable.rb +36 -0
- data/patterns/subscription-billing/files/config/initializers/stripe.rb +29 -0
- data/patterns/subscription-billing/files/config/routes/subscription_billing.rb +10 -0
- data/patterns/subscription-billing/files/db/migrate/20260801000000_add_subscription_billing.rb +61 -0
- data/patterns/subscription-billing/files/test/controllers/billing_flow_test.rb +60 -0
- data/patterns/subscription-billing/files/test/models/billing/subscription_test.rb +40 -0
- data/patterns/subscription-billing/files/test/system/subscription_billing_test.rb +28 -0
- data/patterns/subscription-billing/item.yml +4 -0
- data/patterns/subscription-billing/pattern.md +59 -0
- data/patterns/team-management/files/app/components/ui/invitations/acceptance.rb +33 -0
- data/patterns/team-management/files/app/components/ui/teams/index.rb +87 -0
- data/patterns/team-management/files/app/components/ui/teams/invitation_form.rb +51 -0
- data/patterns/team-management/files/app/components/ui/teams/member_form.rb +78 -0
- data/patterns/team-management/files/app/components/ui/teams/members.rb +125 -0
- data/patterns/team-management/files/app/controllers/invitations/acceptances_controller.rb +29 -0
- data/patterns/team-management/files/app/controllers/teams/base_controller.rb +18 -0
- data/patterns/team-management/files/app/controllers/teams/invitations_controller.rb +42 -0
- data/patterns/team-management/files/app/controllers/teams/memberships_controller.rb +53 -0
- data/patterns/team-management/files/app/controllers/teams_controller.rb +30 -0
- data/patterns/team-management/files/app/mailers/team_invitation_mailer.rb +10 -0
- data/patterns/team-management/files/app/models/concerns/current_team.rb +13 -0
- data/patterns/team-management/files/app/models/concerns/user_teams.rb +37 -0
- data/patterns/team-management/files/app/models/invitation.rb +41 -0
- data/patterns/team-management/files/app/models/membership.rb +45 -0
- data/patterns/team-management/files/app/models/team.rb +25 -0
- data/patterns/team-management/files/app/views/invitations/acceptances/show.html.erb +1 -0
- data/patterns/team-management/files/app/views/team_invitation_mailer/invite.html.erb +10 -0
- data/patterns/team-management/files/app/views/team_invitation_mailer/invite.text.erb +7 -0
- data/patterns/team-management/files/app/views/teams/index.html.erb +15 -0
- data/patterns/team-management/files/app/views/teams/invitations/new.html.erb +22 -0
- data/patterns/team-management/files/app/views/teams/memberships/edit.html.erb +22 -0
- data/patterns/team-management/files/app/views/teams/memberships/index.html.erb +20 -0
- data/patterns/team-management/files/config/routes/team_management.rb +11 -0
- data/patterns/team-management/files/db/migrate/20260717000000_create_team_management.rb +31 -0
- data/patterns/team-management/files/test/models/invitation_test.rb +28 -0
- data/patterns/team-management/files/test/models/membership_test.rb +29 -0
- data/patterns/team-management/files/test/models/team_test.rb +31 -0
- data/patterns/team-management/files/test/support/team_management_test_helpers.rb +22 -0
- data/patterns/team-management/item.yml +4 -0
- data/patterns/team-management/pattern.md +47 -0
- data/patterns/webhook-deliveries/files/app/assets/stylesheets/ui/webhooks.css +179 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/base.rb +38 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/delivery.rb +160 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/endpoint.rb +149 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/form.rb +75 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/index.rb +142 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/page.rb +33 -0
- data/patterns/webhook-deliveries/files/app/components/ui/webhooks/secret.rb +38 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries/replays_controller.rb +13 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_deliveries_controller.rb +7 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints/secrets_controller.rb +41 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhook_endpoints_controller.rb +67 -0
- data/patterns/webhook-deliveries/files/app/controllers/webhooks/base_controller.rb +15 -0
- data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_job.rb +9 -0
- data/patterns/webhook-deliveries/files/app/jobs/webhook_delivery_repair_job.rb +11 -0
- data/patterns/webhook-deliveries/files/app/models/concerns/team/webhookable.rb +11 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/attempt.rb +30 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/delivery.rb +268 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/endpoint.rb +58 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/event.rb +98 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/secret_reveal.rb +53 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/signature.rb +22 -0
- data/patterns/webhook-deliveries/files/app/models/webhook/transport.rb +176 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_deliveries/show.html.erb +5 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/edit.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/index.html.erb +6 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/new.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/secrets/new.html.erb +1 -0
- data/patterns/webhook-deliveries/files/app/views/webhook_endpoints/show.html.erb +7 -0
- data/patterns/webhook-deliveries/files/config/recurring/webhooks.yml +4 -0
- data/patterns/webhook-deliveries/files/config/routes/webhook_deliveries.rb +10 -0
- data/patterns/webhook-deliveries/files/db/migrate/20260803000000_add_webhook_deliveries.rb +126 -0
- data/patterns/webhook-deliveries/files/test/controllers/webhook_endpoints_flow_test.rb +48 -0
- data/patterns/webhook-deliveries/files/test/models/webhook/delivery_test.rb +70 -0
- data/patterns/webhook-deliveries/files/test/system/webhook_deliveries_test.rb +29 -0
- data/patterns/webhook-deliveries/item.yml +4 -0
- data/patterns/webhook-deliveries/pattern.md +120 -0
- data/plugins/nitro-kit/.codex-plugin/plugin.json +4 -4
- data/plugins/nitro-kit/skills/nitro-kit-hotwire/SKILL.md +7 -9
- data/plugins/nitro-kit/skills/nitro-kit-hotwire/agents/openai.yaml +1 -1
- data/plugins/nitro-kit/skills/nitro-kit-rails/SKILL.md +10 -9
- data/plugins/nitro-kit/skills/nitro-kit-rails/agents/openai.yaml +1 -1
- data/plugins/nitro-kit/skills/nitro-kit-ui/SKILL.md +27 -16
- data/plugins/nitro-kit/skills/nitro-kit-ui/agents/openai.yaml +1 -1
- data/src/stylesheets/nitro_kit/components/accordion.css +40 -40
- data/src/stylesheets/nitro_kit/components/alert.css +7 -6
- data/src/stylesheets/nitro_kit/components/app_navigation.css +50 -41
- data/src/stylesheets/nitro_kit/components/app_shell.css +371 -280
- data/src/stylesheets/nitro_kit/components/appearance_picker.css +38 -38
- data/src/stylesheets/nitro_kit/components/avatar.css +3 -3
- data/src/stylesheets/nitro_kit/components/avatar_stack.css +18 -18
- data/src/stylesheets/nitro_kit/components/badge.css +5 -2
- data/src/stylesheets/nitro_kit/components/button.css +57 -49
- data/src/stylesheets/nitro_kit/components/button_group.css +14 -14
- data/src/stylesheets/nitro_kit/components/checkbox.css +24 -24
- data/src/stylesheets/nitro_kit/components/checkbox_group.css +13 -13
- data/src/stylesheets/nitro_kit/components/combobox.css +152 -25
- data/src/stylesheets/nitro_kit/components/command_palette.css +59 -59
- data/src/stylesheets/nitro_kit/components/control_group.css +71 -54
- data/src/stylesheets/nitro_kit/components/details_table.css +9 -9
- data/src/stylesheets/nitro_kit/components/dialog.css +8 -12
- data/src/stylesheets/nitro_kit/components/dropdown.css +22 -26
- data/src/stylesheets/nitro_kit/components/dropzone.css +97 -100
- data/src/stylesheets/nitro_kit/components/empty_state.css +1 -0
- data/src/stylesheets/nitro_kit/components/field.css +26 -30
- data/src/stylesheets/nitro_kit/components/fieldset.css +2 -2
- data/src/stylesheets/nitro_kit/components/input.css +6 -14
- data/src/stylesheets/nitro_kit/components/layout.css +165 -165
- data/src/stylesheets/nitro_kit/components/page_header.css +3 -3
- data/src/stylesheets/nitro_kit/components/pagination.css +66 -49
- data/src/stylesheets/nitro_kit/components/pagination_bar.css +6 -6
- data/src/stylesheets/nitro_kit/components/palette.css +24 -22
- data/src/stylesheets/nitro_kit/components/progressive_image.css +38 -41
- data/src/stylesheets/nitro_kit/components/radio_button.css +19 -19
- data/src/stylesheets/nitro_kit/components/radio_button_group.css +43 -43
- data/src/stylesheets/nitro_kit/components/rich_text_area.css +4 -4
- data/src/stylesheets/nitro_kit/components/select.css +2 -2
- data/src/stylesheets/nitro_kit/components/settings_layout.css +17 -18
- data/src/stylesheets/nitro_kit/components/settings_section.css +12 -12
- data/src/stylesheets/nitro_kit/components/sheet.css +10 -10
- data/src/stylesheets/nitro_kit/components/stat_grid.css +9 -9
- data/src/stylesheets/nitro_kit/components/switch.css +23 -23
- data/src/stylesheets/nitro_kit/components/table.css +27 -27
- data/src/stylesheets/nitro_kit/components/tabs.css +32 -34
- data/src/stylesheets/nitro_kit/components/toolbar.css +6 -6
- data/src/stylesheets/nitro_kit/components/tooltip.css +26 -28
- data/src/stylesheets/nitro_kit/layers.css +10 -1
- data/src/stylesheets/nitro_kit/reset.css +10 -10
- data/{app/assets/stylesheets/nitro_kit-tailwind-v4.css → src/stylesheets/nitro_kit/tailwind.css} +10 -7
- data/src/stylesheets/nitro_kit/tokens.css +18 -9
- metadata +240 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Draw this file from config/routes.rb with:
|
|
2
|
+
# draw :authentication
|
|
3
|
+
#
|
|
4
|
+
# Also add :token, :password, :password_confirmation, and :email_address to
|
|
5
|
+
# config.filter_parameters.
|
|
6
|
+
|
|
7
|
+
resource :session, only: %i[new create destroy]
|
|
8
|
+
resource :password_reset, only: %i[new create]
|
|
9
|
+
resources :passwords, param: :token, only: %i[edit update]
|
|
10
|
+
resource :verification_email, only: %i[new create]
|
|
11
|
+
resources :email_verifications, param: :token, only: %i[show update]
|
data/patterns/authentication/files/db/migrate/20260731000000_add_authentication_and_recovery.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class AddAuthenticationAndRecovery < ActiveRecord::Migration[8.1]
|
|
2
|
+
def change
|
|
3
|
+
add_column :users, :password_digest, :string
|
|
4
|
+
add_column :users, :email_verified_at, :datetime
|
|
5
|
+
|
|
6
|
+
create_table :sessions do |t|
|
|
7
|
+
t.references :user, null: false, foreign_key: true
|
|
8
|
+
t.string :ip_address
|
|
9
|
+
t.string :user_agent
|
|
10
|
+
t.timestamps
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class AuthenticationControllerFlowTest < ActionDispatch::IntegrationTest
|
|
4
|
+
include ActiveJob::TestHelper
|
|
5
|
+
|
|
6
|
+
test "unknown and known recovery addresses have the same response" do
|
|
7
|
+
post password_reset_path, params: {
|
|
8
|
+
authentication_email_request: { email_address: users(:verified).email_address }
|
|
9
|
+
}
|
|
10
|
+
known_response = response
|
|
11
|
+
|
|
12
|
+
post password_reset_path, params: {
|
|
13
|
+
authentication_email_request: { email_address: "unknown@example.test" }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
assert_equal known_response.status, response.status
|
|
17
|
+
assert_equal URI.parse(known_response.location).path, URI.parse(response.location).path
|
|
18
|
+
assert_enqueued_jobs 2, only: AuthenticationDeliveryJob
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test "password token GET does not mutate and PATCH revokes sessions" do
|
|
22
|
+
user = users(:verified)
|
|
23
|
+
token = user.password_reset_token
|
|
24
|
+
|
|
25
|
+
assert_no_changes -> { user.reload.password_digest } do
|
|
26
|
+
get edit_password_path(token)
|
|
27
|
+
assert_response :success
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
assert_difference -> { user.sessions.count }, -user.sessions.count do
|
|
31
|
+
patch password_path(token), params: {
|
|
32
|
+
user: { password: "new secure password", password_confirmation: "new secure password" }
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
assert_redirected_to new_session_path
|
|
37
|
+
assert_raises(ActiveSupport::MessageVerifier::InvalidSignature) do
|
|
38
|
+
User.find_by_password_reset_token!(token)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test "blank or unconfirmed password does not revoke sessions or consume the token" do
|
|
43
|
+
user = users(:verified)
|
|
44
|
+
token = user.password_reset_token
|
|
45
|
+
digest = user.password_digest
|
|
46
|
+
|
|
47
|
+
assert_no_difference -> { user.sessions.count } do
|
|
48
|
+
patch password_path(token), params: {
|
|
49
|
+
user: { password: "", password_confirmation: "" }
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
assert_response :unprocessable_entity
|
|
54
|
+
assert_equal digest, user.reload.password_digest
|
|
55
|
+
assert_equal user, User.find_by_password_reset_token!(token)
|
|
56
|
+
|
|
57
|
+
patch password_path(token), params: {
|
|
58
|
+
user: { password: "new secure password" }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
assert_response :unprocessable_entity
|
|
62
|
+
assert_equal digest, user.reload.password_digest
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
test "verification GET does not mutate and PATCH verifies without signing in" do
|
|
66
|
+
user = users(:unverified)
|
|
67
|
+
token = user.email_verification_token
|
|
68
|
+
|
|
69
|
+
get email_verification_path(token)
|
|
70
|
+
assert_response :success
|
|
71
|
+
assert_not user.reload.email_verified?
|
|
72
|
+
|
|
73
|
+
assert_no_difference "Session.count" do
|
|
74
|
+
patch email_verification_path(token)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
assert user.reload.email_verified?
|
|
78
|
+
assert_redirected_to new_session_path
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
test "invalid tokens render recoverable states" do
|
|
82
|
+
get edit_password_path("tampered")
|
|
83
|
+
assert_response :success
|
|
84
|
+
assert_select "[data-nk='alert']", text: /invalid or expired/i
|
|
85
|
+
|
|
86
|
+
get email_verification_path("tampered")
|
|
87
|
+
assert_response :success
|
|
88
|
+
assert_select "[data-nk='alert']", text: /invalid or expired/i
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
test "tokens for deleted users render recoverable states" do
|
|
92
|
+
user = users(:unverified)
|
|
93
|
+
reset_token = user.password_reset_token
|
|
94
|
+
verification_token = user.email_verification_token
|
|
95
|
+
user.destroy!
|
|
96
|
+
|
|
97
|
+
get edit_password_path(reset_token)
|
|
98
|
+
assert_response :success
|
|
99
|
+
|
|
100
|
+
get email_verification_path(verification_token)
|
|
101
|
+
assert_response :success
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class SafeReturnNavigationTest < ActionController::TestCase
|
|
4
|
+
tests SessionsController
|
|
5
|
+
|
|
6
|
+
test "accepts local destinations and rejects external or looping destinations" do
|
|
7
|
+
assert_equal "/projects?state=active", safe_destination("/projects?state=active")
|
|
8
|
+
assert_nil safe_destination("https://attacker.example/projects")
|
|
9
|
+
assert_nil safe_destination("//attacker.example/projects")
|
|
10
|
+
assert_nil safe_destination(new_session_path)
|
|
11
|
+
assert_nil safe_destination(new_password_reset_path)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
def safe_destination(value)
|
|
16
|
+
@controller.send(:safe_destination, value)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class AuthenticationMailerTest < ActionMailer::TestCase
|
|
4
|
+
test "password recovery contains an absolute expiring reset link" do
|
|
5
|
+
mail = AuthenticationMailer.password_reset(users(:verified))
|
|
6
|
+
|
|
7
|
+
assert_equal [ users(:verified).email_address ], mail.to
|
|
8
|
+
assert_match "Reset your password", mail.subject
|
|
9
|
+
assert_match %r{https?://.+/passwords/.+/edit}, mail.html_part.body.decoded
|
|
10
|
+
assert_match "15 minutes", mail.text_part.body.decoded
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "verification contains an absolute verification link" do
|
|
14
|
+
mail = AuthenticationMailer.email_verification(users(:unverified))
|
|
15
|
+
|
|
16
|
+
assert_equal [ users(:unverified).email_address ], mail.to
|
|
17
|
+
assert_match "Verify your email", mail.subject
|
|
18
|
+
assert_match %r{https?://.+/email_verifications/.+}, mail.html_part.body.decoded
|
|
19
|
+
assert_match "two days", mail.text_part.body.decoded
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class UserEmailVerifiableTest < ActiveSupport::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@user = users(:unverified)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
test "verification changes state and invalidates the link" do
|
|
9
|
+
token = @user.email_verification_token
|
|
10
|
+
|
|
11
|
+
@user.verify_email!
|
|
12
|
+
|
|
13
|
+
assert @user.email_verified?
|
|
14
|
+
assert_raises(ActiveSupport::MessageVerifier::InvalidSignature) do
|
|
15
|
+
User.find_by_email_verification_token!(token)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test "changing the address invalidates the link" do
|
|
20
|
+
token = @user.email_verification_token
|
|
21
|
+
|
|
22
|
+
@user.update!(email_address: "new-address@example.test")
|
|
23
|
+
|
|
24
|
+
assert_raises(ActiveSupport::MessageVerifier::InvalidSignature) do
|
|
25
|
+
User.find_by_email_verification_token!(token)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test "changing a verified address requires verification again" do
|
|
30
|
+
@user.verify_email!
|
|
31
|
+
|
|
32
|
+
@user.update!(email_address: "new-address@example.test")
|
|
33
|
+
|
|
34
|
+
assert_not @user.email_verified?
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "application_system_test_case"
|
|
2
|
+
|
|
3
|
+
class AuthenticationSystemFlowTest < ApplicationSystemTestCase
|
|
4
|
+
test "signs in and returns to the protected destination" do
|
|
5
|
+
visit projects_path
|
|
6
|
+
assert_current_path new_session_path
|
|
7
|
+
|
|
8
|
+
fill_in "Email address", with: users(:verified).email_address
|
|
9
|
+
fill_in "Password", with: "password"
|
|
10
|
+
click_on "Sign in"
|
|
11
|
+
|
|
12
|
+
assert_current_path projects_path
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
test "recovers from an unusable reset link" do
|
|
16
|
+
visit edit_password_path("tampered")
|
|
17
|
+
|
|
18
|
+
assert_text "This link is invalid or expired"
|
|
19
|
+
click_on "Request a new link"
|
|
20
|
+
|
|
21
|
+
assert_current_path new_password_reset_path
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
version: 1.0.0
|
|
2
|
+
title: Authentication and recovery
|
|
3
|
+
summary: Sign-in, email verification, password recovery, and safe return navigation for Rails.
|
|
4
|
+
tags: [authentication, sessions, password-recovery, email-verification, rails]
|
|
5
|
+
variants:
|
|
6
|
+
- id: centered-card
|
|
7
|
+
summary: One calm, focused card centered on the page.
|
|
8
|
+
default: true
|
|
9
|
+
- id: split-screen
|
|
10
|
+
summary: Two-column layout pairing the sign-in card with a large brand or image panel.
|
|
11
|
+
- id: minimal
|
|
12
|
+
summary: Bare sign-in stripped to the form and an unadorned brand mark.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Authentication and recovery
|
|
2
|
+
|
|
3
|
+
## When to use
|
|
4
|
+
|
|
5
|
+
Use this pattern when a Rails 8.1 application owns password authentication and needs one coherent path through sign-in, email verification, and password recovery. It starts with Rails' generated authentication primitives, keeps policy in the host application, and uses `NitroKit::AuthShell` only for the narrow standalone form surface.
|
|
6
|
+
|
|
7
|
+
## Domain boundary
|
|
8
|
+
|
|
9
|
+
- Include `User::EmailVerifiable` beside the host's existing `has_secure_password`. Rails owns password-reset token signing, expiry, and invalidation when the password changes; the concern adds an independently purposed verification token bound to the normalized address and verification timestamp.
|
|
10
|
+
- Keep `Session` persistence and `Current` integration application-owned. The included controller concern shows a plain user session; adapt `start_new_session_for`, `revoke_sessions_for`, and `default_authenticated_path` rather than selecting a team or membership implicitly.
|
|
11
|
+
- Queue `AuthenticationDeliveryJob` for every valid recovery or verification request. The job performs the user lookup so known and unknown addresses receive the same HTTP response and request-time work.
|
|
12
|
+
- Do not disclose whether an address exists. Malformed input receives ordinary validation; every well-formed address receives the same sent state.
|
|
13
|
+
|
|
14
|
+
## Token lifecycle
|
|
15
|
+
|
|
16
|
+
Password-reset tokens come from Rails 8.1 `has_secure_password`. They expire after 15 minutes and are bound to the password salt, so a successful update invalidates every outstanding reset link. Email-verification tokens expire after two days and are bound to both `email_address` and `email_verified_at`; changing or verifying the address invalidates old links.
|
|
17
|
+
|
|
18
|
+
Mail links open a confirmation form. `GET` validates and explains; `PATCH` mutates. This avoids consuming credentials when mail scanners follow links. Invalid, expired, wrong-purpose, and already-used links share a neutral unusable state because signed tokens intentionally do not reveal why verification failed. Every failure screen offers a fresh request path.
|
|
19
|
+
|
|
20
|
+
## Session and return navigation
|
|
21
|
+
|
|
22
|
+
Remember only same-origin HTML `GET` destinations. Store the path server-side, validate it again with Rails `url_from`, reject authentication-loop destinations, consume it once, and fall back to the host's authenticated root. Never redirect to a `return_to` parameter.
|
|
23
|
+
|
|
24
|
+
Rotate the Rails session before creating an authenticated session record. Sign the persistent record cookie, mark it `HttpOnly` and `SameSite=Lax`, and use `Secure` over HTTPS. A password reset revokes every persisted session and does not sign the user in automatically.
|
|
25
|
+
|
|
26
|
+
## Rendering
|
|
27
|
+
|
|
28
|
+
Each route renders one application-owned Card inside `NitroKit::AuthShell`. Use `NitroKit::FormBuilder`, preserve only the email address after validation, and never render a password value. Keep `email`, `current-password`, and `new-password` autocomplete values accurate. Turbo Drive handles normal submissions and 422 replacements; no authentication-specific JavaScript or Turbo Frame is required.
|
|
29
|
+
|
|
30
|
+
## Variants
|
|
31
|
+
|
|
32
|
+
Variants share this pattern's entire core — controllers, models, security rules, token lifecycle, and return navigation. They differ only in the view/layout of the sign-in (other authentication screens follow the same family). Structural differences, such as magic-link sign-in instead of password, are separate patterns, not variants.
|
|
33
|
+
|
|
34
|
+
Choose a variant by product context:
|
|
35
|
+
|
|
36
|
+
- **centered-card** *(default)* — One calm, focused `Card` centered in `AuthShell`. Use when sign-in is the page's single job and the product wants no distraction: most internal tools, minimal apps, and anything where the form itself must carry the attention.
|
|
37
|
+
- **split-screen** — A two-column layout pairing the sign-in `Card` with a large brand/image/benefit panel on the other side. Use for consumer-facing or marketing-adjacent products where sign-in doubles as an on-brand moment: a product screenshot, a photo, or a benefit headline.
|
|
38
|
+
- **minimal** — Chrome stripped to the bare form plus an unadorned brand mark; no panel, minimal copy. Use where quiet confidence fits — high-trust contexts, logged-out pages that should feel effortless, or designs that avoid visual furniture entirely.
|
|
39
|
+
|
|
40
|
+
Keep `autocomplete` values, error handling, and non-disclosure behavior identical across every variant; only the surrounding layout changes.
|
|
41
|
+
|
|
42
|
+
## Adaptation
|
|
43
|
+
|
|
44
|
+
Mount `config/routes/authentication.rb` from the host route set, include `User::EmailVerifiable`, and merge the migration with the host user/session schema. Replace product copy and mailer sender. Override the session hooks for tenant selection and destination policy. Add token parameters to `config.filter_parameters`; the exemplar filter list is included in the route fragment comments.
|
|
45
|
+
|
|
46
|
+
## Verification
|
|
47
|
+
|
|
48
|
+
- Compare wrong-password and unknown-address responses; they must use identical status, copy, and field treatment.
|
|
49
|
+
- Prove known and unknown recovery requests enqueue the same job and render the same sent response.
|
|
50
|
+
- Exercise valid, expired, tampered, wrong-purpose, and reused links without mutating on `GET`.
|
|
51
|
+
- Verify password mismatch returns 422, a valid update revokes sessions, and the old token no longer resolves.
|
|
52
|
+
- Verify email change invalidates a verification token and successful verification does not create a session.
|
|
53
|
+
- Test local, external, protocol-relative, malformed, repeated, and authentication-loop return destinations.
|
|
54
|
+
- Browser-test keyboard use, Turbo validation, mail-to-reset and mail-to-verify paths, 390px layout, both appearances, and password-value absence.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UI
|
|
4
|
+
module Projects
|
|
5
|
+
class Form < Base
|
|
6
|
+
def initialize(project:)
|
|
7
|
+
@project = project
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.form_id(project)
|
|
11
|
+
ActionView::RecordIdentifier.dom_id(project, :form)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def view_template
|
|
15
|
+
Container(size: :lg) do
|
|
16
|
+
Flex(dir: :col, gap: 8, align: :stretch) do
|
|
17
|
+
render_form
|
|
18
|
+
render_deletion if project.persisted?
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
attr_reader :project
|
|
26
|
+
|
|
27
|
+
def render_form
|
|
28
|
+
Fieldset(
|
|
29
|
+
legend: "Project details",
|
|
30
|
+
description: "Keep the record concise enough to scan in a table."
|
|
31
|
+
) do
|
|
32
|
+
render_errors
|
|
33
|
+
form_with(
|
|
34
|
+
model: project,
|
|
35
|
+
builder: NitroKit::FormBuilder,
|
|
36
|
+
id: self.class.form_id(project)
|
|
37
|
+
) do |form|
|
|
38
|
+
form.group do
|
|
39
|
+
form.field(:name, required: true, control_html: { autofocus: true })
|
|
40
|
+
form.field(:description, as: :textarea, rows: 8)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def render_errors
|
|
47
|
+
return unless project.errors.any?
|
|
48
|
+
|
|
49
|
+
render NitroKit::Alert.new(variant: :destructive) do |alert|
|
|
50
|
+
alert.title("Please review the highlighted fields")
|
|
51
|
+
alert.description(project.errors.full_messages.to_sentence)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def render_deletion
|
|
56
|
+
DangerZone(
|
|
57
|
+
title: "Delete project",
|
|
58
|
+
description: "This permanently removes the project and its history."
|
|
59
|
+
) do |zone|
|
|
60
|
+
zone.confirmation do
|
|
61
|
+
Dialog(id: dom_id(project, :delete_dialog)) do |dialog|
|
|
62
|
+
dialog.trigger("Review deletion", variant: :destructive)
|
|
63
|
+
dialog.panel(
|
|
64
|
+
title: "Delete #{project.name}?",
|
|
65
|
+
description: "This action cannot be undone."
|
|
66
|
+
) do
|
|
67
|
+
Flex(dir: :row, gap: 2, justify: :end, wrap: :wrap) do
|
|
68
|
+
Button("Cancel", html: { command: "close", commandfor: "#{dialog.id}-panel" })
|
|
69
|
+
form_with(model: project, method: :delete) do
|
|
70
|
+
Button(
|
|
71
|
+
"Delete project",
|
|
72
|
+
type: :submit,
|
|
73
|
+
variant: :destructive,
|
|
74
|
+
data: { turbo_submits_with: "Deleting…" }
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
zone.escape NitroKit::Button.new(
|
|
82
|
+
"Keep project",
|
|
83
|
+
href: project_path(project)
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UI
|
|
4
|
+
module Projects
|
|
5
|
+
class Index < Base
|
|
6
|
+
def initialize(projects:, filter:, pagy:)
|
|
7
|
+
@projects = projects
|
|
8
|
+
@filter = filter
|
|
9
|
+
@pagy = pagy
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def view_template
|
|
13
|
+
Flex(dir: :col, gap: 6, align: :stretch) do
|
|
14
|
+
render_filters
|
|
15
|
+
render_results
|
|
16
|
+
render_pagination if pagy.pages > 1
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
attr_reader :projects, :filter, :pagy
|
|
23
|
+
|
|
24
|
+
def render_filters
|
|
25
|
+
form_with(
|
|
26
|
+
model: filter,
|
|
27
|
+
scope: :filter,
|
|
28
|
+
url: projects_path,
|
|
29
|
+
method: :get,
|
|
30
|
+
builder: NitroKit::FormBuilder,
|
|
31
|
+
data: { turbo_action: "replace" },
|
|
32
|
+
html: { role: "search" }
|
|
33
|
+
) do |form|
|
|
34
|
+
Grid(cols: "1 md:3", gap: 3) do
|
|
35
|
+
form.field(
|
|
36
|
+
:query,
|
|
37
|
+
as: :search,
|
|
38
|
+
label: "Search projects",
|
|
39
|
+
placeholder: "Name",
|
|
40
|
+
autocomplete: "off"
|
|
41
|
+
)
|
|
42
|
+
form.field(
|
|
43
|
+
:state,
|
|
44
|
+
as: :select,
|
|
45
|
+
label: "State",
|
|
46
|
+
options: [
|
|
47
|
+
[ "All projects", "all" ],
|
|
48
|
+
[ "Active", "active" ],
|
|
49
|
+
[ "Archived", "archived" ]
|
|
50
|
+
]
|
|
51
|
+
)
|
|
52
|
+
Flex(dir: :row, gap: 2, align: :end, justify: :end) do
|
|
53
|
+
if filter.active?
|
|
54
|
+
Button(
|
|
55
|
+
"Reset",
|
|
56
|
+
href: projects_path,
|
|
57
|
+
data: { turbo_action: "replace" }
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
form.submit(
|
|
61
|
+
"Apply filters",
|
|
62
|
+
data: { turbo_submits_with: "Filtering…" }
|
|
63
|
+
)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def render_results
|
|
70
|
+
return render_table if projects.any?
|
|
71
|
+
|
|
72
|
+
EmptyState(
|
|
73
|
+
title: filter.active? ? "No projects match" : "No projects yet",
|
|
74
|
+
description: empty_description,
|
|
75
|
+
level: 2
|
|
76
|
+
) do |empty|
|
|
77
|
+
empty.icon NitroKit::Icon.new(:folder, size: :lg)
|
|
78
|
+
if filter.active?
|
|
79
|
+
empty.action NitroKit::Button.new(
|
|
80
|
+
"Clear filters",
|
|
81
|
+
href: projects_path,
|
|
82
|
+
data: { turbo_action: "replace" }
|
|
83
|
+
)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def empty_description
|
|
89
|
+
if filter.active?
|
|
90
|
+
"Try a broader search or clear the current filters."
|
|
91
|
+
else
|
|
92
|
+
"Use the persistent New project action to create the first one."
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def render_table
|
|
97
|
+
Table(data: { ui: "projects-table" }, table_aria: { label: "Projects" }) do |table|
|
|
98
|
+
table.thead do
|
|
99
|
+
table.tr do
|
|
100
|
+
table.th("Project", data: { projects_column: "name" })
|
|
101
|
+
table.th("State", data: { projects_column: "status" })
|
|
102
|
+
table.th("Created by", data: { projects_column: "creator" })
|
|
103
|
+
table.th("Updated", data: { projects_column: "updated" })
|
|
104
|
+
table.th("Actions", align: :right, data: { projects_column: "actions" })
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
table.tbody { projects.each { |project| render_row(table, project) } }
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def render_row(table, project)
|
|
112
|
+
table.tr do
|
|
113
|
+
table.th(project.name, scope: :row, data: { projects_column: "name" })
|
|
114
|
+
table.td(data: { projects_column: "status" }) do
|
|
115
|
+
Badge(
|
|
116
|
+
project.archived? ? "Archived" : "Active",
|
|
117
|
+
color: project.archived? ? :neutral : :success,
|
|
118
|
+
variant: :outline,
|
|
119
|
+
size: :sm
|
|
120
|
+
)
|
|
121
|
+
end
|
|
122
|
+
table.td(project.creator.name, data: { projects_column: "creator" })
|
|
123
|
+
table.td(data: { projects_column: "updated" }) do
|
|
124
|
+
time(datetime: project.updated_at.iso8601) do
|
|
125
|
+
project.updated_at.to_date.to_fs(:long)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
table.td(align: :right, data: { projects_column: "actions" }) do
|
|
129
|
+
Flex(dir: :row, gap: 1, align: :stretch, justify: :end) do
|
|
130
|
+
Button(
|
|
131
|
+
"View",
|
|
132
|
+
href: project_path(project),
|
|
133
|
+
size: :sm
|
|
134
|
+
)
|
|
135
|
+
Button(
|
|
136
|
+
"Edit",
|
|
137
|
+
href: edit_project_path(project),
|
|
138
|
+
size: :sm
|
|
139
|
+
)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def render_pagination
|
|
146
|
+
PaginationBar do |bar|
|
|
147
|
+
first = ((pagy.page - 1) * pagy.limit) + 1
|
|
148
|
+
last = [ pagy.page * pagy.limit, pagy.count ].min
|
|
149
|
+
bar.summary("Showing #{first}–#{last} of #{pagy.count} projects")
|
|
150
|
+
bar.pagination NitroKit::Pagination.new(
|
|
151
|
+
pagy:,
|
|
152
|
+
page_url: ->(page) do
|
|
153
|
+
projects_path(page:, filter: filter.parameters)
|
|
154
|
+
end,
|
|
155
|
+
label: "Project pages"
|
|
156
|
+
)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module UI
|
|
4
|
+
module Projects
|
|
5
|
+
class Show < Base
|
|
6
|
+
def initialize(project:, events:)
|
|
7
|
+
@project = project
|
|
8
|
+
@events = events
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.archival_form_id(project)
|
|
12
|
+
ActionView::RecordIdentifier.dom_id(project, :archival_form)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def view_template
|
|
16
|
+
Flex(dir: :col, gap: 8, align: :stretch) do
|
|
17
|
+
render_summary
|
|
18
|
+
render_archival_form
|
|
19
|
+
render_history
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
attr_reader :project, :events
|
|
26
|
+
|
|
27
|
+
def render_summary
|
|
28
|
+
DetailsTable(project) do |details|
|
|
29
|
+
details.field(:status, value: project.archived?) do |archived|
|
|
30
|
+
Badge(
|
|
31
|
+
archived ? "Archived" : "Active",
|
|
32
|
+
color: archived ? :neutral : :success,
|
|
33
|
+
variant: :outline
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
details.field(:description)
|
|
37
|
+
details.field(:creator, label: "Created by")
|
|
38
|
+
details.field(:created_at, label: "Created")
|
|
39
|
+
details.field(:updated_at, label: "Last updated")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def render_archival_form
|
|
44
|
+
form_with(
|
|
45
|
+
url: project_archival_path(project),
|
|
46
|
+
method: project.archived? ? :delete : :post,
|
|
47
|
+
id: self.class.archival_form_id(project)
|
|
48
|
+
) { }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def render_history
|
|
52
|
+
DataSection(
|
|
53
|
+
title: "History",
|
|
54
|
+
description: "Lifecycle changes remain attached to this project."
|
|
55
|
+
) do |section|
|
|
56
|
+
section.table NitroKit::Table.new(
|
|
57
|
+
table_aria: { label: "Project history" }
|
|
58
|
+
) do |table|
|
|
59
|
+
table.thead do
|
|
60
|
+
table.tr do
|
|
61
|
+
table.th("Change")
|
|
62
|
+
table.th("By")
|
|
63
|
+
table.th("When")
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
table.tbody do
|
|
67
|
+
events.each do |event|
|
|
68
|
+
table.tr do
|
|
69
|
+
table.th(event.action.humanize, scope: :row)
|
|
70
|
+
table.td(event.actor.name)
|
|
71
|
+
table.td do
|
|
72
|
+
time(datetime: event.created_at.iso8601) do
|
|
73
|
+
event.created_at.to_fs(:long)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Projects
|
|
4
|
+
class ArchivalsController < ApplicationController
|
|
5
|
+
before_action :set_project
|
|
6
|
+
|
|
7
|
+
def create
|
|
8
|
+
@project.archive!
|
|
9
|
+
redirect_to @project, status: :see_other, notice: "Project archived"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def destroy
|
|
13
|
+
@project.restore!
|
|
14
|
+
redirect_to @project, status: :see_other, notice: "Project restored"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def set_project
|
|
20
|
+
@project = Current.team.projects.find(params[:project_id])
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|