Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added notes to constructor #987

Open
wants to merge 25 commits into
base: calculators-constructor
Choose a base branch
from

Conversation

alexy78
Copy link
Contributor

@alexy78 alexy78 commented Nov 28, 2024

Resolves:

Code reviewers

Second Level Review

Summary of issue

The current form for the calculator does not include fields for creating additional notes.

Summary of change

This update introduces two new Ukrainian and English note fields in the calculator form. The changes include creating a YAML file for TinyMCE styling, adding a Stimulus controller to handle TinyMCE initialization, creating a partial for the TinyMCE form, and writing tests for the new fields.

Знімок екрана 2024-11-28 о 16 47 00 Знімок екрана 2024-11-28 о 16 47 06

CHECK LIST

  • СI passed
  • Сode coverage >=95%
  • PR is reviewed manually again (to make sure you have 100% ready code)
  • All reviewers agreed to merge the PR
  • I've checked new feature as logged in and logged out user if needed
  • PR meets all conventions

Comment on lines 38 to 39
validates :english_additional_notes, length: { maximum: 150 }
validates :ukranian_additional_notes, length: { maximum: 150 }
Copy link
Contributor

Choose a reason for hiding this comment

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

а шо коротке таке? може довше зробити?

<%= tinymce_assets %>
<div data-controller="tinymce">
<div class="pt-4">
<%= f.label :ukranian_additional_notes, "Ukrainian Additional Notes" %>
Copy link
Contributor

Choose a reason for hiding this comment

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

l18n?

</div>

<div class="pt-4 pb-4">
<%= f.label :english_additional_notes, "English Additional Notes" %>
Copy link
Contributor

Choose a reason for hiding this comment

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

то саме

Copy link
Collaborator

Choose a reason for hiding this comment

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

локалізація

Comment on lines 1 to 16
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static targets = ['input']

connect() {
let config = Object.assign({ target: this.inputTarget }, TinyMCERails.configuration.default )
tinymce.init(config)

}

disconnect () {
tinymce.remove()
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

порівняй тут гарно код і винеси конфіги в getter, також юзай 2 пробіли, а не 4 і думаю можна без object assign, просто обʼєкт заюзати

Comment on lines 38 to 39
validates :english_additional_notes, length: { maximum: 500 }
validates :ukranian_additional_notes, length: { maximum: 500 }
Copy link
Collaborator

Choose a reason for hiding this comment

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

ну диви, ти молодець, що додала валідацію, але тут не враховані теги, тобто я напишу одну букву, а довжина її буде 7 символів, бо буде огорнута в як мінімум тег p, отож потрібно дещо специфічну валіадацію зробити

</div>

<div class="pt-4 pb-4">
<%= f.label :english_additional_notes, "English Additional Notes" %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

локалізація

Copy link

codecov bot commented Dec 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.19%. Comparing base (e558ac1) to head (1180df7).

Additional details and impacted files
@@                     Coverage Diff                     @@
##           calculators-constructor     #987      +/-   ##
===========================================================
+ Coverage                    89.14%   89.19%   +0.05%     
===========================================================
  Files                           68       68              
  Lines                         1059     1064       +5     
===========================================================
+ Hits                           944      949       +5     
  Misses                         115      115              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

validates :ukranian_additional_notes,
length: {
maximum: 500,
tokenizer: ->(string) { ActionController::Base.helpers.strip_tags(string).chars }
Copy link
Collaborator

Choose a reason for hiding this comment

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

use method to do that and test it

@@ -0,0 +1,14 @@
<%= tinymce_assets %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<%= tinymce_assets %>
<%= tinymce_assets %>

Copy link
Collaborator

Choose a reason for hiding this comment

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

align that all

Comment on lines 4 to 8
<% if I18n.locale == :uk %>
<%= raw calculator.ukranian_additional_notes %>
<% else %>
<%= raw calculator.english_additional_notes %>
<% end %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<% if I18n.locale == :uk %>
<%= raw calculator.ukranian_additional_notes %>
<% else %>
<%= raw calculator.english_additional_notes %>
<% end %>
<%== calculator.notes %>

then you have:
uk_notes
en_notes
and Translatable concern in a model

@@ -361,6 +361,8 @@ uk:
prohibited_to_update: " перешкоджають оновленню калькулятора"
prohibited_to_save: " перешкоджають збереженню калькулятора"
error: "помилки"
ukranian_additional_notes: "Додаткові нотатки українською"
english_additional_notes: "Додаткові нотатки англійською"
Copy link
Collaborator

Choose a reason for hiding this comment

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

у нас же нема основних нотаток)

@KseniaGovorun KseniaGovorun self-requested a review December 26, 2024 11:05
@DanielVajnagi DanielVajnagi self-assigned this Dec 30, 2024
spec/models/calculator_spec.rb Outdated Show resolved Hide resolved
<div class="description-block">
<%# TODO: ADD text here %>
<div class="description-section">
<%== calculator.notes %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there any XSS protection?

<div class="description-block">
<%# TODO: ADD text here %>
<div class="description-section">
<%= sanitize(calculator.notes, tags: %w[p strong em ul li a div span img], attributes: %w[href target class src alt style]) %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

перенеси це в хелпер

Copy link
Collaborator

Choose a reason for hiding this comment

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

і не юзай цей %, то зло

<div class="description-block">
<%# TODO: ADD text here %>
<div class="description-section">
<%= sanitized_notes(calculator.notes) %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

sanitize_content

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Rejected
4 participants