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

Custom dimension tile wrapper #7680

Merged
merged 50 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6d229ff
Add necessary datastore selectors.
nfmohit Oct 9, 2023
f7ac9f6
Extend `CTA` to allow a new `headerContent` prop.
nfmohit Oct 9, 2023
1c65e51
Create new `InfoTooltip` component.
nfmohit Oct 9, 2023
5a48840
Update `MetricTileError`.
nfmohit Oct 9, 2023
a6268e2
Use `MetricTileWrapper`.
nfmohit Oct 9, 2023
46d8300
Update snapshot.
nfmohit Oct 9, 2023
806db7a
Update `syncAvailableCustomDimensions` action.
nfmohit Oct 10, 2023
f1014ea
Error handling for unavailable custom dimension.
nfmohit Oct 10, 2023
cb6abfd
Update `MetricTileError` location.
nfmohit Oct 10, 2023
825d026
Do not show custom dimension errors when loading.
nfmohit Oct 10, 2023
343b6c4
Fix typo.
nfmohit Oct 10, 2023
87ffac6
Add tile skeletons.
nfmohit Oct 10, 2023
c4be532
Add `receiveCustomDimensionCreationError` action.
nfmohit Oct 12, 2023
7e16c94
Fix styling issues.
nfmohit Oct 12, 2023
62a3750
Add Storybook stories.
nfmohit Oct 12, 2023
b1805aa
Make stories concise.
nfmohit Oct 12, 2023
88c49aa
Rename action & selector.
nfmohit Oct 12, 2023
b722d80
Update datastore test cases.
nfmohit Oct 12, 2023
b3dfa19
Update Storybook story.
nfmohit Oct 12, 2023
f1fb97c
Add test cases for `MetricTileWrapper`.
nfmohit Oct 12, 2023
6bbbb70
Track custom dimensions creation state.
nfmohit Oct 12, 2023
42fc1f4
Update custom dimension creation initiation.
nfmohit Oct 12, 2023
10e4262
Merge branch 'develop' into enhancement/#7601-custom-dimension-wrapper.
nfmohit Oct 12, 2023
b5a6237
Update VRT references.
nfmohit Oct 12, 2023
01a8307
Create `CustomDimensionsWrapper`.
nfmohit Oct 13, 2023
157bd14
Update translation strings.
nfmohit Oct 13, 2023
3d19e6f
Fix failing tests.
nfmohit Oct 13, 2023
392943b
Merge branch 'develop' into enhancement/#7601-custom-dimension-wrapper.
nfmohit Oct 16, 2023
c9808ef
Render `InfoTooltip` unconditionally in `MetricTileHeader`.
nfmohit Oct 16, 2023
faa8659
Replace `MetricTileLoading` with `MetricTileWrapper`.
nfmohit Oct 16, 2023
ee220a5
Update datapoint to work without parameter.
nfmohit Oct 16, 2023
1bd7c19
Create HOC for custom dimensions.
nfmohit Oct 16, 2023
4d9338d
Address CR feedback.
nfmohit Oct 16, 2023
481dfa1
Fix failing test.
nfmohit Oct 16, 2023
8b667c7
Update VRT references.
nfmohit Oct 16, 2023
c7f843b
Render `InfoTooltip` unconditionally in `MetricTileError`.
nfmohit Oct 17, 2023
0346a2c
Correctly order props.
nfmohit Oct 17, 2023
fc8ee31
Remove feature flag check from `withCustomDimensions`.
nfmohit Oct 17, 2023
3788886
Use state for assertion instead of selector.
nfmohit Oct 17, 2023
e5a5851
Create test registry in `beforeEach`.
nfmohit Oct 17, 2023
818329e
Merge branch 'develop' into enhancement/#7601-custom-dimension-wrapper.
nfmohit Oct 17, 2023
ae363c9
Fix failing tests.
nfmohit Oct 17, 2023
eff625a
Render `InfoTooltip` in `MetricTileError` conditionally.
nfmohit Oct 17, 2023
0eabcf5
Remove unnecessary VRT scenarios.
nfmohit Oct 17, 2023
1e5f159
Replace `receiveCreateCustomDimensionError` action with `provideCusto…
nfmohit Oct 17, 2023
443a91d
Remove `syncAvailableCustomDimensions`.
nfmohit Oct 17, 2023
20be742
Address CR feedback.
nfmohit Oct 17, 2023
498c466
Move test-utils.js file to the utils folder and rename it to be custo…
eugene-manuilov Oct 17, 2023
b2cfa63
Update report options to allow passing a function.
eugene-manuilov Oct 17, 2023
6553776
Fix broken imports.
eugene-manuilov Oct 17, 2023
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
Expand Up @@ -30,7 +30,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import Link from '../../Link';
import Link from '../Link';

export default function GetHelpLink( { linkURL } ) {
return createInterpolateElement(
Expand Down
53 changes: 53 additions & 0 deletions assets/js/components/KeyMetrics/InfoTooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* InfoTooltip component.
*
* Site Kit by Google, Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
import PropTypes from 'prop-types';

/**
* Internal dependencies
*/
import { Tooltip } from 'googlesitekit-components';
import InfoIcon from '../../../svg/icons/info-green.svg';

export default function InfoTooltip( { title } ) {
if ( ! title ) {
return null;
}

return (
<Tooltip
tooltipClassName="googlesitekit-km-widget-tile-title__tooltip"
title={ title }
placement="top"
enterTouchDelay={ 0 }
leaveTouchDelay={ 5000 }
interactive
>
<span>
<InfoIcon width="16" height="16" />
</span>
</Tooltip>
);
}

InfoTooltip.propTypes = {
title: PropTypes.string,
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,27 @@
* limitations under the License.
*/

/**
* External dependencies
*/
import { castArray } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import CTA from '../../notifications/CTA';
import ReportErrorActions from '../../ReportErrorActions';
import GetHelpLink from './GetHelpLink';
import { isInsufficientPermissionsError } from '../../../util/errors';
import CTA from '../notifications/CTA';
import InfoTooltip from './InfoTooltip';

export default function MetricTileError( props ) {
const { error, headerText, moduleSlug } = props;
const hasInsufficientPermissionsError = castArray( error ).some(
isInsufficientPermissionsError
);
const { children, headerText, infoTooltip, title } = props;

return (
<div className="googlesitekit-km-widget-tile--error">
<CTA
title={
hasInsufficientPermissionsError
? __( 'Insufficient permissions', 'google-site-kit' )
: __( 'Data loading failed', 'google-site-kit' )
}
title={ title }
headerText={ headerText }
headerContent={
infoTooltip && <InfoTooltip title={ infoTooltip } />
eugene-manuilov marked this conversation as resolved.
Show resolved Hide resolved
}
description=""
error
>
<ReportErrorActions
moduleSlug={ moduleSlug }
error={ error }
GetHelpLink={
hasInsufficientPermissionsError
? GetHelpLink
: undefined
}
/>
{ children }
</CTA>
</div>
);
Expand Down
18 changes: 2 additions & 16 deletions assets/js/components/KeyMetrics/MetricTileHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,13 @@ import PropTypes from 'prop-types';
/**
* Internal dependencies
*/
import { Tooltip } from 'googlesitekit-components';
import InfoIcon from '../../../svg/icons/info-green.svg';
import InfoTooltip from './InfoTooltip';

export default function MetricTileHeader( { title, infoTooltip } ) {
return (
<div className="googlesitekit-km-widget-tile__title-container">
<h3 className="googlesitekit-km-widget-tile__title">{ title }</h3>
{ infoTooltip && (
<Tooltip
tooltipClassName="googlesitekit-km-widget-tile-title__tooltip"
title={ infoTooltip }
placement="top"
enterTouchDelay={ 0 }
leaveTouchDelay={ 5000 }
interactive
>
<span>
<InfoIcon width="16" height="16" />
</span>
</Tooltip>
) }
<InfoTooltip title={ infoTooltip } />
</div>
);
}
Expand Down
90 changes: 23 additions & 67 deletions assets/js/components/KeyMetrics/MetricTileNumeric.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,82 +21,44 @@
*/
import PropTypes from 'prop-types';

/**
* WordPress dependencies
*/
import { Fragment } from '@wordpress/element';

/**
* Internal dependencies
*/
import { numFmt, expandNumFmtOptions } from '../../util';
import ChangeBadge from '../ChangeBadge';
import MetricTileError from './MetricTileError';
import MetricTileLoader from './MetricTileLoader';
import MetricTileHeader from './MetricTileHeader';

export default function MetricTileNumeric( props ) {
const {
Widget,
loading,
title,
metricValue,
metricValueFormat,
subText,
previousValue,
currentValue,
error,
moduleSlug,
infoTooltip,
} = props;
import MetricTileWrapper from './MetricTileWrapper';

export default function MetricTileNumeric( {
metricValue,
metricValueFormat,
subText,
previousValue,
currentValue,
...props
} ) {
const formatOptions = expandNumFmtOptions( metricValueFormat );

if ( error ) {
return (
<MetricTileError
moduleSlug={ moduleSlug }
error={ error }
headerText={ title }
/>
);
}

return (
<Widget noPadding>
<div className="googlesitekit-km-widget-tile googlesitekit-km-widget-tile--numeric">
<MetricTileHeader title={ title } infoTooltip={ infoTooltip } />
<div className="googlesitekit-km-widget-tile__body">
{ loading && <MetricTileLoader /> }
{ ! loading && (
<Fragment>
<div className="googlesitekit-km-widget-tile__metric-change-container">
<div className="googlesitekit-km-widget-tile__metric">
{ numFmt( metricValue, formatOptions ) }
</div>
<ChangeBadge
previousValue={ previousValue }
currentValue={ currentValue }
isAbsolute={
formatOptions?.style === 'percent'
}
/>
</div>
<p className="googlesitekit-km-widget-tile__subtext">
{ subText }
</p>
</Fragment>
) }
<MetricTileWrapper
className="googlesitekit-km-widget-tile--numeric"
{ ...props }
>
<div className="googlesitekit-km-widget-tile__metric-change-container">
<div className="googlesitekit-km-widget-tile__metric">
{ numFmt( metricValue, formatOptions ) }
</div>
<ChangeBadge
previousValue={ previousValue }
currentValue={ currentValue }
isAbsolute={ formatOptions?.style === 'percent' }
/>
</div>
</Widget>
<p className="googlesitekit-km-widget-tile__subtext">{ subText }</p>
</MetricTileWrapper>
);
}

MetricTileNumeric.propTypes = {
Widget: PropTypes.elementType.isRequired,
loading: PropTypes.bool,
title: PropTypes.string,
metricValue: PropTypes.oneOfType( [ PropTypes.string, PropTypes.number ] ),
metricValueFormat: PropTypes.oneOfType( [
PropTypes.string,
Expand All @@ -105,10 +67,4 @@ MetricTileNumeric.propTypes = {
subtext: PropTypes.string,
previousValue: PropTypes.number,
currentValue: PropTypes.number,
error: PropTypes.oneOfType( [
PropTypes.arrayOf( PropTypes.object ),
PropTypes.object,
] ),
moduleSlug: PropTypes.string.isRequired,
infoTooltip: PropTypes.oneOfType( [ PropTypes.string, PropTypes.element ] ),
};
63 changes: 15 additions & 48 deletions assets/js/components/KeyMetrics/MetricTileTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,15 @@ import classnames from 'classnames';
/**
* Internal dependencies
*/
import MetricTileError from './MetricTileError';
import MetricTileLoader from './MetricTileLoader';
import MetricTileHeader from './MetricTileHeader';

export default function MetricTileTable( props ) {
const {
Widget,
loading,
title,
rows = [],
columns = [],
limit,
infoTooltip,
ZeroState,
error,
moduleSlug,
} = props;

if ( error ) {
return (
<MetricTileError
moduleSlug={ moduleSlug }
error={ error }
headerText={ title }
/>
);
}
import MetricTileWrapper from './MetricTileWrapper';

export default function MetricTileTable( {
rows = [],
columns = [],
limit,
ZeroState,
...props
} ) {
let tileBody = null;

if ( rows?.length > 0 ) {
Expand Down Expand Up @@ -98,34 +79,20 @@ export default function MetricTileTable( props ) {
}

return (
<Widget noPadding>
<div className="googlesitekit-km-widget-tile googlesitekit-km-widget-tile--table">
<MetricTileHeader title={ title } infoTooltip={ infoTooltip } />
<div className="googlesitekit-km-widget-tile__body">
{ loading && <MetricTileLoader /> }
{ ! loading && (
<div className="googlesitekit-km-widget-tile__table">
{ tileBody }
</div>
) }
</div>
<MetricTileWrapper
className="googlesitekit-km-widget-tile--table"
{ ...props }
>
<div className="googlesitekit-km-widget-tile__table">
{ tileBody }
</div>
</Widget>
</MetricTileWrapper>
);
}

MetricTileTable.propTypes = {
Widget: PropTypes.elementType.isRequired,
loading: PropTypes.bool,
title: PropTypes.string,
rows: PropTypes.array,
columns: PropTypes.array,
limit: PropTypes.number,
infoTooltip: PropTypes.oneOfType( [ PropTypes.string, PropTypes.element ] ),
ZeroState: PropTypes.elementType,
error: PropTypes.oneOfType( [
PropTypes.arrayOf( PropTypes.object ),
PropTypes.object,
] ),
moduleSlug: PropTypes.string.isRequired,
};
Loading
Loading