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

workspace template init commit #6

Merged
merged 4 commits into from
Jun 12, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refacter workspace template into hooks
Signed-off-by: Hailong Cui <ihailong@amazon.com>
  • Loading branch information
Hailong-am committed Jun 9, 2023
commit b84a894485b614dfd7123185646127d447c31b98
32 changes: 32 additions & 0 deletions src/plugins/workspace/public/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { ApplicationStart, PublicAppInfo } from 'opensearch-dashboards/public';
import { WorkspaceTemplate } from '../../../core/types';

export function useWorkspaceTemplate(application: ApplicationStart) {
Hailong-am marked this conversation as resolved.
Show resolved Hide resolved
let workspaceTemplates = [] as WorkspaceTemplate[];
const templateFeatureMap = new Map<string, PublicAppInfo[]>();

application.applications$.subscribe((applications) =>
applications.forEach((app) => {
const { workspaceTemplate: templates = [] } = app;
workspaceTemplates.push(...templates);
for (const template of templates) {
const features = templateFeatureMap.get(template.id) || [];
features.push(app);
templateFeatureMap.set(template.id, features);
}
})
);

workspaceTemplates.sort((a, b) => (a.order || 0) - (b.order || 0));
workspaceTemplates = [...new Set(workspaceTemplates)];
Hailong-am marked this conversation as resolved.
Show resolved Hide resolved

return {
workspaceTemplates,
templateFeatureMap,
};
}