Skip to content

Commit 4153e5f

Browse files
committed
Create utility functions.
1 parent c7441e7 commit 4153e5f

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

  • assets/js/modules/search-console/components/dashboard/SearchFunnelWidgetGA4/Overview
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* Utility functions for SearchFunnelWidgetGA4/Overview.
3+
*
4+
* Site Kit by Google, Copyright 2025 Google LLC
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* Internal dependencies
21+
*/
22+
import { calculateChange } from '../../../../../../util';
23+
24+
/**
25+
* Gets the cell props for responsive grid layout.
26+
* These props define the cell sizes for different screen breakpoints.
27+
*
28+
* @since n.e.x.t
29+
*
30+
* @param {boolean} showConversionsCTA Whether to show the conversions CTA.
31+
* @return {Object} Object with the cell props for the DataBlocks.
32+
*/
33+
export function getCellProps( showConversionsCTA ) {
34+
const quarterCellProps = {
35+
smSize: 2,
36+
mdSize: showConversionsCTA ? 4 : 2,
37+
lgSize: 3,
38+
};
39+
40+
const oneThirdCellProps = {
41+
smSize: 2,
42+
mdSize: 4,
43+
lgSize: 4,
44+
};
45+
46+
const halfCellProps = {
47+
smSize: 4,
48+
mdSize: 4,
49+
lgSize: 6,
50+
};
51+
52+
const threeQuartersCellProps = {
53+
smSize: 4,
54+
mdSize: 4,
55+
lgSize: 9,
56+
};
57+
58+
const fullCellProps = {
59+
smSize: 4,
60+
mdSize: 8,
61+
lgSize: 12,
62+
};
63+
64+
return {
65+
quarterCellProps,
66+
halfCellProps,
67+
oneThirdCellProps,
68+
threeQuartersCellProps,
69+
fullCellProps,
70+
};
71+
}
72+
73+
/**
74+
* Gets the datapoint and change for the given report and selected stat.
75+
*
76+
* @since n.e.x.t
77+
*
78+
* @param {Object} report The report object.
79+
* @param {number} selectedStat The selected stat.
80+
* @param {number} divider The divider.
81+
* @return {Object} Object with the datapoint and change.
82+
*/
83+
export function getDatapointAndChange( report, selectedStat, divider = 1 ) {
84+
return {
85+
datapoint:
86+
report?.totals?.[ 0 ]?.metricValues?.[ selectedStat ]?.value /
87+
divider,
88+
change: calculateChange(
89+
report?.totals?.[ 1 ]?.metricValues?.[ selectedStat ]?.value,
90+
report?.totals?.[ 0 ]?.metricValues?.[ selectedStat ]?.value
91+
),
92+
};
93+
}

0 commit comments

Comments
 (0)