Skip to content

Commit

Permalink
include more coremetadata, update csv format
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiggr committed Nov 24, 2022
1 parent 8e2b040 commit 6311876
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 160 deletions.
4 changes: 0 additions & 4 deletions src/Blocks/EmbedEEAVisualization/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ const Edit = (props) => {
has_data_query_by_context: data.has_data_query_by_context,
vis_url: data.vis_url,
with_sources: data.show_sources,
include_sources_download: data?.include_sources_download,
include_other_org_download: data?.include_other_org_download,
include_temporal_coverage_download:
data?.include_temporal_coverage_download,
}}
hoverFormatXY={data.hover_format_xy}
withSources={data.show_sources}
Expand Down
4 changes: 0 additions & 4 deletions src/Blocks/EmbedEEAVisualization/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ const View = (props) => {
use_live_data: true,
vis_url: data.vis_url,
with_sources: data.show_sources,
include_sources_download: data?.include_sources_download,
include_other_org_download: data?.include_other_org_download,
include_temporal_coverage_download:
data?.include_temporal_coverage_download,
}}
hoverFormatXY={data.hover_format_xy}
withSources={data.show_sources}
Expand Down
86 changes: 23 additions & 63 deletions src/Blocks/EmbedEEAVisualization/schema.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,6 @@
import React from 'react';

const makeMetadataOptions = (data) => {
if (data && data.length > 0) {
return data
.map((item) => [...Object.keys(item)]) //get all keys, should be the same for all
.flat(1) // flatten all arrays
.reduce(function (a, b) {
if (a.indexOf(b) < 0) a.push(b);
return a;
}, []) //remove duplicates. We need only one set of keys
.map((item) => [item, item]); //map them for choices
}
return [];
};

