UNPKG

@finos/legend-application-marketplace

Version:
75 lines 5.01 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /** * 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 { observer } from 'mobx-react-lite'; import { LegendMarketplaceSearchBar } from '../../components/SearchBar/LegendMarketplaceSearchBar.js'; import { useApplicationStore } from '@finos/legend-application'; import { generateSearchResultsRoute } from '../../__lib__/LegendMarketplaceNavigation.js'; import { DataProductSearchResult } from '@finos/legend-server-marketplace'; import { useEffect, useState } from 'react'; import { CubesLoadingIndicator, CubesLoadingIndicatorIcon, } from '@finos/legend-art'; import { useLegendMarketplaceBaseStore } from '../../application/LegendMarketplaceFrameworkProvider.js'; import { assertErrorThrown } from '@finos/legend-shared'; import { LegendMarketplaceSearchResultDrawerContent } from './LegendMarketplaceSearchResultDrawerContent.js'; import { Drawer, Grid2 as Grid } from '@mui/material'; import { LegendMarketplaceProductSearchCard } from '../../components/DataProductCard/LegendMarketplaceDataProductSearchCard.js'; import { LegendMarketplacePage } from '../LegendMarketplacePage.js'; export const LegendMarketplaceSearchResults = observer(() => { const applicationStore = useApplicationStore(); const store = useLegendMarketplaceBaseStore(); const marketplaceServerClient = store.marketplaceServerClient; const params = applicationStore.navigationService.navigator.getCurrentLocationParameters(); const [results, setResults] = useState([]); const [isError, setIsError] = useState(false); const [isLoading, setIsLoading] = useState(false); const [selectedPreviewResult, setSelectedPreviewResult] = useState(); useEffect(() => { const fetchResults = async () => { setIsLoading(true); try { const vendorName = params.vendorName?.trim() ?? ''; const query = params.query?.trim() ?? ''; const _results = await marketplaceServerClient.semanticSearch(query, vendorName, 30); setResults(_results.map((result) => DataProductSearchResult.serialization.fromJson(result))); } catch (error) { assertErrorThrown(error); setIsError(true); } finally { setIsLoading(false); } }; // eslint-disable-next-line no-void void fetchResults(); }, [marketplaceServerClient, params.query, params.vendorName]); const onSearch = (provider, query) => { applicationStore.navigationService.navigator.goToLocation(generateSearchResultsRoute(provider, query)); }; return (_jsxs(LegendMarketplacePage, { className: "legend-marketplace-search-results", children: [_jsx("div", { className: "legend-marketplace-search-results__search-bar", children: _jsx(LegendMarketplaceSearchBar, { onSearch: onSearch, initialValue: params.query?.trim() ?? '' }) }), _jsxs("div", { className: "legend-marketplace-search-results__results", children: [_jsx(CubesLoadingIndicator, { isLoading: isLoading, children: _jsx(CubesLoadingIndicatorIcon, {}) }), isError ? (_jsx("div", { children: "Error loading results" })) : (_jsx(Grid, { container: true, spacing: { xs: 4 }, columns: { xs: 1, sm: 2, lg: 3, xxl: 4, xxxl: 5, xxxxl: 6 }, className: "legend-marketplace-search-results__results__cards", children: results.map((result) => (_jsx(Grid, { size: 1, children: _jsx(LegendMarketplaceProductSearchCard, { productSearchResult: result, onPreviewClick: () => { setSelectedPreviewResult(result); }, onLearnMoreClick: () => { applicationStore.navigationService.navigator.visitAddress(result.data_product_link); } }) }, `${result.vendor_name}-${result.data_product_name}`))) }))] }), _jsx(Drawer, { anchor: "right", open: selectedPreviewResult !== undefined, onClose: () => setSelectedPreviewResult(undefined), slotProps: { paper: { sx: { width: '40%', maxWidth: '100rem', }, }, }, children: _jsx(LegendMarketplaceSearchResultDrawerContent, { productSearchResult: selectedPreviewResult }) })] })); }); //# sourceMappingURL=LegendMarketplaceSearchResults.js.map