Skip to content

Commit

Permalink
review findings: reverted some refactorings & specified alert text
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Herrmann committed Oct 9, 2024
1 parent fda698c commit 12fe218
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 138 deletions.
30 changes: 15 additions & 15 deletions app/api/chemotion/sample_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SampleAPI < Grape::API
col_id = ui_state[:currentCollectionId]
sample_ids = Sample.for_user(current_user.id)
.for_ui_state_with_collection(ui_state[:sample], CollectionsSample, col_id)
Sample.where(id: sample_ids).find_each do |sample|
Sample.where(id: sample_ids).each do |sample|
subsample = sample.create_subsample(current_user, col_id, true, 'sample')
end

Expand Down Expand Up @@ -319,7 +319,7 @@ class SampleAPI < Grape::API
optional :description, type: String, desc: 'Sample description'
optional :metrics, type: String, desc: 'Sample metric units'
optional :purity, type: Float, desc: 'Sample purity'
optional :solvent, type: [Hash], desc: 'Sample solvent'
optional :solvent, type: Array[Hash], desc: 'Sample solvent'
optional :location, type: String, desc: 'Sample location'
optional :molfile, type: String, desc: 'Sample molfile'
optional :sample_svg_file, type: String, desc: 'Sample SVG file'
Expand Down Expand Up @@ -382,14 +382,14 @@ class SampleAPI < Grape::API
next if prop_value.blank?

attributes.merge!(
"#{prop}_attributes": prop_value,
"#{prop}_attributes".to_sym => prop_value,
)
end

boiling_point_lowerbound = params['boiling_point_lowerbound'].presence || -Float::INFINITY
boiling_point_upperbound = params['boiling_point_upperbound'].presence || Float::INFINITY
melting_point_lowerbound = params['melting_point_lowerbound'].presence || -Float::INFINITY
melting_point_upperbound = params['melting_point_upperbound'].presence || Float::INFINITY
boiling_point_lowerbound = (params['boiling_point_lowerbound'].presence || -Float::INFINITY)
boiling_point_upperbound = (params['boiling_point_upperbound'].presence || Float::INFINITY)
melting_point_lowerbound = (params['melting_point_lowerbound'].presence || -Float::INFINITY)
melting_point_upperbound = (params['melting_point_upperbound'].presence || Float::INFINITY)
attributes['boiling_point'] = Range.new(boiling_point_lowerbound, boiling_point_upperbound)
attributes['melting_point'] = Range.new(melting_point_lowerbound, melting_point_upperbound)
attributes.delete(:boiling_point_lowerbound)
Expand Down Expand Up @@ -452,7 +452,7 @@ class SampleAPI < Grape::API
requires :purity, type: Float, desc: 'Sample purity'
optional :dry_solvent, default: false, type: Boolean, desc: 'Sample dry solvent'
# requires :solvent, type: String, desc: "Sample solvent"
optional :solvent, type: [Hash], desc: 'Sample solvent', default: []
optional :solvent, type: Array[Hash], desc: 'Sample solvent', default: []
requires :location, type: String, desc: 'Sample location'
optional :molfile, type: String, desc: 'Sample molfile'
optional :sample_svg_file, type: String, desc: 'Sample SVG file'
Expand Down Expand Up @@ -519,10 +519,10 @@ class SampleAPI < Grape::API
sum_formula: params[:sum_formula],
}

boiling_point_lowerbound = params['boiling_point_lowerbound'].presence || -Float::INFINITY
boiling_point_upperbound = params['boiling_point_upperbound'].presence || Float::INFINITY
melting_point_lowerbound = params['melting_point_lowerbound'].presence || -Float::INFINITY
melting_point_upperbound = params['melting_point_upperbound'].presence || Float::INFINITY
boiling_point_lowerbound = (params['boiling_point_lowerbound'].presence || -Float::INFINITY)
boiling_point_upperbound = (params['boiling_point_upperbound'].presence || Float::INFINITY)
melting_point_lowerbound = (params['melting_point_lowerbound'].presence || -Float::INFINITY)
melting_point_upperbound = (params['melting_point_upperbound'].presence || Float::INFINITY)
attributes['boiling_point'] = Range.new(boiling_point_lowerbound, boiling_point_upperbound)
attributes['melting_point'] = Range.new(melting_point_lowerbound, melting_point_upperbound)

Expand All @@ -543,7 +543,7 @@ class SampleAPI < Grape::API
next if prop_value.blank?

attributes.merge!(
"#{prop}_attributes": prop_value,
"#{prop}_attributes".to_sym => prop_value,
)
end
attributes.delete(:segments)
Expand All @@ -552,13 +552,13 @@ class SampleAPI < Grape::API
sample = Sample.new(attributes)

if params[:collection_id]
collection = current_user.collections.find_by(id: params[:collection_id])
collection = current_user.collections.where(id: params[:collection_id]).take
sample.collections << collection if collection.present?
end

