From 0801610966785f53107cc8ac9a5f79ca47bbd3af Mon Sep 17 00:00:00 2001 From: Miu Razvan Date: Thu, 15 Oct 2020 14:31:09 +0300 Subject: [PATCH] Updated Pollutant index --- .../Blocks/GlossarySearchBlock/View.jsx | 4 +- .../manage/Blocks/PollutantIndex/View.jsx | 201 +++++++++++++----- .../volto/components/theme/Search/Search.jsx | 2 +- 3 files changed, 156 insertions(+), 51 deletions(-) diff --git a/src/components/manage/Blocks/GlossarySearchBlock/View.jsx b/src/components/manage/Blocks/GlossarySearchBlock/View.jsx index 48d39063..390870a4 100644 --- a/src/components/manage/Blocks/GlossarySearchBlock/View.jsx +++ b/src/components/manage/Blocks/GlossarySearchBlock/View.jsx @@ -220,8 +220,8 @@ class View extends Component { const sql = `SELECT POL.name, POL_DET.pollutantId, POL.parentId - FROM [IED].[latest].[LOV_POLLUTANT] as POL - LEFT JOIN [IED].[latest].[pollutants_details_table] AS POL_DET + FROM [IED].[latest].[Glo_Pollutants] as POL + LEFT JOIN [IED].[latest].[Glo_PollutantsDetails] AS POL_DET ON POL.pollutantId = POL_DET.pollutantId WHERE name LIKE '%${name}%' ORDER BY name`; diff --git a/src/components/manage/Blocks/PollutantIndex/View.jsx b/src/components/manage/Blocks/PollutantIndex/View.jsx index 5ad4d919..391c112e 100644 --- a/src/components/manage/Blocks/PollutantIndex/View.jsx +++ b/src/components/manage/Blocks/PollutantIndex/View.jsx @@ -460,7 +460,21 @@ const panes = [ { menuItem: 'Hazards and other technical characteristics', render: (props) => { - const { pollutant = {} } = props.data; + const { pollutant = {}, phrases = [] } = props.data; + const phrasesTypes = { + clp_phrase: 'clp_phrase', + ghs_phrase: 'ghs_phrase', + r_phrase: 'r_s_phrase', + s_phrase: 'r_s_phrase', + }; + const phrasesByType = {}; + phrases.forEach((phrase) => { + if (!phrasesByType[phrasesTypes[phrase.phrase_type]]) { + phrasesByType[phrasesTypes[phrase.phrase_type]] = [phrase]; + } else { + phrasesByType[phrasesTypes[phrase.phrase_type]].push(phrase); + } + }); return ( @@ -474,16 +488,12 @@ const panes = [ celled={false} headless={true} headers={[ - { key: 'label', value: 'Label' }, - { key: 'value', value: 'Value' }, - ]} - rows={[ - { - label: 'R23/25', - value: pollutant.pollutantId || '-', - }, + { key: 'phrase_id', value: 'Id' }, + { key: 'phrase_text', value: 'Text' }, ]} + rows={phrasesByType.r_s_phrase || [{ phrase_id: 'No data' }]} /> +

Classification & Labelling

The Regulation (EC) No 1272/2008 establishes a standard @@ -494,7 +504,27 @@ const panes = [ Regulation (EC) No 1272/2008, OJ L 353

Hazard Class

+

Hazard Statements

+

Physical Properties

row.value)} />

Human Health & Environmental Hazard Assessment

row.value)} />
); @@ -614,6 +714,9 @@ const View = (props) => { props.discodata_resources.data.index_pollutant_other_provisions?.[ indexPollutantId ]?.results || []; + const currentPhrases = + props.discodata_resources.data.index_pollutant_phrases?.[indexPollutantId] + ?.results || []; const currentPollutants = indexPollutants.filter( (pollutant) => parseInt(pollutant.parentId) === indexPollutantGroupId, ); @@ -622,17 +725,43 @@ const View = (props) => { const newPollutant = indexPollutants.filter( (pollutant) => pollutant.pollutantId === indexPollutantId, )?.[0]; + const newQueries = {}; + const phrasesKeys = newPollutant + ? ['clp_phrases', 'ghs_phrases', 'r_phrases', 's_phrases'] + : []; + const phrases = newPollutant + ? phrasesKeys + .filter( + (phrase) => + newPollutant[phrase] && newPollutant[phrase] !== 'NoData', + ) + .map((phrase) => + newPollutant[phrase] + .split('|') + .map((item) => item.replace(/['"]+/g, '')), + ) + : []; + setCurrentPollutant( indexPollutantId !== null && indexPollutantId !== undefined ? newPollutant : undefined, ); + if (newPollutant && newPollutant.other_provisions) { + newQueries.index_pollutant_other_provisions = newPollutant.other_provisions + .split('|') + .map((item) => item.replace(/['"]+/g, '')); + } + + if (newPollutant && phrases.length > 0) { + newQueries.index_pollutant_phrases = phrases.join().split(','); + } + + if (Object.keys(newQueries).length) { props.setQueryParam({ queryParam: { - index_pollutant_other_provisions: newPollutant.other_provisions - .split('|') - .map((item) => item.replace(/['"]+/g, '')), + ...newQueries, }, }); } @@ -650,31 +779,6 @@ const View = (props) => { ); }, [indexPollutantGroupId, JSON.stringify(indexPollutantGroups)]); - // useEffect(() => { - // if ( - // mounted.current && - // !initialized && - // !indexPollutantGroupId && - // indexPollutantGroups.length > 0 && - // indexPollutants.length > 0 - // ) { - // props.setQueryParam({ - // queryParam: { - // index_pollutant_group_id: parseInt(indexPollutants[0].parentId), - // index_pollutant_id: parseInt(indexPollutants[0].pollutantId), - // }, - // }); - // setCurrentPollutantGroup( - // indexPollutantGroups.filter( - // (group) => - // parseInt(group.pollutantId) === - // parseInt(indexPollutants[0].parentId), - // )[0], - // ); - // setInitialized(true); - // } - // }, [indexPollutantGroups?.length, indexPollutants?.length]); - useEffect(() => { mounted.current = true; return () => { @@ -689,11 +793,11 @@ const View = (props) => { '@type': 'discodata_sql_builder', sql: { value: - '{"fieldsets":[{"id":"sql_metadata","title":"SQL","fields":["index_pollutant_groups","index_pollutants","index_pollutant_iso","index_pollutant_other_provisions"]}],"properties":{"index_pollutant_groups":{"title":"Index pollutant groups","isCollection":true,"hasPagination":false,"urlQuery":false,"sql":"SELECT POL.*, POL_GROUPS.sub, POL_GROUPS.description\\nFROM [IED].[latest].[LOV_POLLUTANT] as POL\\nLEFT JOIN [IED].[latest].[pollutants_groups_details_table] as POL_GROUPS\\nON POL.pollutantId = POL_GROUPS.pollutant_group_id \\nWHERE [parentId] = \'NULL\'\\nORDER BY name"},"index_pollutant_iso":{"title":"Index pollutants iso","hasPagination":true,"urlQuery":false,"sql":"SELECT *\\nFROM [IED].[latest].[pollutants_iso_provisions_table]","packageName":"index_pollutant_id"},"index_pollutant_other_provisions":{"title":"index_pollutant_other_provisions","hasPagination":true,"urlQuery":false,"sql":"SELECT *\\nFROM [IED].[latest].[pollutants_other_provisions_table]","packageName":"index_pollutant_id"},"index_pollutants":{"title":"Index pollutants","isCollection":true,"hasPagination":false,"urlQuery":false,"sql":"SELECT POL.code,\\nPOL.name,\\nPOL.startYear,\\nPOL.endYear,\\nPOL.parentId,\\nPOL.cas,\\nPOL.eperPollutantId,\\nPOL.codeEPER,\\nPOL_DET.*\\nFROM [IED].[latest].[LOV_POLLUTANT] as POL\\nLEFT JOIN [IED].[latest].[pollutants_details_table] AS POL_DET\\nON POL.pollutantId = POL_DET.pollutantId\\nORDER BY name","packageName":"index_pollutant_group_id"}},"required":[]}', + '{"fieldsets":[{"id":"sql_metadata","title":"SQL","fields":["index_pollutant_groups","index_pollutants","index_pollutant_iso","index_pollutant_other_provisions","index_pollutant_phrases"]}],"properties":{"index_pollutant_groups":{"title":"Index pollutant groups","isCollection":true,"hasPagination":false,"urlQuery":false,"sql":"SELECT POL.*, POL_GROUPS.sub, POL_GROUPS.description\\nFROM [IED].[latest].[Glo_Pollutants] as POL\\nLEFT JOIN [IED].[latest].[Glo_PollutantsGroupsDetails] as POL_GROUPS\\nON POL.pollutantId = POL_GROUPS.pollutant_group_id \\nWHERE [parentId] = \'NULL\'\\nORDER BY name"},"index_pollutants":{"title":"Index pollutants","isCollection":true,"hasPagination":false,"urlQuery":false,"sql":"SELECT POL.code,\\nPOL.name,\\nPOL.startYear,\\nPOL.endYear,\\nPOL.parentId,\\nPOL.cas,\\nPOL.eperPollutantId,\\nPOL.codeEPER,\\nPOL_DET.*\\nFROM [IED].[latest].[Glo_Pollutants] as POL\\nLEFT JOIN [IED].[latest].[Glo_PollutantsDetails] AS POL_DET\\nON POL.pollutantId = POL_DET.pollutantId\\nORDER BY name","packageName":"index_pollutant_group_id"},"index_pollutant_iso":{"title":"Index pollutants iso","hasPagination":true,"urlQuery":false,"sql":"SELECT *\\nFROM [IED].[latest].[Glo_PollutantsIsoProvision]","packageName":"index_pollutant_id"},"index_pollutant_other_provisions":{"title":"index_pollutant_other_provisions","hasPagination":true,"urlQuery":false,"sql":"SELECT *\\nFROM [IED].[latest].[Glo_PollutantsOtherProvisions]","packageName":"index_pollutant_id"},"index_pollutant_phrases":{"title":"index_pollutant_phrases","hasPagination":true,"urlQuery":false,"sql":"SELECT *\\nFROM [IED].[latest].[Glo_PollutantsPrase]","packageName":"index_pollutant_id"}},"required":[]}', }, where: { value: - '{"fieldsets":[{"id":"where_statements_metadata","title":"Where statements","fields":["w1","w2"]}],"properties":{"w1":{"title":"W1","sqlId":"index_pollutant_iso","urlQuery":false,"key":"pollutantId","queryParam":"index_pollutant_id"},"w2":{"title":"W2","sqlId":"index_pollutant_other_provisions","urlQuery":false,"key":"other_provision_id","queryParam":"index_pollutant_other_provisions","isExact":true}},"required":[]}', + '{"fieldsets":[{"id":"where_statements_metadata","title":"Where statements","fields":["w1","w2","w3"]}],"properties":{"w1":{"title":"W1","sqlId":"index_pollutant_iso","urlQuery":false,"key":"pollutantId","queryParam":"index_pollutant_id"},"w2":{"title":"W2","sqlId":"index_pollutant_other_provisions","urlQuery":false,"key":"other_provision_id","queryParam":"index_pollutant_other_provisions","isExact":true},"w3":{"title":"W3","sqlId":"index_pollutant_phrases","urlQuery":false,"key":"phrase_id","queryParam":"index_pollutant_phrases"}},"required":[]}', }, }} /> @@ -738,6 +842,7 @@ const View = (props) => { pollutant_iso: indexPollutantIso, pollutant_group: currentPollutantGroup, other_provisions: currentOtherProvisions, + phrases: currentPhrases, }} /> diff --git a/src/customizations/volto/components/theme/Search/Search.jsx b/src/customizations/volto/components/theme/Search/Search.jsx index 8f194737..08de4657 100644 --- a/src/customizations/volto/components/theme/Search/Search.jsx +++ b/src/customizations/volto/components/theme/Search/Search.jsx @@ -251,7 +251,7 @@ class Search extends Component { '@type': 'discodata_sql_builder', sql: { value: - '{"fieldsets":[{"id":"sql_metadata","title":"SQL","fields":["index_pollutants"]}],"properties":{"index_pollutants":{"title":"Index pollutants","isCollection":true,"hasPagination":false,"urlQuery":false,"sql":"SELECT POL.code,\\nPOL.name,\\nPOL.startYear,\\nPOL.endYear,\\nPOL.parentId,\\nPOL.cas,\\nPOL.eperPollutantId,\\nPOL.codeEPER,\\nPOL_DET.*\\nFROM [IED].[latest].[LOV_POLLUTANT] as POL\\nLEFT JOIN [IED].[latest].[pollutants_details_table] AS POL_DET\\nON POL.pollutantId = POL_DET.pollutantId\\nORDER BY name","packageName":"index_pollutant_group_id"}},"required":[]}', + '{"fieldsets":[{"id":"sql_metadata","title":"SQL","fields":["index_pollutants"]}],"properties":{"index_pollutants":{"title":"Index pollutants","isCollection":true,"hasPagination":false,"urlQuery":false,"sql":"SELECT POL.code,\\nPOL.name,\\nPOL.startYear,\\nPOL.endYear,\\nPOL.parentId,\\nPOL.cas,\\nPOL.eperPollutantId,\\nPOL.codeEPER,\\nPOL_DET.*\\nFROM [IED].[latest].[Glo_Pollutants] as POL\\nLEFT JOIN [IED].[latest].[Glo_PollutantsDetails] AS POL_DET\\nON POL.pollutantId = POL_DET.pollutantId\\nORDER BY name","packageName":"index_pollutant_group_id"}},"required":[]}', }, where: { value: