Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 32 additions & 10 deletions assets/js/components/email-reporting/FrequencySelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
} from '@/js/googlesitekit/datastore/user/constants';
import { Fragment } from 'react';
import Typography from '@/js/components/Typography';
import Tick from '@/svg/icons/tick.svg';

export default function FrequencySelector( { isUserSubscribed } ) {
const DAY_NAMES = useMemo(
Expand Down Expand Up @@ -118,6 +117,12 @@ export default function FrequencySelector( { isUserSubscribed } ) {
}
}

// Determine which column the saved frequency is in (0, 1, or 2).
const savedFrequencyIndex =
EMAIL_REPORT_FREQUENCIES.indexOf( savedFrequency );
const showCurrentSubscription =
isUserSubscribed && savedFrequencyIndex !== -1;

return (
<Fragment>
<Typography
Expand All @@ -128,6 +133,32 @@ export default function FrequencySelector( { isUserSubscribed } ) {
>
{ __( 'Frequency', 'google-site-kit' ) }
</Typography>
{ showCurrentSubscription && (
<div className="googlesitekit-frequency-selector__badge-row">
{ EMAIL_REPORT_FREQUENCIES.map(
( reportFrequency, index ) => (
<div
key={ reportFrequency }
className="googlesitekit-frequency-selector__badge-cell"
>
{ index === savedFrequencyIndex && (
<Typography
className="googlesitekit-frequency-selector__current-subscription"
type="body"
size="small"
as="div"
>
{ __(
'Current subscription',
'google-site-kit'
) }
</Typography>
) }
</div>
)
) }
</div>
) }
<div
className="googlesitekit-frequency-selector"
role="radiogroup"
Expand Down Expand Up @@ -167,15 +198,6 @@ export default function FrequencySelector( { isUserSubscribed } ) {
>
{ label }
</Typography>
{ savedFrequency === reportFrequency &&
isUserSubscribed && (
<div className="googlesitekit-frequency-selector__saved-indicator">
<Tick
className="googlesitekit-frequency-selector__label-tick"
aria-hidden="true"
/>
</div>
) }
</div>

<Typography
Expand Down
12 changes: 0 additions & 12 deletions assets/js/components/email-reporting/FrequencySelector.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,3 @@ PreviouslySavedFrequency.args = {
},
};
PreviouslySavedFrequency.scenario = {};

export const PreviouslySavedFrequencySameAsCurrent = Template.bind( {} );
PreviouslySavedFrequencySameAsCurrent.args = {
isUserSubscribed: true,
savedSettings: {
frequency: 'monthly',
},
clientSettings: {
frequency: 'monthly',
},
};
PreviouslySavedFrequencySameAsCurrent.scenario = {};
80 changes: 37 additions & 43 deletions assets/js/components/email-reporting/FrequencySelector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,79 +108,73 @@ describe( 'FrequencySelector', () => {
expect( containerElement ).toMatchSnapshot();
} );

it( 'Previously saved frequency (saved monthly, current weekly) indicates saved on monthly only and matches snapshot', () => {
it( 'Previously saved frequency (saved monthly, current weekly) shows current subscription pill above monthly card and matches snapshot', () => {
setupRegistry( registry, {
startOfWeek: 1,
frequency: 'weekly',
savedFrequency: 'monthly',
} );

const { containerElement, getByText } = renderSelector( registry, {
isUserSubscribed: true,
} );

const indicators = containerElement.querySelectorAll(
'.googlesitekit-frequency-selector__saved-indicator'
const { container, containerElement, getByText } = renderSelector(
registry,
{
isUserSubscribed: true,
}
);
expect( indicators.length ).toBe( 1 );

const monthlyLabel = getByText( 'Monthly' );
const monthlyCard = monthlyLabel.closest(
'.googlesitekit-frequency-selector__card'
// Check that there's exactly one current subscription pill.
const pills = container.querySelectorAll(
'.googlesitekit-frequency-selector__current-subscription'
);
expect( monthlyCard ).toBeTruthy();
expect(
monthlyCard.querySelector(
'.googlesitekit-frequency-selector__saved-indicator'
)
).toBeInTheDocument();
expect( pills.length ).toBe( 1 );

const weeklyLabel = getByText( 'Weekly' );
const weeklyCard = weeklyLabel.closest(
'.googlesitekit-frequency-selector__card'
// Check that the badge row exists and contains the pill.
const badgeRow = container.querySelector(
'.googlesitekit-frequency-selector__badge-row'
);
expect( badgeRow ).toBeInTheDocument();
expect(
weeklyCard.querySelector(
'.googlesitekit-frequency-selector__saved-indicator'
badgeRow.querySelector(
'.googlesitekit-frequency-selector__current-subscription'
)
).not.toBeInTheDocument();
).toBeInTheDocument();

const quarterlyLabel = getByText( 'Quarterly' );
const quarterlyCard = quarterlyLabel.closest(
'.googlesitekit-frequency-selector__card'
);
expect(
quarterlyCard.querySelector(
'.googlesitekit-frequency-selector__saved-indicator'
)
).not.toBeInTheDocument();
// Check that the pill text is correct.
expect( getByText( 'Current subscription' ) ).toBeInTheDocument();

expect( containerElement ).toMatchSnapshot();
} );

it( 'Previously saved frequency (same as the current frequency) shows saved indicator on selected card and matches snapshot', () => {
it( 'Previously saved frequency (same as the current frequency) shows current subscription pill above selected card and matches snapshot', () => {
setupRegistry( registry, {
startOfWeek: 1,
frequency: 'monthly',
savedFrequency: 'monthly',
} );

const { containerElement, getByText } = renderSelector( registry, {
isUserSubscribed: true,
} );

const monthlyLabel = getByText( 'Monthly' );
const monthlyCard = monthlyLabel.closest(
'.googlesitekit-frequency-selector__card'
const { container, containerElement, getByText } = renderSelector(
registry,
{
isUserSubscribed: true,
}
);
expect( monthlyCard ).toBeTruthy();

// Check that there's exactly one current subscription pill in the badge row.
const badgeRow = container.querySelector(
'.googlesitekit-frequency-selector__badge-row'
);
expect( badgeRow ).toBeInTheDocument();
expect(
monthlyCard.querySelector(
'.googlesitekit-frequency-selector__saved-indicator'
badgeRow.querySelector(
'.googlesitekit-frequency-selector__current-subscription'
)
).toBeInTheDocument();

// Check that the monthly card is selected.
const monthlyLabel = getByText( 'Monthly' );
const monthlyCard = monthlyLabel.closest(
'.googlesitekit-frequency-selector__card'
);
expect(
monthlyCard.classList.contains(
'googlesitekit-frequency-selector__card--selected'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ exports[`FrequencySelector Story states (visual + DOM) Monthly selected renders
</div>
`;

exports[`FrequencySelector Story states (visual + DOM) Previously saved frequency (same as the current frequency) shows saved indicator on selected card and matches snapshot 1`] = `
exports[`FrequencySelector Story states (visual + DOM) Previously saved frequency (same as the current frequency) shows current subscription pill above selected card and matches snapshot 1`] = `
<div
aria-label="Frequency"
class="googlesitekit-frequency-selector"
Expand Down Expand Up @@ -133,11 +133,6 @@ exports[`FrequencySelector Story states (visual + DOM) Previously saved frequenc
>
Monthly
</div>
<div
class="googlesitekit-frequency-selector__saved-indicator"
>
<svg />
</div>
</div>
<div
class="googlesitekit-typography googlesitekit-frequency-selector__period googlesitekit-typography--body googlesitekit-typography--small"
Expand Down Expand Up @@ -179,7 +174,7 @@ exports[`FrequencySelector Story states (visual + DOM) Previously saved frequenc
</div>
`;

exports[`FrequencySelector Story states (visual + DOM) Previously saved frequency (saved monthly, current weekly) indicates saved on monthly only and matches snapshot 1`] = `
exports[`FrequencySelector Story states (visual + DOM) Previously saved frequency (saved monthly, current weekly) shows current subscription pill above monthly card and matches snapshot 1`] = `
<div
aria-label="Frequency"
class="googlesitekit-frequency-selector"
Expand Down Expand Up @@ -225,11 +220,6 @@ exports[`FrequencySelector Story states (visual + DOM) Previously saved frequenc
>
Monthly
</div>
<div
class="googlesitekit-frequency-selector__saved-indicator"
>
<svg />
</div>
</div>
<div
class="googlesitekit-typography googlesitekit-frequency-selector__period googlesitekit-typography--body googlesitekit-typography--small"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ h3.googlesitekit-frequency-selector-title {
color: $c-surfaces-on-surface-variant;
}

.googlesitekit-frequency-selector__badge-row {
display: grid;
gap: $grid-gap-phone;
grid-template-columns: repeat(3, minmax(0, 1fr));
margin-bottom: 8px;
}

.googlesitekit-frequency-selector__badge-cell {
display: flex;
justify-content: center;
}

.googlesitekit-frequency-selector__current-subscription {
background-color: $c-blue-b-50;
border-radius: 4px;
color: $c-blue-b-500;
padding: 4px 8px;
text-align: center;
width: 100%;
}

.googlesitekit-frequency-selector {
display: grid;
gap: $grid-gap-phone;
Expand All @@ -44,19 +65,6 @@ h3.googlesitekit-frequency-selector-title {
display: flex;
justify-content: space-between;
margin-bottom: 4px;

.googlesitekit-frequency-selector__saved-indicator {
background-color: $c-neutral-n-10;
border-radius: 50%;
height: 24px;
width: 24px;
svg {
color: $c-neutral-n-300;
height: 14px;
margin: 5px 0 0 5px;
width: 14px;
}
}
}

.googlesitekit-frequency-selector__period {
Expand All @@ -74,16 +82,6 @@ h3.googlesitekit-frequency-selector-title {
.googlesitekit-frequency-selector__card--selected {
background: $c-content-primary-container;

.googlesitekit-frequency-selector__label-row {
.googlesitekit-frequency-selector__saved-indicator {
background-color: $c-site-kit-sk-50;

svg {
color: $c-site-kit-sk-400;
}
}
}

.googlesitekit-frequency-selector__period {
border-color: $c-site-kit-sk-200;
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.