Skip to content

Commit

Permalink
Merge branch 'main' into feature/migrate-vislib-legend-colors-oui
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuarrrr committed Jun 29, 2023
2 parents 90d8ffb + f6e22cb commit 1782d1b
Show file tree
Hide file tree
Showing 11 changed files with 582 additions and 78 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [CVE-2022-37603] Bump loader-utils from `2.0.3` to `2.0.4` ([#3031](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3031)). Backwards-compatible fixes included in v2.6.0 and v1.3.7 releases.
- [WS-2021-0638] Bump mocha from `7.2.0` to `10.1.0` ([#2711](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2711))
- Bump `joi` to v14 to avoid the possibility of prototype poisoning in a nested dependency ([#3952](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3952))
- [CVE-2022-25883] Resolve `semver` to `7.5.3` and remove unused package ([#4411](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4411))

### 馃搱 Features/Enhancements

Expand All @@ -22,10 +23,12 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Hide any output from use_node checking for Node compatibility ([#4237](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4237))
- Add category option within groups for context menus ([#4144](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4144))
- [Saved Object Service] Add Repository Factory Provider ([#4149](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4149))
- [Sample Data] Add visual consistency dashboard to sample logs data ([#4339](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4339))
- [@osd/pm] Fix `file:`-linked dependencies' resolution to improve ability to test with local packages ([#4342](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4342))
- [Multiple DataSource] Backend support for adding sample data ([#4268](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4268))
- Add configurable defaults and overrides to uiSettings ([#4344](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4344))
- Bump OUI to `1.1.2` to make `anomalyDetection` icon available ([#4408](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4408))
- [Multiple DataSource] Frontend support for adding sample data ([#4412](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4412))

### 馃悰 Bug Fixes

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"**/unset-value": "^2.0.1",
"**/jest-config": "npm:@amoo-miki/jest-config@27.5.1",
"**/jest-jasmine2": "npm:@amoo-miki/jest-jasmine2@27.5.1",
"**/semver": "^7.5.3",
"**/set-value": "^4.1.0",
"**/xml2js": "^0.5.0",
"**/yaml": "^2.2.2"
Expand Down Expand Up @@ -211,7 +212,7 @@
"require-in-the-middle": "^5.0.2",
"rison-node": "1.0.2",
"rxjs": "^6.5.5",
"semver": "^5.7.0",
"semver": "^7.5.3",
"set-value": "^4.1.0",
"source-map-support": "^0.5.19",
"symbol-observable": "^1.2.0",
Expand Down Expand Up @@ -322,7 +323,7 @@
"@types/react-virtualized": "^9.18.7",
"@types/recompose": "^0.30.6",
"@types/selenium-webdriver": "^4.0.9",
"@types/semver": "^5.5.0",
"@types/semver": "^7.5.0",
"@types/sinon": "^7.0.13",
"@types/strip-ansi": "^5.2.1",
"@types/styled-components": "^5.1.19",
Expand Down
1 change: 0 additions & 1 deletion packages/osd-pm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@babel/preset-typescript": "^7.16.5",
"@node-rs/xxhash": "^1.3.0",
"@types/cmd-shim": "^2.0.0",
"@types/cpy": "^5.1.0",
"@types/dedent": "^0.7.0",
"@types/getopts": "^2.0.1",
"@types/glob": "^7.1.3",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/home/opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"requiredPlugins": ["data", "urlForwarding"],
"optionalPlugins": ["usageCollection", "telemetry", "dataSource"],
"requiredBundles": [
"opensearchDashboardsReact"
"opensearchDashboardsReact", "dataSourceManagement"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export class SampleDataSetCard extends React.Component {
};

install = () => {
this.props.onInstall(this.props.id);
this.props.onInstall(this.props.id, this.props.dataSourceId);
};

uninstall = () => {
this.props.onUninstall(this.props.id);
this.props.onUninstall(this.props.id, this.props.dataSourceId);
};

renderBtn = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,21 @@ export class SampleDataSetCards extends React.Component {
this.loadSampleDataSets();
}

loadSampleDataSets = async () => {
componentDidUpdate(prevProps) {
if (this.props.isDataSourceEnabled) {
this._isMounted = true;
if (prevProps && prevProps.dataSourceId !== this.props.dataSourceId) {
this.setState({ dataSourceId: this.props.dataSourceId }, () =>
this.loadSampleDataSets(this.state.dataSourceId)
);
}
}
}

loadSampleDataSets = async (dataSourceId) => {
let sampleDataSets;
try {
sampleDataSets = await listSampleDataSets();
sampleDataSets = await listSampleDataSets(dataSourceId);
} catch (fetchError) {
this.toastNotifications.addDanger({
title: i18n.translate('home.sampleDataSet.unableToLoadListErrorMessage', {
Expand All @@ -93,7 +104,7 @@ export class SampleDataSetCards extends React.Component {
});
};

install = async (id) => {
install = async (id, dataSourceId) => {
const targetSampleDataSet = this.state.sampleDataSets.find((sampleDataSet) => {
return sampleDataSet.id === id;
});
Expand All @@ -103,7 +114,7 @@ export class SampleDataSetCards extends React.Component {
}));

try {
await installSampleDataSet(id, targetSampleDataSet.defaultIndex);
await installSampleDataSet(id, targetSampleDataSet.defaultIndex, dataSourceId);
} catch (fetchError) {
if (this._isMounted) {
this.setState((prevState) => ({
Expand Down Expand Up @@ -141,7 +152,7 @@ export class SampleDataSetCards extends React.Component {
});
};

uninstall = async (id) => {
uninstall = async (id, dataSourceId) => {
const targetSampleDataSet = this.state.sampleDataSets.find((sampleDataSet) => {
return sampleDataSet.id === id;
});
Expand All @@ -151,7 +162,7 @@ export class SampleDataSetCards extends React.Component {
}));

try {
await uninstallSampleDataSet(id, targetSampleDataSet.defaultIndex);
await uninstallSampleDataSet(id, targetSampleDataSet.defaultIndex, dataSourceId);
} catch (fetchError) {
if (this._isMounted) {
this.setState((prevState) => ({
Expand Down Expand Up @@ -213,6 +224,7 @@ export class SampleDataSetCards extends React.Component {
previewUrl={this.props.addBasePath(this.lightOrDarkImage(sampleDataSet))}
onInstall={this.install}
onUninstall={this.uninstall}
dataSourceId={this.state.dataSourceId}
/>
</EuiFlexItem>
);
Expand Down
104 changes: 92 additions & 12 deletions src/plugins/home/public/application/components/tutorial_directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ import PropTypes from 'prop-types';
import { Synopsis } from './synopsis';
import { SampleDataSetCards } from './sample_data_set_cards';
import { getServices } from '../opensearch_dashboards_services';
// eslint-disable-next-line @osd/eslint/no-restricted-paths
import { getDataSources } from '../../../../data_source_management/public/components/utils';

import {
EuiPage,
EuiPanel,
EuiTabs,
EuiTab,
EuiFlexItem,
Expand All @@ -45,10 +48,10 @@ import {
EuiSpacer,
EuiTitle,
EuiPageBody,
EuiComboBox,
} from '@elastic/eui';

import { getTutorials } from '../load_tutorials';

import { injectI18n, FormattedMessage } from '@osd/i18n/react';
import { i18n } from '@osd/i18n';

Expand All @@ -59,6 +62,9 @@ const homeTitle = i18n.translate('home.breadcrumbs.homeTitle', { defaultMessage:
const addDataTitle = i18n.translate('home.breadcrumbs.addDataTitle', {
defaultMessage: 'Add data',
});
const localCluster = i18n.translate('home.dataSource.localCluster', {
defaultMessage: 'Local Cluster',
});

class TutorialDirectoryUi extends React.Component {
constructor(props) {
Expand All @@ -81,6 +87,8 @@ class TutorialDirectoryUi extends React.Component {
selectedTabId: openTab,
tutorialCards: [],
notices: getServices().tutorialService.getDirectoryNotices(),
isDataSourceEnabled: !!getServices().dataSource,
selectedOption: [{ label: localCluster }],
};
}

Expand Down Expand Up @@ -152,6 +160,31 @@ class TutorialDirectoryUi extends React.Component {
return a.name.toLowerCase().localeCompare(b.name.toLowerCase());
});

if (this.state.isDataSourceEnabled) {
getDataSources(getServices().savedObjectsClient)
.then((fetchedDataSources) => {
if (fetchedDataSources?.length) {
const dataSourceOptions = fetchedDataSources.map((dataSource) => ({
id: dataSource.id,
label: dataSource.title,
}));

dataSourceOptions.push({ label: localCluster });
this.setState({
// eslint-disable-line react/no-did-mount-set-state
dataSources: dataSourceOptions,
});
}
})
.catch(() => {
getServices().toastNotifications.addWarning(
i18n.translate('home.dataSource.fetchDataSourceError', {
defaultMessage: 'Unable to fetch existing data sources',
})
);
});
}

this.setState({
// eslint-disable-line react/no-did-mount-set-state
tutorialCards: tutorialCards,
Expand All @@ -164,6 +197,12 @@ class TutorialDirectoryUi extends React.Component {
});
};

onSelectedDataSourceChange = (e) => {
this.setState({ selectedOption: e });
const dataSourceId = e[0] ? e[0].id : undefined;
this.setState({ selectedDataSourceId: dataSourceId });
};

renderTabs = () => {
return this.tabs.map((tab, index) => (
<EuiTab
Expand All @@ -178,7 +217,13 @@ class TutorialDirectoryUi extends React.Component {

renderTabContent = () => {
if (this.state.selectedTabId === SAMPLE_DATA_TAB_ID) {
return <SampleDataSetCards addBasePath={this.props.addBasePath} />;
return (
<SampleDataSetCards
addBasePath={this.props.addBasePath}
dataSourceId={this.state.selectedDataSourceId}
isDataSourceEnabled={this.state.isDataSourceEnabled}
/>
);
}

return (
Expand Down Expand Up @@ -210,6 +255,30 @@ class TutorialDirectoryUi extends React.Component {
);
};

renderDataSourceSelector = () => {
const { isDataSourceEnabled, dataSources, selectedOption } = this.state;

return isDataSourceEnabled ? (
<div className="sampledataSourcePicker">
<EuiComboBox
aria-label={i18n.translate('sampleData.DataSourceComboBoxAriaLabel', {
defaultMessage: 'Select a Data Source',
})}
placeholder={i18n.translate('sampleData.DataSourceComboBoxPlaceholder', {
defaultMessage: 'Select a Data Source',
})}
singleSelection={{ asPlainText: true }}
options={dataSources}
selectedOptions={selectedOption}
onChange={this.onSelectedDataSourceChange}
prepend="DataSource"
compressed
isDisabled={!isDataSourceEnabled}
/>
</div>
) : null;
};

renderNotices = () => {
const notices = getServices().tutorialService.getDirectoryNotices();
return notices.length ? (
Expand Down Expand Up @@ -260,17 +329,28 @@ class TutorialDirectoryUi extends React.Component {
);
};

render() {
renderPageBody = () => {
return (
<EuiPage restrictWidth={1200}>
<EuiPageBody component="main">
{this.renderHeader()}
<EuiSpacer size="m" />
<EuiTabs>{this.renderTabs()}</EuiTabs>
<EuiSpacer />
{this.renderTabContent()}
</EuiPageBody>
</EuiPage>
<EuiPageBody component="main">
{this.renderHeader()}
<EuiSpacer size="m" />
{this.renderDataSourceSelector()}
<EuiTabs>{this.renderTabs()}</EuiTabs>
<EuiSpacer />
{this.renderTabContent()}
</EuiPageBody>
);
};

render() {
const { isDataSourceEnabled } = this.state;

return isDataSourceEnabled ? (
<EuiPanel paddingSize={'l'} style={{ width: '70%', margin: '50px auto' }}>
{this.renderPageBody()}
</EuiPanel>
) : (
<EuiPage restrictWidth={1200}>{this.renderPageBody()}</EuiPage>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { FeatureCatalogueRegistry } from '../services/feature_catalogue';
import { EnvironmentService } from '../services/environment';
import { ConfigSchema } from '../../config';
import { HomePluginBranding } from '..';
import { DataSourcePluginStart } from '../../../data_source/public';

export interface HomeOpenSearchDashboardsServices {
indexPatternService: any;
Expand All @@ -71,6 +72,7 @@ export interface HomeOpenSearchDashboardsServices {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
getBranding: () => HomePluginBranding;
};
dataSource?: DataSourcePluginStart;
}

let services: HomeOpenSearchDashboardsServices | null = null;
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/home/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ import { UsageCollectionSetup } from '../../usage_collection/public';
import { UrlForwardingSetup, UrlForwardingStart } from '../../url_forwarding/public';
import { AppNavLinkStatus } from '../../../core/public';
import { PLUGIN_ID, HOME_APP_BASE_PATH } from '../common/constants';
import { DataSourcePluginStart } from '../../data_source/public';

export interface HomePluginStartDependencies {
data: DataPublicPluginStart;
telemetry?: TelemetryPluginStart;
urlForwarding: UrlForwardingStart;
dataSource?: DataSourcePluginStart;
}

export interface HomePluginSetupDependencies {
Expand Down Expand Up @@ -96,7 +98,7 @@ export class HomePublicPlugin
: () => {};
const [
coreStart,
{ telemetry, data, urlForwarding: urlForwardingStart },
{ telemetry, data, urlForwarding: urlForwardingStart, dataSource },
] = await core.getStartServices();
setServices({
trackUiMetric,
Expand All @@ -119,6 +121,7 @@ export class HomePublicPlugin
tutorialService: this.tutorialService,
featureCatalogue: this.featuresCatalogueRegistry,
injectedMetadata: coreStart.injectedMetadata,
dataSource,
});
coreStart.chrome.docTitle.change(
i18n.translate('home.pageTitle', { defaultMessage: 'Home' })
Expand Down
Loading

0 comments on commit 1782d1b

Please sign in to comment.