/** * Copyright (c) 2020-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 { EXTERNAL_APPLICATION_NAVIGATION__generateStudioProjectViewUrl } from '@finos/legend-application'; import { OpenIcon, clsx, InfoCircleIcon, MarkdownTextViewer, } from '@finos/legend-art'; import { Popover, Box, TableContainer, Table, TableBody, TableRow, TableCell, IconButton, } from '@mui/material'; import { observer } from 'mobx-react-lite'; import { useState } from 'react'; import { type LegendMarketplaceApplicationStore } from '../../stores/LegendMarketplaceBaseStore.js'; import { LegendMarketplaceCard } from '../MarketplaceCard/LegendMarketplaceCard.js'; import type { ProductCardState } from '../../stores/lakehouse/dataProducts/ProductCardState.js'; import { LakehouseDataProductSearchResultDetails, LakehouseSDLCDataProductSearchResultOrigin, LegacyDataProductSearchResultDetails, } from '@finos/legend-server-marketplace'; import { LakehouseProductTags, DATA_PRODUCT_MARKDOWN_COMPONENTS, } from './LakehouseProductCardSharedUtils.js'; const MAX_DESCRIPTION_LENGTH = 250; export const LakehouseDataProductCardInfoPopover = observer( (props: { dataProductCardState: ProductCardState; popoverAnchorEl: HTMLButtonElement | null; setPopoverAnchorEl: React.Dispatch< React.SetStateAction >; applicationStore: LegendMarketplaceApplicationStore; }) => { const { dataProductCardState, popoverAnchorEl, setPopoverAnchorEl, applicationStore, } = props; const popoverOpen = Boolean(popoverAnchorEl); const popoverId = popoverOpen ? 'popover' : undefined; const dataProductDetails = dataProductCardState.searchResult.dataProductDetails; const dataProductId = dataProductDetails instanceof LakehouseDataProductSearchResultDetails ? dataProductDetails.dataProductId : undefined; const deploymentId = dataProductDetails instanceof LakehouseDataProductSearchResultDetails ? dataProductDetails.deploymentId : undefined; const producerEnvironmentName = dataProductDetails instanceof LakehouseDataProductSearchResultDetails ? dataProductDetails.producerEnvironmentName : undefined; const producerEnvironmentType = dataProductDetails instanceof LakehouseDataProductSearchResultDetails ? dataProductDetails.producerEnvironmentType : undefined; const groupId = dataProductDetails instanceof LakehouseDataProductSearchResultDetails && dataProductDetails.origin instanceof LakehouseSDLCDataProductSearchResultOrigin ? dataProductDetails.origin.groupId : dataProductDetails instanceof LegacyDataProductSearchResultDetails ? dataProductDetails.groupId : undefined; const artifactId = dataProductDetails instanceof LakehouseDataProductSearchResultDetails && dataProductDetails.origin instanceof LakehouseSDLCDataProductSearchResultOrigin ? dataProductDetails.origin.artifactId : dataProductDetails instanceof LegacyDataProductSearchResultDetails ? dataProductDetails.artifactId : undefined; const versionId = dataProductDetails instanceof LakehouseDataProductSearchResultDetails && dataProductDetails.origin instanceof LakehouseSDLCDataProductSearchResultOrigin ? dataProductDetails.origin.versionId : dataProductDetails instanceof LegacyDataProductSearchResultDetails ? dataProductDetails.versionId : undefined; const path = dataProductDetails instanceof LakehouseDataProductSearchResultDetails && dataProductDetails.origin instanceof LakehouseSDLCDataProductSearchResultOrigin ? dataProductDetails.origin.path : dataProductDetails instanceof LegacyDataProductSearchResultDetails ? dataProductDetails.path : undefined; return ( setPopoverAnchorEl(null)} slotProps={{ paper: { className: 'marketplace-lakehouse-data-product-card__popover', onClick: (event) => [ event.preventDefault(), event.stopPropagation(), ], }, backdrop: { onClick: (event) => { event.preventDefault(); event.stopPropagation(); }, }, }} > {dataProductCardState.title} Description {dataProductId !== undefined || deploymentId !== undefined || producerEnvironmentName !== undefined || producerEnvironmentType !== undefined ? ( Deployment Details Data Product ID {dataProductId ?? 'Unknown'} Deployment ID {deploymentId ?? 'Unknown'} Producer Environment Name {producerEnvironmentName ?? 'Unknown'} Producer Environment Type {producerEnvironmentType ?? 'Unknown'}
) : null} {groupId !== undefined || artifactId !== undefined || versionId !== undefined || path !== undefined ? ( Data Product Project {groupId && artifactId && versionId && path ? ( applicationStore.navigationService.navigator.visitAddress( EXTERNAL_APPLICATION_NAVIGATION__generateStudioProjectViewUrl( applicationStore.config.studioApplicationUrl, groupId, artifactId, versionId, path, ), ) } > ) : null} Group {groupId ?? 'Unknown'} Artifact {artifactId ?? 'Unknown'} Version {versionId ?? 'Unknown'} Path {path ?? 'Unknown'}
) : null}
); }, ); export const LakehouseProductCard = observer( (props: { productCardState: ProductCardState; onClick: (productCardState: ProductCardState) => void; moreInfoPreview?: 'small' | 'large' | undefined; hideInfoPopover?: boolean; hideTags?: boolean; }): React.ReactNode => { const { productCardState, onClick, moreInfoPreview, hideInfoPopover, hideTags, } = props; const [popoverAnchorEl, setPopoverAnchorEl] = useState(null); const truncatedDescription = productCardState.description && productCardState.description.length > MAX_DESCRIPTION_LENGTH ? `${productCardState.description.substring( 0, MAX_DESCRIPTION_LENGTH, )}...` : productCardState.description; const content = ( <> {!hideTags && ( )} {moreInfoPreview === undefined && ( {productCardState.title} )} ); const moreInfoContent = ( <> {productCardState.title} {!hideInfoPopover && ( <> ) => { event.preventDefault(); event.stopPropagation(); setPopoverAnchorEl(event.currentTarget); }} className={clsx( 'marketplace-lakehouse-data-product-card__more-info-btn', { 'marketplace-lakehouse-data-product-card__more-info-btn--selected': Boolean(popoverAnchorEl), }, )} title="More Info" > )} ); return ( onClick(productCardState)} className="marketplace-lakehouse-data-product-card" moreInfo={moreInfoContent} moreInfoPreview={moreInfoPreview} cardMedia={productCardState.icon ?? productCardState.displayImage} loadingMedia={productCardState.initState.isInProgress} /> ); }, );