const Schema = (props) => {
const hasSources =
props.data_provenance &&
props.data.download_button &&
props.data_provenance.data &&
props.data_provenance.data.length > 0;
const hasOtherOrg =
props.data.download_button &&
props.other_organisations &&
props.other_organisations.length > 0;
const hasTemporalCoverage =
props.data.download_button &&
props.temporal_coverage &&
props.temporal_coverage.temporal &&
props.temporal_coverage.temporal.length > 0;

const data_provenance_options = makeMetadataOptions(
props?.data_provenance?.data,
);

const temporal_coverage_options = makeMetadataOptions(
props?.temporal_coverage?.temporal,
);

const other_organisations_options = makeMetadataOptions(
props?.other_organisations,
);
return {
title: 'Embed EEA visualization',

Expand All @@ -55,11 +15,11 @@ const Schema = (props) => {
title: 'Download',
fields: [
'download_button',
...(hasSources ? ['include_sources_download'] : []),
...(hasOtherOrg ? ['include_other_org_download'] : []),
...(hasTemporalCoverage
? ['include_temporal_coverage_download']
: []),
// ...(hasSources ? ['include_sources_download'] : []),
// ...(hasOtherOrg ? ['include_other_org_download'] : []),
// ...(hasTemporalCoverage
// ? ['include_temporal_coverage_download']
// : []),
],
},
{
Expand Down Expand Up @@ -101,24 +61,24 @@ const Schema = (props) => {
title: 'Toggle download',
type: 'boolean',
},
include_sources_download: {
title: 'Download sources',
description: 'Include sources in the dowloaded CSV',
choices: data_provenance_options,
isMulti: true,
},
include_other_org_download: {
title: 'Download other organisations',
description: 'Include other organisations in the dowloaded CSV',
choices: other_organisations_options,
isMulti: true,
},
include_temporal_coverage_download: {
title: 'Download temporal coverage',
description: 'Include temporal coverage in the dowloaded CSV',
choices: temporal_coverage_options,
isMulti: true,
},
// include_sources_download: {
// title: 'Download sources',
// description: 'Include sources in the dowloaded CSV',
// choices: data_provenance_options,
// isMulti: true,
// },
// include_other_org_download: {
// title: 'Download other organisations',
// description: 'Include other organisations in the dowloaded CSV',
// choices: other_organisations_options,
// isMulti: true,
// },
// include_temporal_coverage_download: {
// title: 'Download temporal coverage',
// description: 'Include temporal coverage in the dowloaded CSV',
// choices: temporal_coverage_options,
// isMulti: true,
// },
show_sources: {
title: 'Toggle sources',
type: 'boolean',
Expand Down
57 changes: 13 additions & 44 deletions src/ConnectedChart2/ConnectedChart2.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { compose } from 'redux';
import loadable from '@loadable/component';
import { connectToProviderData } from '@eeacms/volto-datablocks/hocs';
import { updateChartDataFromProvider } from '@eeacms/volto-datablocks/helpers';
import { toPublicURL } from '@plone/volto/helpers';

import { connect } from 'react-redux';
import { connectBlockToVisualization } from '@eeacms/volto-plotlycharts/hocs';

Expand All @@ -13,23 +15,6 @@ import { Download } from '../Download';
import { Sources } from '../Sources';

const LoadablePlotly = loadable(() => import('react-plotly.js'));

const filterItemsIds = (items, allowedIds) => {
const newItems =
items && items.length > 0
? items
.map((item) => {
var newItem = {};
allowedIds.forEach((id) => {
newItem[id] = item[id];
});
return newItem;
})
.filter((value) => Object.keys(value).length !== 0)
: [];
return newItems;
};

/*
* ConnectedChart
*/
Expand All @@ -47,6 +32,8 @@ function ConnectedChart2(props) {
data_provenance,
other_organisations,
temporal_coverage,
publisher,
geo_coverage,
} = props;
const with_sources = props?.withSources ?? false;

Expand Down Expand Up @@ -100,9 +87,6 @@ function ConnectedChart2(props) {
'',
};
}
// console.log(provider_data, ' provider_data');
// console.log(props.data.data_query, ' props.data.data_query');
// console.log(chartData, ' chartData');
let data = provider_data
? updateChartDataFromProvider(chartData.data || [], provider_data)
: chartData.data || [];
Expand Down Expand Up @@ -147,29 +131,13 @@ function ConnectedChart2(props) {
}
provider_data={provider_data}
provider_metadata={provider_metadata}
url_source={toPublicURL(props?.location?.pathname)}
core_metadata={{
data_provenance: props.data?.include_sources_download
? filterItemsIds(
data_provenance?.data,
props.data?.include_sources_download,
)
: '',
other_organisations: props.data?.include_other_org_download
? filterItemsIds(
other_organisations,
props.data?.include_other_org_download,
)
: '',
temporal_coverage:
props.data?.include_temporal_coverage_download &&
props.data?.include_temporal_coverage_download.length > 0 &&
temporal_coverage?.temporal &&
temporal_coverage?.temporal?.length > 0
? filterItemsIds(
temporal_coverage?.temporal,
props.data?.include_temporal_coverage_download,
)
: '',
data_provenance: data_provenance?.data,
other_organisations: other_organisations,
temporal_coverage: temporal_coverage?.temporal,
publisher: publisher,
geo_coverage: geo_coverage?.geolocation,
}}
/>
)}
Expand All @@ -191,10 +159,11 @@ function ConnectedChart2(props) {
export default compose(
connect(
(state, props) => ({
//mapped core metadata data to props. Include more if needed
subreq: state.content.subrequests?.[props.id]?.data,
visualization:
state.content.subrequests?.[props.id]?.data?.visualization?.chartData,
//mapped core metadata data to props. Include more if needed
publisher: state.content.subrequests?.[props.id]?.data?.publisher,
geo_coverage: state.content.subrequests?.[props.id]?.data?.geo_coverage,
temporal_coverage:
state.content.subrequests?.[props.id]?.data?.temporal_coverage,
other_organisations:
Expand Down
Loading

0 comments on commit 6311876

Please sign in to comment.