Skip to content

Commit

Permalink
DEV stash
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Jun 3, 2024
1 parent 9646b9f commit 271c36b
Show file tree
Hide file tree
Showing 6 changed files with 304 additions and 113 deletions.
47 changes: 37 additions & 10 deletions src/components/toolbar/toolbarFieldExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,28 @@ const toolbarFieldOptions = Object.values(FIELD_TYPES).map(type => ({
*/
const useExportStatus = ({
useProduct: useAliasProduct = useProduct,
// useSelectors: useAliasSelectors = storeHooks.reactRedux.useSelectorsResponse
useSelectors: useAliasSelectors = storeHooks.reactRedux.useSelectors
} = {}) => {
const { productId } = useAliasProduct();
const [product, global] = useAliasSelectors([
({ app }) => app?.exports?.[productId],
({ app }) => app?.exports?.global
]);
// const { data } = useAliasSelectors([({ app }) => app?.exports?.[productId], ({ app }) => app?.exports?.global]);

// const [product, global] = data || [];

const data = useAliasSelectors([({ app }) => app?.exports?.[productId], ({ app }) => app?.exports?.global]);
const [product, global] = data || [];

/*
* const [product, global] = useAliasSelectors([
* ({ app }) => app?.exports?.[productId],
* ({ app }) => app?.exports?.global
* ]);
*/

const pendingProductFormats = [];
const isProductPending =
product?.data?.data?.products?.[productId]?.isPending ||
product?.isPending ||
// product?.data?.data?.products?.[productId]?.isPending ||
global?.data?.data?.products?.[productId]?.isPending ||
false;

Expand All @@ -67,6 +78,14 @@ const useExportStatus = ({
);
}

console.log(
'>>>>> HOOK STATUS',
isProductPending,
// product?.pending,

Check warning on line 84 in src/components/toolbar/toolbarFieldExport.js

View workflow job for this annotation

GitHub Actions / Integration-checks (18.x)

Expected a block comment instead of consecutive line comments

Check warning on line 84 in src/components/toolbar/toolbarFieldExport.js

View workflow job for this annotation

GitHub Actions / Integration-checks (20.x)

Expected a block comment instead of consecutive line comments
// product?.data?.data?.products?.[productId]?.isPending,
global?.data?.data?.products?.[productId]?.isPending
);

return {
isProductPending,
pendingProductFormats
Expand Down Expand Up @@ -159,24 +178,32 @@ const ToolbarFieldExport = ({
useExportStatus: useAliasExportStatus,
useOnSelect: useAliasOnSelect
}) => {
// const [selectedOptions, setSelectedOptions] = useState([]);
const { isProductPending, pendingProductFormats = [] } = useAliasExportStatus();
const { checkExports } = useAliasExport();

Check failure on line 183 in src/components/toolbar/toolbarFieldExport.js

View workflow job for this annotation

GitHub Actions / Integration-checks (18.x)

'checkExports' is assigned a value but never used

Check failure on line 183 in src/components/toolbar/toolbarFieldExport.js

View workflow job for this annotation

GitHub Actions / Integration-checks (20.x)

'checkExports' is assigned a value but never used
const onSelect = useAliasOnSelect();
//
const updatedOptions = options.map(option => ({
...option,
title:
(isProductPending &&
pendingProductFormats?.includes(option.value) &&
(((isProductPending && !pendingProductFormats?.length) ||
(isProductPending && pendingProductFormats?.includes(option.value))) &&
t('curiosity-toolbar.label', { context: ['export', 'loading'] })) ||
option.title,
selected: isProductPending && pendingProductFormats?.includes(option.value),
isDisabled: isProductPending && pendingProductFormats?.includes(option.value)
selected:
(isProductPending && !pendingProductFormats?.length) ||
(isProductPending && pendingProductFormats?.includes(option.value)),
isDisabled:
(isProductPending && !pendingProductFormats?.length) ||
(isProductPending && pendingProductFormats?.includes(option.value))
}));

useMount(() => {
checkExports();
// checkExports();
});

console.log('>>>> pending', isProductPending, pendingProductFormats);

return (
<Select
title={t('curiosity-toolbar.placeholder', { context: 'export' })}
Expand Down
253 changes: 161 additions & 92 deletions src/redux/actions/platformActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,20 @@ const authorizeUser = appName => dispatch =>
/**
* Return a "dispatch ready" export poll status check.
*
* @param {Function} dispatch
* @param {string} id
* @param {boolean} isPending
* @param {Array} pending
* @returns {Function}
*/
const setExportStatus =
const setExportStatus = (id, isPending, pending) => dispatch =>
dispatch({
type: platformTypes.SET_PLATFORM_EXPORT_STATUS,
id,
isPending,
pending
});

const setExportStatusWORKS =

Check failure on line 68 in src/redux/actions/platformActions.js

View workflow job for this annotation

GitHub Actions / Integration-checks (18.x)

'setExportStatusWORKS' is assigned a value but never used

Check failure on line 68 in src/redux/actions/platformActions.js

View workflow job for this annotation

GitHub Actions / Integration-checks (20.x)

'setExportStatusWORKS' is assigned a value but never used
dispatch =>
(id, success = {}, error) =>
dispatch({
Expand All @@ -74,8 +84,8 @@ const setExportStatus =
*/
const getExistingExports =
(options = {}) =>
dispatch => {
let hasPendingNotificationDisplayed = false;
dispatch =>
// let hasPendingNotificationDisplayed = false;

dispatch({
type: platformTypes.SET_PLATFORM_EXPORT_STATUS,
Expand All @@ -84,46 +94,56 @@ const getExistingExports =
poll: {
...options.poll,
status: (successResponse, ...args) => {
dispatch(removeNotification('swatch-global-export'));

console.log('>>>>>>>>>>>>> GLOBAL STATUS', successResponse);
if (successResponse?.data?.data?.isAnythingPending) {
if (!hasPendingNotificationDisplayed) {
hasPendingNotificationDisplayed = true;
const pendingCount = successResponse?.data?.data?.pending?.length;

dispatch(
addNotification({
id: 'swatch-global-export',
title: translate('curiosity-toolbar.notifications', {
context: ['export', 'pending', 'titleGlobal'],
count: pendingCount
}),
description: translate('curiosity-toolbar.notifications', {
context: ['export', 'pending', 'descriptionGlobal'],
count: pendingCount
}),
dismissable: true
})
);
}
console.log('>>>>>>>>>>>>> GLOBAL STATUS PENDING', successResponse);
} else if (successResponse?.data?.data?.isAnythingCompleted) {
const completedCount = successResponse?.data?.data?.completed?.length;
dispatch(
addNotification({
id: 'swatch-global-export',
title: translate('curiosity-toolbar.notifications', {
context: ['export', 'completed', 'titleGlobal'],
count: completedCount
}),
description: translate('curiosity-toolbar.notifications', {
context: ['export', 'completed', 'descriptionGlobal'],
count: completedCount
}),
dismissable: true
})
);
console.log('>>>>>>>>>>>>> GLOBAL STATUS COMPLETED', successResponse);
}

/*
*if (successResponse?.data?.data?.isAnythingPending) {
* if (!hasPendingNotificationDisplayed) {
* hasPendingNotificationDisplayed = true;
* const pendingCount = successResponse?.data?.data?.pending?.length;
* dispatch(removeNotification('swatch-global-export'));
* dispatch(
* addNotification({
* id: 'swatch-global-export',
* title: translate('curiosity-toolbar.notifications', {
* context: ['export', 'pending', 'titleGlobal'],
* count: pendingCount
* }),
* description: translate('curiosity-toolbar.notifications', {
* context: ['export', 'pending', 'descriptionGlobal'],
* count: pendingCount
* }),
* dismissable: true
* })
* );
* }
*} else if (successResponse?.data?.data?.isAnythingCompleted) {
* console.log('>>>>>>>>>>>>> STATUS COMPLETED', successResponse);
*
* const completedCount = successResponse?.data?.data?.completed?.length;
* dispatch(removeNotification('swatch-global-export'));
* dispatch(
* addNotification({
* id: 'swatch-global-export',
* title: translate('curiosity-toolbar.notifications', {
* context: ['export', 'completed', 'titleGlobal'],
* count: completedCount
* }),
* description: translate('curiosity-toolbar.notifications', {
* context: ['export', 'completed', 'descriptionGlobal'],
* count: completedCount
* }),
* dismissable: true
* })
* );
*}
*/

setExportStatus(dispatch)('global', successResponse, ...args);
}
}
Expand All @@ -144,8 +164,13 @@ const getExistingExports =
}
}
});
};

/*
* .then(({ value: successResponse } = {}) => {
* console.log('>>>>>>>>>>>>> CALLBACK', successResponse);
* return successResponse;
* });
*/
/**
* Create an export for download with toast notifications.
*
Expand All @@ -156,62 +181,106 @@ const getExistingExports =
*/
const createExport =
(id, data = {}, options = {}) =>
dispatch => {
dispatch({
type: platformTypes.SET_PLATFORM_EXPORT_CREATE,
payload: platformServices.postExport(data, {
...options,
poll: {
...options.poll,
status: (successResponse, ...args) => {
if (
!successResponse?.data?.data?.products?.[id]?.isPending &&
successResponse?.data?.data?.products?.[id]?.isCompleted
) {
dispatch(removeNotification(`swatch-create-export-${id}`));
dispatch(
addNotification({
variant: 'success',
id: `swatch-create-export-${id}`,
title: translate('curiosity-toolbar.notifications', {
context: ['export', 'completed', 'title']
}),
description: translate('curiosity-toolbar.notifications', {
context: ['export', 'completed', 'description'],
fileName: successResponse?.data?.data?.products?.[id]?.completed?.[0]?.fileName
}),
dismissable: true
})
);
}
dispatch =>
dispatch([
setExportStatus(id, true, []),
{
type: platformTypes.SET_PLATFORM_EXPORT_CREATE,
payload: platformServices.postExport(data, {
...options,
poll: {
...options.poll,
status: successResponse => {
const isCompleted = successResponse?.data?.data?.products?.[id]?.isCompleted;
const isPending = !isCompleted;
const pending = successResponse?.data?.data?.products?.[id]?.pending || [];

setExportStatus(dispatch)(id, successResponse, ...args);
if (isCompleted) {
dispatch(removeNotification(`swatch-create-export-${id}`));
dispatch(
addNotification({
variant: 'success',
id: `swatch-create-export-${id}`,
title: translate('curiosity-toolbar.notifications', {
context: ['export', 'completed', 'title']
}),
description: translate('curiosity-toolbar.notifications', {
context: ['export', 'completed', 'description'],
fileName: successResponse?.data?.data?.products?.[id]?.completed?.[0]?.fileName
}),
dismissable: true
})
);
}

setExportStatus(id, isPending, pending)(dispatch);
},
statusWORKS: (successResponse, errorResponse, retryCount) => {
if (retryCount < 0) {
/*
*dispatch(removeNotification(`swatch-create-export-${id}`));
*dispatch(
* addNotification({
* id: `swatch-create-export-${id}`,
* title: translate('curiosity-toolbar.notifications', {
* context: ['export', 'pending', 'title', id]
* }),
* dismissable: true
* })
*);
*/
return;
}

if (
!successResponse?.data?.data?.products?.[id]?.isPending &&
successResponse?.data?.data?.products?.[id]?.isCompleted
) {
dispatch(removeNotification(`swatch-create-export-${id}`));
dispatch(
addNotification({
variant: 'success',
id: `swatch-create-export-${id}`,
title: translate('curiosity-toolbar.notifications', {
context: ['export', 'completed', 'title']
}),
description: translate('curiosity-toolbar.notifications', {
context: ['export', 'completed', 'description'],
fileName: successResponse?.data?.data?.products?.[id]?.completed?.[0]?.fileName
}),
dismissable: true
})
);
}

setExportStatus(dispatch)(id, successResponse, errorResponse, retryCount);
}
}
}
}),
meta: {
notifications: {
rejected: {
variant: 'warning',
title: translate('curiosity-toolbar.notifications', {
context: ['export', 'error', 'title']
}),
description: translate('curiosity-toolbar.notifications', {
context: ['export', 'error', 'description']
}),
dismissable: true
},
pending: {
id: `swatch-create-export-${id}`,
title: translate('curiosity-toolbar.notifications', {
context: ['export', 'pending', 'title', id]
}),
dismissable: true
}),
meta: {
id,
notifications: {
rejected: {
variant: 'warning',
title: translate('curiosity-toolbar.notifications', {
context: ['export', 'error', 'title']
}),
description: translate('curiosity-toolbar.notifications', {
context: ['export', 'error', 'description']
}),
dismissable: true
},
pending: {
id: `swatch-create-export-${id}`,
title: translate('curiosity-toolbar.notifications', {
context: ['export', 'pending', 'title', id]
}),
dismissable: true
}
}
}
}
});
};
]);

/**
* Hide platform global filter.
Expand Down
Loading

0 comments on commit 271c36b

Please sign in to comment.