Skip to content

Commit

Permalink
feat: optimize code
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Feb 29, 2024
1 parent 9ebadcd commit ed4126a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
7 changes: 0 additions & 7 deletions src/core/server/saved_objects/service/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,4 @@ export class SavedObjectsUtils {
total: 0,
saved_objects: [],
});

public static filterWorkspacesAccordingToSourceWorkspaces(
targetWorkspaces?: string[],
baseWorkspaces?: string[]
): string[] {
return targetWorkspaces?.filter((item) => !baseWorkspaces?.includes(item)) || [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import {

const errorContent = (error: Boom.Boom) => error.output.payload;

const filterWorkspacesAccordingToSourceWorkspaces = (
targetWorkspaces?: string[],
baseWorkspaces?: string[]
): string[] => targetWorkspaces?.filter((item) => !baseWorkspaces?.includes(item)) || [];

export class WorkspaceConflictSavedObjectsClientWrapper {
private _serializer?: SavedObjectsSerializer;
public setSerializer(serializer: SavedObjectsSerializer) {
Expand Down Expand Up @@ -53,10 +58,7 @@ export class WorkspaceConflictSavedObjectsClientWrapper {
}
if (currentItem) {
if (
SavedObjectsUtils.filterWorkspacesAccordingToSourceWorkspaces(
workspaces,
currentItem.workspaces
).length
filterWorkspacesAccordingToSourceWorkspaces(workspaces, currentItem.workspaces).length
) {
throw SavedObjectsErrorHelpers.createConflictError(type, id);
} else {
Expand Down Expand Up @@ -112,7 +114,7 @@ export class WorkspaceConflictSavedObjectsClientWrapper {
* We need to check if the options.workspaces is the subset of object.workspaces,
* Or it will be treated as a conflict
*/
const filteredWorkspaces = SavedObjectsUtils.filterWorkspacesAccordingToSourceWorkspaces(
const filteredWorkspaces = filterWorkspacesAccordingToSourceWorkspaces(
options.workspaces,
object.workspaces
);
Expand Down Expand Up @@ -229,7 +231,7 @@ export class WorkspaceConflictSavedObjectsClientWrapper {
*/
if (!object.error) {
let workspaceConflict = false;
const filteredWorkspaces = SavedObjectsUtils.filterWorkspacesAccordingToSourceWorkspaces(
const filteredWorkspaces = filterWorkspacesAccordingToSourceWorkspaces(
options.workspaces,
object.workspaces
);
Expand Down

0 comments on commit ed4126a

Please sign in to comment.