Skip to content

Commit

Permalink
[Page Header]Implement new page header for admin data sources page (#…
Browse files Browse the repository at this point in the history
…7833)

* Implement new page header for admin data sources page

Signed-off-by: Wei Wang <weiwangv@amazon.com>

* update unit tests for page header change

Signed-off-by: Wei Wang <weiwangv@amazon.com>

* make button group smaller and change section title to h2

Signed-off-by: Wei Wang <weiwangv@amazon.com>

---------

Signed-off-by: Wei Wang <weiwangv@amazon.com>
Co-authored-by: Wei Wang <weiwangv@amazon.com>
  • Loading branch information
weiwang118 and Wei Wang authored Aug 28, 2024
1 parent 56fc8f4 commit cb273fc
Show file tree
Hide file tree
Showing 29 changed files with 549 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "opensearchDashboards",
"server": true,
"ui": true,
"requiredPlugins": ["management", "indexPatternManagement"],
"requiredPlugins": ["navigation", "management", "indexPatternManagement"],
"optionalPlugins": ["dataSource"],
"requiredBundles": ["opensearchDashboardsReact", "dataSource", "opensearchDashboardsUtils"],
"extraPublicDirs": ["public/components/utils"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,44 @@ export function getCreateBreadcrumbs() {
},
];
}
export function getCreateOpenSearchDataSourceBreadcrumbs() {
export function getCreateOpenSearchDataSourceBreadcrumbs(useNewUX: boolean) {
return [
...getCreateBreadcrumbs(),
{
text: i18n.translate(
'dataSourcesManagement.dataSources.createOpenSearchDataSourceBreadcrumbs',
{
defaultMessage: 'Open Search',
defaultMessage: useNewUX ? 'Connect OpenSearch Cluster' : 'Open Search',
}
),
href: `/configure/OpenSearch`,
},
];
}

export function getCreateAmazonS3DataSourceBreadcrumbs() {
export function getCreateAmazonS3DataSourceBreadcrumbs(useNewUX: boolean) {
return [
...getCreateBreadcrumbs(),
{
text: i18n.translate(
'dataSourcesManagement.dataSources.createAmazonS3DataSourceBreadcrumbs',
{
defaultMessage: 'Amazon S3',
defaultMessage: useNewUX ? 'Connect Amazon S3' : 'Amazon S3',
}
),
href: `/configure/AmazonS3AWSGlue`,
},
];
}

export function getCreatePrometheusDataSourceBreadcrumbs() {
export function getCreatePrometheusDataSourceBreadcrumbs(useNewUX: boolean) {
return [
...getCreateBreadcrumbs(),
{
text: i18n.translate(
'dataSourcesManagement.dataSources.createPrometheusDataSourceBreadcrumbs',
{
defaultMessage: 'Prometheus',
defaultMessage: useNewUX ? 'Connect Prometheus' : 'Prometheus',
}
),
href: `/configure/Prometheus`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
} from '@elastic/eui';
import { i18n } from '@osd/i18n';
import { FormattedMessage } from '@osd/i18n/react';
import { NavigationPublicPluginStart } from 'src/plugins/navigation/public';
import { ApplicationStart } from 'opensearch-dashboards/public';
import { AuthenticationMethodRegistry } from '../../../../auth_registry';
import { SigV4Content, SigV4ServiceName } from '../../../../../../data_source/common/data_sources';
import {
Expand All @@ -47,6 +49,9 @@ import {
} from '../../../utils';

export interface CreateDataSourceProps {
useNewUX: boolean;
navigation: NavigationPublicPluginStart;
application: ApplicationStart;
existingDatasourceNamesList: string[];
handleSubmit: (formValues: DataSourceAttributes) => void;
handleTestConnection: (formValues: DataSourceAttributes) => void;
Expand Down Expand Up @@ -367,21 +372,41 @@ export class CreateDataSourceForm extends React.Component<
return null;
};

description = [
{
renderComponent: (
<EuiText size="s" color="subdued">
<FormattedMessage
id="dataSourcesManagement.createDataSource.description"
defaultMessage="Create a new data source connection to help you retrieve data from an external OpenSearch compatible source."
/>
</EuiText>
),
},
];

/* Render methods */

/* Render header*/
renderHeader = () => {
return <Header />;
return this.props.useNewUX ? (
<this.props.navigation.ui.HeaderControl
setMountPoint={this.props.application.setAppDescriptionControls}
controls={this.description}
/>
) : (
<Header />
);
};

/* Render Section header*/
renderSectionHeader = (i18nId: string, defaultMessage: string) => {
return (
<>
<EuiText grow={false}>
<h4>
<EuiText grow={false} size="s">
<h2>
<FormattedMessage id={i18nId} defaultMessage={defaultMessage} />
</h4>
</h2>
</EuiText>
</>
);
Expand Down Expand Up @@ -554,7 +579,6 @@ export class CreateDataSourceForm extends React.Component<
<>
<EuiPageContent>
{this.renderHeader()}
<EuiSpacer size="m" />
<EuiForm data-test-subj="data-source-creation">
{/* Endpoint section */}
{this.renderSectionHeader(
Expand Down Expand Up @@ -749,7 +773,7 @@ export class CreateDataSourceForm extends React.Component<
>
<FormattedMessage
id="dataSourcesManagement.createDataSource.createButtonLabel"
defaultMessage="Create data source"
defaultMessage="Connect to OpenSearch Cluster"
/>
</EuiButton>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const Header = () => {
<br />
</p>
</EuiText>
<EuiSpacer size="s" />
</div>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ export const CreateDataSourceWizard: React.FunctionComponent<CreateDataSourceWiz
http,
notifications: { toasts },
uiSettings,
navigation,
application,
} = useOpenSearchDashboards<DataSourceManagementContext>().services;

/* State Variables */
const [existingDatasourceNamesList, setExistingDatasourceNamesList] = useState<string[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(false);
const useNewUX = uiSettings.get('home:useNewHomePage');

/* Set breadcrumb */
useEffectOnce(() => {
setBreadcrumbs(getCreateOpenSearchDataSourceBreadcrumbs());
setBreadcrumbs(getCreateOpenSearchDataSourceBreadcrumbs(useNewUX));
getExistingDataSourceNames();
});

Expand Down Expand Up @@ -128,6 +131,9 @@ export const CreateDataSourceWizard: React.FunctionComponent<CreateDataSourceWiz
return (
<>
<CreateDataSourceForm
useNewUX={useNewUX}
navigation={navigation}
application={application}
handleSubmit={handleSubmit}
handleTestConnection={handleTestConnection}
handleCancel={() => props.history.push('/create')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { CreateDataSourcePanelHeader } from './create_data_source_panel_header';
import { CreateDataSourceCardView } from './create_data_source_card_view';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import { getCreateBreadcrumbs } from '../breadcrumbs';
import { DataSourceManagementContext } from '../../types';
import { RouteComponentProps } from 'react-router-dom';
import { navigationPluginMock } from 'src/plugins/navigation/public/mocks';

jest.mock('../../../../opensearch_dashboards_react/public');
jest.mock('../breadcrumbs');
Expand All @@ -34,6 +34,7 @@ describe('CreateDataSourcePanel', () => {
},
},
uiSettings: {},
navigation: navigationPluginMock.createStartContract(),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiFlexGroup, EuiFlexItem, EuiPageHeader, EuiPanel } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem, EuiPageHeader, EuiPanel, EuiText } from '@elastic/eui';
import React, { useEffect } from 'react';
import { RouteComponentProps } from 'react-router-dom';
import { FormattedMessage } from '@osd/i18n/react';
import { CreateDataSourcePanelHeader } from './create_data_source_panel_header';
import { CreateDataSourceCardView } from './create_data_source_card_view';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
Expand All @@ -14,24 +15,56 @@ import { DataSourceManagementContext } from '../../types';

interface CreateDataSourcePanelProps extends RouteComponentProps {
featureFlagStatus: boolean;
useNewUX: boolean;
}

export const CreateDataSourcePanel: React.FC<CreateDataSourcePanelProps> = ({
featureFlagStatus,
useNewUX,
...props
}) => {
const {
chrome,
application,
setBreadcrumbs,
notifications: { toasts },
uiSettings,
navigation,
} = useOpenSearchDashboards<DataSourceManagementContext>().services;

useEffect(() => {
setBreadcrumbs(getCreateBreadcrumbs());
}, [setBreadcrumbs]);

return (
const { HeaderControl } = navigation.ui;
const description = [
{
renderComponent: (
<EuiText size="s" color="subdued">
<FormattedMessage
id="dataSourcesManagement.createDataSourcePanel.description"
defaultMessage="Select a data source type to get started. "
/>
</EuiText>
),
},
];

return useNewUX ? (
<>
<HeaderControl setMountPoint={application.setAppDescriptionControls} controls={description} />
<EuiPanel color="transparent" hasBorder={false} paddingSize="none">
<EuiFlexGroup direction="column">
<EuiFlexItem>
<CreateDataSourceCardView
history={props.history}
featureFlagStatus={featureFlagStatus}
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
</>
) : (
<EuiPanel>
<EuiFlexGroup direction="column">
<EuiFlexItem>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { EuiTab } from '@elastic/eui';
import { DataSourceHomePanel } from './data_source_home_panel';
import { DataSourceTableWithRouter } from '../data_source_table/data_source_table';
import { ManageDirectQueryDataConnectionsTable } from '../direct_query_data_sources_components/direct_query_data_connection/manage_direct_query_data_connections_table';
import { CreateButton } from '../create_button';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import { getListBreadcrumbs } from '../breadcrumbs';
import { navigationPluginMock } from 'src/plugins/navigation/public/mocks';

jest.mock('../../../../opensearch_dashboards_react/public');
jest.mock('../breadcrumbs');
Expand Down Expand Up @@ -42,6 +42,16 @@ describe('DataSourceHomePanel', () => {
savedObjects: {},
uiSettings: {},
application: { capabilities: { dataSource: { canManage: true } } },
docLinks: {
links: {
opensearchDashboards: {
dataSource: {
guide: 'https://opensearch.org/docs/latest/dashboards/discover/multi-data-sources/',
},
},
},
},
navigation: navigationPluginMock.createStartContract(),
},
};

Expand Down
Loading

0 comments on commit cb273fc

Please sign in to comment.