forked from forcedotcom/commerce-on-lightning-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
37 lines (34 loc) · 1.16 KB
/
utils.js
File metadata and controls
37 lines (34 loc) · 1.16 KB
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
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* For full license text, see the LICENSE file in the repo
* root or https://opensource.org/licenses/apache-2-0/
*/
import { resolve } from 'experience/resourceResolver';
/**
* @typedef {import('./productAttachments').ProductDetailData} ProductDetailData
*/
/**
* @typedef {import('./productAttachments').File} File
*/
/**
* @param {ProductDetailData} product
* The product data to create the files/attachments list from.
* @returns {Array<File>}
* The list of files/attachments extracted from the given
* _`product`_'s list of media items.
*/
export function transformMediaItems(product) {
const mediaGroups = product && Array.isArray(product?.mediaGroups) ? product.mediaGroups : [];
return mediaGroups.reduce((acc, group) => {
if (group.usageType === 'Attachment') {
const mediaItems = group?.mediaItems?.map?.((mediaItem) => ({
name: mediaItem.title,
url: resolve(mediaItem.url ?? ''),
}));
mediaItems && acc.push(...mediaItems);
}
return acc;
}, []);
}