Skip to content

Commit

Permalink
[Discover] support description in data-structures (#9296)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Li <joshuali925@gmail.com>
  • Loading branch information
joshuali925 authored Feb 19, 2025
1 parent 3c90fa3 commit 9787330
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/plugins/data/common/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export interface DataStructure {
title: string;
/** The type of the data structure */
type: string;
/** Optional description of the data structure */
description?: string;
/** Optional reference to the parent data structure */
parent?: DataStructure;
/** Optional array of child data structures */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export class DatasetService {
id: cachedChild.id,
title: cachedChild.title,
type: cachedChild.type,
description: cachedChild.description,
meta: cachedChild.meta,
} as DataStructure;
})
Expand All @@ -209,6 +210,7 @@ export class DatasetService {
id: dataStructure.id,
title: dataStructure.title,
type: dataStructure.type,
description: dataStructure.description,
parent: dataStructure.parent?.id || '',
children: dataStructure.children?.map((child) => child.id) || [],
hasNext: dataStructure.hasNext,
Expand All @@ -225,6 +227,7 @@ export class DatasetService {
id: child.id,
title: child.title,
type: child.type,
description: child.description,
parent: dataStructure.id,
children: [],
meta: child.meta,
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/data/public/ui/dataset_selector/_dataset_table.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

.datasetTable {
&__itemDescription {
white-space: pre;
}
}
1 change: 1 addition & 0 deletions src/plugins/data/public/ui/dataset_selector/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
@import "./dataset_explorer";
@import "./dataset_selector";
@import "./dataset_configurator";
@import "./dataset_table";
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ describe('DataSetTable', () => {
title: 'Parent',
type: 'cluster',
children: [
{ id: 'child1', title: 'Child 1', type: 'index' },
{ id: 'child2', title: 'Child 2', type: 'index' },
{ id: 'child1', title: 'Child 1', description: 'Description 1', type: 'index' },
{ id: 'child2', title: 'Child 2', description: 'Description 2', type: 'index' },
],
paginationToken: 'token',
multiSelect: true,
Expand Down Expand Up @@ -78,6 +78,8 @@ describe('DataSetTable', () => {

expect(screen.getByText('Child 1')).toBeInTheDocument();
expect(screen.getByText('Child 2')).toBeInTheDocument();
expect(screen.getByText('Description 1')).toBeInTheDocument();
expect(screen.getByText('Description 2')).toBeInTheDocument();
expect(screen.getByText('Load more')).toBeInTheDocument();
});

Expand Down
34 changes: 28 additions & 6 deletions src/plugins/data/public/ui/dataset_selector/dataset_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiBasicTable, EuiFieldSearch, EuiLink, EuiText } from '@elastic/eui';
import React, { useRef, useState } from 'react';
import { FormattedMessage } from '@osd/i18n/react';
import { EuiBasicTable, EuiFieldSearch, EuiLink, EuiText, EuiTextColor } from '@elastic/eui';
import { i18n } from '@osd/i18n';
import { FormattedMessage } from '@osd/i18n/react';
import React, { useRef, useState } from 'react';
import { IDataPluginServices } from '../..';
import { DataStructure } from '../../../common';
import { getQueryService } from '../../services';
import { DatasetTypeConfig, DataStructureFetchOptions } from '../../query';
import { IDataPluginServices } from '../..';
import { getQueryService } from '../../services';

interface DatasetTableProps {
services: IDataPluginServices;
Expand Down Expand Up @@ -86,7 +86,29 @@ export const DatasetTable: React.FC<DatasetTableProps> = (props) => {
<EuiBasicTable
items={dataStructures}
itemId="id"
columns={[{ field: 'title', name: 'Name' }]}
columns={[
{
field: 'title',
name: 'Name',
textOnly: true,
render: (title: string, item: DataStructure) => {
return (
<>
<EuiText size="s" className="datasetTable__itemTitle">
{title}
</EuiText>
{item.description && (
<EuiText size="xs" className="eui-textTruncate">
<EuiTextColor color="subdued" className="datasetTable__itemDescription">
{item.description}
</EuiTextColor>
</EuiText>
)}
</>
);
},
},
]}
loading={loading}
isSelectable
selection={{ onSelectionChange }}
Expand Down

0 comments on commit 9787330

Please sign in to comment.