Skip to content

Commit

Permalink
manage redux and action right
Browse files Browse the repository at this point in the history
  • Loading branch information
dobri1408 committed Aug 21, 2024
1 parent 6cc0ef0 commit 85be516
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/middlewares/preview_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,49 @@ export const preview_image = (middlewares) => [
}
const state = store.getState();
const contentData = state.content.data;
const lastPreviewImage = Object.keys(action?.request?.data).includes(
'preview_image',
)
? action?.request?.data.preview_image
: contentData?.preview_image;
const type = action?.request?.data?.['@type'] || contentData['@type'];

if (
!contentData ||
contentData['@type'] !== 'tableau_visualization' ||
type !== 'tableau_visualization' ||
contentData.preview_image_saved ||
!action?.request?.data?.tableau_visualization?.preview
) {
return next(action);
}

if (
contentData?.preview_image &&
contentData?.preview_image?.filename !==
'preview_image_generated_map_simple.png'
lastPreviewImage &&
lastPreviewImage !== 'preview_image_generated_tableau_visualization.png'
) {
return next(action);
if (action?.request?.data?.tableau_visualization) {
const tableauVisualizationData = {
...action.request.data.tableau_visualization,
};
if (
tableauVisualizationData.preview &&
tableauVisualizationData.preview_url_loaded
)
delete tableauVisualizationData.preview;
delete tableauVisualizationData.preview_url_loaded;

return next({
...action,
request: {
...action.request,
data: {
...action.request.data,

tableau_visualization: tableauVisualizationData,
},
},
});
} else return next(action);
}

try {
Expand All @@ -33,7 +61,7 @@ export const preview_image = (middlewares) => [
data: action.request.data.tableau_visualization.preview.split(',')[1],
encoding: 'base64',
'content-type': 'image/png',
filename: 'preview_image_generated_map_simple.png',
filename: 'preview_image_generated_tableau_visualization.png',
},
preview_image_saved: true,
};
Expand All @@ -42,6 +70,7 @@ export const preview_image = (middlewares) => [
...action.request.data.tableau_visualization,
};
delete tableauVisualizationData.preview;
delete tableauVisualizationData.preview_url_loaded;

return next({
...action,
Expand Down

0 comments on commit 85be516

Please sign in to comment.