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]Fix maximum call stack error in use case service #7817

Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions changelogs/fragments/7817.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- [Workspace] maximum call stack error in use case service ([#7817](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7817))
7 changes: 6 additions & 1 deletion src/plugins/workspace/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ export type Services = CoreStart & {
navigationUI?: NavigationPublicPluginStart['ui'];
};

export interface WorkspaceUseCaseFeature {
id: string;
title?: string;
}

export interface WorkspaceUseCase {
id: string;
title: string;
description: string;
features: Array<{ id: string; title?: string }>;
features: WorkspaceUseCaseFeature[];
systematic?: boolean;
order?: number;
}
32 changes: 32 additions & 0 deletions src/plugins/workspace/public/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,38 @@ describe('workspace utils: isEqualWorkspaceUseCase', () => {
})
).toEqual(false);
});
it('should return false for duplicate features', () => {
expect(
isEqualWorkspaceUseCase(
{ ...useCaseMock, features: [useCaseMock.features[0], useCaseMock.features[0]] },
{
...useCaseMock,
features: [
useCaseMock.features[0],
{
id: 'another',
title: 'Another',
},
],
}
)
).toEqual(false);
});
it('should return true for multi same features', () => {
const anotherFeature = {
id: 'another',
title: 'Another',
};
expect(
isEqualWorkspaceUseCase(
{ ...useCaseMock, features: [useCaseMock.features[0], anotherFeature] },
{
...useCaseMock,
features: [useCaseMock.features[0], anotherFeature],
}
)
).toEqual(true);
});
it('should return true when all properties equal', () => {
expect(
isEqualWorkspaceUseCase(useCaseMock, {
Expand Down
23 changes: 14 additions & 9 deletions src/plugins/workspace/public/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
WorkspaceAvailability,
} from '../../../core/public';
import { DEFAULT_SELECTED_FEATURES_IDS, WORKSPACE_DETAIL_APP_ID } from '../common/constants';
import { WorkspaceUseCase } from './types';
import { WorkspaceUseCase, WorkspaceUseCaseFeature } from './types';
import { formatUrlWithWorkspaceId } from '../../../core/public/utils';
import { SigV4ServiceName } from '../../../plugins/data_source/common/data_sources';

Expand Down Expand Up @@ -260,6 +260,18 @@ export const convertNavGroupToWorkspaceUseCase = ({
order,
});

const compareFeatures = (
features1: WorkspaceUseCaseFeature[],
features2: WorkspaceUseCaseFeature[]
) => {
const featuresSerializer = (features: WorkspaceUseCaseFeature[]) =>
features
.map(({ id, title }) => `${id}-${title}`)
.sort()
.join();
return featuresSerializer(features1) === featuresSerializer(features2);
};

export const isEqualWorkspaceUseCase = (a: WorkspaceUseCase, b: WorkspaceUseCase) => {
if (a.id !== b.id) {
return false;
Expand All @@ -276,14 +288,7 @@ export const isEqualWorkspaceUseCase = (a: WorkspaceUseCase, b: WorkspaceUseCase
if (a.order !== b.order) {
return false;
}
if (
a.features.length !== b.features.length ||
a.features.some((aFeature) =>
b.features.some(
(bFeature) => aFeature.id !== bFeature.id || aFeature.title !== bFeature.title
)
)
) {
if (a.features.length !== b.features.length || !compareFeatures(a.features, b.features)) {
return false;
}
return true;
Expand Down
Loading