-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A4A Referrals: convert the actions field into proper actions #94250
Changes from all commits
1fc00d0
c48b921
608712e
d964217
2e23e62
a7e05a1
84b00ab
a08c26a
487199f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Button, Gridicon } from '@automattic/components'; | ||
import { useDesktopBreakpoint } from '@automattic/viewport-react'; | ||
import { filterSortAndPaginate } from '@wordpress/dataviews'; | ||
import { chevronRight } from '@wordpress/icons'; | ||
import { useTranslate } from 'i18n-calypso'; | ||
import { useMemo, useCallback, ReactNode, useEffect } from 'react'; | ||
import { DATAVIEWS_LIST } from 'calypso/a8c-for-agencies/components/items-dashboard/constants'; | ||
|
@@ -11,7 +11,7 @@ import { recordTracksEvent } from 'calypso/state/analytics/actions'; | |
import { Referral, ReferralInvoice } from '../types'; | ||
import CommissionsColumn from './commissions-column'; | ||
import SubscriptionStatus from './subscription-status'; | ||
import type { Field } from '@wordpress/dataviews'; | ||
import type { Field, Action } from '@wordpress/dataviews'; | ||
|
||
import './style.scss'; | ||
|
||
|
@@ -48,62 +48,24 @@ export default function ReferralList( { | |
() => | ||
dataViewsState.selectedItem || ! isDesktop | ||
? [ | ||
// Show the client column as a button on mobile | ||
{ | ||
id: 'client', | ||
label: translate( 'Client' ).toUpperCase(), | ||
getValue: () => '-', | ||
render: ( { item }: { item: Referral } ): ReactNode => ( | ||
<Button | ||
className="view-details-button client-email-button" | ||
data-client-id={ item.client.id } | ||
onClick={ () => openSitePreviewPane( item ) } | ||
borderless | ||
> | ||
{ item.client.email } | ||
</Button> | ||
<span className="a4a-referrals-client">{ item.client.email }</span> | ||
), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to make it look the same as before, so added this class to target it. Is this the proper naming structure? |
||
width: '100%', | ||
enableHiding: false, | ||
enableSorting: false, | ||
}, | ||
// Only show the actions column only on mobile | ||
...( ! dataViewsState.selectedItem | ||
? [ | ||
{ | ||
id: 'actions', | ||
label: '', | ||
render: ( { item }: { item: Referral } ) => ( | ||
<div> | ||
<Button | ||
className="view-details-button" | ||
onClick={ () => openSitePreviewPane( item ) } | ||
borderless | ||
> | ||
<Gridicon icon="chevron-right" /> | ||
</Button> | ||
</div> | ||
), | ||
enableHiding: false, | ||
enableSorting: false, | ||
}, | ||
] | ||
: [] ), | ||
] | ||
: [ | ||
{ | ||
id: 'client', | ||
label: translate( 'Client' ).toUpperCase(), | ||
getValue: () => '-', | ||
render: ( { item }: { item: Referral } ): ReactNode => ( | ||
<Button | ||
className="view-details-button" | ||
data-client-id={ item.client.id } | ||
onClick={ () => openSitePreviewPane( item ) } | ||
borderless | ||
> | ||
{ item.client.email } | ||
</Button> | ||
<span className="a4a-referrals-client">{ item.client.email }</span> | ||
), | ||
enableHiding: false, | ||
enableSorting: false, | ||
|
@@ -154,25 +116,8 @@ export default function ReferralList( { | |
enableHiding: false, | ||
enableSorting: false, | ||
}, | ||
{ | ||
id: 'actions', | ||
label: translate( 'Actions' ).toUpperCase(), | ||
render: ( { item }: { item: Referral } ) => ( | ||
<div> | ||
<Button | ||
className="view-details-button action-button" | ||
onClick={ () => openSitePreviewPane( item ) } | ||
borderless | ||
> | ||
<Gridicon icon="chevron-right" /> | ||
</Button> | ||
</div> | ||
), | ||
enableHiding: false, | ||
enableSorting: false, | ||
}, | ||
], | ||
[ dataViewsState.selectedItem, isDesktop, openSitePreviewPane, referralInvoices, translate ] | ||
[ dataViewsState.selectedItem, isDesktop, referralInvoices, translate ] | ||
); | ||
|
||
useEffect( () => { | ||
|
@@ -220,7 +165,25 @@ export default function ReferralList( { | |
}; | ||
}, [ dataViewsState ] ); | ||
|
||
const { data: items, paginationInfo } = useMemo( () => { | ||
const actions: Action< Referral >[] = useMemo( () => { | ||
if ( dataViewsState.type === 'table' ) { | ||
return [ | ||
{ | ||
id: 'view-details', | ||
label: translate( 'View Details' ), | ||
isPrimary: true, | ||
icon: chevronRight, | ||
callback( items ) { | ||
openSitePreviewPane( items[ 0 ] ); | ||
}, | ||
}, | ||
]; | ||
} | ||
|
||
return []; | ||
}, [ openSitePreviewPane, translate, dataViewsState.type ] ); | ||
|
||
const { data: items, paginationInfo: pagination } = useMemo( () => { | ||
return filterSortAndPaginate( referrals, dataViewsState, fields ); | ||
}, [ referrals, dataViewsState, fields ] ); | ||
|
||
|
@@ -236,12 +199,12 @@ export default function ReferralList( { | |
openSitePreviewPane( referral ); | ||
} | ||
}, | ||
pagination: paginationInfo, | ||
pagination, | ||
enableSearch: false, | ||
fields: fields, | ||
actions: [], | ||
setDataViewsState: setDataViewsState, | ||
dataViewsState: dataViewsState, | ||
fields, | ||
actions, | ||
setDataViewsState, | ||
dataViewsState, | ||
defaultLayouts: { table: {} }, | ||
} } | ||
/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
@import "@wordpress/base-styles/breakpoints"; | ||
@import "@wordpress/base-styles/mixins"; | ||
|
||
.theme-a8c-for-agencies .button.client-email-button { | ||
max-width: 215px; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
display: block; | ||
|
||
@include break-medium { | ||
max-width: unset; | ||
|
||
} | ||
.a4a-referrals-client { | ||
font-size: 0.875rem; | ||
color: var(--color-accent-80); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,6 @@ | |
color: var(--color-jetpack-50); | ||
} | ||
|
||
.dataviews-view-table__actions-column { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this style (and the other two in a8c-for-agencies & components/dataviews) is affecting any other screen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not as far as I've reviewed: A4A Sites, A4A Sites Import Modal, A4A Referrals Details, A4A Team, Dotcom Sites. Also, DataViews doesn't render the actions column if no actions are declared. Not sure why this rule was necessary. |
||
display: none; | ||
} | ||
|
||
thead { | ||
th.sites-dataviews__site { | ||
background: var(--color-light-backdrop); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -600,21 +600,8 @@ html { | |
padding-inline-start: 16px; | ||
} | ||
} | ||
|
||
th[data-field-id="actions"] { | ||
text-align: right; | ||
padding-inline-end: 16px; | ||
} | ||
} | ||
|
||
.dataviews-view-list li { | ||
cursor: pointer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already taken care of in dataviews. |
||
} | ||
|
||
.dataviews-view-list li .components-h-stack { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what this was for, but it was creating some issues with vertical alignment and spacing in the list view when actions were visible. |
||
display: block; | ||
width: 100%; | ||
} | ||
} | ||
|
||
.full-width-layout-with-table { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,10 +49,6 @@ | |
padding: 0; | ||
} | ||
} | ||
th[data-field-id="actions"] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DataViews no longer includes |
||
padding-inline-end: 16px; | ||
text-align: end; | ||
} | ||
@media (min-width: $break-large) { | ||
background: inherit; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This provides some styles (bolder, etc.), renders the field in a special place for list layout (comparing before/after, the field is rendered vertical aligned while before it was ). It also makes it not hidable in list layout and soon in table as well (see).