有没有人找到一种方法来使他们的上下文菜单项有条件?(贡献 ID 像ms.vss-work-web.work-item-context-menu
)
我想添加一个工作项上下文菜单项,但我只想为某些工作项类型显示它。
有没有人找到一种方法来使他们的上下文菜单项有条件?(贡献 ID 像ms.vss-work-web.work-item-context-menu
)
我想添加一个工作项上下文菜单项,但我只想为某些工作项类型显示它。
作为贡献,您使用如下操作:
{
"id": "action-id",
"type": "ms.vss-web.action",
"description": "Context menu action",
"targets": [
"ms.vss-work-web.work-item-context-menu",
"ms.vss-work-web.query-result-work-item-menu",
"ms.vss-work-web.work-item-toolbar-menu",
"ms.vss-work-web.backlog-item-menu"
],
"properties": {
"uri": "yourpagehere.html"
}
}
您的操作提供者应该只为不相关的工作项返回一个空菜单项:
function getTypesFromContext(context: any): string[] {
// Not all areas use the same format for passing work item type names.
// "workItemTypeName" for Query preview
// "workItemTypeNames" for backlogs
// "workItemType" for boards
let types = context.workItemTypeNames;
if (!types && context.workItemType) {
// Boards only support a single work item
types = [context.workItemType];
}
if (!types && context.workItemTypeName) {
// Query wi preview
types = [context.workItemTypeName];
}
return types;
}
const action = {
getMenuItems: (context) => {
const mi = {
text: "sometext",
title: "sometitle",
groupId: "modify",
icon: "someicon.png",
action: (actionContext) => {
// someaction
}
} as IContributedMenuItem;
const types = getTypesFromContext(context);
if (types.every((type) => [ <<Your relevant types here>> ].indexOf(type) >= 0)) {
return [mi];
}
return [] as IContributedMenuItem[];
}
} as IContributedMenuSource;
VSS.register(VSS.getContribution().id, action);