Skip to content

Commit 02ee1a2

Browse files
authored
Merge pull request #473 from easyops-cn/steve/sidebar
feat(): support customize personal dropdown actions
2 parents c81afe4 + 94e7e98 commit 02ee1a2

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

bricks/ai-portal/src/elevo-sidebar/ChatHistory.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ export interface ProjectActionClickDetail {
5858
project: Project;
5959
}
6060

61+
export interface PersonalActionClickDetail {
62+
action: SimpleActionType;
63+
}
64+
6165
export interface Project {
6266
/** 实例ID */
6367
instanceId: string;

bricks/ai-portal/src/elevo-sidebar/index.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
ChatHistory,
3131
type ActionClickDetail,
3232
type ChatHistoryRef,
33+
type PersonalActionClickDetail,
3334
type Project,
3435
type ProjectActionClickDetail,
3536
} from "./ChatHistory.js";
@@ -60,6 +61,7 @@ export interface ElevoSidebarProps {
6061
projectActiveId?: string;
6162
projectUrlTemplate?: string;
6263
projectActions?: ActionType[];
64+
personalActions?: ActionType[];
6365
links?: SidebarLink[];
6466
canAddProject?: boolean;
6567
myLinks?: SidebarLink[];
@@ -111,6 +113,9 @@ class ElevoSidebar extends ReactNextElement implements ElevoSidebarProps {
111113
@property({ attribute: false })
112114
accessor projectActions: ActionType[] | undefined;
113115

116+
@property({ attribute: false })
117+
accessor personalActions: ActionType[] | undefined;
118+
114119
@property({ attribute: false })
115120
accessor links: SidebarLink[] | undefined;
116121

@@ -170,6 +175,16 @@ class ElevoSidebar extends ReactNextElement implements ElevoSidebarProps {
170175
this.#addServiceflow.emit();
171176
};
172177

178+
/**
179+
* 点击项目操作按钮时触发
180+
*/
181+
@event({ type: "personal.action.click" })
182+
accessor #personalActionClick!: EventEmitter<PersonalActionClickDetail>;
183+
184+
#handlePersonalActionClick = (detail: PersonalActionClickDetail) => {
185+
this.#personalActionClick.emit(detail);
186+
};
187+
173188
#ref = createRef<ElevoSidebarRef>();
174189

175190
/**
@@ -221,6 +236,7 @@ class ElevoSidebar extends ReactNextElement implements ElevoSidebarProps {
221236
historyActions={this.historyActions}
222237
projectUrlTemplate={this.projectUrlTemplate}
223238
projectActions={this.projectActions}
239+
personalActions={this.personalActions}
224240
links={this.links}
225241
canAddProject={this.canAddProject}
226242
myLinks={this.myLinks}
@@ -231,6 +247,7 @@ class ElevoSidebar extends ReactNextElement implements ElevoSidebarProps {
231247
onProjectActionClick={this.#handleProjectActionClick}
232248
onAddProject={this.#handleAddProject}
233249
onAddServiceflow={this.#handleAddServiceflow}
250+
onPersonalActionClick={this.#handlePersonalActionClick}
234251
/>
235252
);
236253
}
@@ -242,6 +259,7 @@ interface ElevoSidebarComponentProps extends ElevoSidebarProps {
242259
onProjectActionClick: (detail: ProjectActionClickDetail) => void;
243260
onAddProject: () => void;
244261
onAddServiceflow: () => void;
262+
onPersonalActionClick: (detail: PersonalActionClickDetail) => void;
245263
}
246264

247265
function LegacyElevoSidebarComponent(
@@ -260,11 +278,13 @@ function LegacyElevoSidebarComponent(
260278
myLinks,
261279
scope,
262280
spaceNav,
281+
personalActions,
263282
onLogout,
264283
onActionClick,
265284
onProjectActionClick,
266285
onAddProject,
267286
onAddServiceflow,
287+
onPersonalActionClick,
268288
}: ElevoSidebarComponentProps,
269289
ref: React.Ref<ElevoSidebarRef>
270290
) {
@@ -430,9 +450,11 @@ function LegacyElevoSidebarComponent(
430450
<WrappedDropdownActions
431451
className="dropdown"
432452
themeVariant="elevo"
433-
actions={dropdownActions}
453+
actions={personalActions || dropdownActions}
434454
onActionClick={async (e) => {
435-
if (e.detail.key === "logout") {
455+
if (personalActions) {
456+
onPersonalActionClick({ action: e.detail });
457+
} else if (e.detail.key === "logout") {
436458
onLogout();
437459
} else {
438460
await i18n.changeLanguage(

bricks/ai-portal/src/jsx.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import type { Tab, TabList, TabListProps } from "./tab-list";
7979
import type { ChatPayload } from "./shared/interfaces";
8080
import type { FeedbackDetail } from "./cruise-canvas/interfaces";
8181
import type { GoalItem } from "./goal-card-list/CardItem/CardItem";
82+
import type { PersonalActionClickDetail } from "./elevo-sidebar/ChatHistory";
8283

8384
declare global {
8485
// eslint-disable-next-line @typescript-eslint/no-namespace
@@ -189,6 +190,9 @@ declare global {
189190
onProjectActionClick?: (
190191
event: CustomEvent<ProjectActionClickDetail>
191192
) => void;
193+
onPersonalActionClick?: (
194+
event: CustomEvent<PersonalActionClickDetail>
195+
) => void;
192196
};
193197

194198
"ai-portal--flow-tabs": DetailedHTMLProps<

0 commit comments

Comments
 (0)