/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import { EuiCallOut, EuiFieldSearch, EuiFlexGroup, EuiFlexItem, EuiForm, EuiFormRow, EuiSelect, EuiSpacer, EuiBasicTable, EuiButtonIcon, } from '@elastic/eui'; import { i18n } from '@osd/i18n'; import { FormattedMessage } from '@osd/i18n/react'; import React, { useMemo, useState } from 'react'; import { RIGHT_ALIGNMENT } from '@elastic/eui/lib/services'; import { useOpenSearchDashboards } from '../../../../src/plugins/opensearch_dashboards_react/public'; import { ExpressionsExampleServices } from '../types'; import { ExplorerSection } from './explorer_section'; interface ExpressionFunctionItem { name: string; type: string; help: string; } export function ExplorerTab() { const { services: { expressions }, } = useOpenSearchDashboards(); const [search, setSearch] = useState(''); const [filter, setFilter] = useState('all'); const [itemIdToExpandedRowMap, setItemIdToExpandedRowMap] = useState({}); const functions = expressions.getFunctions(); const types = useMemo(() => { const allTypes = new Set(Object.values(functions).map((fn) => fn.type)); // Catch all filter and remove allTypes.add('all'); return [...allTypes].map((type) => ({ text: type })); }, [functions]); const items = useMemo( () => Object.values(functions) .filter((fn) => fn.name.includes(search)) .filter((fn) => (filter === 'all' ? true : fn.type === filter)) .map((fn) => ({ name: fn.name, type: fn.type, help: fn.help, })), [filter, functions, search] ); const toggleDetails = (item: ExpressionFunctionItem) => { const { name: id } = item; const itemIdToExpandedRowMapValues = { ...itemIdToExpandedRowMap }; if (itemIdToExpandedRowMapValues[id]) { delete itemIdToExpandedRowMapValues[id]; } else { itemIdToExpandedRowMapValues[id] = ; } setItemIdToExpandedRowMap(itemIdToExpandedRowMapValues); }; return ( <> setSearch(e.target.value)} /> setFilter(e.target.value)} /> ( toggleDetails(item)} aria-label={itemIdToExpandedRowMap[item.name] ? 'Collapse' : 'Expand'} iconType={itemIdToExpandedRowMap[item.name] ? 'arrowUp' : 'arrowDown'} /> ), }, ]} items={items} /> {/* {sections} */} ); }