Skip to content

Commit

Permalink
feat: merge by title
Browse files Browse the repository at this point in the history
  • Loading branch information
shanexi committed Jan 15, 2025
1 parent e36fe68 commit f3d0b8b
Showing 1 changed file with 52 additions and 15 deletions.
67 changes: 52 additions & 15 deletions web/apps/web/src/stores/app/models/app-builder.model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
type MaterialListType,
type IFlow,
type MaterialListType,
type ReactFlowInstance,
NodeTypeEnum,
WidgetItem,
} from '@shellagent/flow-engine';
import { CustomKey, CustomEventName } from '@shellagent/pro-config';
import { CustomEventName, CustomKey } from '@shellagent/pro-config';
import {
customSnakeCase,
getRefOptions,
Expand All @@ -19,7 +19,7 @@ import {
import { Issue, IssueTypeEnum } from '@shellagent/shared/type';
import type { FieldValues } from '@shellagent/ui';
import { message } from 'antd';
import { injectable, inject } from 'inversify';
import { inject, injectable } from 'inversify';
import { isEmpty } from 'lodash-es';
import {
action,
Expand All @@ -38,36 +38,36 @@ import {
import { AppBuilderChatModel } from '@/components/chat/app-builder-chat.model';
import { SettingsModel } from '@/components/settings/settings.model';
import {
type type_get_local_widget_list_res,
type type_get_myshell_widget_list,
checkIp,
exportApp,
fetchAppVersionList,
fetchAutomata,
fetchFlow,
releaseApp,
exportApp,
checkIp,
saveApp,
getIntroDisplay,
getLocalWidgetList,
type type_get_local_widget_list_res,
type type_get_myshell_widget_list,
getMyShellWidgetList,
releaseApp,
saveApp,
} from '@/services/app';
import type {
GetAppFlowRequest,
GetAppVersionListResponse,
GetAutomataRequest,
} from '@/services/app/type';
import { fetchList as fetchFlowList, editItem } from '@/services/home';
import { editItem, fetchList as fetchFlowList } from '@/services/home';
import type { GetListRequest, GetListResponse } from '@/services/home/type';
import emitter, { EventType } from '@/stores/app/models/emitter';
import {
onDownload,
checkDependency,
LackDependency,
onDownload,
} from '@/stores/app/utils/automata-export';
import {
genNodeData,
genAutomata,
formatReactFlow2Flow,
genAutomata,
genNodeData,
} from '@/stores/app/utils/data-transformer';
import type { Config, Metadata, NodeDataType } from '@/types/app/types';
import { ToastModel } from '@/utils/toast.model';
Expand All @@ -86,7 +86,6 @@ import {
handleRenameRefOpt,
handleReorderTask,
} from './node-data-utils';
import { z } from 'zod';

const settingsDisabled = process.env.NEXT_PUBLIC_DISABLE_SETTING === 'yes';

Expand Down Expand Up @@ -195,7 +194,45 @@ export class AppBuilderModel {
plain: true,
};
});
return LocalWigets.concat(backendLocalWidgets).concat(myshellWidgets);

const mergedWidgets = [...LocalWigets];

// 合并 backendLocalWidgets
backendLocalWidgets.forEach(backendWidget => {
const existingIndex = mergedWidgets.findIndex(
w => w.title === backendWidget.title,
);
if (existingIndex !== -1) {
mergedWidgets[existingIndex] = {
...mergedWidgets[existingIndex],
items: [
...mergedWidgets[existingIndex].items,
...backendWidget.items,
],
};
} else {
mergedWidgets.push(backendWidget);
}
});

// 合并 myshellWidgets
myshellWidgets.forEach(myshellWidget => {
const existingIndex = mergedWidgets.findIndex(
w => w.title === myshellWidget.title,
);
if (existingIndex !== -1) {
mergedWidgets[existingIndex] = {
...mergedWidgets[existingIndex],
items: [
...mergedWidgets[existingIndex].items,
...myshellWidget.items,
],
};
} else {
mergedWidgets.push(myshellWidget);
}
});
return mergedWidgets;
}

copyNodeData: FieldValues = {};
Expand Down

0 comments on commit f3d0b8b

Please sign in to comment.