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

feat: Allow to hide bank assessment results at charts #446

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion 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
permit_params :number, :indicator_type, :text, :comment, :disable_bubbles_at_chart

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

f.actions
Expand Down
15 changes: 10 additions & 5 deletions app/javascript/components/tpi/charts/bank-bubble/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const SINGLE_CELL_SVG_HEIGHT = 100 * SCALE;
const tooltipDisclaimer = 'Market cap size';
let tooltip = null;

const BubbleChart = ({ results }) => {
const BubbleChart = ({ results, disabled_bubbles_areas }) => {
const tooltipEl = '<div id="bubble-chart-tooltip" class="bubble-tip" hidden style="position:absolute;"></div>';
useEffect(() => {
document.body.insertAdjacentHTML('beforeend', tooltipEl);
Expand Down Expand Up @@ -91,7 +91,7 @@ const BubbleChart = ({ results }) => {
</div>
</div>
))}
{Object.keys(parsedData).map((area, index) => createRow(parsedData[area], area, index + 1))}
{Object.keys(parsedData).map((area, index) => createRow(parsedData[area], area, index + 1, disabled_bubbles_areas))}
</div>
);
};
Expand Down Expand Up @@ -139,13 +139,13 @@ const hideTooltip = () => {
tooltip.setAttribute('hidden', true);
};

const createRow = (dataRow, area, index) => (
const createRow = (dataRow, area, index, disabled_bubbles_areas) => (
<React.Fragment key={Math.random()}>
<div className="bubble-chart__row-link">
{index}.&nbsp;{area}
</div>
{dataRow.map((el, i) => {
const companiesBubbles = el.map(result => ({
const companiesBubbles = disabled_bubbles_areas.includes(area) ? [] : el.map(result => ({
value: COMPANIES_MARKET_CAP_GROUPS[result.market_cap_group],
tooltipContent: {
header: result.bank_name,
Expand All @@ -168,6 +168,10 @@ const createRow = (dataRow, area, index) => (
</React.Fragment>
);

BubbleChart.defaultProps = {
disabled_bubbles_areas: []
};

BubbleChart.propTypes = {
results: PropTypes.arrayOf(PropTypes.shape({
area: PropTypes.string.isRequired,
Expand All @@ -176,6 +180,7 @@ BubbleChart.propTypes = {
bank_id: PropTypes.number.isRequired,
bank_name: PropTypes.string.isRequired,
bank_path: PropTypes.string.isRequired
})).isRequired
})).isRequired,
disabled_bubbles_areas: PropTypes.arrayOf(PropTypes.string)
};
export default BubbleChart;
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ DropdownIndicator.propTypes = {
selectProps: PropTypes.object.isRequired
};

const CompaniesAccordion = ({ results }) => {
const CompaniesAccordion = ({ results, disabled_bubbles_areas }) => {
const areas = uniq(results.map(r => r.area));
const selectOptions = areas.map((level) => ({label: level, value: level}));
const [openItems, setOpenItems] = useState([]);
Expand All @@ -82,7 +82,9 @@ const CompaniesAccordion = ({ results }) => {
}
});

const activeArea = parsedData[activeOption.value];
const activeArea = disabled_bubbles_areas.includes(activeOption.value)
? Array.from({ length: ranges.length }, () => [])
: parsedData[activeOption.value];

function setOpenItemByIndex(index) {
setOpenItems(openItems.includes(index) ? openItems.filter(i => i !== index) : [...openItems, index]);
Expand Down Expand Up @@ -113,21 +115,21 @@ const CompaniesAccordion = ({ results }) => {
<div className="item-header" onClick={() => setOpenItemByIndex(i)}>
<div className="item-title">
<div>Score Range</div>
<div>{activeArea[i].length} {activeArea[i].length === 1 ? 'company' : 'companies'}</div>
<div>{activeArea[i].length} {activeArea[i].length === 1 ? 'bank' : 'banks'}</div>
</div>
<div className="sector-subtitle">{range.min}-{range.max}%</div>
</div>
<div className="item-body">
<hr />
{activeArea[i].length === 0 && <div className="no-companies">No companies</div>}
{activeArea[i].length === 0 && <div className="no-companies">No banks</div>}
{activeArea[i].length > 0 && (
<ul className="companies-list">
{sortBy(activeArea[i], 'bank_name').map((company, index) => (
{sortBy(activeArea[i], 'bank_name').map((bank, index) => (
<li
key={`chart-companies-${index}`}
onClick={() => { window.location.href = company.bank_path; }}
onClick={() => { window.location.href = bank.bank_path; }}
>
{company.bank_name}
{bank.bank_name}
</li>
))}
</ul>
Expand All @@ -141,6 +143,7 @@ const CompaniesAccordion = ({ results }) => {
};

CompaniesAccordion.defaultProps = {
disabled_bubbles_areas: []
};

CompaniesAccordion.propTypes = {
Expand All @@ -151,6 +154,7 @@ CompaniesAccordion.propTypes = {
bank_id: PropTypes.number.isRequired,
bank_name: PropTypes.string.isRequired,
bank_path: PropTypes.string.isRequired
})).isRequired
})).isRequired,
disabled_bubbles_areas: PropTypes.arrayOf(PropTypes.string)
};
export default CompaniesAccordion;
10 changes: 8 additions & 2 deletions app/views/tpi/banks/_index_charts.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<%= react_component('charts/average-bank-score', { dataUrl: average_bank_score_chart_data_tpi_banks_path }) %>
<%= react_component('charts/bank-bubble/Chart', { results: @results }) %>
<%= react_component('charts/bank-bubble/CompaniesAccordion', { results: @results }) %>
<%= react_component('charts/bank-bubble/Chart', {
results: @results,
disabled_bubbles_areas: BankAssessmentIndicator.area.where(disable_bubbles_at_chart: true).pluck(:text)
}) %>
<%= react_component('charts/bank-bubble/CompaniesAccordion', {
results: @results,
disabled_bubbles_areas: BankAssessmentIndicator.area.where(disable_bubbles_at_chart: true).pluck(:text)
}) %>
2 changes: 1 addition & 1 deletion app/views/tpi/banks/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</div>
</div>
<div class="banks-score-description">
Assessed banks alignment across the six areas (% of sub-indicators aligned with)
Assessed banks alignment across the ten areas (% of sub-indicators aligned with)
</div>

<div id="assessment-charts">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddDisableBubblesAtGraphToBankAssessmentIndicator < ActiveRecord::Migration[6.1]
def change
add_column :bank_assessment_indicators, :disable_bubbles_at_chart, :boolean, default: false
BankAssessmentIndicator.area.where(number: ["4"]).update_all disable_bubbles_at_chart: true
end
end
6 changes: 4 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ CREATE TABLE public.bank_assessment_indicators (
text text NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
comment text
comment text,
disable_bubbles_at_chart boolean DEFAULT false
);


Expand Down Expand Up @@ -3732,6 +3733,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230622073030'),
('20230622093001'),
('20230712074753'),
('20230713121501');
('20230713121501'),
('20230926075145');


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