Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Forms: disable export button if no form entries.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useNavigate } from 'react-router';
*/
import useCreateForm from '../../hooks/use-create-form';
import useExportResponses from '../../hooks/use-export-responses';
import useInboxData from '../../hooks/use-inbox-data';
import ExportResponsesModal from '../export-responses-modal';

type ActionsDropdownMenuProps = {
Expand All @@ -23,6 +24,8 @@ const ActionsDropdownMenu = ( { exportData }: ActionsDropdownMenuProps ) => {
const { showExportModal, openModal, closeModal, onExport, autoConnectGdrive, exportLabel } =
useExportResponses();
const navigate = useNavigate();
const { totalItems, isLoadingData } = useInboxData();
const hasItems = ! isLoadingData && totalItems > 0;

const analyticsEvent = useCallback( () => {
jetpackAnalytics.tracks.recordEvent( 'jetpack_wpa_forms_landing_page_cta_click', {
Expand All @@ -44,12 +47,17 @@ const ActionsDropdownMenu = ( { exportData }: ActionsDropdownMenuProps ) => {
}, [ navigate ] );

const controls = [
{
icon: plus,
onClick: onCreateFormClick,
title: __( 'Create form', 'jetpack-forms' ),
},
{
icon: plugins,
onClick: onIntegrationsClick,
title: __( 'Integrations', 'jetpack-forms' ),
},
...( exportData.show
...( exportData.show && hasItems
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was suggested we also go ahead and hide the Export item on the mobile menu if there's nothing to export. As part of this, I moved the Create Form button up so Export is the last item. This reduces jumpiness. With the change, the Export button only appears when there are form entries on the current screen. But this also means it's hidden while form entries are loading.

If export button is higher up, the whole menu jumps as items load or are removed from, say, inbox or spam or trash.

Video
https://github.com/user-attachments/assets/0a067ffe-fde8-40ba-bbd6-7ddf8e06e7cd

? [
{
icon: download,
Expand All @@ -58,11 +66,6 @@ const ActionsDropdownMenu = ( { exportData }: ActionsDropdownMenuProps ) => {
},
]
: [] ),
{
icon: plus,
onClick: onCreateFormClick,
title: __( 'Create form', 'jetpack-forms' ),
},
];

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
* External dependencies
*/
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { download } from '@wordpress/icons';
/**
* Internal dependencies
*/
import ExportResponsesModal from '../../components/export-responses-modal';
import useExportResponses from '../../hooks/use-export-responses';
import useInboxData from '../../hooks/use-inbox-data';

import './style.scss';

Expand All @@ -21,14 +23,25 @@ const ExportResponsesButton = () => {
autoConnectGdrive,
exportLabel,
} = useExportResponses();
const { totalItems, isLoadingData } = useInboxData();
const isEmpty = isLoadingData || totalItems === 0;

if ( ! userCanExport ) {
return null;
}

return (
<>
<Button size="compact" variant="primary" icon={ download } onClick={ openModal }>
<Button
size="compact"
variant="primary"
icon={ download }
onClick={ openModal }
accessibleWhenDisabled
disabled={ isEmpty }
label={ isEmpty ? __( 'Nothing to export.', 'jetpack-forms' ) : '' }
showTooltip={ isEmpty }
>
{ exportLabel }
</Button>

Expand Down
Loading