Skip to content

Commit 908c6ff

Browse files
committed
Merge branch 'report-builder-prototype-i2' into report-builder-prototype
2 parents adcc719 + 2bd70cb commit 908c6ff

File tree

23 files changed

+1321
-176
lines changed

23 files changed

+1321
-176
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { Button } from '@wordpress/components';
2+
import { useTranslate } from 'i18n-calypso';
3+
import { useCallback, useState } from 'react';
4+
import { useDispatch } from 'calypso/state';
5+
import { recordTracksEvent } from 'calypso/state/analytics/actions';
6+
import SelectSiteModal from './modal';
7+
8+
export type SelectSiteButtonProps = {
9+
onSiteSelect: ( siteId: number, siteDomain: string ) => void;
10+
buttonLabel?: string;
11+
modalTitle?: string;
12+
modalSubtitle?: string;
13+
trackingEvent?: string;
14+
className?: string;
15+
};
16+
17+
const SelectSiteButton = ( {
18+
onSiteSelect,
19+
buttonLabel,
20+
modalTitle,
21+
modalSubtitle,
22+
trackingEvent = 'calypso_select_site_button_click',
23+
className,
24+
}: SelectSiteButtonProps ) => {
25+
const translate = useTranslate();
26+
const dispatch = useDispatch();
27+
const [ isOpen, setIsOpen ] = useState( false );
28+
29+
const handleOpenModal = useCallback( () => {
30+
setIsOpen( true );
31+
dispatch( recordTracksEvent( trackingEvent ) );
32+
}, [ dispatch, trackingEvent ] );
33+
34+
return (
35+
<>
36+
<Button
37+
__next40pxDefaultSize
38+
variant="secondary"
39+
onClick={ handleOpenModal }
40+
className={ className }
41+
>
42+
{ buttonLabel || translate( 'Select a site' ) }
43+
</Button>
44+
45+
{ isOpen && (
46+
<SelectSiteModal
47+
onClose={ () => setIsOpen( false ) }
48+
onSiteSelect={ onSiteSelect }
49+
title={ modalTitle }
50+
subtitle={ modalSubtitle }
51+
/>
52+
) }
53+
</>
54+
);
55+
};
56+
57+
export default SelectSiteButton;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import './style.scss';
2+
3+
export { default } from './button';
4+
export type { SelectSiteButtonProps } from './button';
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { Button } from '@wordpress/components';
2+
import { useTranslate } from 'i18n-calypso';
3+
import { useState } from 'react';
4+
import A4AModal from 'calypso/a8c-for-agencies/components/a4a-modal';
5+
import { A4A_SITES_LINK } from 'calypso/a8c-for-agencies/components/sidebar-menu/lib/constants';
6+
import { useDispatch } from 'calypso/state';
7+
import { recordTracksEvent } from 'calypso/state/analytics/actions';
8+
import SelectSiteTable, { type SiteItem } from './site-table';
9+
10+
type SelectSiteModalProps = {
11+
onClose: () => void;
12+
onSiteSelect: ( siteId: number, siteDomain: string ) => void;
13+
title?: string;
14+
subtitle?: string;
15+
};
16+
17+
const SelectSiteModal = ( { onClose, onSiteSelect, title, subtitle }: SelectSiteModalProps ) => {
18+
const translate = useTranslate();
19+
const dispatch = useDispatch();
20+
21+
const [ selectedSite, setSelectedSite ] = useState< SiteItem | null >( null );
22+
23+
const handleSelectSite = () => {
24+
if ( selectedSite ) {
25+
onSiteSelect( selectedSite.id, selectedSite.site );
26+
onClose();
27+
}
28+
};
29+
30+
return (
31+
<A4AModal
32+
title={ title || translate( 'Select a site' ) }
33+
subtile={
34+
subtitle ||
35+
translate(
36+
"If you don't see the site in the list, connect it first via the {{a}}Sites Dashboard{{/a}}.",
37+
{
38+
components: {
39+
a: (
40+
<a
41+
href={ A4A_SITES_LINK }
42+
onClick={ () =>
43+
dispatch(
44+
recordTracksEvent( 'calypso_select_site_modal_sites_dashboard_click' )
45+
)
46+
}
47+
/>
48+
),
49+
},
50+
}
51+
)
52+
}
53+
onClose={ onClose }
54+
extraActions={
55+
<Button variant="primary" onClick={ handleSelectSite } disabled={ ! selectedSite }>
56+
{ translate( 'Select site' ) }
57+
</Button>
58+
}
59+
>
60+
<SelectSiteTable setSelectedSite={ setSelectedSite } selectedSite={ selectedSite } />
61+
</A4AModal>
62+
);
63+
};
64+
65+
export default SelectSiteModal;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { filterSortAndPaginate } from '@wordpress/dataviews';
2+
import { useTranslate } from 'i18n-calypso';
3+
import { useCallback, useMemo, useState } from 'react';
4+
import A4ATablePlaceholder from 'calypso/a8c-for-agencies/components/a4a-table-placeholder';
5+
import { initialDataViewsState } from 'calypso/a8c-for-agencies/components/items-dashboard/constants';
6+
import ItemsDataViews from 'calypso/a8c-for-agencies/components/items-dashboard/items-dataviews';
7+
import { DataViewsState } from 'calypso/a8c-for-agencies/components/items-dashboard/items-dataviews/interfaces';
8+
import {
9+
useFetchAllManagedSites,
10+
type SiteItem,
11+
} from 'calypso/a8c-for-agencies/sections/migrations/hooks/use-fetch-all-managed-sites';
12+
import FormRadio from 'calypso/components/forms/form-radio';
13+
import { useDispatch } from 'calypso/state';
14+
import { recordTracksEvent } from 'calypso/state/analytics/actions';
15+
16+
type SelectSiteTableProps = {
17+
selectedSite: SiteItem | null;
18+
setSelectedSite: ( site: SiteItem | null ) => void;
19+
};
20+
21+
const SelectSiteTable = ( { selectedSite, setSelectedSite }: SelectSiteTableProps ) => {
22+
const translate = useTranslate();
23+
const dispatch = useDispatch();
24+
25+
const { items, isLoading } = useFetchAllManagedSites();
26+
27+
const [ dataViewsState, setDataViewsState ] = useState< DataViewsState >( {
28+
...initialDataViewsState,
29+
fields: [ 'site' ],
30+
} );
31+
32+
const onSelectSite = useCallback(
33+
( item: SiteItem ) => {
34+
setSelectedSite( item );
35+
dispatch( recordTracksEvent( 'calypso_select_site_table_select_site_click' ) );
36+
},
37+
[ dispatch, setSelectedSite ]
38+
);
39+
40+
const fields = useMemo( () => {
41+
const siteColumn = {
42+
id: 'site',
43+
label: translate( 'Site' ),
44+
getValue: ( { item }: { item: SiteItem } ) => item.site,
45+
render: ( { item }: { item: SiteItem } ) => (
46+
<div>
47+
<FormRadio
48+
htmlFor={ `site-${ item.id }` }
49+
id={ `site-${ item.id }` }
50+
checked={ selectedSite?.id === item.id }
51+
onChange={ () => onSelectSite( item ) }
52+
label={ item.site }
53+
/>
54+
</div>
55+
),
56+
enableGlobalSearch: true,
57+
enableHiding: false,
58+
enableSorting: false,
59+
};
60+
61+
return [ siteColumn ];
62+
}, [ onSelectSite, selectedSite?.id, translate ] );
63+
64+
const { data: allSites, paginationInfo } = useMemo( () => {
65+
return filterSortAndPaginate( items as SiteItem[], dataViewsState, fields );
66+
}, [ items, dataViewsState, fields ] );
67+
68+
return (
69+
<div className="redesigned-a8c-table show-overflow-overlay search-enabled">
70+
{ isLoading ? (
71+
<A4ATablePlaceholder />
72+
) : (
73+
<ItemsDataViews
74+
data={ {
75+
items: allSites,
76+
fields,
77+
getItemId: ( item ) => `${ item.id }`,
78+
pagination: paginationInfo,
79+
enableSearch: true,
80+
actions: [],
81+
dataViewsState: dataViewsState,
82+
setDataViewsState: setDataViewsState,
83+
defaultLayouts: { table: {} },
84+
} }
85+
/>
86+
) }
87+
</div>
88+
);
89+
};
90+
91+
export default SelectSiteTable;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.redesigned-a8c-table {
2+
&.show-overflow-overlay {
3+
overflow: visible;
4+
}
5+
6+
&.search-enabled {
7+
.dataviews-module__table-header {
8+
padding-top: 16px;
9+
}
10+
}
11+
}

client/a8c-for-agencies/components/sidebar-menu/lib/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export const A4A_WOOPAYMENTS_OVERVIEW_LINK = `${ A4A_WOOPAYMENTS_LINK }/overview
5757
export const A4A_REPORTS_LINK = '/reports';
5858
export const A4A_REPORTS_OVERVIEW_LINK = `${ A4A_REPORTS_LINK }/overview`;
5959
export const A4A_REPORTS_DASHBOARD_LINK = `${ A4A_REPORTS_LINK }/dashboard`;
60+
export const A4A_REPORTS_BUILD_LINK = `${ A4A_REPORTS_LINK }/build`;
61+
export const A4A_REPORTS_EXAMPLE_LINK = `${ A4A_REPORTS_LINK }/example`;
6062

6163
// Client
6264
export const A4A_CLIENT_LANDING_LINK = '/client/landing';

0 commit comments

Comments
 (0)