Skip to content

Commit

Permalink
feat(toolbarFieldExport): sw-2769 activate csv export
Browse files Browse the repository at this point in the history
* toolbarFieldExport, selected format display check
* platformConstants, activate csv format
  • Loading branch information
cdcabrera committed Jul 31, 2024
1 parent 06b974c commit 0d98340
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

exports[`ToolbarFieldExport Component should export select options: toolbarFieldOptions 1`] = `
[
{
"selected": false,
"title": "t(curiosity-toolbar.label_export, {"context":"csv"})",
"value": "csv",
},
{
"selected": false,
"title": "t(curiosity-toolbar.label_export, {"context":"json"})",
Expand Down Expand Up @@ -56,6 +61,12 @@ exports[`ToolbarFieldExport Component should render a basic component: basic 1`]
onSplitButton={null}
options={
[
{
"isDisabled": false,
"selected": false,
"title": "t(curiosity-toolbar.label_export, {"context":"csv"})",
"value": "csv",
},
{
"isDisabled": false,
"selected": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('ToolbarFieldExport Component', () => {
loremIpsum: {
completed: [{ id: 'helloWorld', fileName: 'helloWorldFileName' }],
isCompleted: true,
isPending: false,
pending: [{ id: 'dolorSit', fileName: 'dolorSitFileName' }]
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/components/toolbar/toolbarFieldExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,11 @@ const ToolbarFieldExport = ({
const updatedOptions = options.map(option => ({
...option,
title:
(((isProductPending && !pendingProductFormats?.length) ||
(isProductPending && pendingProductFormats?.includes(option.value))) &&
(isProductPending &&
pendingProductFormats?.includes(option.value) &&
t('curiosity-toolbar.label', { context: ['export', 'loading'] })) ||
option.title,
selected:
(isProductPending && !pendingProductFormats?.length) ||
(isProductPending && pendingProductFormats?.includes(option.value)),
selected: isProductPending && pendingProductFormats?.includes(option.value),
isDisabled:
(isProductPending && !pendingProductFormats?.length) ||
(isProductPending && pendingProductFormats?.includes(option.value))
Expand Down
79 changes: 42 additions & 37 deletions src/components/toolbar/toolbarFieldExportContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,54 +41,59 @@ const useExportConfirmation = ({

return useCallback(
({ error, data } = {}, retryCount) => {
const { completed = [], isCompleted, pending = [] } = data?.data?.products?.[productId] || {};
const isPending = !isCompleted;
let notification;
const { completed = [], isCompleted, isPending, pending = [] } = data?.data?.products?.[productId] || {};

if (error || !confirmAppLoaded()) {
return;
}

// Display pending notification. No data is returned on the initial status response.
if (retryCount === -1) {
notification = {
id: 'swatch-exports-individual-status',
variant: 'info',
title: t('curiosity-toolbar.notifications', {
context: ['export', 'pending', 'title'],
testId: 'exportNotification-individual-pending'
}),
dismissable: true
};
dispatch([
addAliasNotification({
id: 'swatch-exports-individual-status',
variant: 'info',
title: t('curiosity-toolbar.notifications', {
context: ['export', 'pending', 'title'],
testId: 'exportNotification-individual-pending'
}),
dismissable: true
})
]);
return;
}

// Dispatch a status regardless of completion
const updatedDispatch = [
{
type: reduxTypes.platform.SET_PLATFORM_EXPORT_STATUS,
id: productId,
isPending,
pending
}
];

// Display completed notification
if (isCompleted) {
notification = {
id: 'swatch-exports-individual-status',
variant: 'success',
title: t('curiosity-toolbar.notifications', {
context: ['export', 'completed', 'title'],
testId: 'exportNotification-individual-completed'
}),
description: t('curiosity-toolbar.notifications', {
context: ['export', 'completed', 'description'],
count: completed.length,
fileName: completed?.[0]?.fileName
}),
dismissable: true
};
updatedDispatch.unshift(
addAliasNotification({
id: 'swatch-exports-individual-status',
variant: 'success',
title: t('curiosity-toolbar.notifications', {
context: ['export', 'completed', 'title'],
testId: 'exportNotification-individual-completed'
}),
description: t('curiosity-toolbar.notifications', {
context: ['export', 'completed', 'description'],
count: completed.length,
fileName: completed?.[0]?.fileName
}),
dismissable: true
})
);
}

if (notification) {
dispatch([
addAliasNotification(notification),
{
type: reduxTypes.platform.SET_PLATFORM_EXPORT_STATUS,
id: productId,
isPending,
pending
}
]);
}
dispatch(updatedDispatch);
},
[addAliasNotification, confirmAppLoaded, dispatch, productId, t]
);
Expand Down
6 changes: 5 additions & 1 deletion src/redux/reducers/appReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ const appReducer = (state = initialState, action) => {
'exports',
{
[action.id]: {
...action
...action,
pending: [
...(state?.exports?.[action.id]?.pending || []),
...((Array.isArray(action.pending) && action.pending) || (action.pending && [action.pending]) || [])
]
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`Platform Constants should have specific properties: all exported consta
"SUBSCRIPTIONS": "subscriptions",
},
"PLATFORM_API_EXPORT_CONTENT_TYPES": {
"CSV": "csv",
"JSON": "json",
},
"PLATFORM_API_EXPORT_FILENAME_PREFIX": "swatch",
Expand Down Expand Up @@ -80,6 +81,7 @@ exports[`Platform Constants should have specific properties: all exported consta
"SUBSCRIPTIONS": "subscriptions",
},
"PLATFORM_API_EXPORT_CONTENT_TYPES": {
"CSV": "csv",
"JSON": "json",
},
"PLATFORM_API_EXPORT_FILENAME_PREFIX": "swatch",
Expand Down Expand Up @@ -155,6 +157,7 @@ exports[`Platform Constants should have specific properties: all exported consta
"SUBSCRIPTIONS": "subscriptions",
},
"PLATFORM_API_EXPORT_CONTENT_TYPES": {
"CSV": "csv",
"JSON": "json",
},
"PLATFORM_API_EXPORT_FILENAME_PREFIX": "swatch",
Expand Down Expand Up @@ -234,6 +237,7 @@ exports[`Platform Constants should have specific properties: specific constants
"SUBSCRIPTIONS": "subscriptions",
},
"PLATFORM_API_EXPORT_CONTENT_TYPES": {
"CSV": "csv",
"JSON": "json",
},
"PLATFORM_API_EXPORT_FILENAME_PREFIX": "swatch",
Expand Down
2 changes: 1 addition & 1 deletion src/services/platform/platformConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const PLATFORM_API_EXPORT_RESOURCE_TYPES = {
* @type {{CSV: string, JSON: string}}
*/
const PLATFORM_API_EXPORT_CONTENT_TYPES = {
// CSV: 'csv',
CSV: 'csv',
JSON: 'json'
};

Expand Down

0 comments on commit 0d98340

Please sign in to comment.