forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add column service to index pattern & Register data source column (op…
…ensearch-project#2542) Signed-off-by: Kristen Tian <[email protected]> Signed-off-by: Kristen Tian <[email protected]> Signed-off-by: Sergey V. Osipov <[email protected]>
- Loading branch information
1 parent
3bfabf4
commit 3696483
Showing
16 changed files
with
193 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...lugins/data_source_management/public/components/data_source_column/data_source_column.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { i18n } from '@osd/i18n'; | ||
import { HttpStart, SavedObjectsStart } from 'opensearch-dashboards/public'; | ||
import { EuiBadge, EuiLink } from '@elastic/eui'; | ||
import React from 'react'; | ||
import { | ||
IndexPatternTableColumn, | ||
IndexPatternTableRecord, | ||
} from '../../../../index_pattern_management/public'; | ||
import { getDataSources } from '../utils'; | ||
import { DataSourceTableItem } from '../../types'; | ||
|
||
type DataSourceColumnItem = DataSourceTableItem & { relativeUrl: string }; | ||
type DataSourceMap = Map<string, DataSourceColumnItem> | undefined; | ||
|
||
export class DataSourceColumn implements IndexPatternTableColumn<DataSourceMap> { | ||
public readonly id: string = 'data_source'; | ||
public data: DataSourceMap; | ||
|
||
public euiColumn = { | ||
field: 'referenceId', | ||
name: i18n.translate('dataSource.management.dataSourceColumn', { | ||
defaultMessage: 'Data Source', | ||
}), | ||
render: (referenceId: string, index: IndexPatternTableRecord) => { | ||
if (!referenceId) { | ||
return null; | ||
} | ||
|
||
const dataSource = this.data?.get(referenceId); | ||
if (!dataSource) { | ||
// Index pattern has the referenceId but data source not found. | ||
return <EuiBadge color="danger">Deleted</EuiBadge>; | ||
} | ||
|
||
const { title, relativeUrl } = dataSource; | ||
return <EuiLink href={relativeUrl}>{title}</EuiLink>; | ||
}, | ||
}; | ||
|
||
constructor( | ||
private readonly savedObjectPromise: Promise<SavedObjectsStart>, | ||
private readonly httpPromise: Promise<HttpStart> | ||
) {} | ||
|
||
public loadData = async () => { | ||
const savedObject = await this.savedObjectPromise; | ||
const { basePath } = await this.httpPromise; | ||
|
||
return getDataSources(savedObject.client).then((dataSources?: DataSourceTableItem[]) => { | ||
this.data = dataSources | ||
?.map((dataSource) => { | ||
return { | ||
...dataSource, | ||
relativeUrl: basePath.prepend( | ||
`/app/management/opensearch-dashboards/dataSources/${encodeURIComponent( | ||
dataSource.id | ||
)}` | ||
), | ||
}; | ||
}) | ||
?.reduce( | ||
(map, dataSource) => map.set(dataSource.id, dataSource), | ||
new Map<string, DataSourceColumnItem>() | ||
); | ||
return this.data; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/plugins/index_pattern_management/public/components/__snapshots__/utils.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/plugins/index_pattern_management/public/service/column_service/column_service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { IndexPatternTableColumn } from '../../types'; | ||
|
||
export interface IndexPatternTableColumnServiceSetup { | ||
/** | ||
* register given column in the registry. | ||
*/ | ||
register: (column: IndexPatternTableColumn<unknown>) => void; | ||
} | ||
|
||
export interface IndexPatternTableColumnServiceStart { | ||
/** | ||
* return all {@link IndexPatternTableColumn | columns} currently registered. | ||
*/ | ||
getAll: () => Array<IndexPatternTableColumn<unknown>>; | ||
} | ||
|
||
export class IndexPatternTableColumnService { | ||
private readonly columns = new Map<string, IndexPatternTableColumn<unknown>>(); | ||
|
||
setup(): IndexPatternTableColumnServiceSetup { | ||
return { | ||
register: (column) => { | ||
if (this.columns.has(column.id)) { | ||
throw new Error(`Index Pattern Table Column with id '${column.id}' already exists`); | ||
} | ||
this.columns.set(column.id, column); | ||
}, | ||
}; | ||
} | ||
|
||
start(): IndexPatternTableColumnServiceStart { | ||
return { | ||
getAll: () => [...this.columns.values()], | ||
}; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/plugins/index_pattern_management/public/service/column_service/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './column_service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.