/** * Copyright (c) 2025-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { useMemo, useState, type JSX } from 'react'; import { observer } from 'mobx-react-lite'; import { Box, Button, Dialog, DialogActions, DialogContent, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, } from '@mui/material'; import { type TerminalResult } from '@finos/legend-server-marketplace'; import { formatItemPrice, formatProfileSummaryLine, OrderProfileLabel, OrderProfileTableHeader, } from './orderProfileUtils.js'; import { CategoryChip, OrderProfileModalHeader, } from './OrderProfileModalHeader.js'; import { ColumnFilterButton } from '../Filters/ColumnFilterButton.js'; export const OwnedTerminalDetailModal = observer( (props: { terminal: TerminalResult; open: boolean; onClose: () => void; }): JSX.Element => { const { terminal, open, onClose } = props; const ownedAddons = useMemo(() => terminal.items ?? [], [terminal.items]); const addOnCount = ownedAddons.length; const summaryLine = formatProfileSummaryLine(1, addOnCount); const totalPrice = terminal.price + ownedAddons.reduce((sum, addon) => sum + addon.price, 0); const [categoryFilter, setCategoryFilter] = useState>( () => new Set(), ); const categoryOptions = useMemo( () => Array.from( new Set([terminal, ...ownedAddons].map((item) => item.category)), ).sort((a, b) => a.localeCompare(b)), [terminal, ownedAddons], ); const showTerminalRow = categoryFilter.size === 0 || categoryFilter.has(terminal.category); const filteredAddons = categoryFilter.size === 0 ? ownedAddons : ownedAddons.filter((addon) => categoryFilter.has(addon.category)); // When the terminal row is filtered out, add-on rows lose their visible // parent, so render them without sub-item indentation to avoid looking // like an orphaned child (see `showTerminalRow` usage below). return ( {OrderProfileTableHeader.PRODUCT_NAME} {OrderProfileTableHeader.CATEGORY} {OrderProfileTableHeader.COST_MONTHLY} {showTerminalRow && ( {terminal.productName} {formatItemPrice(terminal.price)} )} {filteredAddons.map((addon) => ( {addon.productName} {formatItemPrice(addon.price)} ))}
); }, );