2018-07-16 18:37:25 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-06-02 18:25:41 +00:00
|
|
|
import { __, _n } from '@wordpress/i18n';
|
2022-10-13 11:36:02 +00:00
|
|
|
import { useEffect, useState, useMemo } from '@wordpress/element';
|
2021-11-05 03:51:30 +00:00
|
|
|
import {
|
|
|
|
EmptyContent,
|
|
|
|
Section,
|
|
|
|
Badge,
|
|
|
|
EllipsisMenu,
|
|
|
|
} from '@woocommerce/components';
|
2022-10-13 11:36:02 +00:00
|
|
|
import { Card, CardHeader, Button, CardFooter } from '@wordpress/components';
|
2021-11-17 20:15:48 +00:00
|
|
|
import { NOTES_STORE_NAME, QUERY_DEFAULTS } from '@woocommerce/data';
|
2021-06-02 18:25:41 +00:00
|
|
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2020-10-06 14:07:06 +00:00
|
|
|
import { CSSTransition, TransitionGroup } from 'react-transition-group';
|
2021-06-02 18:25:41 +00:00
|
|
|
import {
|
|
|
|
InboxNoteCard,
|
|
|
|
InboxNotePlaceholder,
|
2021-11-05 03:51:30 +00:00
|
|
|
Text,
|
2021-06-02 18:25:41 +00:00
|
|
|
} from '@woocommerce/experimental';
|
2021-12-09 03:08:47 +00:00
|
|
|
import moment from 'moment';
|
2022-03-07 04:09:26 +00:00
|
|
|
|
2018-07-16 18:37:25 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-12-14 16:56:42 +00:00
|
|
|
import { ActivityCard } from '~/activity-panel/activity-card';
|
2021-11-23 23:47:48 +00:00
|
|
|
import { hasValidNotes, truncateRenderableHTML } from './utils';
|
2021-06-02 18:25:41 +00:00
|
|
|
import { getScreenName } from '../utils';
|
2022-02-04 15:26:56 +00:00
|
|
|
import DismissAllModal from './dismiss-all-modal';
|
2021-06-02 18:25:41 +00:00
|
|
|
import './index.scss';
|
2018-07-16 18:37:25 +00:00
|
|
|
|
2022-10-13 11:36:02 +00:00
|
|
|
const ADD_NOTES_AMOUNT = 10;
|
|
|
|
const DEFAULT_INBOX_QUERY = {
|
|
|
|
page: 1,
|
|
|
|
per_page: 5,
|
|
|
|
status: 'unactioned',
|
|
|
|
type: QUERY_DEFAULTS.noteTypes,
|
|
|
|
orderby: 'date',
|
|
|
|
order: 'desc',
|
|
|
|
_fields: [
|
|
|
|
'id',
|
|
|
|
'name',
|
|
|
|
'title',
|
|
|
|
'content',
|
|
|
|
'type',
|
|
|
|
'status',
|
|
|
|
'actions',
|
|
|
|
'date_created',
|
|
|
|
'date_created_gmt',
|
|
|
|
'layout',
|
|
|
|
'image',
|
|
|
|
'is_deleted',
|
|
|
|
'is_read',
|
|
|
|
'locale',
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const supportedLocales = [ 'en_US', 'en_AU', 'en_CA', 'en_GB', 'en_ZA' ];
|
|
|
|
|
|
|
|
const WC_VERSION_61_RELEASE_DATE = moment(
|
|
|
|
'2022-01-11',
|
|
|
|
'YYYY-MM-DD'
|
|
|
|
).valueOf();
|
|
|
|
|
2020-06-10 16:46:46 +00:00
|
|
|
const renderEmptyCard = () => (
|
|
|
|
<ActivityCard
|
|
|
|
className="woocommerce-empty-activity-card"
|
2022-03-30 09:00:04 +00:00
|
|
|
title={ __( 'Your inbox is empty', 'woocommerce' ) }
|
2020-06-10 16:46:46 +00:00
|
|
|
icon={ false }
|
|
|
|
>
|
|
|
|
{ __(
|
|
|
|
'As things begin to happen in your store your inbox will start to fill up. ' +
|
|
|
|
"You'll see things like achievements, new feature announcements, extension recommendations and more!",
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2020-06-10 16:46:46 +00:00
|
|
|
) }
|
|
|
|
</ActivityCard>
|
|
|
|
);
|
|
|
|
|
2021-06-02 18:25:41 +00:00
|
|
|
const onBodyLinkClick = ( note, innerLink ) => {
|
|
|
|
recordEvent( 'inbox_action_click', {
|
|
|
|
note_name: note.name,
|
|
|
|
note_title: note.title,
|
|
|
|
note_content_inner_link: innerLink,
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2021-12-27 08:38:31 +00:00
|
|
|
let hasFiredPanelViewTrack = false;
|
|
|
|
|
2021-06-02 18:25:41 +00:00
|
|
|
const renderNotes = ( {
|
|
|
|
hasNotes,
|
|
|
|
isBatchUpdating,
|
|
|
|
notes,
|
2021-11-17 05:56:05 +00:00
|
|
|
onDismiss,
|
2021-06-02 18:25:41 +00:00
|
|
|
onNoteActionClick,
|
2022-11-23 16:52:46 +00:00
|
|
|
onNoteVisible,
|
2021-11-17 05:56:05 +00:00
|
|
|
setShowDismissAllModal: onDismissAll,
|
2021-11-23 10:27:32 +00:00
|
|
|
showHeader = true,
|
2022-10-13 11:36:02 +00:00
|
|
|
loadMoreNotes,
|
|
|
|
allNotesFetched,
|
|
|
|
notesHaveResolved,
|
2022-11-23 16:52:46 +00:00
|
|
|
unreadNotesCount,
|
2021-06-02 18:25:41 +00:00
|
|
|
} ) => {
|
2020-08-13 13:23:38 +00:00
|
|
|
if ( isBatchUpdating ) {
|
2020-06-10 16:46:46 +00:00
|
|
|
return;
|
2019-03-21 02:54:36 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 16:46:46 +00:00
|
|
|
if ( ! hasNotes ) {
|
|
|
|
return renderEmptyCard();
|
2019-03-21 02:54:36 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 08:38:31 +00:00
|
|
|
if ( ! hasFiredPanelViewTrack ) {
|
|
|
|
recordEvent( 'inbox_panel_view', {
|
|
|
|
total: notes.length,
|
|
|
|
} );
|
|
|
|
hasFiredPanelViewTrack = true;
|
|
|
|
}
|
2021-12-07 01:18:54 +00:00
|
|
|
|
2020-06-10 16:46:46 +00:00
|
|
|
const notesArray = Object.keys( notes ).map( ( key ) => notes[ key ] );
|
2019-04-15 07:06:34 +00:00
|
|
|
|
2020-10-06 14:07:06 +00:00
|
|
|
return (
|
2021-11-05 03:51:30 +00:00
|
|
|
<Card size="large">
|
2021-11-23 10:27:32 +00:00
|
|
|
{ showHeader && (
|
|
|
|
<CardHeader size="medium">
|
|
|
|
<div className="wooocommerce-inbox-card__header">
|
|
|
|
<Text size="20" lineHeight="28px" variant="title.small">
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( 'Inbox', 'woocommerce' ) }
|
2021-11-23 10:27:32 +00:00
|
|
|
</Text>
|
2022-11-23 16:52:46 +00:00
|
|
|
<Badge count={ unreadNotesCount } />
|
2021-11-23 10:27:32 +00:00
|
|
|
</div>
|
|
|
|
<EllipsisMenu
|
2022-03-30 09:00:04 +00:00
|
|
|
label={ __( 'Inbox Notes Options', 'woocommerce' ) }
|
2021-11-23 10:27:32 +00:00
|
|
|
renderContent={ ( { onToggle } ) => (
|
|
|
|
<div className="woocommerce-inbox-card__section-controls">
|
|
|
|
<Button
|
|
|
|
onClick={ () => {
|
|
|
|
onDismissAll( true );
|
|
|
|
onToggle();
|
|
|
|
} }
|
|
|
|
>
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( 'Dismiss all', 'woocommerce' ) }
|
2021-11-23 10:27:32 +00:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
</CardHeader>
|
|
|
|
) }
|
2021-11-05 03:51:30 +00:00
|
|
|
<TransitionGroup role="menu">
|
|
|
|
{ notesArray.map( ( note ) => {
|
|
|
|
const { id: noteId, is_deleted: isDeleted } = note;
|
|
|
|
if ( isDeleted ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<CSSTransition
|
2020-10-06 14:07:06 +00:00
|
|
|
key={ noteId }
|
2021-11-05 03:51:30 +00:00
|
|
|
timeout={ 500 }
|
|
|
|
classNames="woocommerce-inbox-message"
|
|
|
|
>
|
|
|
|
<InboxNoteCard
|
|
|
|
key={ noteId }
|
|
|
|
note={ note }
|
2021-11-17 05:56:05 +00:00
|
|
|
onDismiss={ onDismiss }
|
2021-11-05 03:51:30 +00:00
|
|
|
onNoteActionClick={ onNoteActionClick }
|
|
|
|
onBodyLinkClick={ onBodyLinkClick }
|
|
|
|
onNoteVisible={ onNoteVisible }
|
|
|
|
/>
|
|
|
|
</CSSTransition>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
</TransitionGroup>
|
2022-10-13 11:36:02 +00:00
|
|
|
{ allNotesFetched
|
|
|
|
? null
|
|
|
|
: ( () => {
|
|
|
|
if ( ! notesHaveResolved ) {
|
|
|
|
return (
|
|
|
|
<InboxNotePlaceholder className="banner message-is-unread" />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<CardFooter
|
|
|
|
className="wooocommerce-inbox-card__footer"
|
|
|
|
size="medium"
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
isPrimary={ true }
|
|
|
|
onClick={ () => {
|
|
|
|
loadMoreNotes();
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
{ notesArray.length >
|
|
|
|
DEFAULT_INBOX_QUERY.per_page
|
|
|
|
? __( 'Show more', 'woocommerce' )
|
|
|
|
: __( 'Show older', 'woocommerce' ) }
|
|
|
|
</Button>
|
|
|
|
</CardFooter>
|
|
|
|
);
|
|
|
|
} )() }
|
2021-11-05 03:51:30 +00:00
|
|
|
</Card>
|
2020-10-06 14:07:06 +00:00
|
|
|
);
|
2020-06-22 14:53:36 +00:00
|
|
|
};
|
2018-10-12 19:20:48 +00:00
|
|
|
|
2021-11-23 10:27:32 +00:00
|
|
|
const InboxPanel = ( { showHeader = true } ) => {
|
2022-10-13 11:36:02 +00:00
|
|
|
const [ noteDisplayQty, setNoteDisplayQty ] = useState(
|
|
|
|
DEFAULT_INBOX_QUERY.per_page
|
|
|
|
);
|
|
|
|
const [ allNotesFetched, setAllNotesFetched ] = useState( false );
|
|
|
|
const [ allNotes, setAllNotes ] = useState( [] );
|
2022-11-23 16:52:46 +00:00
|
|
|
const [ viewedNotes, setViewedNotes ] = useState( {} );
|
2021-06-02 18:25:41 +00:00
|
|
|
const { createNotice } = useDispatch( 'core/notices' );
|
2022-10-13 11:36:02 +00:00
|
|
|
const {
|
|
|
|
removeNote,
|
|
|
|
updateNote,
|
|
|
|
triggerNoteAction,
|
|
|
|
invalidateResolutionForStoreSelector,
|
|
|
|
} = useDispatch( NOTES_STORE_NAME );
|
2022-11-23 16:52:46 +00:00
|
|
|
const screen = getScreenName();
|
2021-11-17 20:15:48 +00:00
|
|
|
|
2022-10-13 11:36:02 +00:00
|
|
|
const inboxQuery = useMemo( () => {
|
|
|
|
return {
|
|
|
|
...DEFAULT_INBOX_QUERY,
|
|
|
|
per_page: noteDisplayQty,
|
|
|
|
};
|
|
|
|
}, [ noteDisplayQty ] );
|
2021-06-02 18:25:41 +00:00
|
|
|
|
2022-11-23 16:52:46 +00:00
|
|
|
const {
|
|
|
|
isError,
|
|
|
|
notes,
|
|
|
|
notesHaveResolved,
|
|
|
|
isBatchUpdating,
|
|
|
|
unreadNotesCount,
|
|
|
|
} = useSelect( ( select ) => {
|
|
|
|
const {
|
|
|
|
getNotes,
|
|
|
|
getNotesError,
|
|
|
|
isNotesRequesting,
|
|
|
|
hasFinishedResolution,
|
|
|
|
} = select( NOTES_STORE_NAME );
|
2021-12-09 18:43:04 +00:00
|
|
|
|
2022-11-23 16:52:46 +00:00
|
|
|
return {
|
|
|
|
notes: getNotes( inboxQuery ),
|
|
|
|
unreadNotesCount: getNotes( {
|
|
|
|
...DEFAULT_INBOX_QUERY,
|
|
|
|
is_read: false,
|
|
|
|
per_page: -1,
|
|
|
|
} ).length,
|
|
|
|
isError: Boolean( getNotesError( 'getNotes', [ inboxQuery ] ) ),
|
|
|
|
isBatchUpdating: isNotesRequesting( 'batchUpdateNotes' ),
|
|
|
|
notesHaveResolved:
|
|
|
|
! isNotesRequesting( 'batchUpdateNotes' ) &&
|
|
|
|
hasFinishedResolution( 'getNotes', [ inboxQuery ] ),
|
|
|
|
};
|
|
|
|
} );
|
2022-10-13 11:36:02 +00:00
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
if ( notesHaveResolved && notes.length < noteDisplayQty ) {
|
|
|
|
setAllNotesFetched( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( notesHaveResolved && notes.length ) {
|
|
|
|
setAllNotes(
|
|
|
|
notes.map( ( note ) => {
|
2021-12-09 03:08:47 +00:00
|
|
|
const noteDate = moment(
|
|
|
|
note.date_created_gmt,
|
|
|
|
'YYYY-MM-DD'
|
|
|
|
).valueOf();
|
|
|
|
|
2021-12-09 18:43:04 +00:00
|
|
|
if (
|
|
|
|
supportedLocales.includes( note.locale ) &&
|
|
|
|
noteDate >= WC_VERSION_61_RELEASE_DATE
|
|
|
|
) {
|
2022-03-07 04:09:26 +00:00
|
|
|
return {
|
|
|
|
...note,
|
|
|
|
content: truncateRenderableHTML(
|
|
|
|
note.content,
|
|
|
|
320
|
|
|
|
),
|
|
|
|
};
|
2021-12-09 03:08:47 +00:00
|
|
|
}
|
2021-11-23 23:47:48 +00:00
|
|
|
return note;
|
2022-10-13 11:36:02 +00:00
|
|
|
} )
|
|
|
|
);
|
2021-06-02 18:25:41 +00:00
|
|
|
}
|
2022-10-13 11:36:02 +00:00
|
|
|
}, [ notes, notesHaveResolved ] );
|
2020-06-10 16:46:46 +00:00
|
|
|
|
2021-11-17 20:15:48 +00:00
|
|
|
const [ showDismissAllModal, setShowDismissAllModal ] = useState( false );
|
Inbox notification: layout changes (https://github.com/woocommerce/woocommerce-admin/pull/4218)
* Inbox notification: Added layout changes (https://github.com/woocommerce/woocommerce-admin/pull/4256)
* Added notes layout and image to the API
Added note layout and note image to the API and the DB
* Unit test modified
Unit test where modified to adapt them to the new elements
* Changed the frontend following the new designs.
The fronted was changed to follow the new inbox messages design.
* Changed default layout type in DB
* Added all the requested visual element
Changed the cards' js, css and actions to achieve the visual requirements
* Added "layout" and "image" to inboxQuery
* Modal confirmation buttons repaired
* Added "layout" and "image" to docs examples.
* Removed "updateNote" from action.js
Removed "updateNote" from action.js, I left it by mistake.
* Spelling error corrected
The button text "Dismiss all message" was corrected
* noteName removed and icon added to make code reviewing easier
This commit removes the "noteName" from card.js and adds the icon to make code reviewing easier
* Dismiss action button refactor
Refactor of the dismiss action button in the InboxNoteCard class
* Removed unnecessary control
* Destructured all the note properties
* Colors replaced by existing variable
* Removed setting of layout and image in the creation of the notes
* Removed blank lines added by mistake
* Close dismiss dropdown when clicking away from the popover.
* Prevented the closing of the inbox panel with an action in the modal
* Added small design changes
* Removed unused "Gridicon" import
* Prevent showing the image tag when the layout is blank
* The method name getDismissButton was changed to getDismissConfirmationButton
* Removed unnecessary vendor-prefixed properties
* Improved note filtering in unreadNotes method
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Inbox notification: Remove icons (https://github.com/woocommerce/woocommerce-admin/pull/4258)
* Info icon removed from inbox notifications
The info icon was removed from inbox notifications
# Conflicts:
# src/Notes/DataStore.php
* Removed "icon" from inboxQuery
* Tests repeared
Some problems with the unit tests were repaired in this commit
# Conflicts:
# docs/examples/activity-panel-inbox.md
# Conflicts:
# tests/api/admin-notes.php
* Removed icon from card.js
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
* Inbox notification: Add dismiss functionality (https://github.com/woocommerce/woocommerce-admin/pull/4262)
* Added is_deleted param to soft delete
# Conflicts:
# src/API/Notes.php
# src/Install.php
# src/Notes/DataStore.php
# src/Notes/WC_Admin_Note.php
# src/Notes/WC_Admin_Notes.php
# tests/api/admin-notes.php
* Added the Dismiss functionality
# Conflicts:
# client/header/activity-panel/panels/inbox/action.js
* Where clause repeared
* Added Snackbar after action.
* API modified to dismiss notes
* Small refactor in "get_item" method
This commit adds a small refactor in "get_item" method to use "prepare_note_data_for_response"
* Added missing logic to Dismiss note
This commit adds missing client logic to Dismiss note.
# Conflicts:
# client/header/activity-panel/panels/inbox/action.js
# client/header/activity-panel/panels/inbox/card.js
* Moved the delete action to WC_Admin_Notes.php
The delete action was moved to WC_Admin_Notes.php to follow the pattern.
* Added changes to dismiss messages
This commit addeds changes to the messages soft delete.
* DataStore.php repaired
This commits adds some code that was deleted by mistake and the param "is_deleted" has been escaped.
* Spelling error corrected
The button text "Dismiss all message" was corrected
* Repaired "get_notes_where_clauses" method
A problem with the deleted notes was repaired
* Added a comment to DataStore.php
* Stopped sending the "dismissType" to action.js
The "dismissType" is not sent to action.js anymore.
* Bugfix: now the method get_notes_with_name also returns deleted notes
* Bugfix: repaired empty notification list
This commit repairs a bug that happens when there isn't anything in the inbox notification list
* Small refactor to not use "some" Lodash method anymore
* Small refactor in rednderNotes method
* Added check to set_layout
* Added small refactor to delete_all_notes method
* Fixed code comment error
* Bugfix: repaired the "delete_note" call
* Inbox notification: Added layout changes (https://github.com/woocommerce/woocommerce-admin/pull/4256)
* Added notes layout and image to the API
Added note layout and note image to the API and the DB
* Unit test modified
Unit test where modified to adapt them to the new elements
* Changed the frontend following the new designs.
The fronted was changed to follow the new inbox messages design.
* Changed default layout type in DB
* Added all the requested visual element
Changed the cards' js, css and actions to achieve the visual requirements
* Added "layout" and "image" to inboxQuery
* Modal confirmation buttons repaired
* Added "layout" and "image" to docs examples.
* Removed "updateNote" from action.js
Removed "updateNote" from action.js, I left it by mistake.
* Spelling error corrected
The button text "Dismiss all message" was corrected
* noteName removed and icon added to make code reviewing easier
This commit removes the "noteName" from card.js and adds the icon to make code reviewing easier
* Dismiss action button refactor
Refactor of the dismiss action button in the InboxNoteCard class
* Removed unnecessary control
* Destructured all the note properties
* Colors replaced by existing variable
* Removed setting of layout and image in the creation of the notes
* Removed blank lines added by mistake
* Close dismiss dropdown when clicking away from the popover.
* Prevented the closing of the inbox panel with an action in the modal
* Added small design changes
* Removed unused "Gridicon" import
* Prevent showing the image tag when the layout is blank
* The method name getDismissButton was changed to getDismissConfirmationButton
* Removed unnecessary vendor-prefixed properties
* Improved note filtering in unreadNotes method
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Inbox notification: Remove icons (https://github.com/woocommerce/woocommerce-admin/pull/4258)
* Info icon removed from inbox notifications
The info icon was removed from inbox notifications
# Conflicts:
# src/Notes/DataStore.php
* Removed "icon" from inboxQuery
* Tests repeared
Some problems with the unit tests were repaired in this commit
# Conflicts:
# docs/examples/activity-panel-inbox.md
# Conflicts:
# tests/api/admin-notes.php
* Removed icon from card.js
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
* Improved error handling for the set_layout method
* Bugfix: fixed error handling clicks inside dropdowns
* Bugfix: repaired dropdown onBlur handler
This commit repairs a weird behavior that the dropdown onBlur handler method had sometimes.
* Text error changed
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Inbox notification: Add undo snackbar button after deletion (https://github.com/woocommerce/woocommerce-admin/pull/4281)
* Added undo snakbar button for a single note
# Conflicts:
# client/wc-api/notes/mutations.js
# src/Notes/DataStore.php
# src/Notes/WC_Admin_Notes.php
* Added a button to undo the deletion of all notes
# Conflicts:
# client/wc-api/notes/operations.js
# src/API/Notes.php
* Code adapted to make code reviewing easier
There was some code that also was present in another PR, that code was removed to make code reviewing easier.
* UnitTest added
This commit adds some unit tests
* Added verification for API response
* Added casting to $note_id
* Inbox notification: Added layout changes (https://github.com/woocommerce/woocommerce-admin/pull/4256)
* Added notes layout and image to the API
Added note layout and note image to the API and the DB
* Unit test modified
Unit test where modified to adapt them to the new elements
* Changed the frontend following the new designs.
The fronted was changed to follow the new inbox messages design.
* Changed default layout type in DB
* Added all the requested visual element
Changed the cards' js, css and actions to achieve the visual requirements
* Added "layout" and "image" to inboxQuery
* Modal confirmation buttons repaired
* Added "layout" and "image" to docs examples.
* Removed "updateNote" from action.js
Removed "updateNote" from action.js, I left it by mistake.
* Spelling error corrected
The button text "Dismiss all message" was corrected
* noteName removed and icon added to make code reviewing easier
This commit removes the "noteName" from card.js and adds the icon to make code reviewing easier
* Dismiss action button refactor
Refactor of the dismiss action button in the InboxNoteCard class
* Removed unnecessary control
* Destructured all the note properties
* Colors replaced by existing variable
* Removed setting of layout and image in the creation of the notes
* Removed blank lines added by mistake
* Close dismiss dropdown when clicking away from the popover.
* Prevented the closing of the inbox panel with an action in the modal
* Added small design changes
* Removed unused "Gridicon" import
* Prevent showing the image tag when the layout is blank
* The method name getDismissButton was changed to getDismissConfirmationButton
* Removed unnecessary vendor-prefixed properties
* Improved note filtering in unreadNotes method
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Inbox notification: Remove icons (https://github.com/woocommerce/woocommerce-admin/pull/4258)
* Info icon removed from inbox notifications
The info icon was removed from inbox notifications
# Conflicts:
# src/Notes/DataStore.php
* Removed "icon" from inboxQuery
* Tests repeared
Some problems with the unit tests were repaired in this commit
# Conflicts:
# docs/examples/activity-panel-inbox.md
# Conflicts:
# tests/api/admin-notes.php
* Removed icon from card.js
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
* Inbox notification: Add dismiss functionality (https://github.com/woocommerce/woocommerce-admin/pull/4262)
* Added is_deleted param to soft delete
# Conflicts:
# src/API/Notes.php
# src/Install.php
# src/Notes/DataStore.php
# src/Notes/WC_Admin_Note.php
# src/Notes/WC_Admin_Notes.php
# tests/api/admin-notes.php
* Added the Dismiss functionality
# Conflicts:
# client/header/activity-panel/panels/inbox/action.js
* Where clause repeared
* Added Snackbar after action.
* API modified to dismiss notes
* Small refactor in "get_item" method
This commit adds a small refactor in "get_item" method to use "prepare_note_data_for_response"
* Added missing logic to Dismiss note
This commit adds missing client logic to Dismiss note.
# Conflicts:
# client/header/activity-panel/panels/inbox/action.js
# client/header/activity-panel/panels/inbox/card.js
* Moved the delete action to WC_Admin_Notes.php
The delete action was moved to WC_Admin_Notes.php to follow the pattern.
* Added changes to dismiss messages
This commit addeds changes to the messages soft delete.
* DataStore.php repaired
This commits adds some code that was deleted by mistake and the param "is_deleted" has been escaped.
* Spelling error corrected
The button text "Dismiss all message" was corrected
* Repaired "get_notes_where_clauses" method
A problem with the deleted notes was repaired
* Added a comment to DataStore.php
* Stopped sending the "dismissType" to action.js
The "dismissType" is not sent to action.js anymore.
* Bugfix: now the method get_notes_with_name also returns deleted notes
* Bugfix: repaired empty notification list
This commit repairs a bug that happens when there isn't anything in the inbox notification list
* Small refactor to not use "some" Lodash method anymore
* Small refactor in rednderNotes method
* Added check to set_layout
* Added small refactor to delete_all_notes method
* Fixed code comment error
* Bugfix: repaired the "delete_note" call
* Inbox notification: Added layout changes (https://github.com/woocommerce/woocommerce-admin/pull/4256)
* Added notes layout and image to the API
Added note layout and note image to the API and the DB
* Unit test modified
Unit test where modified to adapt them to the new elements
* Changed the frontend following the new designs.
The fronted was changed to follow the new inbox messages design.
* Changed default layout type in DB
* Added all the requested visual element
Changed the cards' js, css and actions to achieve the visual requirements
* Added "layout" and "image" to inboxQuery
* Modal confirmation buttons repaired
* Added "layout" and "image" to docs examples.
* Removed "updateNote" from action.js
Removed "updateNote" from action.js, I left it by mistake.
* Spelling error corrected
The button text "Dismiss all message" was corrected
* noteName removed and icon added to make code reviewing easier
This commit removes the "noteName" from card.js and adds the icon to make code reviewing easier
* Dismiss action button refactor
Refactor of the dismiss action button in the InboxNoteCard class
* Removed unnecessary control
* Destructured all the note properties
* Colors replaced by existing variable
* Removed setting of layout and image in the creation of the notes
* Removed blank lines added by mistake
* Close dismiss dropdown when clicking away from the popover.
* Prevented the closing of the inbox panel with an action in the modal
* Added small design changes
* Removed unused "Gridicon" import
* Prevent showing the image tag when the layout is blank
* The method name getDismissButton was changed to getDismissConfirmationButton
* Removed unnecessary vendor-prefixed properties
* Improved note filtering in unreadNotes method
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Update client/header/activity-panel/panels/inbox/style.scss
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Inbox notification: Remove icons (https://github.com/woocommerce/woocommerce-admin/pull/4258)
* Info icon removed from inbox notifications
The info icon was removed from inbox notifications
# Conflicts:
# src/Notes/DataStore.php
* Removed "icon" from inboxQuery
* Tests repeared
Some problems with the unit tests were repaired in this commit
# Conflicts:
# docs/examples/activity-panel-inbox.md
# Conflicts:
# tests/api/admin-notes.php
* Removed icon from card.js
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
* Improved error handling for the set_layout method
* Bugfix: fixed error handling clicks inside dropdowns
* Bugfix: repaired dropdown onBlur handler
This commit repairs a weird behavior that the dropdown onBlur handler method had sometimes.
* Text error changed
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Stopped sending the "dismissType" to action.js
The "dismissType" is not sent to action.js anymore.
# Conflicts:
# client/header/activity-panel/panels/inbox/card.js
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
* Bugfix: solved problem when a note was undismissed
There was a problem with the undismiss functionality. When a note was undismissed, it always was recovered with "plain" layout. This commit solves this problem.
* Inbox notification: add event recording (https://github.com/woocommerce/woocommerce-admin/pull/4320)
* Added events recording
This commit adds events recording to the inbox notifications
# Conflicts:
# client/header/activity-panel/panels/inbox/index.js
* Added 'home_screen' verification
Changed recorded name, now when the client is in the WooCommerce 'home' page we record 'home_screen' instead of 'wc-admin'.
* Added a naming fix and a new prop to the recordEvent
* bugfix: added control before interaction with bodyNotificationRef
* Added more unit tests for new endpoints
This commit adds tests for deleting a single note and for deleting all the notes, both without permission.
* Modified variable name
* Refactor: prop rename and small logic change
* Screen name getter moved into the InboxNoteCard
This commit moves the screen name getter inside the InboxNoteCard.
# Conflicts:
# client/header/activity-panel/panels/inbox/index.js
* Removed "screen" from state
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
* Refactor in admin-notes unit tests
Some unnecessary controls were removed from the admin-notes unit tests
* Indentation fixed in Install.php. Replaced spaces with tabs.
* Inbox notification: added new placeholder and empty card (https://github.com/woocommerce/woocommerce-admin/pull/4379)
* Added a new placeholder and an empty card
This commit adds a new placeholder and a new empty card to the inbox panel
# Conflicts:
# client/header/activity-panel/panels/inbox/index.js
# client/header/activity-panel/panels/inbox/style.scss
* Added border to read notes
* Improved note filtering in unreadNotes method and validNotes
# Conflicts:
# client/header/activity-panel/panels/inbox/index.js
* Actions render refactored
The actions render was refactored in InboxNoteCard component
* Refactor of InboxPanel component
The methods getUnreadNotesCount and hasValidNotes were separated from the InboxPanel component
# Conflicts:
# client/header/activity-panel/panels/inbox/index.js
* Refactor inbox panel subtitle classes
* Added changes for when a note is undismissed
This commit adds the requested changes in behavior and design for when a note is dismissed.
# Conflicts:
# client/header/activity-panel/panels/inbox/index.js
* Bugfix: Added key to itemlist
The InboxNotePlaceholder is shown as an itemlist but it didn't have a key. This commit adds it.
* Removed unnecessary validation
* Refactored actionList map
This commit adds a refactor to the actionList map
* Changes to the getUndoDismissRequesting functionality
This commit adds a few changes to the getUndoDismissRequesting functionality
* Changed className prop
* Changed other className prop
* Modified InboxPanel rendering
* Removed unnecessary method in placeholder.js
* Simplified the card.js renderActions method
* Change renderActions return in card.js
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
* Inbox notification: add client unit tests (https://github.com/woocommerce/woocommerce-admin/pull/4386)
* Added client unit tests
* Added test cases for getUnreadNotesCount and hasValidNotes
* Corrected typo error
* Removed Enzyme and added React Testing Library
* Removed unnecessary param
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
* Resolved some conflicts with master
* Marketing note test repaired
This commit repairs the marketing note test
* Added note type 'marketing' to delete all functionality
* Removed set_icon method from some notes and docs
* Added set_icon method as deprecated to prevent errors.
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
Co-authored-by: Joshua T Flowers <joshuatf@gmail.com>
2020-06-03 11:43:35 +00:00
|
|
|
|
2022-11-23 16:52:46 +00:00
|
|
|
const onNoteVisible = ( note ) => {
|
|
|
|
if ( ! viewedNotes[ note.id ] && ! note.is_read ) {
|
|
|
|
setViewedNotes( { ...viewedNotes, [ note.id ]: true } );
|
|
|
|
setTimeout( () => {
|
|
|
|
updateNote( note.id, {
|
|
|
|
is_read: true,
|
|
|
|
} );
|
|
|
|
}, 3000 );
|
|
|
|
}
|
|
|
|
recordEvent( 'inbox_note_view', {
|
|
|
|
note_content: note.content,
|
|
|
|
note_name: note.name,
|
|
|
|
note_title: note.title,
|
|
|
|
note_type: note.type,
|
|
|
|
screen,
|
|
|
|
} );
|
|
|
|
};
|
2021-06-02 18:25:41 +00:00
|
|
|
|
2022-11-23 16:52:46 +00:00
|
|
|
const onDismiss = async ( note ) => {
|
2021-06-02 18:25:41 +00:00
|
|
|
recordEvent( 'inbox_action_dismiss', {
|
2021-11-05 03:51:30 +00:00
|
|
|
note_name: note.name,
|
|
|
|
note_title: note.title,
|
|
|
|
note_name_dismiss_all: false,
|
|
|
|
note_name_dismiss_confirmation: true,
|
2021-06-02 18:25:41 +00:00
|
|
|
screen,
|
|
|
|
} );
|
|
|
|
|
2021-11-05 03:51:30 +00:00
|
|
|
const noteId = note.id;
|
|
|
|
try {
|
2022-10-13 11:36:02 +00:00
|
|
|
await removeNote( noteId );
|
|
|
|
invalidateResolutionForStoreSelector( 'getNotes' );
|
2022-03-30 09:00:04 +00:00
|
|
|
createNotice( 'success', __( 'Message dismissed', 'woocommerce' ), {
|
|
|
|
actions: [
|
|
|
|
{
|
|
|
|
label: __( 'Undo', 'woocommerce' ),
|
2022-10-13 11:36:02 +00:00
|
|
|
onClick: async () => {
|
|
|
|
await updateNote( noteId, {
|
2022-03-30 09:00:04 +00:00
|
|
|
is_deleted: 0,
|
|
|
|
} );
|
2022-10-13 11:36:02 +00:00
|
|
|
invalidateResolutionForStoreSelector( 'getNotes' );
|
2021-11-05 03:51:30 +00:00
|
|
|
},
|
2022-03-30 09:00:04 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
} );
|
2021-11-05 03:51:30 +00:00
|
|
|
} catch ( e ) {
|
|
|
|
createNotice(
|
|
|
|
'error',
|
|
|
|
_n(
|
|
|
|
'Message could not be dismissed',
|
|
|
|
'Messages could not be dismissed',
|
|
|
|
1,
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-11-05 03:51:30 +00:00
|
|
|
)
|
|
|
|
);
|
2021-06-02 18:25:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-10 16:46:46 +00:00
|
|
|
if ( isError ) {
|
|
|
|
const title = __(
|
|
|
|
'There was an error getting your inbox. Please try again.',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2020-06-10 16:46:46 +00:00
|
|
|
);
|
2022-03-30 09:00:04 +00:00
|
|
|
const actionLabel = __( 'Reload', 'woocommerce' );
|
2020-06-10 16:46:46 +00:00
|
|
|
const actionCallback = () => {
|
|
|
|
// @todo Add tracking for how often an error is displayed, and the reload action is clicked.
|
|
|
|
window.location.reload();
|
|
|
|
};
|
2020-06-05 16:28:25 +00:00
|
|
|
|
2018-07-16 18:37:25 +00:00
|
|
|
return (
|
2020-11-06 17:53:03 +00:00
|
|
|
<EmptyContent
|
|
|
|
title={ title }
|
|
|
|
actionLabel={ actionLabel }
|
|
|
|
actionURL={ null }
|
|
|
|
actionCallback={ actionCallback }
|
|
|
|
/>
|
2018-07-16 18:37:25 +00:00
|
|
|
);
|
|
|
|
}
|
2020-06-10 16:46:46 +00:00
|
|
|
|
2022-10-13 11:36:02 +00:00
|
|
|
if ( notesHaveResolved && ! allNotes.length ) {
|
|
|
|
return null;
|
|
|
|
}
|
2020-06-10 16:46:46 +00:00
|
|
|
|
|
|
|
return (
|
2020-11-06 17:53:03 +00:00
|
|
|
<>
|
2021-11-17 05:56:05 +00:00
|
|
|
{ showDismissAllModal && (
|
|
|
|
<DismissAllModal
|
|
|
|
onClose={ () => {
|
|
|
|
setShowDismissAllModal( false );
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
) }
|
2020-06-10 16:46:46 +00:00
|
|
|
<div className="woocommerce-homepage-notes-wrapper">
|
2022-10-13 11:36:02 +00:00
|
|
|
{ ! notesHaveResolved && ! allNotes.length && (
|
2020-06-10 16:46:46 +00:00
|
|
|
<Section>
|
|
|
|
<InboxNotePlaceholder className="banner message-is-unread" />
|
|
|
|
</Section>
|
|
|
|
) }
|
|
|
|
<Section>
|
2022-10-13 11:36:02 +00:00
|
|
|
{ Boolean( allNotes.length ) &&
|
2020-06-10 16:46:46 +00:00
|
|
|
renderNotes( {
|
2022-10-13 11:36:02 +00:00
|
|
|
loadMoreNotes: () => {
|
|
|
|
recordEvent( 'inbox_action_load_more', {
|
|
|
|
quantity_shown: allNotes.length,
|
|
|
|
} );
|
|
|
|
setNoteDisplayQty(
|
|
|
|
noteDisplayQty + ADD_NOTES_AMOUNT
|
|
|
|
);
|
|
|
|
},
|
|
|
|
hasNotes: hasValidNotes( allNotes ),
|
2020-08-13 13:23:38 +00:00
|
|
|
isBatchUpdating,
|
2022-10-13 11:36:02 +00:00
|
|
|
notes: allNotes,
|
2021-11-17 05:56:05 +00:00
|
|
|
onDismiss,
|
2022-02-28 19:40:35 +00:00
|
|
|
onNoteActionClick: ( note, action ) => {
|
|
|
|
triggerNoteAction( note.id, action.id );
|
|
|
|
},
|
2022-11-23 16:52:46 +00:00
|
|
|
onNoteVisible,
|
2021-11-17 05:56:05 +00:00
|
|
|
setShowDismissAllModal,
|
2021-11-23 10:27:32 +00:00
|
|
|
showHeader,
|
2022-10-13 11:36:02 +00:00
|
|
|
allNotesFetched,
|
|
|
|
notesHaveResolved,
|
2022-11-23 16:52:46 +00:00
|
|
|
unreadNotesCount,
|
2020-06-10 16:46:46 +00:00
|
|
|
} ) }
|
|
|
|
</Section>
|
|
|
|
</div>
|
2020-11-06 17:53:03 +00:00
|
|
|
</>
|
2020-06-10 16:46:46 +00:00
|
|
|
);
|
2020-06-22 14:53:36 +00:00
|
|
|
};
|
2018-07-16 18:37:25 +00:00
|
|
|
|
2021-06-02 18:25:41 +00:00
|
|
|
export default InboxPanel;
|