@growth-operations/ui-shared 1.22.0 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@growth-operations/ui-shared",
3
- "version": "1.22.0",
3
+ "version": "1.23.0",
4
4
  "description": "Shared HubSpot UI-extension modules (Home, Billing) for Growth Operations apps.",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -1,6 +1,10 @@
1
1
  import React from "react";
2
2
  import { Flex, Tile, Text, Link } from "@hubspot/ui-extensions";
3
- import { featureUsageOf } from "../lib/featureUsage";
3
+ import {
4
+ featureUsageOf,
5
+ pickDailyRecommendations,
6
+ recommendationsRotated,
7
+ } from "../lib/featureUsage";
4
8
 
5
9
  // The Home "Most used features" / "Recommended to explore" sections, fed by
6
10
  // the additive state.feature_usage block (per-app feature registry + credit
@@ -44,21 +48,33 @@ function MostUsedTile({ mostUsed }) {
44
48
 
45
49
  function RecommendedTile({ notInUse }) {
46
50
  if (notInUse.length === 0) return null;
51
+ // Long lists (ATS: 13 features) render as a rotating daily slice instead of
52
+ // a wall — the whole list still arrives in the payload; the window is a
53
+ // pure function of the UTC date (see ../lib/featureUsage).
54
+ const picks = pickDailyRecommendations(
55
+ notInUse,
56
+ new Date().toISOString().slice(0, 10)
57
+ );
47
58
  return (
48
59
  <Tile>
49
60
  <Flex direction="column" gap="small">
50
61
  <Text format={{ fontWeight: "bold" }}>Recommended to explore</Text>
51
- {notInUse.map((f) => (
62
+ {picks.map((f) => (
52
63
  <Flex key={f.key} direction="column" gap="extra-small">
53
64
  <Text format={{ fontWeight: "demibold" }}>{f.name}</Text>
54
65
  {f.rationale ? <Text>{f.rationale}</Text> : null}
55
66
  {f.docsUrl ? (
56
67
  <Link href={{ url: f.docsUrl, external: true }}>
57
- Read the guide →
68
+ Learn more →
58
69
  </Link>
59
70
  ) : null}
60
71
  </Flex>
61
72
  ))}
73
+ {recommendationsRotated(notInUse) ? (
74
+ <Text variant="microcopy">
75
+ New picks daily — {notInUse.length} features to explore in all.
76
+ </Text>
77
+ ) : null}
62
78
  </Flex>
63
79
  </Tile>
64
80
  );
package/src/index.js CHANGED
@@ -50,7 +50,12 @@ export {
50
50
  SUPPORT_FOOTER,
51
51
  } from "./lib/format";
52
52
  export { useStrictModeEffect } from "./lib/useStrictModeEffect";
53
- export { resolveFeatureUsage, featureUsageOf } from "./lib/featureUsage";
53
+ export {
54
+ resolveFeatureUsage,
55
+ featureUsageOf,
56
+ pickDailyRecommendations,
57
+ recommendationsRotated,
58
+ } from "./lib/featureUsage";
54
59
  export {
55
60
  hasTopUpBank,
56
61
  creditsBlockOf,
@@ -52,3 +52,44 @@ export function featureUsageOf(state) {
52
52
  if (!state || typeof state !== "object") return null;
53
53
  return resolveFeatureUsage(state.state?.feature_usage ?? state.feature_usage);
54
54
  }
55
+
56
+ // --- Recommendation rotation ------------------------------------------------
57
+
58
+ // A long not_in_use list is a firehose: a fresh install of a big app (ATS
59
+ // has 13 registered features) gets the whole registry dumped on Home exactly
60
+ // when focus matters most, and a wall of 13 "Read the guide" links teaches
61
+ // nothing. So short lists (<= RECOMMENDATION_WHOLE_LIST_MAX) render whole;
62
+ // longer lists show a deterministic daily slice that rotates day over day.
63
+ // The seed is the UTC date alone — same picks all day, no per-portal state,
64
+ // no backend involvement (the full list still arrives in the payload).
65
+ export const RECOMMENDATION_PICK_COUNT = 3;
66
+ export const RECOMMENDATION_WHOLE_LIST_MAX = 4;
67
+
68
+ // djb2 over the date string — tiny, stable across browsers, good enough for
69
+ // a day offset (not a security or money decision).
70
+ export function rotationDayHash(dateISO) {
71
+ let h = 5381;
72
+ for (let i = 0; i < dateISO.length; i++) {
73
+ h = ((h << 5) + h + dateISO.charCodeAt(i)) >>> 0;
74
+ }
75
+ return h;
76
+ }
77
+
78
+ // The slice to render for `todayISO` ("YYYY-MM-DD", UTC). Order within the
79
+ // day stays registry order; the window wraps around the end of the list.
80
+ // Pure + date-injected so tests don't depend on the wall clock.
81
+ export function pickDailyRecommendations(notInUse, todayISO) {
82
+ if (!Array.isArray(notInUse)) return [];
83
+ if (notInUse.length <= RECOMMENDATION_WHOLE_LIST_MAX) return notInUse;
84
+ const start = rotationDayHash(todayISO) % notInUse.length;
85
+ return Array.from(
86
+ { length: RECOMMENDATION_PICK_COUNT },
87
+ (_, i) => notInUse[(start + i) % notInUse.length]
88
+ );
89
+ }
90
+
91
+ // True when rotation truncated the list — the tile shows a quiet "new picks
92
+ // daily" hint only then, so small registries read exactly as before.
93
+ export function recommendationsRotated(notInUse) {
94
+ return Array.isArray(notInUse) && notInUse.length > RECOMMENDATION_WHOLE_LIST_MAX;
95
+ }