-
Notifications
You must be signed in to change notification settings - Fork 293
/
AudienceSegmentationErrorWidget.js
152 lines (142 loc) · 4.47 KB
/
AudienceSegmentationErrorWidget.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
* AudienceSegmentationErrorWidget component.
*
* Site Kit by Google, Copyright 2024 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 { castArray } from 'lodash';
import PropTypes from 'prop-types';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useEffect } from '@wordpress/element';
/**
* Internal dependencies
*/
import whenActive from '../../../../../util/when-active';
import { useDispatch } from 'googlesitekit-data';
import { Cell, Grid, Row } from '../../../../../material-components';
import {
BREAKPOINT_SMALL,
BREAKPOINT_TABLET,
useBreakpoint,
} from '../../../../../hooks/useBreakpoint';
import AudienceSegmentationErrorSVG from '../../../../../../svg/graphics/audience-segmentation-error-full-width.svg';
import { isInsufficientPermissionsError } from '../../../../../util/errors';
import ReportErrorActions from '../../../../../components/ReportErrorActions';
import GetHelpLink from './GetHelpLink';
import { CORE_UI } from '../../../../../googlesitekit/datastore/ui/constants';
import { AUDIENCE_INFO_NOTICE_HIDE_UI } from './InfoNoticeWidget/constants';
function AudienceSegmentationErrorWidget( { Widget, errors, onRetry } ) {
const breakpoint = useBreakpoint();
const isMobileBreakpoint = breakpoint === BREAKPOINT_SMALL;
const isTabletBreakpoint = breakpoint === BREAKPOINT_TABLET;
const { setValue } = useDispatch( CORE_UI );
const hasInsufficientPermissionsError = errors
? castArray( errors ).some( isInsufficientPermissionsError )
: false;
const handleRetry = () => {
setValue( AUDIENCE_INFO_NOTICE_HIDE_UI, false );
onRetry?.();
};
useEffect( () => {
// Set UI key to hide the info notice.
setValue( AUDIENCE_INFO_NOTICE_HIDE_UI, true );
}, [ setValue ] );
return (
<Widget
noPadding
className="googlesitekit-audience-segmentation-error-widget"
>
<Grid
collapsed
className="googlesitekit-audience-segmentation-error__widget-primary-cell"
>
<Row>
<Cell smSize={ 6 } mdSize={ 8 } lgSize={ 7 }>
<h3 className="googlesitekit-publisher-win__title">
{ hasInsufficientPermissionsError
? __(
'Insufficient permissions',
'google-site-kit'
)
: __(
'Your visitor groups data loading failed',
'google-site-kit'
) }
</h3>
<div className="googlesitekit-widget-audience-segmentation-error__actions">
<ReportErrorActions
moduleSlug="analytics-4"
error={ errors }
GetHelpLink={
hasInsufficientPermissionsError
? GetHelpLink
: undefined
}
hideGetHelpLink={
! hasInsufficientPermissionsError
}
buttonVariant="danger"
getHelpClassName="googlesitekit-error-retry-text"
onRetry={ handleRetry }
overrideShowRetryButton={
typeof onRetry === 'function'
}
/>
</div>
</Cell>
{ ! isMobileBreakpoint && ! isTabletBreakpoint && (
<Cell
className="googlesitekit-widget-audience-segmentation-error__svg-wrapper"
smSize={ 6 }
mdSize={ 3 }
lgSize={ 5 }
>
<AudienceSegmentationErrorSVG width="233px" />
</Cell>
) }
{ isTabletBreakpoint && (
<Cell
className="googlesitekit-widget-audience-segmentation-error__svg-wrapper"
mdSize={ 8 }
>
<AudienceSegmentationErrorSVG width="233px" />
</Cell>
) }
{ isMobileBreakpoint && (
<Cell
className="googlesitekit-widget-audience-segmentation-error__svg-wrapper"
smSize={ 8 }
>
<AudienceSegmentationErrorSVG width="233px" />
</Cell>
) }
</Row>
</Grid>
</Widget>
);
}
AudienceSegmentationErrorWidget.propTypes = {
Widget: PropTypes.elementType.isRequired,
errors: PropTypes.arrayOf( PropTypes.object ).isRequired,
onRetry: PropTypes.func,
};
export default whenActive( { moduleName: 'analytics-4' } )(
AudienceSegmentationErrorWidget
);