Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluesmile82 committed Oct 27, 2022
2 parents 513e013 + 9b11601 commit cda4e8f
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ GEM
net-ssh (>= 2.6.5, < 7.0.0)
net-ssh (6.1.0)
nio4r (2.5.8)
nokogiri (1.13.8)
nokogiri (1.13.9)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
oj (3.6.8)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/ndcs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def sectors_cache_key
end

def index_json
# params[:source] -> one of ["CAIT", "LTS", "WB", "NDC Explorer", "Pledges"]
# params[:source] -> one of ["CAIT", "LTS", "WB", "NDC Explorer", "Pledges", "UNICEF"]
if params[:source].present?
source = ::Indc::Source.where(name: params[:source])
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const CONFLICTS = {
// E.g. UNFCCC should go before UN.

export const ABBREVIATIONS = {
ACE: 'Action for Climate Empowerment',
AILAC:
'Asociación Independiente de Latinoamérica y el Caribe (Independent Association of Latin America and the Caribbean)',
AR2: "IPCC's Second Assessment Report in 1995",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const fetchNdcsCountryAccordion = createThunkAction(
}?location=${locations}&category=${category}${
lts
? '&source=LTS'
: '&source[]=CAIT&source[]=WB&source[]=NDC%20Explorer'
: '&source[]=CAIT&source[]=WB&source[]=NDC%20Explorer&source[]=UNICEF'
}${documentParam}${!compare ? '&filter=overview' : ''}`
)
.then(response => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ const renderLegend = (legendData, emissionsCardData, isPNG) => (
emissionsCardData.data &&
getHoverIndex(emissionsCardData, l)
}
infoText={
emissionsCardData &&
emissionsCardData.tooltip &&
emissionsCardData.tooltip[l.name]
}
name={l.name}
number={l.partiesNumber}
value={l.value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ import { getSubmitted2020Isos } from 'utils/indicatorCalculations';

const NOT_APPLICABLE_LABEL = 'Not Applicable';

const getColorException = (indicator, label) => {
if (indicator.value !== 'child_sensitive_NDC') return null;
// Child sensitive NDC indicator label colors
return {
'Category A': '#53AF5C',
'Category B': '#8EC593',
'Category C': '#C8DAC9',
'No new or updated NDC submitted': '#757584'
}[label.name];
};

const getSearch = state => state.search || null;
const getCountries = state => state.countries || null;
const getSectors = state => state.sectors || null;
Expand Down Expand Up @@ -256,8 +267,10 @@ export const getPathsWithStyles = createSelector(
}
};
if (countryData && countryData.label_id) {
const legendIndex = legendBuckets[countryData.label_id].index;
const color = getColorByIndex(legendBuckets, legendIndex);
const label = legendBuckets[countryData.label_id];
const color =
getColorException(indicator, label) ||
getColorByIndex(legendBuckets, label.index);
style.default.fill = color;
style.hover.fill = color;
}
Expand Down Expand Up @@ -312,7 +325,9 @@ export const getLegend = createSelector(
...label,
value: percentage(partiesNumber, maximumCountries),
partiesNumber,
color: getColorByIndex(indicator.legendBuckets, label.index)
color:
getColorException(indicator, label) ||
getColorByIndex(indicator.legendBuckets, label.index)
});
});
return legendItems.sort(sortByIndexAndNotInfo);
Expand Down Expand Up @@ -352,6 +367,15 @@ export const getEmissionsCardData = createSelector(
getIndicatorEmissionsData(emissionsIndicator, selectedIndicator, legend),
'value'
);
// Info tooltip only available for this indicator
const tooltip = selectedIndicator.value === 'child_sensitive_NDC' && {
'Category A':
'The NDC is Category A because it meets 4 of 4 criteria for child sensitivity',
'Category B':
'The NDC is Category B because it meets 3 of 4 criteria for child sensitivity',
'Category C':
'The NDC is Category C because it meets 0-2 of 4 criteria for child sensitivity'
};

const config = {
animation: true,
Expand All @@ -370,7 +394,8 @@ export const getEmissionsCardData = createSelector(

return {
config,
data
data,
tooltip
};
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
height: 10px;
display: inline-block;
margin-right: 5px;
min-width: 10px;
width: 10px;
border-radius: 50%;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,14 @@ class NDCSExploreMapContainer extends PureComponent {
this.props.setModalMetadata({
customTitle: 'Explore NDCs',
category: 'NDCS Explore Map',
slugs: ['ndc_cw', 'ndc_wb', 'ndc_die', 'ndc_adaptation'],
slugs: [
'ndc_cw',
'ndc_wb',
'ndc_die',
'ndc_adaptation',
'ndc_unicef',
'ndc_finance'
],
open: true
});
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import ReactTooltip from 'react-tooltip';
import Progress from 'components/progress';
import AbbrReplace from 'components/abbr-replace';
import infoIcon from 'assets/icons/info.svg';
import Icon from 'components/icon';
import PropTypes from 'prop-types';
import styles from './legend-item-styles.scss';

Expand All @@ -12,7 +15,8 @@ const LegendItem = ({
itemsName,
hoverIndex,
selectActiveDonutIndex,
disableAbbr
disableAbbr,
infoText
}) => (
<div
className={styles.legendItem}
Expand All @@ -21,6 +25,16 @@ const LegendItem = ({
<div className={styles.legendName}>
<span className={styles.legendDot} style={{ backgroundColor: color }} />
<span>{disableAbbr ? name : <AbbrReplace>{name}</AbbrReplace>}</span>
{infoText && (
<div
className={styles.infoContainer}
data-for="legend-info-tooltip"
data-tip={infoText}
>
<Icon icon={infoIcon} />
<ReactTooltip id="legend-info-tooltip" effect="solid" />
</div>
)}
</div>
<div className={styles.progressContainer}>
<Progress value={value} className={styles.progressBar} color={color} />
Expand All @@ -39,7 +53,8 @@ LegendItem.propTypes = {
hoverIndex: PropTypes.number.isRequired,
color: PropTypes.string,
selectActiveDonutIndex: PropTypes.func.isRequired,
disableAbbr: PropTypes.bool
disableAbbr: PropTypes.bool,
infoText: PropTypes.string
};

LegendItem.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ $progress-bar-width: 180px;
}

.legendName {
display: flex;
align-items: center;
max-width: $progress-bar-width;
margin-bottom: 2px;
}

.infoContainer {
margin: 0 0 -3px 5px;
}

.legendDot {
height: 10px;
display: inline-block;
margin-right: 5px;
width: 10px;
min-width: 10px;
border-radius: 50%;
}

Expand Down
4 changes: 2 additions & 2 deletions app/javascript/app/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ export const AGRICULTURE_INDICATORS_MAP_BUCKETS = {
export const DEFAULT_NDC_EXPLORE_CATEGORY_SLUG = 'unfccc_process';

export const CATEGORY_SOURCES = {
NDC_EXPLORE: ['CAIT', 'WB', 'NDC Explorer'],
NDC_CONTENT: ['CAIT', 'WB', 'NDC Explorer']
NDC_EXPLORE: ['CAIT', 'WB', 'NDC Explorer', 'UNICEF'],
NDC_CONTENT: ['CAIT', 'WB', 'NDC Explorer', 'UNICEF']
};

export const ENHANCEMENT_CATEGORIES = [
Expand Down
9 changes: 8 additions & 1 deletion app/javascript/app/data/data-explorer-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,14 @@ export const DATA_EXPLORER_METHODOLOGY_SOURCE = {
GCP: ['historical_emissions_gcp']
},
'ndc-sdg-linkages': ['ndc_sdg_all indicators'],
'ndc-content': ['ndc_cw', 'ndc_wb', 'ndc_die', 'ndc_adaptation'],
'ndc-content': [
'ndc_cw',
'ndc_wb',
'ndc_die',
'ndc_adaptation',
'ndc_unicef',
'ndc_finance'
],
'lts-content': ['lts'],
'net-zero-content': ['net_zero'],
'emission-pathways': [null] // model, scenario and indicator related metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const fetchNDCS = createThunkAction('fetchNDCS', props => (dispatch, state) => {
if (ndcsExplore && !ndcsExplore.loading) {
promises.push(
apiWithCache.get(
`/api/v1/ndcs?filter=map&source[]=CAIT&source[]=WB&source[]=NDC%20Explorer'${
`/api/v1/ndcs?filter=map&source[]=CAIT&source[]=WB&source[]=NDC%20Explorer&source[]=UNICEF${
params.length ? `&${params.join('&')}` : ''
}`
)
Expand All @@ -33,7 +33,7 @@ const fetchNDCS = createThunkAction('fetchNDCS', props => (dispatch, state) => {
// and as it is not filtered by category also serves the whole list of categories
promises.push(
apiWithCache.get(
'/api/v1/ndcs?indicators=ndce_ghg, submission, submission_date&filter=map&source[]=CAIT&source[]=WB&source[]=NDC%20Explorer'
'/api/v1/ndcs?indicators=ndce_ghg, submission, submission_date&filter=map&source[]=CAIT&source[]=WB&source[]=NDC%20Explorer&source[]=UNICEF'
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const fetchNDCS = createThunkAction('fetchNDCS', props => (dispatch, state) => {
params.push(`indicators=${indicatorSlugs.join(',')}`);
}
if (!overrideFilter) {
params.push('filter=map&source[]=CAIT&source[]=WB&source[]=NDC%20Explorer');
params.push(
'filter=map&source[]=CAIT&source[]=WB&source[]=NDC%20Explorer&source[]=UNICEF'
);
}
if (subcategory) {
params.push(`subcategory=${subcategory}`);
Expand Down Expand Up @@ -54,7 +56,7 @@ const fetchNDCS = createThunkAction('fetchNDCS', props => (dispatch, state) => {
`/api/v1/ndcs?indicators=${additionalIndicatorSlugs.join(',')}${
overrideFilter
? ''
: '&filter=map&source[]=CAIT&source[]=WB&source[]=NDC%20Explorer'
: '&filter=map&source[]=CAIT&source[]=WB&source[]=NDC%20Explorer&source[]=UNICEF'
}`
)
);
Expand Down
19 changes: 17 additions & 2 deletions app/models/indc/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,23 @@
#
module Indc
class Source < ApplicationRecord
validates :name, presence: true
validates :name, uniqueness: true
VALID_SOURCES = [
'CAIT',
'LSE',
'LTS',
'NDC Explorer',
'Net_Zero',
'Pledges',
'UNICEF',
'WB'
].freeze

validates :name, presence: true, uniqueness: true, inclusion: {
in: VALID_SOURCES,
message: "%{value} is not supported. Supported values for source: #{VALID_SOURCES.join(', ')}",
allow_blank: true # to have only presence error if nil
}

scope :lts, -> { where("name ilike 'LTS'") }
scope :net_zero, -> { where("name ilike 'Net_Zero'") }
scope :ndc, -> { where.not(id: lts).where.not(id: net_zero) }
Expand Down
3 changes: 2 additions & 1 deletion app/services/import_indc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ def import_labels

def import_values_ndc
valid_sources = [@sources_index['CAIT'], @sources_index['NDC Explorer'],
@sources_index['WB'], @sources_index['Net_Zero']]
@sources_index['WB'], @sources_index['Net_Zero'],
@sources_index['UNICEF']]
values = []
Indc::Indicator.
where(source: valid_sources).
Expand Down
4 changes: 3 additions & 1 deletion spec/factories/indc_sources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#
FactoryBot.define do
factory :indc_source, class: 'Indc::Source' do
sequence(:name) { |n| 'My Name ' + ('AA'..'ZZ').to_a[n] }
name { 'CAIT' }

initialize_with { Indc::Source.find_or_create_by(name: name) }
end
end
14 changes: 11 additions & 3 deletions spec/models/indc/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
require 'rails_helper'

describe Indc::Source, type: :model do
subject { FactoryBot.build(:indc_source) }

it { is_expected.to be_valid }

it 'should be invalid when name not present' do
expect(
FactoryBot.build(:indc_source, name: nil)
).to have(1).errors_on(:name)
subject.name = nil
expect(subject).to have(1).errors_on(:name)
end

it 'should be invalid with wrong name' do
subject.name = 'source'
expect(subject).to have(1).errors_on(:name)
end
end

0 comments on commit cda4e8f

Please sign in to comment.