@edx/frontend-app-subscription-learner-dashboard 1.55.3 → 1.55.4
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/dist/containers/PopularProgramsPanel/PopularPrograms/index.d.ts +2 -0
- package/dist/containers/PopularProgramsPanel/PopularPrograms/index.js +21 -1
- package/dist/containers/PopularProgramsPanel/PopularPrograms/index.js.map +1 -1
- package/dist/hooks/usePopularCoursesAndPrograms.js +12 -7
- package/dist/hooks/usePopularCoursesAndPrograms.js.map +1 -1
- package/dist/hooks/utils.d.ts +2 -0
- package/dist/hooks/utils.js +8 -0
- package/dist/hooks/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { PopularProgramsProps } from './data/types';
|
|
3
|
+
export declare const getProductSlugFromMarketingUrl: (marketingUrl: string | null | undefined) => string | null;
|
|
4
|
+
export declare const buildEnrollPath: (marketingUrl: string | null | undefined) => string;
|
|
3
5
|
export declare const PopularPrograms: FC<PopularProgramsProps>;
|
|
4
6
|
export default PopularPrograms;
|
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { ProductCard } from '../../ProductCard';
|
|
3
|
+
export const getProductSlugFromMarketingUrl = (marketingUrl) => {
|
|
4
|
+
if (!marketingUrl) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
try {
|
|
8
|
+
const pathname = new URL(marketingUrl).pathname;
|
|
9
|
+
const slug = pathname.split('/').filter(Boolean).at(-1);
|
|
10
|
+
return slug !== null && slug !== void 0 ? slug : null;
|
|
11
|
+
}
|
|
12
|
+
catch (_a) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export const buildEnrollPath = (marketingUrl) => {
|
|
17
|
+
const slug = getProductSlugFromMarketingUrl(marketingUrl);
|
|
18
|
+
if (!slug) {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
return `/program/${encodeURIComponent(slug)}`;
|
|
22
|
+
};
|
|
3
23
|
export const PopularPrograms = ({ items }) => {
|
|
4
|
-
return (_jsx("div", { "data-testid": "popular-programs-items", children: _jsx("div", { className: "row g-3 flex-nowrap flex-md-wrap overflow-auto", children: items.map((item) => (_jsx("div", { className: "col-12 col-md-6 col-xl-3 d-flex mb-2", children: _jsx(ProductCard, { item: item }) }, item.objectID))) }) }));
|
|
24
|
+
return (_jsx("div", { "data-testid": "popular-programs-items", children: _jsx("div", { className: "row g-3 flex-nowrap flex-md-wrap overflow-auto", children: items.map((item) => (_jsx("div", { className: "col-12 col-md-6 col-xl-3 d-flex mb-2", children: _jsx(ProductCard, { item: Object.assign(Object.assign({}, item), { marketing_url: buildEnrollPath(item.marketing_url) }) }) }, item.objectID))) }) }));
|
|
5
25
|
};
|
|
6
26
|
export default PopularPrograms;
|
|
7
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/containers/PopularProgramsPanel/PopularPrograms/index.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,MAAM,CAAC,MAAM,eAAe,GAA6B,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACrE,OAAO,CACL,6BAAiB,wBAAwB,YACvC,cAAK,SAAS,EAAC,gDAAgD,YAC5D,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACnB,cAAyB,SAAS,EAAC,sCAAsC,YACvE,KAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/containers/PopularProgramsPanel/PopularPrograms/index.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,MAAM,CAAC,MAAM,8BAA8B,GA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ProgramsProps } from './data/types';\n\nexport const getProductSlugFromMarketingUrl = (\n marketingUrl: string | null | undefined,\n): string | null => {\n if (!marketingUrl) {\n return null;\n }\n\n try {\n const pathname = new URL(marketingUrl).pathname;\n const slug = pathname.split('/').filter(Boolean).at(-1);\n return slug ?? null;\n } catch {\n return null;\n }\n};\n\nexport const buildEnrollPath = (\n marketingUrl: string | null | undefined,\n): string => {\n const slug = getProductSlugFromMarketingUrl(marketingUrl);\n\n if (!slug) {\n return '';\n }\n\n return `/program/${encodeURIComponent(slug)}`;\n};\n\nexport const PopularPrograms: FC<PopularProgramsProps> = ({ items }) => {\n return (\n <div data-testid=\"popular-programs-items\">\n <div className=\"row g-3 flex-nowrap flex-md-wrap overflow-auto\">\n {items.map((item) => (\n <div key={item.objectID} className=\"col-12 col-md-6 col-xl-3 d-flex mb-2\">\n <ProductCard\n item={{\n ...item,\n marketing_url: buildEnrollPath(item.marketing_url),\n }}\n />\n </div>\n ))}\n </div>\n </div>\n );\n};\n\nexport default PopularPrograms;\n"]}
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { useQuery } from '@tanstack/react-query';
|
|
11
11
|
import { PRODUCT_TYPE_COURSE } from '../constants';
|
|
12
12
|
import { fetchPopularProducts } from '../utils/algoliaUtils';
|
|
13
|
+
import { firstOf } from './utils';
|
|
13
14
|
// ─── Query key factories ──────────────────────────────────────────────────────
|
|
14
15
|
// Centralised so cache invalidation is never a typo
|
|
15
16
|
export const searchKeys = {
|
|
@@ -18,12 +19,16 @@ export const searchKeys = {
|
|
|
18
19
|
courses: (query, tags, page) => [...searchKeys.all, 'courses', query, tags, page],
|
|
19
20
|
popular: (productType, limit, skill) => [...searchKeys.all, 'popular', productType, limit, skill !== null && skill !== void 0 ? skill : null],
|
|
20
21
|
};
|
|
22
|
+
const hitPartner = (hit) => {
|
|
23
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
24
|
+
return (Array.isArray(hit.partner) ? hit.partner[0] : (_l = (_k = (_g = (_d = (_a = hit.partner) !== null && _a !== void 0 ? _a : (_c = (_b = hit.owners) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : (_f = (_e = hit.authoring_organizations) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.name) !== null && _g !== void 0 ? _g : (_j = (_h = hit.partners) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.name) !== null && _k !== void 0 ? _k : hit.institution) !== null && _l !== void 0 ? _l : '');
|
|
25
|
+
};
|
|
21
26
|
export const usePopularCoursesAndProgramsData = (searchClient, enabled, productType = PRODUCT_TYPE_COURSE, skill) => useQuery({
|
|
22
27
|
queryKey: searchKeys.popular(productType, 4, skill),
|
|
23
28
|
queryFn: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
29
|
const hits = yield fetchPopularProducts(searchClient, productType, 4, skill);
|
|
25
30
|
return hits.map((hit) => {
|
|
26
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
31
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
27
32
|
const hitDetails = hit;
|
|
28
33
|
return {
|
|
29
34
|
objectID: hit.objectID,
|
|
@@ -31,13 +36,13 @@ export const usePopularCoursesAndProgramsData = (searchClient, enabled, productT
|
|
|
31
36
|
primary_description: (_e = (_d = (_c = hitDetails.primary_description) !== null && _c !== void 0 ? _c : hitDetails.short_description) !== null && _d !== void 0 ? _d : hitDetails.description) !== null && _e !== void 0 ? _e : '',
|
|
32
37
|
url: (_g = (_f = hitDetails.card_image_url) !== null && _f !== void 0 ? _f : hitDetails.image_url) !== null && _g !== void 0 ? _g : '',
|
|
33
38
|
marketing_url: (_h = hitDetails.marketing_url) !== null && _h !== void 0 ? _h : '',
|
|
34
|
-
thumbnail: (_j = hitDetails.organization_logo_override) !== null &&
|
|
35
|
-
content_type: (
|
|
39
|
+
thumbnail: (_p = (_o = (_m = (_l = (_k = (_j = hitDetails.owners) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.logoImageUrl) !== null && _l !== void 0 ? _l : hitDetails.organization_logo_override) !== null && _m !== void 0 ? _m : hitDetails.organization_logo_url) !== null && _o !== void 0 ? _o : hitDetails.partner_logo_url) !== null && _p !== void 0 ? _p : '',
|
|
40
|
+
content_type: (_r = (_q = hitDetails.program_type) !== null && _q !== void 0 ? _q : hitDetails.product) !== null && _r !== void 0 ? _r : 'Course',
|
|
36
41
|
product: productType,
|
|
37
|
-
partner: (
|
|
38
|
-
weeks_to_complete: (
|
|
39
|
-
level: (
|
|
40
|
-
subject: (
|
|
42
|
+
partner: (_s = hitPartner(hit)) !== null && _s !== void 0 ? _s : '',
|
|
43
|
+
weeks_to_complete: (_t = hitDetails.weeks_to_complete) !== null && _t !== void 0 ? _t : undefined,
|
|
44
|
+
level: (_v = (_u = firstOf(hitDetails.level)) !== null && _u !== void 0 ? _u : hitDetails.level_type) !== null && _v !== void 0 ? _v : null,
|
|
45
|
+
subject: (_w = hitDetails.subject) !== null && _w !== void 0 ? _w : undefined,
|
|
41
46
|
};
|
|
42
47
|
});
|
|
43
48
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePopularCoursesAndPrograms.js","sourceRoot":"","sources":["../../src/hooks/usePopularCoursesAndPrograms.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,uBAAuB,CAAC;AAGjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"usePopularCoursesAndPrograms.js","sourceRoot":"","sources":["../../src/hooks/usePopular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AAY,mCAAI,UAAU,CAAC,OAAO,mCAAI,QAAQ;gBACvE,OAAO,EAAE,WAAW;gBACpB,OAAO,EAAE,MAAA,UAAU,CAAC,GAAG,CAAC,mCAAI,EAAE;gBAC9B,iBAAiB,EAAE,MAAA,UAAU,CAAC,iBAAiB,mCAAI,SAAS;gBAC5D,KAAK,EAAE,MAAA,MAAA,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,mCAAI,UAAU,CAAC,UAAU,mCAAI,IAAI;gBACjE,OAAO,EAAE,MAAA,UAAU,CAAC,OAAO,mCAAI,SAAS;aACzC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAA;IACD,OAAO,EAAE,CAAC,CAAC,YAAY,IAAI,OAAO;IAClC,SAAS,EAAE,IAAI,GAAG,EAAE,GAAG,EAAE;CAC1B,CAAC,CAAC","sourcesContent":["import { useQuery, UseQueryResult } from '@tanstack/react-query';\nimport { SearchClient } from 'algoliasearch';\nimport { ProductType, Skill } from '@src/types/types';\nimport { PRODUCT_TYPE_COURSE } from '@src/constants';\nimport { fetchPopularProducts } from '@src/utils/algoliaUtils';\nimport { ProductCardItem } from '@src/containers/ProductCard/data/types';\nimport { firstOf } from './utils';\n\n// ─── Query key factories ──────────────────────────────────────────────────────\n// Centralised so cache invalidation is never a typo\n\nexport const searchKeys = {\n all: ['search'] as const,\n programs: (query: string, tags: string[]) =>\n [...searchKeys.all, 'programs', query, tags] as const,\n courses: (query: string, tags: string[], page: number) =>\n [...searchKeys.all, 'courses', query, tags, page] as const,\n popular: (productType: ProductType, limit: number, skill?: Skill) =>\n [...searchKeys.all, 'popular', productType, limit, skill ?? null] as const,\n};\n\nconst hitPartner = (hit: any): string => (\n Array.isArray(hit.partner) ? hit.partner[0] : hit.partner\n ?? hit.owners?.[0]?.name\n ?? hit.authoring_organizations?.[0]?.name\n ?? hit.partners?.[0]?.name\n ?? hit.institution\n ?? ''\n);\n\nexport const usePopularCoursesAndProgramsData = (\n searchClient: SearchClient | null,\n enabled: boolean,\n productType: ProductType = PRODUCT_TYPE_COURSE,\n skill?: Skill,\n): UseQueryResult<ProductCardItem[]> =>\n useQuery({\n queryKey: searchKeys.popular(productType, 4, skill),\n queryFn: async () => {\n const hits = await fetchPopularProducts(searchClient!, productType, 4, skill);\n return hits.map((hit): ProductCardItem => {\n const hitDetails = hit as {\n short_description?: string,\n primary_description?: string,\n description?: string,\n marketing_url?: string,\n image_url?: string,\n card_image_url?: string,\n organization_logo_override?: string,\n content_type?: string,\n program_type?: string,\n product?: string,\n partner?: string,\n weeks_to_complete?: number,\n level?: string,\n subject?: string,\n owners?: { logoImageUrl?: string }[],\n organization_logo_url?: string,\n partner_logo_url?: string,\n level_type?: string,\n authoring_organizations?: [],\n partners?: [],\n institution?: string,\n };\n\n return {\n objectID: hit.objectID,\n title: hit.title ?? hit.name ?? 'Untitled',\n primary_description: hitDetails.primary_description ?? hitDetails.short_description ?? hitDetails.description ?? '',\n url: hitDetails.card_image_url ?? hitDetails.image_url ?? '',\n marketing_url: hitDetails.marketing_url ?? '',\n thumbnail: hitDetails.owners?.[0]?.logoImageUrl ?? hitDetails.organization_logo_override ?? hitDetails.organization_logo_url ?? hitDetails.partner_logo_url ?? '',\n content_type: hitDetails.program_type ?? hitDetails.product ?? 'Course',\n product: productType,\n partner: hitPartner(hit) ?? '',\n weeks_to_complete: hitDetails.weeks_to_complete ?? undefined,\n level: firstOf(hitDetails.level) ?? hitDetails.level_type ?? null,\n subject: hitDetails.subject ?? undefined,\n };\n });\n },\n enabled: !!searchClient && enabled,\n staleTime: 1000 * 60 * 10,\n });\n"]}
|
package/dist/hooks/utils.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export function useValueCallback(cb: any, prereqs?: any[]): (e: any) => any;
|
|
2
2
|
export function useFormatDate(): (date: any) => any;
|
|
3
|
+
export function firstOf(value: any): any;
|
|
3
4
|
declare namespace _default {
|
|
4
5
|
export { useFormatDate };
|
|
5
6
|
export { useValueCallback };
|
|
7
|
+
export { firstOf };
|
|
6
8
|
}
|
|
7
9
|
export default _default;
|
package/dist/hooks/utils.js
CHANGED
|
@@ -7,8 +7,16 @@ export const useFormatDate = () => {
|
|
|
7
7
|
const { formatDate } = useIntl();
|
|
8
8
|
return (date) => dateFormatter(formatDate, date);
|
|
9
9
|
};
|
|
10
|
+
export const firstOf = (value) => {
|
|
11
|
+
var _a;
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
return (_a = value[0]) !== null && _a !== void 0 ? _a : null;
|
|
14
|
+
}
|
|
15
|
+
return value !== null && value !== void 0 ? value : null;
|
|
16
|
+
};
|
|
10
17
|
export default {
|
|
11
18
|
useFormatDate,
|
|
12
19
|
useValueCallback,
|
|
20
|
+
firstOf,
|
|
13
21
|
};
|
|
14
22
|
//# sourceMappingURL=utils.js.map
|
package/dist/hooks/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/hooks/utils.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,aAAa,MAAM,wBAAwB,CAAC;AAEnD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,CAAC,CACpD,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,sBAAsB;CAC3E,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,EAAE,CAAC;IACjC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACnD,CAAC,CAAC;AAEF,eAAe;IACb,aAAa;IACb,gBAAgB;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/hooks/utils.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,aAAa,MAAM,wBAAwB,CAAC;AAEnD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,CAAC,CACpD,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,sBAAsB;CAC3E,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,EAAE,CAAC;IACjC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACnD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,EAAE;;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,MAAA,KAAK,CAAC,CAAC,CAAC,mCAAI,IAAI,CAAC;IAC1B,CAAC;IACD,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,CAAC;AACvB,CAAC,CAAC;AAEF,eAAe;IACb,aAAa;IACb,gBAAgB;IAChB,OAAO;CACR,CAAC","sourcesContent":["import React from 'react';\nimport { useIntl } from '@openedx/frontend-base';\nimport dateFormatter from '../utils/dateFormatter';\n\nexport const useValueCallback = (cb, prereqs = []) => (\n React.useCallback(e => cb(e.target.value), prereqs) // eslint-disable-line\n);\n\nexport const useFormatDate = () => {\n const { formatDate } = useIntl();\n return (date) => dateFormatter(formatDate, date);\n};\n\nexport const firstOf = (value) => {\n if (Array.isArray(value)) {\n return value[0] ?? null;\n }\n return value ?? null;\n};\n\nexport default {\n useFormatDate,\n useValueCallback,\n firstOf,\n};\n"]}
|