Skip to content

Commit

Permalink
Fix index management link issue for both stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Samiul-TheSoccerFan committed Nov 14, 2024
1 parent 6550193 commit 43f8d50
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 79 deletions.
21 changes: 4 additions & 17 deletions x-pack/plugins/search_inference_endpoints/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,9 @@
"id": "searchInferenceEndpoints",
"server": true,
"browser": true,
"configPath": [
"xpack",
"searchInferenceEndpoints"
],
"requiredPlugins": [
"actions",
"features",
"ml",
"share",
],
"optionalPlugins": [
"cloud",
"console",
],
"requiredBundles": [
"kibanaReact"
]
"configPath": ["xpack", "searchInferenceEndpoints"],
"requiredPlugins": ["actions", "features", "ml", "share"],
"optionalPlugins": ["cloud", "console", "serverless"],
"requiredBundles": ["kibanaReact"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const DEFAULT_INFERENCE_ENDPOINTS_TABLE_STATE: AllInferenceEndpointsTable
};

export const PIPELINE_URL = 'ingest/ingest_pipelines';
export const SERVERLESS_INDEX_MANAGEMENT_URL = 'index_details';

export const PRECONFIGURED_ENDPOINTS = {
ELSER: '.elser-2-elasticsearch',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { render, fireEvent, screen } from '@testing-library/react';
import React from 'react';

import { IndexItem } from './index_item';
import { InferenceUsageInfo } from '../../../../types';
import { useKibana } from '../../../../../../hooks/use_kibana';

jest.mock('../../../../../../hooks/use_kibana');
const mockUseKibana = useKibana as jest.Mock;
const mockNavigateToApp = jest.fn();

describe('Index Item', () => {
const item: InferenceUsageInfo = {
id: 'index-1',
type: 'Index',
};
beforeEach(() => {
mockUseKibana.mockReturnValue({
services: {
application: {
navigateToApp: mockNavigateToApp,
},
},
});

render(<IndexItem usageItem={item} />);
});

it('renders', () => {
expect(screen.getByText('index-1')).toBeInTheDocument();
expect(screen.getByText('Index')).toBeInTheDocument();
});

it('opens index in a new tab', () => {
fireEvent.click(screen.getByRole('button'));
expect(mockNavigateToApp).toHaveBeenCalledWith('enterpriseSearchContent', {
openInNewTab: true,
path: 'search_indices/index-1',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,29 @@ import {
} from '@elastic/eui';
import React from 'react';
import { ENTERPRISE_SEARCH_CONTENT_APP_ID } from '@kbn/deeplinks-search';
import { MANAGEMENT_APP_ID } from '@kbn/deeplinks-management/constants';

import { SEARCH_INDICES } from '@kbn/deeplinks-search/constants';

import { useKibana } from '../../../../../../hooks/use_kibana';
import { InferenceUsageInfo } from '../../../../types';
import { PIPELINE_URL } from '../../../../constants';
import { SERVERLESS_INDEX_MANAGEMENT_URL } from '../../../../constants';

interface UsageProps {
usageItem: InferenceUsageInfo;
}
export const UsageItem: React.FC<UsageProps> = ({ usageItem }) => {
export const IndexItem: React.FC<UsageProps> = ({ usageItem }) => {
const {
services: { application },
services: { application, serverless },
} = useKibana();
const handleNavigateToIndex = () => {
if (usageItem.type === 'Index') {
application?.navigateToApp(ENTERPRISE_SEARCH_CONTENT_APP_ID, {
path: `search_indices/${usageItem.id}`,
const navigateToIndex = async () => {
if (serverless) {
application?.navigateToApp(SEARCH_INDICES, {
path: `${SERVERLESS_INDEX_MANAGEMENT_URL}/${usageItem.id}/data`,
openInNewTab: true,
});
} else if (usageItem.type === 'Pipeline') {
application?.navigateToApp(MANAGEMENT_APP_ID, {
path: `${PIPELINE_URL}?pipeline=${usageItem.id}`,
} else {
application?.navigateToApp(ENTERPRISE_SEARCH_CONTENT_APP_ID, {
path: `search_indices/${usageItem.id}`,
openInNewTab: true,
});
}
Expand All @@ -62,9 +63,9 @@ export const UsageItem: React.FC<UsageProps> = ({ usageItem }) => {
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiLink data-test-subj="navigateToIndexPage" onClick={handleNavigateToIndex}>
<EuiLink data-test-subj="navigateToIndexPage" onClick={navigateToIndex}>
<EuiIcon size="s" type="popout" />
</EuiLink>
</EuiLink>{' '}
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { EuiFieldSearch, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';

import { InferenceUsageInfo } from '../../../../types';
import * as i18n from '../delete/confirm_delete_endpoint/translations';
import { UsageItem } from './usage_item';
import { IndexItem } from './index_item';
import { PipelineItem } from './pipeline_item';

interface ListUsageResultsProps {
list: InferenceUsageInfo[];
Expand All @@ -35,9 +36,13 @@ export const ListUsageResults: React.FC<ListUsageResultsProps> = ({ list }) => {
<EuiFlexItem>
{list
.filter((item) => item.id.toLowerCase().includes(term.toLowerCase()))
.map((item, id) => (
<UsageItem usageItem={item} key={id} />
))}
.map((item, id) => {
if (item.type === 'Pipeline') {
return <PipelineItem usageItem={item} key={id} />;
} else {
return <IndexItem usageItem={item} key={id} />;
}
})}
</EuiFlexItem>
</EuiFlexGroup>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
import { render, fireEvent, screen } from '@testing-library/react';
import React from 'react';

import { UsageItem } from './usage_item';
import { PipelineItem } from './pipeline_item';
import { InferenceUsageInfo } from '../../../../types';
import { useKibana } from '../../../../../../hooks/use_kibana';

jest.mock('../../../../../../hooks/use_kibana');
const mockUseKibana = useKibana as jest.Mock;
const mockNavigateToApp = jest.fn();

describe('UsageItem', () => {
describe('Pipeline item', () => {
const item: InferenceUsageInfo = {
id: 'pipeline-1',
type: 'Pipeline',
};
beforeEach(() => {
mockUseKibana.mockReturnValue({
services: {
Expand All @@ -25,41 +29,10 @@ describe('UsageItem', () => {
},
},
});
});

describe('index', () => {
const item: InferenceUsageInfo = {
id: 'index-1',
type: 'Index',
};

beforeEach(() => {
render(<UsageItem usageItem={item} />);
});

it('renders', () => {
expect(screen.getByText('index-1')).toBeInTheDocument();
expect(screen.getByText('Index')).toBeInTheDocument();
});

it('opens index in a new tab', () => {
fireEvent.click(screen.getByRole('button'));
expect(mockNavigateToApp).toHaveBeenCalledWith('enterpriseSearchContent', {
openInNewTab: true,
path: 'search_indices/index-1',
});
});
render(<PipelineItem usageItem={item} />);
});

describe('pipeline', () => {
const item: InferenceUsageInfo = {
id: 'pipeline-1',
type: 'Pipeline',
};

beforeEach(() => {
render(<UsageItem usageItem={item} />);
});
it('renders', () => {
expect(screen.getByText('pipeline-1')).toBeInTheDocument();
expect(screen.getByText('Pipeline')).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import {
EuiBadge,
EuiFlexGroup,
EuiFlexItem,
EuiHorizontalRule,
EuiLink,
EuiText,
EuiTextTruncate,
EuiIcon,
EuiSpacer,
} from '@elastic/eui';
import React from 'react';
import { MANAGEMENT_APP_ID } from '@kbn/deeplinks-management/constants';

import { useKibana } from '../../../../../../hooks/use_kibana';
import { InferenceUsageInfo } from '../../../../types';
import { PIPELINE_URL } from '../../../../constants';

interface UsageProps {
usageItem: InferenceUsageInfo;
}
export const PipelineItem: React.FC<UsageProps> = ({ usageItem }) => {
const {
services: { application },
} = useKibana();
const navigateToPipeline = () => {
application?.navigateToApp(MANAGEMENT_APP_ID, {
path: `${PIPELINE_URL}?pipeline=${usageItem.id}`,
openInNewTab: true,
});
};

return (
<EuiFlexGroup gutterSize="s" direction="column" data-test-subj="usageItem">
<EuiFlexItem grow={false}>
<EuiFlexGroup>
<EuiFlexItem>
<EuiFlexGroup gutterSize="xs" justifyContent="spaceBetween">
<EuiFlexItem>
<EuiText size="s">
<EuiTextTruncate text={usageItem.id} />
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiBadge color="hollow">{usageItem.type}</EuiBadge>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiLink data-test-subj="navigateToPipelinePage" onClick={navigateToPipeline}>
<EuiIcon size="s" type="popout" />
</EuiLink>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem>
<EuiHorizontalRule margin="none" />
<EuiSpacer size="s" />
</EuiFlexItem>
</EuiFlexGroup>
);
};
5 changes: 5 additions & 0 deletions x-pack/plugins/search_inference_endpoints/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { AppMountParameters } from '@kbn/core/public';
import { MlPluginStart } from '@kbn/ml-plugin/public';
import { SharePluginStart } from '@kbn/share-plugin/public';
import React from 'react';

import { ServerlessPluginStart } from '@kbn/serverless/public';
import type { App } from './components/app';
import type { InferenceEndpointsProvider } from './providers/inference_endpoints_provider';

Expand All @@ -27,12 +29,15 @@ export interface AppPluginStartDependencies {
history: AppMountParameters['history'];
share: SharePluginStart;
console?: ConsolePluginStart;
serverless?: ServerlessPluginStart;
}

export interface AppServicesContext {
http: HttpStart;
ml?: MlPluginStart;
console?: ConsolePluginStart;
serverless?: ServerlessPluginStart;
share: SharePluginStart;
}

export interface InferenceUsageResponse {
Expand Down
16 changes: 5 additions & 11 deletions x-pack/plugins/search_inference_endpoints/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"outDir": "target/types"
},
"include": [
"__mocks__/**/*",
"common/**/*",
"public/**/*",
"server/**/*"
],
"include": ["__mocks__/**/*", "common/**/*", "public/**/*", "server/**/*"],
"kbn_references": [
"@kbn/config-schema",
"@kbn/core",
Expand All @@ -33,9 +28,8 @@
"@kbn/features-plugin",
"@kbn/ui-theme",
"@kbn/deeplinks-search",
"@kbn/deeplinks-management"
"@kbn/deeplinks-management",
"@kbn/serverless"
],
"exclude": [
"target/**/*",
]
"exclude": ["target/**/*"]
}

0 comments on commit 43f8d50

Please sign in to comment.