Skip to content

Commit

Permalink
remove render component button and add workspace info in index patter…
Browse files Browse the repository at this point in the history
…n header

Signed-off-by: tygao <[email protected]>
  • Loading branch information
raintygao committed Aug 27, 2024
1 parent 198c2cf commit 620b492
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import { i18n } from '@osd/i18n';
import { IndexPattern } from '../../../data/public';

export function getListBreadcrumbs() {
export function getListBreadcrumbs(currentWorkspaceName?: string) {
return [
{
text: i18n.translate('indexPatternManagement.indexPatterns.listBreadcrumb', {
defaultMessage: 'Index patterns',
defaultMessage: currentWorkspaceName ? 'Workspace index patterns' : 'Index patterns',
}),
href: `/`,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { withRouter, RouteComponentProps } from 'react-router-dom';
import { DocLinksStart } from 'src/core/public';
import { StepIndexPattern } from './components/step_index_pattern';
import { StepTimeField } from './components/step_time_field';
import { Header, Description } from './components/header';
import { Header } from './components/header';
import { LoadingState } from './components/loading_state';

import { context as contextType } from '../../../../opensearch_dashboards_react/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,21 @@ import { EuiPageContent, EuiSpacer, EuiText, EuiFlexItem, EuiFlexGroup } from '@
import { EuiDescriptionListTitle } from '@elastic/eui';
import { EuiDescriptionListDescription, EuiDescriptionList } from '@elastic/eui';
import { EuiLink } from '@elastic/eui';
import { useMount } from 'react-use';
import { getListBreadcrumbs } from '../../breadcrumbs';
import { IndexPatternCreationOption } from '../../types';
import { CreateButton } from '../../create_button';
import { Illustration } from './assets/index_pattern_illustration';
import { ManagementAppMountParams } from '../../../../../management/public';

interface Props {
canSave: boolean;
creationOptions: IndexPatternCreationOption[];
docLinksIndexPatternIntro: string;
setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs'];
}

export const EmptyIndexPatternPrompt = ({
canSave,
creationOptions,
docLinksIndexPatternIntro,
setBreadcrumbs,
}: Props) => {
useMount(() => {
setBreadcrumbs(getListBreadcrumbs());
});

return (
<EuiPageContent
data-test-subj="emptyIndexPatternPrompt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ import { FormattedMessage } from '@osd/i18n/react';
import { withRouter, RouteComponentProps } from 'react-router-dom';
import React, { useState, useEffect } from 'react';
import { i18n } from '@osd/i18n';
import { useEffectOnce, useMount } from 'react-use';
import { useEffectOnce } from 'react-use';
import { useObservable } from 'react-use';
import { of } from 'rxjs';
import {
reactRouterNavigate,
useOpenSearchDashboards,
Expand Down Expand Up @@ -105,6 +107,7 @@ export const IndexPatternTable = ({ canSave, history }: Props) => {
getMlCardState,
data,
dataSourceEnabled,
workspaces,
} = useOpenSearchDashboards<IndexPatternManagmentContext>().services;

const [indexPatterns, setIndexPatterns] = useState<IndexPatternTableItem[]>([]);
Expand All @@ -115,11 +118,13 @@ export const IndexPatternTable = ({ canSave, history }: Props) => {
const [isLoadingIndexPatterns, setIsLoadingIndexPatterns] = useState<boolean>(true);
const [isColumnDataLoaded, setIsColumnDataLoaded] = useState(false);

const currentWorkspace = useObservable(workspaces ? workspaces.currentWorkspace$ : of(null));
const { columns: columnRegistry } = indexPatternManagementStart;

useMount(() => {
setBreadcrumbs(getListBreadcrumbs());
});
const useUpdatedUX = uiSettings.get('home:useNewHomePage');
useEffect(() => {
setBreadcrumbs(getListBreadcrumbs(useUpdatedUX ? currentWorkspace?.name : undefined));
}, [chrome, currentWorkspace, setBreadcrumbs, useUpdatedUX]);

useEffect(() => {
(async function () {
Expand Down Expand Up @@ -219,8 +224,6 @@ export const IndexPatternTable = ({ canSave, history }: Props) => {
}),
];

const showActionsInHeader = uiSettings.get('home:useNewHomePage');

const createButton = (() => {
if (!canSave) return null;

Expand All @@ -233,7 +236,7 @@ export const IndexPatternTable = ({ canSave, history }: Props) => {
</CreateButton>
);

return showActionsInHeader ? (
return useUpdatedUX ? (
<HeaderControl
controls={[{ renderComponent: button }]}
setMountPoint={application.setAppRightControls}
Expand All @@ -243,13 +246,22 @@ export const IndexPatternTable = ({ canSave, history }: Props) => {
);
})();

const description = ((
<FormattedMessage
id="indexPatternManagement.indexPatternTable.indexPatternExplanation"
defaultMessage="Create and manage the index patterns that help you retrieve your data from OpenSearch."
/>
) as unknown) as string;
const pageTitleAndDescription = showActionsInHeader ? (
const description = i18n.translate(
'indexPatternManagement.indexPatternTable.indexPatternExplanation',
currentWorkspace
? {
defaultMessage:
'Create and manage the index patterns that help you retrieve your data from OpenSearch for {name} workspace. ',
values: {
name: currentWorkspace.name,
},
}
: {
defaultMessage:
'Create and manage the index patterns that help you retrieve your data from OpenSearch.',
}
);
const pageTitleAndDescription = useUpdatedUX ? (
<HeaderControl
controls={[{ description }]}
setMountPoint={application.setAppDescriptionControls}
Expand Down Expand Up @@ -291,7 +303,6 @@ export const IndexPatternTable = ({ canSave, history }: Props) => {
canSave={canSave}
creationOptions={creationOptions}
docLinksIndexPatternIntro={docLinks.links.noDocumentation.indexPatterns.introduction}
setBreadcrumbs={setBreadcrumbs}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ export async function mountManagementSection(
dataSource?: DataSourcePluginSetup
) {
const [
{ chrome, application, savedObjects, uiSettings, notifications, overlays, http, docLinks },
{
chrome,
application,
savedObjects,
uiSettings,
notifications,
overlays,
http,
docLinks,
workspaces,
},
{ data, navigation },
indexPatternManagementStart,
] = await getStartServices();
Expand Down Expand Up @@ -94,6 +104,7 @@ export async function mountManagementSection(
getMlCardState,
dataSourceEnabled,
hideLocalCluster,
workspaces,
};

const showActionsInHeader = uiSettings.get('home:useNewHomePage');
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/index_pattern_management/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
DocLinksStart,
HttpSetup,
SavedObjectReference,
WorkspacesStart,
} from 'src/core/public';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { NavigationPublicPluginStart } from 'src/plugins/navigation/public';
Expand All @@ -62,6 +63,7 @@ export interface IndexPatternManagmentContext {
getMlCardState: () => MlCardState;
dataSourceEnabled: boolean;
hideLocalCluster: boolean;
workspaces: WorkspacesStart;
}

export type IndexPatternManagmentContextValue = OpenSearchDashboardsReactContextValue<
Expand Down

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

24 changes: 11 additions & 13 deletions src/plugins/workspace/public/components/workspace_list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,19 @@ export const WorkspaceList = ({ registeredUseCases$ }: WorkspaceListProps) => {
}, [isDashboardAdmin, workspaceCreateUrl]);

const renderCreateWorkspaceButton = () => {
const button = (
<EuiSmallButton
href={workspaceCreateUrl}
key="create_workspace"
data-test-subj="workspaceList-create-workspace"
iconType="plus"
>
{i18n.translate('workspace.list.buttons.createWorkspace', {
defaultMessage: 'Create workspace',
})}
</EuiSmallButton>
);
return (
<HeaderControl
controls={[{ renderComponent: button }]}
controls={[
{
controlType: 'button',
label: i18n.translate('workspace.list.buttons.createWorkspace', {
defaultMessage: 'Create workspace',
}),
testId: 'workspaceList-create-workspace',
iconType: 'plus',
href: workspaceCreateUrl,
},
]}
setMountPoint={application?.setAppRightControls}
/>
);
Expand Down

0 comments on commit 620b492

Please sign in to comment.