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.
refacter workspace template into hooks
Signed-off-by: Hailong Cui <[email protected]>
- Loading branch information
1 parent
2b5e689
commit 80b87af
Showing
2 changed files
with
34 additions
and
18 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
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) { | ||
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)]; | ||
|
||
return { | ||
workspaceTemplates, | ||
templateFeatureMap, | ||
}; | ||
} |