MCPcopy Create free account
hub / github.com/Packstack-Tech/packstack / Items

Function Items

frontend/src/app/Pack/Items.tsx:20–99  ·  view source on GitHub ↗
({ items, unit })

Source from the content-addressed store, hash-verified

18}
19
20const Items: React.FC<ItemsProps> = ({ items, unit }) => {
21 const categories = getCategories(items);
22 const weightByCategory = getWeightByCategory(unit, items);
23
24 const itemDesc = (url?: string, product_name?: string) => {
25 if (product_name && !url) {
26 return product_name;
27 }
28
29 if (url) {
30 const linkLabel = product_name || 'view item';
31 return <a href={url} target="_blank">{linkLabel}</a>
32 }
33
34 return null;
35 };
36
37 return (
38 <ItemList>
39 {categories.map(cat => {
40 const catItems = items.filter(i => i.categoryId === cat.id);
41 const catWeight = weightByCategory.find(c => c.id === cat.id);
42
43 const Header = (
44 <>
45 <h3>{cat.name}</h3>
46 <strong>{catWeight!.total.label} {unit}</strong>
47 </>
48 )
49 return (
50 <CategorySection key={cat.id}>
51 <ExpandablePanel Header={Header}>
52 {catItems.map(item => {
53 const { name, product_name, product_url, packItem: { notes, quantity, worn } } = item;
54 const { label } = getItemWeight(unit, item);
55 const NotesRow = notes && (
56 <ItemNotes>
57 {notes}
58 </ItemNotes>
59 );
60 return (
61 <Row gutter={16} key={item.id} className="item-row">
62 <Col span={18}>
63 <ItemName>
64 {name}
65 </ItemName>
66 <ItemDescription>
67 {itemDesc(product_url, product_name)}
68 </ItemDescription>
69 <ItemQuantity>
70 Quantity: {quantity}
71 </ItemQuantity>
72 {NotesRow}
73 </Col>
74 <Col span={2} className="align-right">
75 {worn && (
76 <WornIndicator className='active display'>
77 <Tooltip title="Worn items are excluded from pack weight"

Callers

nothing calls this directly

Calls 4

getCategoriesFunction · 0.90
getWeightByCategoryFunction · 0.90
getItemWeightFunction · 0.90
itemDescFunction · 0.85

Tested by

no test coverage detected