Skip to content

Commit

Permalink
Merge branch 'feat/mark-bank-indicator-as-placeholder' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
martintomas committed Sep 27, 2023
2 parents f4b11cb + dd0540a commit daae0e9
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 19 deletions.
6 changes: 3 additions & 3 deletions app/admin/bank_assessment_indicators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

data_export_sidebar 'BankAssessmentIndicators', display_name: 'Indicators'

permit_params :number, :indicator_type, :text, :comment, :disable_bubbles_at_chart
permit_params :number, :indicator_type, :text, :comment, :is_placeholder

show do
attributes_table do
Expand All @@ -21,7 +21,7 @@
row :indicator_type
row :text
row :comment
row :disable_bubbles_at_chart
row :is_placeholder
row :created_at
row :updated_at
end
Expand All @@ -37,7 +37,7 @@
f.input :number
f.input :text
f.input :comment
f.input :disable_bubbles_at_chart
f.input :is_placeholder
end

f.actions
Expand Down
11 changes: 8 additions & 3 deletions app/javascript/components/tpi/charts/average-bank-score/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { getOptions } from './options';
import { useChartData } from '../hooks';
import { useDeviceInfo } from 'components/Responsive';

function AverageBankScore({ dataUrl }) {
function AverageBankScore({ dataUrl, disabled_areas }) {
const { data, error, loading } = useChartData(dataUrl);
const { isMobile } = useDeviceInfo();
const options = getOptions(data, isMobile);
const options = getOptions(data, isMobile, disabled_areas);
const noData = !loading && data && data.length === 0;

return (
Expand All @@ -38,8 +38,13 @@ function AverageBankScore({ dataUrl }) {
);
}

AverageBankScore.defaultProps = {
disabled_areas: []
};

AverageBankScore.propTypes = {
dataUrl: PropTypes.string.isRequired
dataUrl: PropTypes.string.isRequired,
disabled_areas: PropTypes.arrayOf(PropTypes.string)
};

export default AverageBankScore;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import merge from 'lodash/merge';

import defaultOptions from '../default-options';

export function getOptions(data, isMobile) {
export function getOptions(data, isMobile, disabled_areas) {
return merge({}, defaultOptions, {
chart: {
type: 'bar'
Expand Down Expand Up @@ -61,7 +61,7 @@ export function getOptions(data, isMobile) {
dataLabels: {
enabled: true,
formatter() {
return `${Number(this.y).toFixed(1)}%`;
return (disabled_areas.includes(this.x)) ? 'N/A' : `${Number(this.y).toFixed(1)}%`;
}
},
states: {
Expand Down
8 changes: 6 additions & 2 deletions app/services/csv_export/user/bank_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def call
assessment.bank.sedol&.tr(',', ';')&.tr(' ', ''),
assessment.assessment_date,
results_columns.map do |column|
next 'N/A' if column.is_placeholder

all_results[[assessment.id, column.type, column.number]]&.first&.decorate&.value
end,
assessment.bank.latest_information&.squish
Expand All @@ -54,12 +56,13 @@ def all_results

def results_columns
@results_columns ||= begin
indicators = indicator_areas.map { |area| [area, child_indicators[area.number]] }.flatten
indicators = indicator_areas.values.flatten.map { |area| [area, child_indicators[area.number]] }.flatten
indicators.map do |indicator|
OpenStruct.new(
type: indicator.indicator_type,
number: indicator.number,
column_name: "#{indicator.indicator_type.humanize} #{indicator.number}"
column_name: "#{indicator.indicator_type.humanize} #{indicator.number}",
is_placeholder: indicator_areas[indicator.number.split('.').first]&.first&.is_placeholder
)
end
end
Expand All @@ -69,6 +72,7 @@ def indicator_areas
@indicator_areas ||= BankAssessmentIndicator
.where(indicator_type: 'area')
.order('length(number), number')
.group_by(&:number)
end

def child_indicators
Expand Down
10 changes: 7 additions & 3 deletions app/views/tpi/banks/_assessment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
</div>
<% if area.percentage < 5 %>
<div class="bank-assessment__area-value-value">
<%= number_with_precision(area.percentage, precision: 1, strip_insignificant_zeros: true) %>%
<% if area.indicator.is_placeholder %>
N/A
<% else %>
<%= number_with_precision(area.percentage, precision: 1, strip_insignificant_zeros: true) %>%
<% end %>
</div>
<% end %>
</div>
Expand Down Expand Up @@ -83,12 +87,12 @@
</div>

<div class="bank-assessment__sub-area-content">
<%= render "indicators", assessment: assessment, indicators: assessment.child_indicators(sub_area, "indicator") %>
<%= render "indicators", assessment: assessment, area: area, indicators: assessment.child_indicators(sub_area, "indicator") %>
</div>
</div>
<% end %>
<% else %>
<%= render "indicators", assessment: assessment, indicators: assessment.child_indicators(area, "indicator") %>
<%= render "indicators", assessment: assessment, area: area, indicators: assessment.child_indicators(area, "indicator") %>
<% end %>
</div>
</div>
Expand Down
9 changes: 6 additions & 3 deletions app/views/tpi/banks/_index_charts.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<%= react_component('charts/average-bank-score', { dataUrl: average_bank_score_chart_data_tpi_banks_path }) %>
<%= react_component('charts/average-bank-score', {
dataUrl: average_bank_score_chart_data_tpi_banks_path,
disabled_areas: BankAssessmentIndicator.area.where(is_placeholder: true).map { |area| "#{area.number}. #{area.text}" }
}) %>
<%= react_component('charts/bank-bubble/Chart', {
results: @results,
disabled_bubbles_areas: BankAssessmentIndicator.area.where(disable_bubbles_at_chart: true).pluck(:text)
disabled_bubbles_areas: BankAssessmentIndicator.area.where(is_placeholder: true).pluck(:text)
}) %>
<%= react_component('charts/bank-bubble/CompaniesAccordion', {
results: @results,
disabled_bubbles_areas: BankAssessmentIndicator.area.where(disable_bubbles_at_chart: true).pluck(:text)
disabled_bubbles_areas: BankAssessmentIndicator.area.where(is_placeholder: true).pluck(:text)
}) %>
6 changes: 5 additions & 1 deletion app/views/tpi/banks/_indicators.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
</h4>
<div class="bank-assessment__indicator-value">
<div>
<%= number_with_precision(indicator.percentage, precision: 1, strip_insignificant_zeros: true) %>%
<% if area.indicator.is_placeholder %>
N/A
<% else %>
<%= number_with_precision(indicator.percentage, precision: 1, strip_insignificant_zeros: true) %>%
<% end %>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameDisableBubblesAtChartToIsPlaceholder < ActiveRecord::Migration[6.1]
def change
rename_column :bank_assessment_indicators, :disable_bubbles_at_chart, :is_placeholder
end
end
5 changes: 3 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ CREATE TABLE public.bank_assessment_indicators (
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
comment text,
disable_bubbles_at_chart boolean DEFAULT false
is_placeholder boolean DEFAULT false
);


Expand Down Expand Up @@ -4157,6 +4157,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230915063557'),
('20230915064402'),
('20230920083300'),
('20230926075145');
('20230926075145'),
('20230927112905');


Binary file modified db/test-dump.psql
Binary file not shown.

0 comments on commit daae0e9

Please sign in to comment.