Skip to content

Commit

Permalink
pretty nice state
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
  • Loading branch information
kavilla committed Jul 21, 2024
1 parent 7f9bdd7 commit 958e56b
Show file tree
Hide file tree
Showing 36 changed files with 734 additions and 246 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7289.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Add DataSet dropdown with index patterns and indices ([#7289](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7289))
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"start": "scripts/use_node scripts/opensearch_dashboards --dev",
"start:docker": "scripts/use_node scripts/opensearch_dashboards --dev --opensearch.hosts=$OPENSEARCH_HOSTS --opensearch.ignoreVersionMismatch=true --server.host=$SERVER_HOST",
"start:security": "scripts/use_node scripts/opensearch_dashboards --dev --security",
"start:enhancements": "scripts/use_node scripts/opensearch_dashboards --dev --uiSettings.overrides['query:enhancements:enabled']=true",
"start:enhancements": "scripts/use_node scripts/opensearch_dashboards --dev --uiSettings.overrides['query:enhancements:enabled']=true --uiSettings.overrides['home:useNewHomePage']=true",
"debug": "scripts/use_node --nolazy --inspect scripts/opensearch_dashboards --dev",
"debug-break": "scripts/use_node --nolazy --inspect-brk scripts/opensearch_dashboards --dev",
"lint": "yarn run lint:es && yarn run lint:style",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { SavedObjectsClientContract } from 'src/core/public';
import { DataSetNavigator, DataSetNavigatorProps } from './';

// Updated function signature to include additional dependencies
export function createDataSetNavigator(savedObjectsClient: SavedObjectsClientContract) {
// Return a function that takes props, omitting the dependencies from the props type
return (props: Omit<DataSetNavigatorProps, 'savedObjectsClient'>) => (
<DataSetNavigator {...props} savedObjectsClient={savedObjectsClient} />
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

// import React, { Component, useEffect, useState } from 'react';
// import { EuiButtonEmpty, EuiContextMenu, EuiPopover } from '@elastic/eui';
// import { SavedObjectsClientContract } from 'opensearch-dashboards/public';
// import _ from 'lodash';
// import { i18n } from '@osd/i18n';
// import { IIndexPattern } from '../..';
// import { createDataFrame } from '../../../common/data_frames';
// import { fetchClusters } from './fetch_clusters';
// import { fetchIndices } from './fetch_indices';
// import { getSearchService } from '../../services';

// export interface DataSetOption {
// id: string;
// name: string;
// dataSourceRef?: string;
// }

// export interface DataSetNavigatorProps {
// dataSet: DataSetOption;
// savedObjectsClient: SavedObjectsClientContract;
// indexPatterns?: Array<IIndexPattern | string>;
// }

// interface DataSetNavigatorState {
// isLoading: boolean;
// indexPatterns: [];
// dataSources: [];
// externalDataSources: [];

// searchValue: string | undefined;
// }

// // Needed for React.lazy
// // eslint-disable-next-line import/no-default-export
// export default class DataSetNavigator extends Component<DataSetNavigatorProps> {
// private isMounted: boolean = false;
// state: DataSetNavigatorState;
// const indexPatternsLabel = i18n.translate('data.query.dataSetNavigator.indexPatternsName', {
// defaultMessage: 'Index Patterns',
// });
// const clustersLabel = i18n.translate('data.query.dataSetNavigator.clustersName', {
// defaultMessage: 'Clusters',
// });
// const [isOpen, setIsOpen] = useState(false);
// const [clusterList, setClusterList] = useState<any>([]);
// const [selectedCluster, setSelectedCluster] = useState<any>(null);
// const [indexList, setIndexList] = useState<any>([]);
// const [selectedDataSet, setSelectedDataSet] = useState<string>(
// typeof props.indexPatterns?.[0] === 'string'
// ? props.indexPatterns?.[0]
// : props.indexPatterns?.[0]?.title ?? ''
// );

// const search = getSearchService();

// const onButtonClick = () => setIsOpen(!isOpen);
// const closePopover = () => setIsOpen(false);

// const handleDataSetChange = (dataSet: IIndexPattern | string) => {
// const dataSetTitle = typeof dataSet === 'string' ? dataSet : dataSet.title;
// if (selectedCluster) {
// setSelectedDataSet(`${selectedCluster.attributes.title}::${dataSetTitle}`);
// } else {
// setSelectedDataSet(dataSetTitle);
// }
// props.onSelectDataSet(dataSet);
// closePopover();
// };

// useEffect(() => {
// // Fetch clusters
// fetchClusters(props.savedObjectsClient).then((res) => {
// setClusterList(res.savedObjects);
// });
// }, [props.savedObjectsClient, search, selectedCluster]);

// useEffect(() => {
// if (selectedCluster) {
// // Fetch indices
// fetchIndices(search, selectedCluster.id).then((res) => {
// // Assuming res is the array to iterate over
// const updatedRes = res.map((index: any) => ({
// ...index,
// dataSourceRef: selectedCluster.id,
// }));
// setIndexList(updatedRes);
// });
// }
// }, [selectedCluster, search]);

// return (
// <EuiPopover
// button={
// <EuiButtonEmpty
// className="dataExplorerDSSelect"
// color="text"
// iconType="arrowDown"
// iconSide="right"
// onClick={onButtonClick}
// >
// {selectedDataSet ? selectedDataSet : 'Select a DataSet'}
// </EuiButtonEmpty>
// }
// isOpen={isOpen}
// closePopover={closePopover}
// anchorPosition="downLeft"
// >
// <EuiContextMenu
// initialPanelId={0}
// className="datasetNavigator"
// panels={[
// {
// id: 0,
// title: 'DATA',
// items: [
// {
// name: indexPatternsLabel,
// panel: 1,
// },
// ...clusterList.map((cluster) => ({
// name: cluster.attributes.title,
// panel: 2,
// onClick: () => setSelectedCluster(cluster),
// })),
// ],
// },
// {
// id: 1,
// title: indexPatternsLabel,
// items: props.indexPatterns?.map((indexPattern) => ({
// name: typeof indexPattern === 'string' ? indexPattern : indexPattern.title,
// onClick: () => {
// setSelectedCluster(null);
// handleDataSetChange(indexPattern);
// },
// })),
// },
// {
// id: 2,
// title: selectedCluster ? selectedCluster.attributes.title : 'Cluster',
// items: [
// {
// name: 'Indexes',
// panel: 3,
// },
// ],
// },
// {
// id: 3,
// title: selectedCluster ? selectedCluster.attributes.title : 'Cluster',
// items: indexList.map((index: any) => ({
// name: index.name,
// onClick: async () => {
// // const await search.df.set(
// // createDataFrame({
// // name: index.name,
// // meta: { queryConfig: { dataSource: selectedCluster } },
// // fields: [],
// // })
// // );
// // TODO: should we just create an index pattern here with get fetch fields?
// handleDataSetChange(index);
// },
// })),
// },
// ]}
// />
// </EuiPopover>
// );
// };
Loading

0 comments on commit 958e56b

Please sign in to comment.