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

fetch widget metadata from RW API #4700

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 7 additions & 3 deletions components/modals/meta/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ export const setModalMetaSettings = createThunkAction('setModalMetaSettings');

export const getModalMetaData = createThunkAction(
'getModalMetaData',
(metaKey) => (dispatch, getState) => {
({metakey, metaType}) => (dispatch, getState) => {
const { modalMeta } = getState();
if (modalMeta && !modalMeta.loading) {
dispatch(setModalMetaLoading({ loading: true, error: false }));
getMetadata(metaKey)
getMetadata(metakey, metaType)
.then((response) => {
dispatch(setModalMetaData(response.data));
if (metaType === 'widget') {
dispatch(setModalMetaData(response.data[0].info))
} else {
dispatch(setModalMetaData(response.data));
}
})
.catch(() => {
dispatch(setModalMetaLoading({ loading: false, error: true }));
Expand Down
9 changes: 5 additions & 4 deletions components/modals/meta/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ModalMeta extends PureComponent {
setModalMetaClosed: PropTypes.func,
metaData: PropTypes.object,
getModalMetaData: PropTypes.func,
metaType: PropTypes.string,
metakey: PropTypes.string,
tableData: PropTypes.object,
loading: PropTypes.bool,
Expand All @@ -23,16 +24,16 @@ class ModalMeta extends PureComponent {
};

componentDidMount() {
const { getModalMetaData, metakey } = this.props;
const { getModalMetaData, metakey, metaType } = this.props;
if (metakey) {
getModalMetaData(metakey);
getModalMetaData({metakey, metaType});
}
}

componentDidUpdate(prevProps) {
const { getModalMetaData, metakey, metaData } = this.props;
const { getModalMetaData, metakey, metaData, metaType } = this.props;
if (metakey && metakey !== prevProps.metakey) {
getModalMetaData(metakey);
getModalMetaData({metakey, metaType});
}

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default {
pendingKeys: ['threshold', 'years'],
refetchKeys: ['landCategory', 'threshold'],
dataType: 'lossPrimary',
metaKey: 'widget_primary_forest_loss',
metaKey: '641b158b-f5be-40ae-9b13-8c5c35925b59',
datasets: [
{
dataset: POLITICAL_BOUNDARIES_DATASET,
Expand Down
2 changes: 1 addition & 1 deletion layouts/dashboards/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class DashboardsPage extends PureComponent {
<MapControls className="map-controls" />
</Desktop>
<Share />
<ModalMeta />
<ModalMeta metaType="widget" />
{widgetAnchor && (
<ScrollTo target={widgetAnchor} afterScroll={clearScrollTo} />
)}
Expand Down
2 changes: 1 addition & 1 deletion layouts/embed/widget/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const WidgetEmbedPage = ({ widget, trase }) => (
<div className={cx('l-embed-widget-page', { '-trase': trase })}>
<Widgets className="embed-widget" embed widget={widget} />
<Share />
<ModalMeta />
<ModalMeta metaType="widget" />
<CountryDataProvider />
<WhitelistsProvider />
<GeodescriberProvider embed />
Expand Down
2 changes: 1 addition & 1 deletion layouts/map/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class MainMapComponent extends PureComponent {
)}
<RecentImagery active={recentActive} />
<ShareModal />
<MetaModal />
<MetaModal metaType="layer" />
<AreaOfInterestModal viewAfterSave clearAfterDelete canDelete />
<ClimateModal />
<FiresModal />
Expand Down
14 changes: 12 additions & 2 deletions services/metadata.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { metadataRequest } from 'utils/request';
import { metadataRequest, rwRequest } from 'utils/request';

export const getMetadata = (slug) => metadataRequest.get(slug);
export const getMetadata = (slug, metaType) => {
if (metaType === 'widget') {
return rwRequest.get(`widget/${slug}`)
.then((resp) => {
const dataset = resp.data?.dataset;
return rwRequest.get(`dataset/${dataset}/widget/${slug}/metadata`)
})
}

return metadataRequest.get(slug);
}

export default {
getMetadata,
Expand Down
Loading