Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Onboarding] Make search_indices index details page as default route in index management #194857

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export interface IndexBadge {
filterExpression?: string;
color: EuiBadgeProps['color'];
}
export interface IndexDetailsPageRoute {
renderRoute: (indexName: string) => string;
}

export interface EmptyListContent {
renderContent: (args: {
Expand Down Expand Up @@ -68,4 +71,6 @@ export interface ExtensionsSetup {
setIndexOverviewContent(content: IndexContent): void;
// sets content to render below the docs link on the mappings tab of the index page
setIndexMappingsContent(content: IndexContent): void;
// sets index details page route
setIndexDetailsPageRoute(route: IndexDetailsPageRoute): void;
}
3 changes: 2 additions & 1 deletion x-pack/plugins/index_management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ This service is exposed from the Index Management setup contract and can be used
- `addToggle(toggle: any)`: adds a toggle to the indices list, for example to display hidden indices
- `addColumn(column: IndicesListColumn)`: adds a column to the indices list, for example to display an ILM phase
- `setEmptyListContent(content: EmptyListContent)`: replaces the default empty prompt displayed when there are no indices in the indices list. The empty list content has the following interface:

```ts
export interface EmptyListContent {
renderContent: (args: {
createIndexButton: ReturnType<FunctionComponent>;
}) => ReturnType<FunctionComponent>;
}
```
- `setIndexDetailsPageRoute`: registers a new route for index details page in indices list table. for example for serverless search users, the indices list page index is navigated to search_indices index detail page


#### Extensions to the indices list and the index details page
- `addAction(action: any)`: adds an option to the "manage index" menu, for example to add an ILM policy to the index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const getColumnConfigs = ({
filterChanged,
extensionsService,
location,
application,
}) => {
const columns = [
{
Expand All @@ -65,17 +66,26 @@ const getColumnConfigs = ({
defaultMessage: 'Name',
}),
order: 10,
render: (index) => (
<>
<EuiLink
data-test-subj="indexTableIndexNameLink"
onClick={() => history.push(getIndexDetailsLink(index.name, location.search || ''))}
>
{index.name}
</EuiLink>
{renderBadges(index, extensionsService, filterChanged)}
</>
),
render: (index) => {
return (
<>
<EuiLink
data-test-subj="indexTableIndexNameLink"
onClick={() => {
if (!extensionsService.indexDetailsPageRoute) {
history.push(getIndexDetailsLink(index.name, location.search || ''));
} else {
const route = extensionsService.indexDetailsPageRoute.renderRoute(index.name);
application.navigateToUrl(route);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work in serverless but in stateful I think you need to prepend the base path.

application.navigateToUrl(http.basePath.prepend(route));

we could do the http.basePath.prepend(route) in the renderRoute function too, we have coreStart available there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work in serverless but in stateful I think you need to prepend the base path.

Curious, why this wouldn't work in stateful ?

}
}}
>
{index.name}
</EuiLink>
{renderBadges(index, extensionsService, filterChanged)}
</>
);
},
},
{
fieldName: 'data_stream',
Expand Down Expand Up @@ -533,15 +543,17 @@ export class IndexTable extends Component {

return (
<AppContextConsumer>
{({ services, config }) => {
{({ services, config, core }) => {
const { extensionsService } = services;
const { application } = core;
const columnConfigs = getColumnConfigs({
showIndexStats: config.enableIndexStats,
showSizeAndDocCount: config.enableSizeAndDocCount,
extensionsService,
filterChanged,
history,
location,
application,
});
const columnsCount = columnConfigs.length + 1;
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const createServiceMock = (): ExtensionsSetupMock => ({
addIndexDetailsTab: jest.fn(),
setIndexOverviewContent: jest.fn(),
setIndexMappingsContent: jest.fn(),
setIndexDetailsPageRoute: jest.fn(),
});

const createMock = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EmptyListContent,
IndexContent,
ExtensionsSetup,
IndexDetailsPageRoute,
} from '@kbn/index-management-shared-types';
import { IndexDetailsTab } from '../../common/constants';

Expand Down Expand Up @@ -48,6 +49,7 @@ export class ExtensionsService {
private _indexDetailsTabs: IndexDetailsTab[] = [];
private _indexOverviewContent: IndexContent | null = null;
private _indexMappingsContent: IndexContent | null = null;
private _indexDetailsPageRoute: IndexDetailsPageRoute | null = null;
private service?: ExtensionsSetup;

public setup(): ExtensionsSetup {
Expand All @@ -62,6 +64,7 @@ export class ExtensionsService {
addIndexDetailsTab: this.addIndexDetailsTab.bind(this),
setIndexOverviewContent: this.setIndexOverviewContent.bind(this),
setIndexMappingsContent: this.setIndexMappingsContent.bind(this),
setIndexDetailsPageRoute: this.setIndexDetailsPageRoute.bind(this),
};

return this.service;
Expand Down Expand Up @@ -118,6 +121,13 @@ export class ExtensionsService {
this._indexMappingsContent = content;
}
}
private setIndexDetailsPageRoute(route: IndexDetailsPageRoute) {
if (this._indexDetailsPageRoute) {
throw new Error(`The route for index details has already been set.`);
} else {
this._indexDetailsPageRoute = route;
}
}

public get actions() {
return this._actions;
Expand Down Expand Up @@ -158,4 +168,7 @@ export class ExtensionsService {
public get indexMappingsContent() {
return this._indexMappingsContent;
}
public get indexDetailsPageRoute() {
return this._indexDetailsPageRoute;
}
}
11 changes: 10 additions & 1 deletion x-pack/plugins/search_indices/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,17 @@ export class SearchIndicesPlugin
};
}

public start(core: CoreStart): SearchIndicesPluginStart {
public start(
core: CoreStart,
deps: SearchIndicesAppPluginStartDependencies
): SearchIndicesPluginStart {
const { indexManagement } = deps;
docLinks.setDocLinks(core.docLinks.links);
indexManagement?.extensionsService.setIndexDetailsPageRoute({
renderRoute: (indexName) => {
return `/app/elasticsearch/indices/index_details/${indexName}`;
},
});
return {};
}

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/search_indices/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface SearchIndicesAppPluginStartDependencies {
cloud?: CloudStart;
share: SharePluginStart;
usageCollection?: UsageCollectionStart;
indexManagement: IndexManagementPluginStart;
}

export interface SearchIndicesServicesContextDeps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await pageObjects.indexManagement.clickCreateIndexSaveButton();
await pageObjects.indexManagement.expectIndexToExist(testIndexName);
});
it('index with no documents', async () => {
await pageObjects.indexManagement.indexDetailsPage.openIndexDetailsPage(0);
await pageObjects.indexManagement.indexDetailsPage.expectIndexDetailsPageIsLoaded();
describe('can view index details', function () {
this.tags(['skipSvlSearch']);
it('index with no documents', async () => {
await pageObjects.indexManagement.indexDetailsPage.openIndexDetailsPage(0);
await pageObjects.indexManagement.indexDetailsPage.expectIndexDetailsPageIsLoaded();
});
});
});
};