Skip to content

Commit

Permalink
Dashboard Lists Integration (#3090)
Browse files Browse the repository at this point in the history
* Dashboard-List Integration
* Plugins register their links with registerDashboardProvider API

Signed-off-by: Peter Fitzgibbons <pjfitz@amazon.com>

* Update CHANGELOG.md

Signed-off-by: Josh Romero <rmerqg@amazon.com>

---------

Signed-off-by: Peter Fitzgibbons <pjfitz@amazon.com>
Signed-off-by: Josh Romero <rmerqg@amazon.com>
Co-authored-by: Peter Fitzgibbons <pjfitz@amazon.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
(cherry picked from commit d2bd318)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
github-actions[bot] committed Mar 30, 2023
1 parent 6754c4d commit e665f9f
Show file tree
Hide file tree
Showing 14 changed files with 1,063 additions and 49 deletions.
6 changes: 3 additions & 3 deletions src/plugins/dashboard/public/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
AppMountParameters,
} from 'opensearch-dashboards/public';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/public';
import { DashboardProvider } from 'src/plugins/dashboard/public/types';
import { Storage } from '../../../opensearch_dashboards_utils/public';
// @ts-ignore
import { initDashboardApp } from './legacy_app';
Expand All @@ -71,6 +72,7 @@ export interface RenderDeps {
navigation: NavigationStart;
savedObjectsClient: SavedObjectsClientContract;
savedDashboards: SavedObjectLoader;
dashboardProviders: () => { [key: string]: DashboardProvider };
dashboardConfig: OpenSearchDashboardsLegacyStart['dashboardConfig'];
dashboardCapabilities: any;
embeddableCapabilities: {
Expand All @@ -79,7 +81,6 @@ export interface RenderDeps {
};
uiSettings: IUiSettingsClient;
chrome: ChromeStart;
addBasePath: (path: string) => string;
savedQueryService: DataPublicPluginStart['query']['savedQueries'];
embeddable: EmbeddableStart;
localStorage: Storage;
Expand Down Expand Up @@ -141,12 +142,11 @@ function createLocalAngularModule() {
createLocalI18nModule();
createLocalIconModule();

const dashboardAngularModule = angular.module(moduleName, [
return angular.module(moduleName, [
...thirdPartyAngularDependencies,
'app/dashboard/I18n',
'app/dashboard/icon',
]);
return dashboardAngularModule;
}

function createLocalIconModule() {
Expand Down
48 changes: 41 additions & 7 deletions src/plugins/dashboard/public/application/legacy_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ export function initDashboardApp(app, deps) {
app.directive('dashboardListing', function (reactDirective) {
return reactDirective(DashboardListing, [
['core', { watchDepth: 'reference' }],
['dashboardProviders', { watchDepth: 'reference' }],
['createItem', { watchDepth: 'reference' }],
['getViewUrl', { watchDepth: 'reference' }],
['editItem', { watchDepth: 'reference' }],
['viewItem', { watchDepth: 'reference' }],
['findItems', { watchDepth: 'reference' }],
['deleteItems', { watchDepth: 'reference' }],
['listingLimit', { watchDepth: 'reference' }],
Expand Down Expand Up @@ -127,14 +128,47 @@ export function initDashboardApp(app, deps) {
$scope.create = () => {
history.push(DashboardConstants.CREATE_NEW_DASHBOARD_URL);
};
$scope.find = (search) => {
return service.find(search, $scope.listingLimit);
$scope.dashboardProviders = deps.dashboardProviders() || [];
$scope.dashboardListTypes = Object.keys($scope.dashboardProviders);

const mapListAttributesToDashboardProvider = (obj) => {
const provider = $scope.dashboardProviders[obj.type];
return {
id: obj.id,
appId: provider.appId,
type: provider.savedObjectsName,
...obj.attributes,
updated_at: obj.updated_at,
viewUrl: provider.viewUrlPathFn(obj),
editUrl: provider.editUrlPathFn(obj),
};
};
$scope.editItem = ({ id }) => {
history.push(`${createDashboardEditUrl(id)}?_a=(viewMode:edit)`);

$scope.find = async (search) => {
const savedObjectsClient = deps.savedObjectsClient;

const res = await savedObjectsClient.find({
type: $scope.dashboardListTypes,
search: search ? `${search}*` : undefined,
fields: ['title', 'type', 'description', 'updated_at'],
perPage: $scope.initialPageSize,
page: 1,
searchFields: ['title^3', 'type', 'description'],
defaultSearchOperator: 'AND',
});
const list = res.savedObjects?.map(mapListAttributesToDashboardProvider) || [];

return {
total: list.length,
hits: list,
};
};

$scope.editItem = ({ editUrl }) => {
history.push(deps.addBasePath(editUrl));
};
$scope.getViewUrl = ({ id }) => {
return deps.addBasePath(`#${createDashboardEditUrl(id)}`);
$scope.viewItem = ({ viewUrl }) => {
history.push(deps.addBasePath(viewUrl));
};
$scope.delete = (dashboards) => {
return service.delete(dashboards.map((d) => d.id));
Expand Down
Loading

0 comments on commit e665f9f

Please sign in to comment.