Skip to content

Commit

Permalink
Fix note edition (#148)
Browse files Browse the repository at this point in the history
* Fix note editor and error styling

* Limit saved journal details for note edition

* Remove useless chars, text will be too long anyway

* Styling

* Ensure empty string as initial value for journal details
  • Loading branch information
relf committed Nov 21, 2022
1 parent 2a590c2 commit f14b8db
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
14 changes: 9 additions & 5 deletions app/javascript/mda_viewer/components/AnalysisEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ class AnalysisEditor extends React.PureComponent {
return (
<div className="container-fluid">
<div className="editor-section">
<div className="editor-section-label">Information</div>
<form className="col-6" onSubmit={onAnalysisUpdate}>
<div className="mb-3">
<div className="editor-section-label">
<i className="fas fa-info-circle" title="Analysis general informations" />
{' '}
General Information
</div>
<form onSubmit={onAnalysisUpdate}>
<div className="mb-3 col-4">
<div className="editor-section-label">
Name
</div>
Expand All @@ -139,7 +143,7 @@ class AnalysisEditor extends React.PureComponent {
onChange={onAnalysisNameChange}
/>
</div>
<div className="mb-3">
<div className="mb-3 col-4">
<div className="editor-section-label">
Design Project
</div>
Expand All @@ -153,7 +157,7 @@ class AnalysisEditor extends React.PureComponent {
<div className="editor-section-label">
Notes
</div>
<div className="editor-section-label">
<div className="editor-section-label col-9">
<AnalysisNoteEditor
mdaId={mdaId}
note={note}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AnalysisNoteEditor extends React.Component {
<div>
<input type="hidden" name="analysis[note]" id={id} value={note} />
{/* <textarea name="analysis[note]" id={id} defaultValue={this.props.note} /> */}
<trix-editor id="analysis_note" input={id} class="trix-content form-control" ref={this.trixInput} />
<trix-editor id="analysis_note" input={id} className="form-control trix-content" ref={this.trixInput} />
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mda_viewer/components/ProjectSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ProjectSelector extends React.Component {
labelKey="name"
minLength={1}
onSearch={this.handleSearch}
placeholder="Search for design project, otherwise none is fine."
placeholder="Search for a design project to attach to, otherwise none is fine."
onChange={this.handleChange}
/>
);
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/utils/components/Error.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class Error extends React.PureComponent {
render() {
const { msg, onClose } = this.props;
return (
<div className="alert alert-warning" role="alert">
<button type="button" className="btn-close" href="#" onClick={onClose} />
<div className="alert alert-warning alert-dismissible fade show" role="alert">
{msg}
<button type="button" className="btn-close" data-bs-dismiss="alert" aria-label="Close" onClick={onClose} />
</div>
);
}
Expand Down
6 changes: 5 additions & 1 deletion app/models/journal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ def journalize(journalized, action, copy_what: nil)

def journalize_changes(journalized, old_attrs)
journalized.journalized_attribute_names.each do |attr_name|
before = old_attrs[attr_name]
# ensure an empty string as all attributes have not a null:false default
before = old_attrs[attr_name] || ""
after = journalized.send(attr_name)
unless before == after || (before.blank? && after.blank?)
# Ensure value size less than 255 characters which correspond to field string max size in db
before = before.truncate(30)
after = after.truncate(30)
add_change_detail(journalized.class.name, journalized.name, attr_name, before, after)
end
end
Expand Down
9 changes: 9 additions & 0 deletions app/models/journal_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
class JournalDetail < ApplicationRecord

belongs_to :journal

after_initialize :ensure_default_values

private

def ensure_default_values
self.old_value = "" if self.old_value.blank?
self.value = "" if self.value.blank?
end

end

0 comments on commit f14b8db

Please sign in to comment.