Skip to content
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

Sites dashboard - remove default filter and dummy column hack #94253

Merged
merged 3 commits into from
Sep 5, 2024
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
37 changes: 19 additions & 18 deletions client/hosting/sites/components/sites-dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { DOTCOM_OVERVIEW, FEATURE_TO_ROUTE_MAP } from './site-preview-pane/const
import DotcomPreviewPane from './site-preview-pane/dotcom-preview-pane';
import SitesDashboardHeader from './sites-dashboard-header';
import DotcomSitesDataViews, { useSiteStatusGroups } from './sites-dataviews';
import { getSitesPagination, addDummyDataViewPrefix } from './sites-dataviews/utils';
import { getSitesPagination } from './sites-dataviews/utils';
import type { SiteDetails } from '@automattic/data-stores';

// todo: we are using A4A styles until we extract them as common styles in the ItemsDashboard component
Expand All @@ -77,7 +77,6 @@ const siteSortingKeys = [
];

const DEFAULT_PER_PAGE = 50;
const DEFAULT_STATUS_GROUP = 'all';
const DEFAULT_SITE_TYPE = 'non-p2';

const SitesDashboard = ( {
Expand All @@ -88,7 +87,7 @@ const SitesDashboard = ( {
perPage = DEFAULT_PER_PAGE,
search,
newSiteID,
status = DEFAULT_STATUS_GROUP,
status,
siteType = DEFAULT_SITE_TYPE,
},
selectedSite,
Expand Down Expand Up @@ -160,13 +159,17 @@ const SitesDashboard = ( {
perPage,
search: search ?? '',
fields: getFieldsByBreakpoint( isDesktop ),
filters: [
{
field: addDummyDataViewPrefix( 'status' ),
operator: 'is',
value: siteStatusGroups.find( ( item ) => item.slug === status )?.value || 1,
},
],
...( status
? {
filters: [
{
field: 'status',
operator: 'is',
value: siteStatusGroups.find( ( item ) => item.slug === status )?.value || 1,
},
],
}
: {} ),
selectedItem: selectedSite,
type: selectedSite ? DATAVIEWS_LIST : DATAVIEWS_TABLE,
layout: {
Expand Down Expand Up @@ -260,17 +263,15 @@ const SitesDashboard = ( {

// Get the status group slug.
const statusSlug = useMemo( () => {
const statusFilter = dataViewsState.filters?.find(
( filter ) => filter.field === addDummyDataViewPrefix( 'status' )
);
const statusNumber = statusFilter?.value || 1;
return ( siteStatusGroups.find( ( status ) => status.value === statusNumber )?.slug ||
'all' ) as GroupableSiteLaunchStatuses;
const statusFilter = dataViewsState.filters?.find( ( filter ) => filter.field === 'status' );
const statusNumber = statusFilter?.value;
return siteStatusGroups.find( ( status ) => status.value === statusNumber )
?.slug as GroupableSiteLaunchStatuses;
}, [ dataViewsState.filters, siteStatusGroups ] );

// Filter sites list by status group.
const { currentStatusGroup } = useSitesListGrouping( allSites, {
status: statusSlug,
status: statusSlug || 'all',
showHidden: true,
} );

Expand Down Expand Up @@ -303,7 +304,7 @@ const SitesDashboard = ( {
useEffect( () => {
const queryParams = {
search: dataViewsState.search?.trim(),
status: statusSlug === DEFAULT_STATUS_GROUP ? undefined : statusSlug,
status: statusSlug,
page: dataViewsState.page && dataViewsState.page > 1 ? dataViewsState.page : undefined,
'per-page': dataViewsState.perPage === DEFAULT_PER_PAGE ? undefined : dataViewsState.perPage,
};
Expand Down
21 changes: 5 additions & 16 deletions client/hosting/sites/components/sites-dataviews/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import ActionsField from './dataviews-fields/actions-field';
import SiteField from './dataviews-fields/site-field';
import { SiteStats } from './sites-site-stats';
import { SiteStatus } from './sites-site-status';
import { addDummyDataViewPrefix } from './utils';
import type { SiteExcerptData } from '@automattic/sites';
import type { Field } from '@wordpress/dataviews';
import type {
Expand Down Expand Up @@ -126,11 +125,14 @@ const DotcomSitesDataViews = ( {
},
{
id: 'status',
// @ts-expect-error -- Need to fix the label type upstream in @wordpress/dataviews to support React elements.
label: <span>{ __( 'Status' ) }</span>,
label: __( 'Status' ),
render: ( { item }: { item: SiteExcerptData } ) => <SiteStatus site={ item } />,
enableHiding: false,
enableSorting: false,
elements: siteStatusGroups,
filterBy: {
operators: [ 'is' ],
},
},
{
id: 'last-publish',
Expand Down Expand Up @@ -170,19 +172,6 @@ const DotcomSitesDataViews = ( {
enableSorting: true,
getValue: () => null,
},
{
id: addDummyDataViewPrefix( 'status' ),
label: __( 'Status' ),
render: () => null,
elements: siteStatusGroups,
filterBy: {
operators: [ 'is' ],
isPrimary: true,
},
enableHiding: false,
enableSorting: false,
getValue: () => null,
},
],
[ __, openSitePreviewPane, userId, dataViewsState, setDataViewsState, siteStatusGroups ]
);
Expand Down
4 changes: 0 additions & 4 deletions client/hosting/sites/components/sites-dataviews/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ export function getSitesPagination(
return { totalItems, totalPages };
}

export function addDummyDataViewPrefix( dataView: string ) {
return `${ DUMMY_DATA_VIEW_PREFIX }${ dataView }`;
}

export function removeDummyDataViewPrefix( dataView: string ) {
return dataView.replace( DUMMY_DATA_VIEW_PREFIX, '' );
}
6 changes: 1 addition & 5 deletions client/hosting/sites/controller.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
DEFAULT_SITE_LAUNCH_STATUS_GROUP_VALUE,
siteLaunchStatusGroupValues,
} from '@automattic/sites';
import { siteLaunchStatusGroupValues } from '@automattic/sites';
import { Global, css } from '@emotion/react';
import { removeQueryArgs } from '@wordpress/url';
import AsyncLoad from 'calypso/components/async-load';
Expand Down Expand Up @@ -35,7 +32,6 @@ export function sanitizeQueryParameters( context: PageJSContext, next: () => voi
* in the route.
*/
if ( context.query.status === undefined ) {
context.query.status = DEFAULT_SITE_LAUNCH_STATUS_GROUP_VALUE;
return next();
}

Expand Down
Loading