Skip to content

Commit

Permalink
Merge pull request #439 from Vizzuality/feat/company-doesnt-have-mq-b…
Browse files Browse the repository at this point in the history
…eta-data

feat: adding beta_mq_assessments? to company model
  • Loading branch information
martintomas authored Sep 8, 2023
2 parents 6a8ac99 + 22d9d16 commit 115c38c
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/tpi.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@import "tpi/bubble-chart";
@import "tpi/charts";
@import "tpi/base-tooltip";
@import "tpi/info-tooltip";
@import "tpi/filters";
@import "tpi/footer";
@import "tpi/dropdown-selector";
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/tpi/_info-tooltip.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.info-tooltip {
position: relative;
max-width: 200px;
}
7 changes: 7 additions & 0 deletions app/assets/stylesheets/tpi/_mq_beta_scores.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
}
}

&__beta-button {
&.disabled {
opacity: 0.5;
cursor: not-allowed;
pointer-events: none;
}
}

&__beta-button:before {
content: "";
Expand Down
25 changes: 25 additions & 0 deletions app/javascript/components/tpi/InfoTooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import PropTypes from 'prop-types';
import ReactTooltip from 'react-tooltip';

const InfoTooltip = ({ trigger, content, html }) => (
<span className="base-tooltip">
{html ? <div data-tip={content} dangerouslySetInnerHTML={{ __html: trigger }} /> : <div data-tip={content}>{trigger}</div>}
<ReactTooltip className="info-tooltip" />
</span>
);

InfoTooltip.propTypes = {
trigger: PropTypes.any,
content: PropTypes.any.isRequired,
html: PropTypes.bool
};

InfoTooltip.defaultProps = {
trigger: (
<span className="base-tooltip__default-trigger">?</span>
),
html: false
};

export default InfoTooltip;
4 changes: 4 additions & 0 deletions app/models/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def latest_mq_assessment
latest_mq_assessment_only_beta_methodologies || latest_mq_assessment_without_beta_methodologies
end

def beta_mq_assessments?
mq_assessments.only_beta_methodologies.exists?
end

def should_generate_new_friendly_id?
name_changed? || super
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/tpi/companies/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="companies-header">
<div class="container is-hidden-touch">
<div class="mq-beta-scores">
<%= render 'tpi/shared/mq_beta_scores' %>
<%= render 'tpi/shared/mq_beta_scores', has_data: @company.beta_mq_assessments? %>
<div>
<a href="#management-quality" class="link with-icon is-pulled-left">
<img src="<%= asset_path 'icons/arrow-down.svg'%>" alt="arrow down" />
Expand All @@ -38,7 +38,7 @@
</div>
<div class="container is-hidden-desktop">
<div class="mq-beta-scores is-hidden-desktop">
<%= render 'tpi/shared/mq_beta_scores' %>
<%= render 'tpi/shared/mq_beta_scores', has_data: @company.beta_mq_assessments? %>
<div>
<a href="#management-quality" class="link with-icon is-pulled-left">
Management Quality
Expand Down
2 changes: 1 addition & 1 deletion app/views/tpi/sectors/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="sectors-header">
<div class="container">
<div class="mq-beta-scores">
<%= render 'tpi/shared/mq_beta_scores' %>
<%= render 'tpi/shared/mq_beta_scores', has_data: true %>
<div>
<a href="#management-quality" class="link with-icon">
<img src="<%= asset_path 'icons/arrow-down.svg'%>" alt="arrow down" class="is-hidden-touch" />
Expand Down
4 changes: 2 additions & 2 deletions app/views/tpi/sectors/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="sectors-header">
<div class="container is-hidden-touch">
<div class="mq-beta-scores">
<%= render 'tpi/shared/mq_beta_scores' %>
<%= render 'tpi/shared/mq_beta_scores', has_data: true %>
<div>
<a href="#management-quality" class="link with-icon is-pulled-left">
<img src="<%= asset_path 'icons/arrow-down.svg'%>" alt="arrow down" />
Expand All @@ -41,7 +41,7 @@
</div>
<div class="container is-hidden-desktop">
<div class="mq-beta-scores">
<%= render 'tpi/shared/mq_beta_scores' %>
<%= render 'tpi/shared/mq_beta_scores', has_data: true %>
<div>
<a href="#management-quality" class="link with-icon is-pulled-left">
Management Quality
Expand Down
18 changes: 13 additions & 5 deletions app/views/tpi/shared/_mq_beta_scores.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
<% if ENV['MQ_BETA_ENABLED'].to_s == 'true' %>
<% link_html = link_to(enable_beta_data_tpi_mq_assessments_path,
class: class_names('button', 'is-primary', 'mq-beta-scores__beta-button', 'active': session[:enable_beta_mq_assessments], 'disabled': !has_data),
style: "min-width: 0;") { "BETA (V5.0)" } %>

<div class="mq-beta-scores__container">
<span class="mq-beta-scores__text">MQ Methodology</span>
<%= link_to disable_beta_data_tpi_mq_assessments_path,
class: class_names('button', 'is-primary', 'no-margin', 'weight-normal': session[:enable_beta_mq_assessments], 'active': !session[:enable_beta_mq_assessments]),
style: "min-width: 0;" do %>
Current (V4.0)
<% end %>
<%= link_to enable_beta_data_tpi_mq_assessments_path,
class: class_names('button', 'is-primary', 'mq-beta-scores__beta-button', 'active': session[:enable_beta_mq_assessments]),
style: "min-width: 0;" do %>
BETA (V5.0)
<% end %>
<% if has_data %>
<%= link_html %>
<% else %>
<%= react_component("InfoTooltip", {
trigger: link_html,
content: 'It is not currently possible to show Beta (V5.0) scores for this company. Scores for the current methodology (V4.0) are shown in their place.',
html: true,
}) %>
<% end %>
</div>
<div class="mq-beta-scores__divider"></div>
<% end %>
26 changes: 26 additions & 0 deletions spec/models/company_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,30 @@
end
end
end

describe '#beta_mq_assessments?' do
context 'when company has beta MQ assessments' do
let(:beta_methodology_version) { MQ::Assessment::BETA_METHODOLOGIES.keys.first }
let(:company) do
create(:company, mq_assessments: [
build(:mq_assessment, assessment_date: '2012-05-01'),
build(:mq_assessment, assessment_date: '2019-06-01', methodology_version: beta_methodology_version)
])
end

it 'returns true' do
expect(company.beta_mq_assessments?).to be_truthy
end
end

context 'when company does not have beta MQ assessments' do
let(:company) do
create(:company, mq_assessments: [build(:mq_assessment, assessment_date: '2012-05-01')])
end

it 'returns false' do
expect(company.beta_mq_assessments?).to be_falsey
end
end
end
end

0 comments on commit 115c38c

Please sign in to comment.