@finos/legend-application-marketplace
Version:
Legend Marketplace application core
141 lines • 13.8 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } 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 { Container, Paper, Typography } from '@mui/material';
import { observer } from 'mobx-react-lite';
import { flowResult } from 'mobx';
import { useCallback, useEffect, useRef } from 'react';
import { useSyncStateAndSearchParam } from '@finos/legend-application';
import { useSearchParams } from '@finos/legend-application/browser';
import { isNonEmptyString, LogEvent } from '@finos/legend-shared';
import { CubesLoadingIndicator, CubesLoadingIndicatorIcon, } from '@finos/legend-art';
import { LEGEND_MARKETPLACE_FIELD_SEARCH_RESULTS_QUERY_PARAM_TOKEN, generateLakehouseSearchResultsRoute, EXTERNAL_APPLICATION_NAVIGATION__generateDataSpaceQueryEditorUrl, } from '../../../__lib__/LegendMarketplaceNavigation.js';
import { LEGEND_MARKETPLACE_PAGE, LegendMarketplaceTelemetryHelper, } from '../../../__lib__/LegendMarketplaceTelemetryHelper.js';
import { LEGEND_MARKETPLACE_APP_EVENT } from '../../../__lib__/LegendMarketplaceAppEvent.js';
import { useLegendMarketplaceFieldSearchResultsStore, withLegendMarketplaceFieldSearchResultsStore, } from '../../../application/providers/LegendMarketplaceFieldSearchResultsStoreProvider.js';
import { FieldSearchFiltersPanel } from '../../../components/FieldSearchFiltersPanel/FieldSearchFiltersPanel.js';
import { FieldSearchResultListRow } from '../../../components/MarketplaceCard/FieldSearchResultListItem.js';
import { LegendMarketplaceOptionSelector } from '../../../components/OptionSelector/LegendMarketplaceOptionSelector.js';
import { LegendMarketplaceSearchBar } from '../../../components/SearchBar/LegendMarketplaceSearchBar.js';
import { PaginationControls } from '../../../components/Pagination/PaginationControls.js';
import { LegendMarketplacePage } from '../../LegendMarketplacePage.js';
import { DataProductTypeFilter, SearchResultViewOption, } from '../../../stores/lakehouse/LegendMarketplaceSearchResultsStore.js';
import {} from '../../../stores/lakehouse/fieldSearch/FieldSearchResultState.js';
const FieldSearchResultsContent = observer((props) => {
const { fieldSearchResultsStore, handlePageChange, handleItemsPerPageChange, handleToggleExpandRow, handleOpenDataProduct, handleOpenDatasetInQuery, } = props;
if (fieldSearchResultsStore.isLoading) {
return (_jsx("div", { className: "marketplace-lakehouse-search-results__loading-container", children: _jsx(CubesLoadingIndicator, { isLoading: true, children: _jsx(CubesLoadingIndicatorIcon, {}) }) }));
}
if (fieldSearchResultsStore.hasFailed) {
return (_jsxs("div", { className: "marketplace-lakehouse-search-results__empty-state", children: [_jsx(Typography, { variant: "h5", className: "marketplace-lakehouse-search-results__empty-state__title", children: "Field search failed" }), _jsx(Typography, { variant: "body1", className: "marketplace-lakehouse-search-results__empty-state__message", children: fieldSearchResultsStore.errorMessage })] }));
}
if (fieldSearchResultsStore.hasActiveFilters &&
fieldSearchResultsStore.totalItems === 0) {
return (_jsxs("div", { className: "marketplace-lakehouse-search-results__empty-state", children: [_jsx(Typography, { variant: "h5", className: "marketplace-lakehouse-search-results__empty-state__title", children: "No fields match the current filters" }), _jsx(Typography, { variant: "body1", className: "marketplace-lakehouse-search-results__empty-state__message", children: "Clear one or more filters to see results again." })] }));
}
if (!fieldSearchResultsStore.hasActiveFilters &&
isNonEmptyString(fieldSearchResultsStore.searchQuery) &&
fieldSearchResultsStore.totalItems === 0) {
return (_jsxs("div", { className: "marketplace-lakehouse-search-results__empty-state", children: [_jsx(Typography, { variant: "h5", className: "marketplace-lakehouse-search-results__empty-state__title", children: "No fields found" }), _jsx(Typography, { variant: "body1", className: "marketplace-lakehouse-search-results__empty-state__message", children: "Try a broader query or switch back to product search." })] }));
}
if (fieldSearchResultsStore.tableRows.length === 0) {
return null;
}
return (_jsxs(_Fragment, { children: [_jsxs(Paper, { elevation: 1, className: "marketplace-lakehouse-field-search-results__list", children: [_jsxs("div", { className: "marketplace-lakehouse-field-search-results__list-header", children: [_jsx(Typography, { className: "marketplace-lakehouse-field-search-results__list-header-cell", children: "Field Name" }), _jsx(Typography, { className: "marketplace-lakehouse-field-search-results__list-header-cell", children: "Type" }), _jsx(Typography, { className: "marketplace-lakehouse-field-search-results__list-header-cell", children: "Description" }), _jsx(Typography, { className: "marketplace-lakehouse-field-search-results__list-header-cell", children: "Data Products" }), _jsx(Typography, { className: "marketplace-lakehouse-field-search-results__list-header-cell", children: "Datasets" })] }), _jsx("div", { className: "marketplace-lakehouse-field-search-results__list-body", children: fieldSearchResultsStore.tableRows.map((row) => (_jsx(FieldSearchResultListRow, { fieldSearchResultState: row, expanded: fieldSearchResultsStore.isRowExpanded(row.id), onToggleExpanded: handleToggleExpandRow, onOpenDataProduct: handleOpenDataProduct, onOpenDatasetInQuery: handleOpenDatasetInQuery }, row.id))) })] }), _jsx(PaginationControls, { totalItems: fieldSearchResultsStore.totalItems, itemsPerPage: fieldSearchResultsStore.itemsPerPage, page: fieldSearchResultsStore.page, onPageChange: handlePageChange, onItemsPerPageChange: handleItemsPerPageChange, disabled: fieldSearchResultsStore.isLoading })] }));
});
const LegendMarketplaceFieldSearchResultsPage = observer(() => {
const fieldSearchResultsStore = useLegendMarketplaceFieldSearchResultsStore();
const marketplaceBaseStore = fieldSearchResultsStore.marketplaceBaseStore;
const applicationStore = marketplaceBaseStore.applicationStore;
const [searchParams, setSearchParams] = useSearchParams();
const pageRef = useRef(null);
useSyncStateAndSearchParam(fieldSearchResultsStore.searchQuery, useCallback((val) => {
if (val === null) {
return;
}
fieldSearchResultsStore.setSearchQuery(val);
}, [fieldSearchResultsStore]), LEGEND_MARKETPLACE_FIELD_SEARCH_RESULTS_QUERY_PARAM_TOKEN.QUERY, searchParams.get(LEGEND_MARKETPLACE_FIELD_SEARCH_RESULTS_QUERY_PARAM_TOKEN.QUERY), setSearchParams, useCallback(() => true, []));
useEffect(() => {
flowResult(fieldSearchResultsStore.executeSearch()).catch(applicationStore.alertUnhandledError);
}, [
applicationStore,
fieldSearchResultsStore,
fieldSearchResultsStore.searchQuery,
]);
const handlePageChange = useCallback((page) => {
pageRef.current?.scrollIntoView({ behavior: 'smooth' });
flowResult(fieldSearchResultsStore.changePageAndFetch(page)).catch(applicationStore.alertUnhandledError);
}, [fieldSearchResultsStore, applicationStore]);
const handleItemsPerPageChange = useCallback((itemsPerPage) => {
flowResult(fieldSearchResultsStore.changeItemsPerPageAndFetch(itemsPerPage)).catch(applicationStore.alertUnhandledError);
}, [fieldSearchResultsStore, applicationStore]);
const handleToggleProductType = useCallback((productType) => {
flowResult(fieldSearchResultsStore.toggleProductTypeAndFetch(productType)).catch(applicationStore.alertUnhandledError);
}, [fieldSearchResultsStore, applicationStore]);
const handleClearFilters = useCallback(() => {
flowResult(fieldSearchResultsStore.clearAllFiltersAndFetch()).catch(applicationStore.alertUnhandledError);
}, [fieldSearchResultsStore, applicationStore]);
const handleSearch = useCallback((query, useProducerSearch, useFieldSearch) => {
if (!isNonEmptyString(query)) {
return;
}
if (!useFieldSearch) {
applicationStore.navigationService.navigator.goToLocation(generateLakehouseSearchResultsRoute(query, useProducerSearch));
return;
}
fieldSearchResultsStore.setSearchQuery(query);
LegendMarketplaceTelemetryHelper.logEvent_SearchQuery(applicationStore.telemetryService, query, false, LEGEND_MARKETPLACE_PAGE.SEARCH_RESULTS_PAGE, true);
}, [applicationStore, fieldSearchResultsStore]);
const openInLegendQuery = useCallback((dataProduct, modelPath) => {
const isLegacyDataProduct = dataProduct.productType === DataProductTypeFilter.LEGACY;
const canOpenLegacyQuery = dataProduct.groupId &&
dataProduct.artifactId &&
dataProduct.versionId &&
dataProduct.executionContextKey;
if (isLegacyDataProduct && canOpenLegacyQuery) {
applicationStore.navigationService.navigator.visitAddress(EXTERNAL_APPLICATION_NAVIGATION__generateDataSpaceQueryEditorUrl(applicationStore.config.queryApplicationUrl, dataProduct.groupId, dataProduct.artifactId, dataProduct.versionId, dataProduct.entityPath, dataProduct.executionContextKey, undefined, modelPath));
return;
}
if (isLegacyDataProduct && !canOpenLegacyQuery) {
applicationStore.logService.warn(LogEvent.create(LEGEND_MARKETPLACE_APP_EVENT.CLICK_QUERY_DATA_PRODUCT), `Falling back to marketplace navigation for legacy data product ${dataProduct.entityPath} due to missing query context`);
}
// Fallback to marketplace data product page for adhoc/lakehouse products
applicationStore.navigationService.navigator.visitAddress(applicationStore.navigationService.navigator.generateAddress(dataProduct.path));
}, [applicationStore]);
const handleOpenDataProduct = useCallback((dataProduct) => {
openInLegendQuery(dataProduct, undefined);
}, [openInLegendQuery]);
const handleOpenDatasetInQuery = useCallback((dataProduct) => {
openInLegendQuery(dataProduct, dataProduct.modelPath);
}, [openInLegendQuery]);
const handleToggleExpandRow = useCallback((rowId) => {
fieldSearchResultsStore.toggleExpandRow(rowId);
}, [fieldSearchResultsStore]);
const handleOpenDataProductsTab = useCallback(() => {
applicationStore.navigationService.navigator.goToLocation(generateLakehouseSearchResultsRoute(fieldSearchResultsStore.searchQuery, false));
}, [applicationStore, fieldSearchResultsStore.searchQuery]);
const handleSearchResultViewChange = useCallback((value) => {
if (value === SearchResultViewOption.DATA_PRODUCTS) {
handleOpenDataProductsTab();
}
}, [handleOpenDataProductsTab]);
return (_jsxs(LegendMarketplacePage, { className: "marketplace-lakehouse-search-results marketplace-lakehouse-field-search-results", children: [_jsx("div", { ref: pageRef }), _jsx(Container, { className: "marketplace-lakehouse-search-results__search-container", children: _jsx(LegendMarketplaceSearchBar, { showSettings: true, onSearch: handleSearch, stateSearchQuery: fieldSearchResultsStore.searchQuery, stateUseProducerSearch: false, stateUseFieldSearch: true, placeholder: "Search Marketplace fields", className: "marketplace-lakehouse-search-results__search-bar", enableAutosuggest: false }) }), _jsx("div", { className: "legend-marketplace-search-results__sort-bar", children: _jsxs("div", { className: "legend-marketplace-search-results__sort-bar__container", children: [_jsxs(Typography, { variant: "h4", className: "marketplace-lakehouse-search-results__subtitles", children: [fieldSearchResultsStore.totalFieldMatches, " Fields"] }), _jsx("div", { className: "legend-marketplace-search-results__search-type-tabs", children: _jsx(LegendMarketplaceOptionSelector, { options: [
SearchResultViewOption.DATA_PRODUCTS,
SearchResultViewOption.DATA_FIELDS,
], selectedOption: SearchResultViewOption.DATA_FIELDS, onChange: handleSearchResultViewChange, ariaLabel: "Search result type" }) })] }) }), _jsx(Container, { maxWidth: "xxxl", className: "marketplace-lakehouse-search-results__results-container", children: _jsxs("div", { className: "marketplace-lakehouse-search-results__results-layout", children: [_jsx("div", { className: "marketplace-lakehouse-search-results__sidebar", children: _jsx(FieldSearchFiltersPanel, { store: fieldSearchResultsStore, onToggleProductType: handleToggleProductType, onClearFilters: handleClearFilters }) }), _jsx("div", { className: "marketplace-lakehouse-search-results__main-content", children: _jsx(FieldSearchResultsContent, { fieldSearchResultsStore: fieldSearchResultsStore, handlePageChange: handlePageChange, handleItemsPerPageChange: handleItemsPerPageChange, handleToggleExpandRow: handleToggleExpandRow, handleOpenDataProduct: handleOpenDataProduct, handleOpenDatasetInQuery: handleOpenDatasetInQuery }) })] }) })] }));
});
export const LegendMarketplaceFieldSearchResults = withLegendMarketplaceFieldSearchResultsStore(LegendMarketplaceFieldSearchResultsPage);
//# sourceMappingURL=LegendMarketplaceFieldSearchResults.js.map