是否有人找到一种条件菜单项? (诸如ms.vss-work-web.work-item-context-menu
之类的贡献ID)
我想添加一个工作项上下文菜单项,但是我只想在某些工作项类型中显示它。
答案 0 :(得分:0)
作为贡献,您可以使用以下操作:
{
"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);