-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
1 deletion.
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
65 changes: 65 additions & 0 deletions
65
src/workbench/browser/src/app/modules/extension-select/import-api/old2new.ts
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,65 @@ | ||
import type { ImportProjectDto } from 'eo/workbench/browser/src/app/shared/services/storage/db/dto/project.dto'; | ||
|
||
import { convertApiData } from './../../../shared/services/storage/db/dataSource/convert'; | ||
|
||
export const old2new = (params, projectUuid, workSpaceUuid): ImportProjectDto => { | ||
const { collections = [], environments } = params; | ||
|
||
const environmentList = environments.map(n => ({ | ||
name: n.name, | ||
hostUri: n.hostUri, | ||
parameters: n.parameters, | ||
projectUuid, | ||
workSpaceUuid | ||
})); | ||
|
||
const genId = () => crypto.getRandomValues(new Uint32Array(1))[0]; | ||
|
||
const genGroup = (name, parentId?) => { | ||
return { | ||
name, | ||
parentId, | ||
id: genId(), | ||
type: 1, | ||
projectUuid, | ||
workSpaceUuid, | ||
children: [] | ||
}; | ||
}; | ||
|
||
const rootGroup = genGroup(collections[0].name); | ||
|
||
const apiList = []; | ||
const groupList = [rootGroup]; | ||
|
||
const formatData = (collections = [], parentGroup) => { | ||
collections.forEach(item => { | ||
// API | ||
if (item.uri) { | ||
const newApiData = convertApiData(item); | ||
newApiData.groupId = parentGroup.id; | ||
apiList.push(newApiData); | ||
} | ||
// 分组 | ||
else { | ||
const group = genGroup(item.name, parentGroup.id); | ||
|
||
parentGroup.children.push(group); | ||
|
||
if (item.children?.length) { | ||
formatData(item.children, group); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
collections[0].id = genId(); | ||
formatData(collections[0]?.children, groupList[0]); | ||
|
||
return { | ||
name: 'Default', | ||
apiList, | ||
groupList, | ||
environmentList | ||
}; | ||
}; |
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