Skip to content

Commit

Permalink
1. Fix UI bugs
Browse files Browse the repository at this point in the history
2.add defult selected group
  • Loading branch information
a793181018 committed Nov 18, 2024
1 parent d53bd0c commit 33908bd
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 36 deletions.
69 changes: 38 additions & 31 deletions gui-sidebar/src/pages/codeContextPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,13 @@ const CodeContextPanel: React.FC = () => {
useWebviewListener("WorkspaceService_Groups_GetGroups", async (data) => {
if (data.groups) {
const parsedGroups = jsonToGroups(data.groups);
console.log("WorkspaceService_Groups_GetGroups");
for (const group of parsedGroups) {
console.log(group.name);
console.log(group);
console.log(group.itemMap);

}
setGroups(parsedGroups);
ideRequest("WorkspaceService.Groups.GetSelectedGroupName","");
}
});
useWebviewListener("WorkspaceService_Groups_GetSelectedGroupName", async (data) => {
if (data.groupName) {
setSelectedGroup(data.groupName);
}
});

Expand Down Expand Up @@ -538,26 +537,31 @@ const CodeContextPanel: React.FC = () => {
/>
<h3>编组名称: {group.name}</h3>
<div>
{Array.from(group.itemMap.entries()).map(([type, ids]) => (
<div key={type}>
<h4>{type === 'CodeSample' ? '代码样例' : '代码上下文'}</h4>
<ul>
{ids.map((id, itemIndex) => {
const itemInfo = getItemById(id);
if (!itemInfo) return null;
const { item } = itemInfo;
return (
<li key={itemIndex}>
<h5>文件路径: {item.filePath}</h5>
<CodeContent>{item.code}</CodeContent>
<p>说明: {item.doc}</p>
</li>
);
})}
</ul>
</div>
))}
</div>
{Array.from(group.itemMap.entries()).map(([type, ids]) => {
if (ids.length > 0) {
return (
<div key={type}>
<h4>{type === 'CodeSample' ? '代码样例' : '代码上下文'}</h4>
<ul>
{ids.map((id, itemIndex) => {
const itemInfo = getItemById(id);
if (!itemInfo) return null;
const { item } = itemInfo;
return (
<li key={itemIndex}>
<h5>文件路径: {item.filePath}</h5>
<CodeContent>{item.code}</CodeContent>
<p>说明: {item.doc}</p>
</li>
);
})}
</ul>
</div>
);
}
return null;
})}
</div>
<Actions>
<Button onClick={() => deleteGroup(groupIndex)}>删除编组</Button>
</Actions>
Expand Down Expand Up @@ -603,7 +607,8 @@ function jsonToGroups(jsonString: string): Group[] {
const itemMap = new Map<string, string[]>();

Object.keys(groupData).forEach(key => {
itemMap.set(key, groupData[key].map(String));
if(groupData[key].length>0)
{ itemMap.set(key, groupData[key].map(String));}
});

return {
Expand All @@ -616,12 +621,14 @@ function jsonToGroups(jsonString: string): Group[] {
}
function GroupToJson(group: Group): string {
const groupData: { [key: string]: { [key: string]: string[] } } = {};

groupData[group.name] = {};

group.itemMap.forEach((ids, type) => {
groupData[group.name][type] = ids;
if(ids.length>0)
{ groupData[group.name][type] = ids;}
});

return JSON.stringify(groupData);
}



3 changes: 2 additions & 1 deletion gui-sidebar/src/shims/webviewProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type WebviewProtocol = Protocol &
'WorkspaceService.Groups.RemoveGroup':[{group:string}, string];
'WorkspaceService.Groups.GetGroups':[string, string[]];
'WorkspaceService.Groups.SelectGroup':[{groupName:string}, string];
'WorkspaceService.Groups.GetSelectedGroupName':[string, string]

};

Expand Down Expand Up @@ -124,5 +125,5 @@ export type ReverseWebviewProtocol = {
WorkspaceService_ChangeDataStorage: [{key:string;originalItem:string;newItem:string},string];
WorkspaceService_GetDataStorage: [{key:string;language:string;storages:string},void];
WorkspaceService_Groups_GetGroups: [{groups:string},void];

WorkspaceService_Groups_GetSelectedGroupName: [{groupName:string},void];
};
7 changes: 5 additions & 2 deletions src/base/common/workspace/DataStorageGroupManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class DataStorageGroupManager {

private async loadGroupsFromDatabase() {
const rows = await this.queryDatabase(`SELECT * FROM Groups`);
this._selectedGroupName=rows[0].name;
rows.forEach(row => {
const groupName = row.name;
const groupJson = JSON.parse(row.groupJson);
Expand Down Expand Up @@ -146,7 +147,9 @@ export class DataStorageGroupManager {
public SetSelectedGroup(groupName: string) {
this._selectedGroupName = groupName;
}

public GetSelectedGroupName(): string {
return this._selectedGroupName;
}

private async saveGroupToDatabase(group: string, groupMap: Map<string, number[]>) {
const groupJson = JSON.stringify(Object.fromEntries(groupMap));
Expand Down Expand Up @@ -176,7 +179,7 @@ export class DataStorageGroupManager {
}


export interface GroupMormat {
export interface GroupFormat {
name: string;
items: string;
}
Expand Down
6 changes: 6 additions & 0 deletions src/editor/views/chat/continue/continueMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ string
'WorkspaceService.Groups.SelectGroup',
{groupName:string},
string
>;

'WorkspaceService.Groups.GetSelectedGroupName':WebviewMessageBuilder<
'WorkspaceService.Groups.GetSelectedGroupName',
{groupName:string},
string
>;
// Actions
applyToCurrentFile: WebviewMessageBuilder<
Expand Down
13 changes: 11 additions & 2 deletions src/editor/views/chat/continue/continueViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
} from './continueMessages';
import { data } from 'node_modules/cheerio/dist/commonjs/api/attributes';
import { FrameworkCodeFragment } from 'src/code-context/_base/LanguageModel/ClassElement/FrameworkCodeFragmentExtractorBase';
import { Group, GroupMormat, JsonToGroup, MapToObject } from 'base/common/workspace/DataStorageGroupManager';
import { Group, JsonToGroup, MapToObject } from 'base/common/workspace/DataStorageGroupManager';

export class ContinueViewProvider extends AbstractWebviewViewProvider implements WebviewViewProvider {
private historySaveDir = path.join(os.homedir(), '.autodev/sessions');
Expand Down Expand Up @@ -278,7 +278,10 @@ export class ContinueViewProvider extends AbstractWebviewViewProvider implements
if (language) {
const group: Group =JsonToGroup(payload.data.data);
for (let [key, value] of group.items) {
await this.workSpace.DataStorageGroupManager?.AddGroupItems(group.name,key,value);
if(value.length>0)
{
await this.workSpace.DataStorageGroupManager?.AddGroupItems(group.name,key,value);
}
}
}
break;
Expand All @@ -302,6 +305,12 @@ export class ContinueViewProvider extends AbstractWebviewViewProvider implements
this.workSpace.DataStorageGroupManager?.SetSelectedGroup(payload.data.groupName);
}
break;
case 'WorkspaceService.Groups.GetSelectedGroupName':
if (language) {
let data= this.workSpace.DataStorageGroupManager?.GetSelectedGroupName();
this.send('WorkspaceService_Groups_GetSelectedGroupName', {groupName:data});
}
break;
default:
logger.debug('(continue): Unknown webview protocol msg: ', payload);
}
Expand Down

0 comments on commit 33908bd

Please sign in to comment.