Skip to content

Code refator and fix bug form validate#79

Merged
tungleduyxyz merged 2 commits into
masterfrom
kaui_5.13
May 14, 2026
Merged

Code refator and fix bug form validate#79
tungleduyxyz merged 2 commits into
masterfrom
kaui_5.13

Conversation

@tungleduyxyz
Copy link
Copy Markdown
Contributor

Related issue: #36
Summary of changes made:

  1. Fixed dashboard default report behavior:
  • If no report name is provided, the dashboard now falls back to the first available report when only one report exists.
  • This prevents the dashboard from showing an empty page and makes the date controls, refresh button, chart area, and advanced controls render correctly.
  1. Added report form validation:
  • When Source name is set, the form now requires exactly one of Source or SQL query.
  • The form blocks invalid submissions when both are filled or both are empty.
  • An inline validation message is shown near the SQL query field.
  1. Improved dashboard AJAX error handling:
  • JSON report requests now return JSON errors instead of redirecting to an HTML page.
  • The chart area now displays the actual backend error message.
  • This avoids the misleading error:
    SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
  1. Improved report success notices:
  • Report create/update/refresh/delete success messages no longer use the global flash.
  • They now render inline on the reports page to avoid overlapping the New Report button.
  • Improved engine layout flash rendering:
  1. Cleaned up the flash container markup.
  • Fixed malformed closing div markup in the layout.
  1. Moved fixed text to i18n:
  • Added translations under kanaui.* in config/locales/en.bootstrap.yml.
  • Replaced hardcoded report labels, notices, buttons, validation messages, table headers, and error text with i18n lookups.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the Kanaui analytics UI behavior and UX around dashboards and report configuration by fixing the default dashboard report selection, adding client-side report form validation, improving AJAX error handling for JSON endpoints, and moving UI strings into i18n.

Changes:

  • Fix dashboard default report fallback so a single configured report still renders dashboard controls and charts.
  • Add client-side validation to prevent invalid report configurations (Source name requires exactly one of Source or SQL query).
  • Improve error/success messaging: return JSON errors for JSON requests, render backend error messages in the chart area, and render report success notices inline; move fixed UI strings to i18n and clean up flash container markup/CSS.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
config/locales/en.bootstrap.yml Adds kanaui.* i18n keys for labels, notices, and error messages used by updated views/controllers.
app/views/kanaui/reports/new.html.erb Switches the “Add new report” title to i18n.
app/views/kanaui/reports/edit.html.erb Switches the “Update report” title to i18n.
app/views/kanaui/reports/index.html.erb Adds an inline notice area and replaces hardcoded labels with i18n lookups.
app/views/kanaui/reports/_reports_table.html.erb Replaces table headers/actions/modal labels with i18n lookups.
app/views/kanaui/reports/_form.html.erb Adds i18n labels/help text plus inline JS to validate Source name vs Source/SQL query configuration.
app/views/kanaui/layouts/kanaui_application.html.erb Refactors flash rendering markup and fixes malformed closing div.
app/views/kanaui/dashboard/index.html.erb Moves “SQL query” advanced control link label to i18n.
app/controllers/kanaui/reports_controller.rb Refactors success notices into a helper flow and exposes an inline notice value for the index page.
app/controllers/kanaui/engine_controller.rb Returns JSON error bodies for JSON requests (instead of redirecting to HTML), using i18n for the base message.
app/controllers/kanaui/dashboard_controller.rb Adjusts default report selection to fall back to the first report when only one is available.
app/assets/stylesheets/kanaui/kanaui.css Adds styling for the flash container and inline report notice spacing.
app/assets/javascripts/kanaui/kiddo/kiddo_initialize.js Parses JSON error responses and renders escaped backend error messages inside the chart area.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +46 to +55
def report_notice_from_params
notice_key = params[:report_notice].presence
return nil if notice_key.blank?

I18n.t("kanaui.reports.notices.#{notice_key}", default: nil)
end

def redirect_to_index_with_notice(notice_key)
redirect_to action: :index, report_notice: notice_key
end
Comment thread app/assets/stylesheets/kanaui/kanaui.css
@tungleduyxyz tungleduyxyz merged commit c6b1c04 into master May 14, 2026
9 checks passed
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