Skip to content

Commit dfcfdd4

Browse files
authored
My Jetpack: Export the product status label and tone (#53917)
1 parent dd33990 commit dfcfdd4

2 files changed

Lines changed: 32 additions & 11 deletions

File tree

‎projects/packages/my-jetpack/_inc/components/product-card/status.tsx‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type StatusStateFunction = (
1919
suppressNeedsAttention: boolean
2020
) => string;
2121

22-
const getStatusLabel: StatusStateFunction = ( status, isOwned, suppressNeedsAttention ) => {
22+
export const getStatusLabel: StatusStateFunction = ( status, isOwned, suppressNeedsAttention ) => {
2323
switch ( status ) {
2424
case PRODUCT_STATUSES.ACTIVE:
2525
case PRODUCT_STATUSES.CAN_UPGRADE:
@@ -59,22 +59,36 @@ const getStatusLabel: StatusStateFunction = ( status, isOwned, suppressNeedsAtte
5959
}
6060
};
6161

62-
const getStatusClassName: StatusStateFunction = ( status, isOwned, suppressNeedsAttention ) => {
62+
export type StatusTone = 'active' | 'warning' | 'inactive' | 'error';
63+
64+
/**
65+
* The tone a product's status is shown in, such as the colour of its dot.
66+
*
67+
* @param {ProductStatus} status - The product status.
68+
* @param {boolean} isOwned - Whether the site owns the product.
69+
* @param {boolean} suppressNeedsAttention - Whether to show "needs attention" as active.
70+
* @return {StatusTone} The tone.
71+
*/
72+
export const getStatusTone = (
73+
status: ProductStatus,
74+
isOwned: boolean,
75+
suppressNeedsAttention: boolean
76+
): StatusTone => {
6377
switch ( status ) {
6478
case PRODUCT_STATUSES.ACTIVE:
6579
case PRODUCT_STATUSES.CAN_UPGRADE:
66-
return styles.active;
80+
return 'active';
6781
case PRODUCT_STATUSES.ABSENT_WITH_PLAN:
6882
case PRODUCT_STATUSES.SITE_CONNECTION_ERROR:
6983
case PRODUCT_STATUSES.USER_CONNECTION_ERROR:
7084
case PRODUCT_STATUSES.EXPIRING_SOON:
71-
return styles.warning;
85+
return 'warning';
7286
case PRODUCT_STATUSES.INACTIVE:
7387
case PRODUCT_STATUSES.NEEDS_FIRST_SITE_CONNECTION:
7488
case PRODUCT_STATUSES.NEEDS_ACTIVATION:
75-
return styles.inactive;
89+
return 'inactive';
7690
case PRODUCT_STATUSES.NEEDS_PLAN:
77-
return isOwned ? styles.warning : styles.inactive;
91+
return isOwned ? 'warning' : 'inactive';
7892
case PRODUCT_STATUSES.EXPIRED:
7993
case PRODUCT_STATUSES.NEEDS_ATTENTION__WARNING:
8094
/**
@@ -83,19 +97,22 @@ const getStatusClassName: StatusStateFunction = ( status, isOwned, suppressNeeds
8397
* status as 'Active'.
8498
*/
8599
if ( suppressNeedsAttention ) {
86-
return styles.active;
100+
return 'active';
87101
}
88-
return styles.warning;
102+
return 'warning';
89103
case PRODUCT_STATUSES.NEEDS_ATTENTION__ERROR:
90104
if ( suppressNeedsAttention ) {
91-
return styles.active;
105+
return 'active';
92106
}
93-
return styles.error;
107+
return 'error';
94108
default:
95-
return styles.inactive;
109+
return 'inactive';
96110
}
97111
};
98112

113+
const getStatusClassName: StatusStateFunction = ( status, isOwned, suppressNeedsAttention ) =>
114+
styles[ getStatusTone( status, isOwned, suppressNeedsAttention ) ];
115+
99116
const Status: FC< StatusProps > = ( {
100117
status,
101118
isFetching,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
Comment: Export the product status label and tone helpers for reuse; no visible change.
4+

0 commit comments

Comments
 (0)