is_shared_collection = false
if collection.blank?
sync_collection = current_user.all_sync_in_collections_users.find_by(id: params[:collection_id])
sync_collection = current_user.all_sync_in_collections_users.where(id: params[:collection_id]).take
if sync_collection.present?
is_shared_collection = true
sample.collections << Collection.find(sync_collection['collection_id'])
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/sample-details.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
background-color: lightgray;
}
}
}
}
4 changes: 2 additions & 2 deletions app/models/reactions_product_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# created_at :datetime default(Fri, 01 Oct 2021 00:00:00 UTC +00:00), not null
# updated_at :datetime default(Fri, 01 Oct 2021 00:00:00 UTC +00:00), not null
# created_at :datetime default(LOCALTIMESTAMP), not null
# updated_at :datetime default(LOCALTIMESTAMP), not null
#
# Indexes
#
Expand Down
4 changes: 2 additions & 2 deletions app/models/reactions_purification_solvent_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# created_at :datetime default(Fri, 01 Oct 2021 00:00:00 UTC +00:00), not null
# updated_at :datetime default(Fri, 01 Oct 2021 00:00:00 UTC +00:00), not null
# created_at :datetime default(LOCALTIMESTAMP), not null
# updated_at :datetime default(LOCALTIMESTAMP), not null
#
# Indexes
#
Expand Down
4 changes: 2 additions & 2 deletions app/models/reactions_reactant_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# created_at :datetime default(Fri, 01 Oct 2021 00:00:00 UTC +00:00), not null
# updated_at :datetime default(Fri, 01 Oct 2021 00:00:00 UTC +00:00), not null
# created_at :datetime default(LOCALTIMESTAMP), not null
# updated_at :datetime default(LOCALTIMESTAMP), not null
#
# Indexes
#
Expand Down
4 changes: 2 additions & 2 deletions app/models/reactions_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# created_at :datetime default(Fri, 01 Oct 2021 00:00:00 UTC +00:00), not null
# updated_at :datetime default(Fri, 01 Oct 2021 00:00:00 UTC +00:00), not null
# created_at :datetime default(LOCALTIMESTAMP), not null
# updated_at :datetime default(LOCALTIMESTAMP), not null
#
# Indexes
#
Expand Down
4 changes: 2 additions & 2 deletions app/models/reactions_solvent_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# created_at :datetime default(Fri, 01 Oct 2021 00:00:00 UTC +00:00), not null
# updated_at :datetime default(Fri, 01 Oct 2021 00:00:00 UTC +00:00), not null
# created_at :datetime default(LOCALTIMESTAMP), not null
# updated_at :datetime default(LOCALTIMESTAMP), not null
#
# Indexes
#
Expand Down
4 changes: 2 additions & 2 deletions app/models/reactions_starting_material_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# created_at :datetime default(Fri, 01 Oct 2021 00:00:00 UTC +00:00), not null
# updated_at :datetime default(Fri, 01 Oct 2021 00:00:00 UTC +00:00), not null
# created_at :datetime default(LOCALTIMESTAMP), not null
# updated_at :datetime default(LOCALTIMESTAMP), not null
#
# Indexes
#
Expand Down
27 changes: 19 additions & 8 deletions app/packs/src/apps/mydb/elements/details/VersionsTableChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ function VersionsTableChanges(props) {
} = props;

const revertibleFields = () => {
let filteredFields = [];

if (isEdited) return -1;

let filteredFields = [];

changes.forEach(({ fields }) => {
filteredFields = filteredFields.concat(
fields.filter((field) => (field.currentValue !== field.oldValue && field.revert.length > 0))
fields.filter((field) => (field.revert.length > 0))
);
});

if (filteredFields.length === 0) {
return -2;
}

filteredFields = filteredFields.filter((field) => (field.currentValue !== field.oldValue));

return filteredFields.length;
};

Expand All @@ -37,15 +43,20 @@ function VersionsTableChanges(props) {
</React.Fragment>
));

const alertText = revertibleFields() < 0
? 'You cannot undo changes. You have unsaved data which would be lost.'
: `You cannot undo these changes.
Either the changes are up to date, it is the first version or all changes are irreversible.`;
const isRevertible = revertibleFields();
let alertText = 'You cannot undo changes. ';
if (isRevertible === 0) {
alertText += 'Every change is either up to date or irreversible';
} else if (isRevertible === -1) {
alertText += 'You have unsaved data which would be lost.';
} else {
alertText += 'Either it is the first version or all changes are irreversible.';
}

return (
<>
{change}
{revertibleFields() > 0 ? <VersionsTableModal name={`# ${id}`} changes={changes} handleRevert={handleRevert} />
{isRevertible > 0 ? <VersionsTableModal name={`# ${id}`} changes={changes} handleRevert={handleRevert} />
: (
<Alert bsStyle="warning" className="history-alert">
{alertText}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ function VersionsTableModal(props) {
}
});

console.log(result);

return result;
};

Expand Down
Loading

0 comments on commit 12fe218

Please sign in to comment.