Git Product home page Git Product logo

vsts-extension-toggle-control's Introduction

Custom Control for the Work Item Form

Learn how to build your own custom control for the work item form.

Control

Usage

  1. Clone the repository.

  2. Open the Command Prompt and change to the directory where you cloned the project. For instance, if it is cloned in a folder called "extensions" and saved as "vsts-toggle-wit-custom-control", you will navigate to the following command line.

     > cd C:\extensions\vsts-toggle-wit-custom-control
    
  3. Run npm install to install required local dependencies.

  4. Run npm install -g grunt to install a global copy of grunt (unless it's already installed).

  5. Run grunt package-dev.

  6. In your browser, navigate to your local instance of TFS, http://YourTFSInstance:8080/tfs.

  7. Go to your personal Marketplace.

  8. Click the Marketplace icon in the upper righthand corner.

  9. Click "Browse local extensions" in the dropdown.

  10. Scroll down and click on the "Manage Extensions" widget.

  11. Click the button "Upload new extension".

  12. Browse to the .vsix file generated when you packaged your extension.

  13. Select the extension, and then click "Open". Click "Upload" when the button activates.

  14. Hover over the extension when it appears in the list, and click "Install".

You have now installed the extension inside your collection. You are now able to put the control on the work item form.

A work item type is defined by XML, including the layout of the work item form. As part of the walkthrough, you will add the control to the layout. Read more information on WebLayout XML. In this example, we will add the control to the Agile "user story".

  1. Open the Developer Command Prompt. Export the XML file to your desktop with command shown below.

    witadmin exportwitd /collection:CollectionURL /p:Project /n:TypeName /f:FileName
    
  2. This creates a file in the directory that you specified. Inside this file, navigate to the section called "Work Item Extensions". This section shows the documentation of the control such as the inputs and ids. All this information was defined in the manifest, vss-extension.json.

        <!--**********************************Work Item Extensions***************************
    
    Extension:
        Name: color-control-dev
        Id: example.color-control-dev
    
        Control contribution:
            Id: example.color-control-dev.color-control-contribution
            Description:
            Inputs:
                Id: FieldName
                Description: The field associated with the control.
                Type: Field
                IsRequired: true
    
                Id: Colors
                Descriptions: The colors that match the values in the control.
                Type: String
                IsRequired: false
  3. Add an extension tag below the "Work Item Extensions" section as shown below to make your control available to work item form.

       <!--**********************************Work Item Extensions***************************
       ...
    
       Note: For more information on work item extensions use the following topic:
       http://go.microsoft.com/fwlink/?LinkId=816513
       -->
    
       <Extensions>
           <Extension Id="example.color-control-dev" />
       </Extensions>
  4. Find your extension ID in the "Work Item Extensions" section:

        <!--**********************************Work Item Extensions***************************
    
    Extension:
        Name: color-control-dev
        Id: example.color-control-dev
        ...
  5. This extension is a contribution, so you add it with a contribution tag in place of the tag. This example adds the "ControlContribution" to the "Planning" group.

    <Page Id="Details">
    ...
        <Section>
        ...
            <Group Id="Planning">
            ...
                <ControlContribution Label="Priority" Id="<your-control-contribution-id>"
                    <Inputs>
                        <Input Id="FieldName" Value="Microsoft.VSTS.Common.Priority" />
                    </Inputs>
                </ControlContribution>
    
                <Control Label="Risk" Type="FieldControl" FieldName="Microsoft.VSTS.Common.Risk" />
  6. Finally, import this .xml file, using witadmin.

    witadmin importwitd /collection:CollectionURL /p:Project /f:FileName
    

Make changes to the control

If you make changes to your extension files, you need to compile the Typescript and create the .vsix file again (steps 4-7 in the "Package & Upload to the marketplace" section).

Instead of re-installing the extension, you can replace the extension with the new .vsix package. Right-click the extension in the "Manage Extensions" page and click "Update". You do not need to make changes to your XML file again.

Make API calls to the work item form service

Reading data from VSTS/TFS server is a common REST API task for a work item control. The VSS SDK provides a set of services for these REST APIs. To use the service, import it into the typescript file.

import * as VSSService from "VSS/Service";
import * as WitService from "TFS/WorkItemTracking/Services";
import * as ExtensionContracts from "TFS/WorkItemTracking/ExtensionContracts";
import * as Q from "q";

To enable Intellisense in Visual Studio Code, include the type definition file index.d.ts. Once you've added this definition file, it shows all functions available in the VSS SDK.

/// <reference path="../typings/index.d.ts" />

Commonly Needed

API Functions Usage
VSSService VSS.getConfiguration() Returns the XML which defines the work item type. Used in the sample to read the inputs of the control to describe its behavior.
WitService getService() Returns an instance of the server to make calls.
getFieldValue() Returns the field's current value.
setFieldValue() Returns the field's current value using your control.
getAllowedFieldValues() Returns the allowed values, or the items in a dropdown, of a field.

How to invoke methods on a service call

Create an instance of the work item service to get information about the work item. Use one of the service's functions to get information about the field. This example asks for the allowed values of a field.

WitService.WorkItemFormService.getservice().then(
        (service) => {
            service.getAllowedFieldValues(this._fieldName), (allowedValues: string[]) => {
                // do something
            }
        }
)

Recommendation: use Q with service calls

To wait on the response of multiple calls, you can use Q. This example shows how to ask for the allowed values and the current value associated with a field using the Q.spread function. You can make two parallel requests, and the code will not be executed until both services have returned a response.

WitService.WorkItemFormService.getService().then(
            (service) => {
                Q.spread<any, any>(
                    [service.getAllowedFieldValues(this._fieldName), service.getFieldValue(this._fieldName)],
                    (allowedValues: string[], currentValue: (string | number)) => {
                        //do something
                    }
                )
            }
)

Structure

/scripts            - Typescript code for extension
/img                - Image assets for extension and description
/typings            - Typescript typings

index.html          - Main entry point
vss-extension.json  - Extension manifest

Grunt

Five basic grunt tasks are defined:

  • build - Compiles TS files in scripts folder
  • package-dev - Builds the development version of the vsix package
  • package-release - Builds the release version of the vsix package
  • publish-dev - Publishes the development version of the extension to the marketplace using tfx-cli
  • publish-release - Publishes the release version of the extension to the marketplace using tfx-cli

VS Code

The included .vscode config allows you to open and build the project using VS Code.

Unit Testing

The project is setup for unit testing using mocha, chai, and the karma test runner. A simple example unit test is included in scripts/logic/messageHelper.tests.ts. To run tests just execute:

grunt test

vsts-extension-toggle-control's People

Contributors

alychow avatar cschleiden avatar joserady avatar mmanela avatar mohitbagra avatar msftgits avatar nelsondaniel avatar ostreifel avatar witwf-interns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vsts-extension-toggle-control's Issues

Support native True/False properties?

I know the control only supports boolean fields, but I'm wondering if it is at all possible to support all VSTS true/false fields in the future, otherwise its use is extremely limited.

Build error in VS Code

Running grunt build gives the following error:

Running "ts:build" (ts) task
Compiling...
Using tsc v2.8.3
node_modules/@types/node/index.d.ts(89,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'require' must be of type 'Require', but here has type 'NodeRequire'.
node_modules/@types/node/index.d.ts(1975,45): error TS2304: Cannot find name 'Iterable'.
node_modules/@types/node/index.d.ts(1976,94): error TS2304: Cannot find name 'Iterable'.
node_modules/@types/node/index.d.ts(1979,20): error TS2304: Cannot find name 'Iterator'.
node_modules/@types/node/index.d.ts(1984,17): error TS2304: Cannot find name 'Iterator'.
node_modules/@types/node/index.d.ts(1988,19): error TS2304: Cannot find name 'Iterator'.
node_modules/@types/node/index.d.ts(1989,10): error TS2304: Cannot find name 'Symbol'.
node_modules/@types/node/index.d.ts(1989,30): error TS2304: Cannot find name 'Iterator'.
typings/globals/vss/index.d.ts(3247,14): error TS2559: Type 'TemplateViewModel' has no properties in common with type 'EnhancementOptions'.
typings/globals/vss/index.d.ts(9312,5): error TS2416: Property 'getValue' in type 'ComboDateBehavior' is not assignable to the same property in base type 'BaseComboBehavior'.
  Type '() => Date' is not assignable to type '<TValue>() => TValue'.
    Type 'Date' is not assignable to type 'TValue'.
typings/globals/vss/index.d.ts(9390,5): error TS2416: Property 'getValue' in type 'ComboMultiValueBehavior' is not assignable to the same property in base type 'ComboListBehavior'.
  Type '() => string[]' is not assignable to type '<TValue>() => TValue'.
    Type 'string[]' is not assignable to type 'TValue'.
typings/globals/vss/index.d.ts(9551,14): error TS2417: Class static side 'typeof DialogO' incorrectly extends base class static side 'typeof AjaxPanelO'.
  Types of property 'create' are incompatible.
    Type '<T extends Dialog>(dialogType: new (options: any) => T, options?: any) => T' is not assignable to type '<TControl extends Control<any>, TOptions>(controlType: new (options: TOptions) => TControl, conta...'.
      Types of parameters 'dialogType' and 'controlType' are incompatible.
        Type 'new (options: TOptions) => TControl' is not assignable to type 'new (options: any) => Dialog'.
          Type 'TControl' is not assignable to type 'Dialog'.
            Type 'Control<any>' is not assignable to type 'Dialog'.
              Property '_title' is missing in type 'Control<any>'.
typings/globals/vss/index.d.ts(19420,14): error TS2415: Class 'Component<TProps, TState>' incorrectly extends base class 'React.Component<TProps, TState>'.
  Property 'componentDidMount' is protected in type 'Component<TProps, TState>' but public in type 'Component<TProps, TState>'.
typings/globals/vss/index.d.ts(19454,14): error TS2415: Class 'Component<TControl, TProps, TState>' incorrectly extends base class 'Component<TProps, TState>'.
  Property 'shouldComponentUpdate' is protected in type 'Component<TControl, TProps, TState>' but public in type 'Component<TProps, TState>'.

>> 14 non-emit-preventing type warnings
>> Error: tsc return code: 2

The error seems the same described here,, however I also read that the version of TypeScript might be causing the issue.

Any Suggestions on how to fix this?


VSCode 1.23.1
Node 7.9.0
TypeScript 2.8.3

Incorrect field descriptions are being displayed

If you have two or more toggle fields in multiple work item types, extension is always displaying the first loaded toggle field description for other fields as description text (in same session) instead of displaying correct field descriptions.

Toggle-control does not load

Added the toggle controls to our forms but they do not load after the spinning wheel times out. Seeing this message "toggle-control by ms-devlabs is taking longer than expected to load. Learn More about this extension, including available support options".

Is this still relevant?

I'm evaluating 2018, both on-prem and VSTS. Particularly, I want to be able to customize WITs, including custom controls that talk to REST services. I'm finding it incredibly difficult to find relevant information on this. Keeping up with MS's constantly changing strategy is like cat-herding.

This project is titled "vsts", which implies it's for Azure TFS, yet, VSTS doesn't support exporting and importing WITS via witadmin.exe. Right????

I've tried getting a custom control hosted locally without any luck, either. Very few current write-ups on it, and I can't get it to work: When I display the WIT I get:

Could not load type 'MyTfs.Controls.ClientPicker' from assembly 'MyTfs.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

Any current guidance or resources would be greatly appreciated!

VS403117: The input value "Microsoft.VSTS.Common.Priority" is not a valid input value for input "FieldName" in contribution "ms-devlabs.vsts-toggle-control-dev.toggle-control-contribution"

I've cloned the latest code for this extension, run the grunt task for package-dev, and packaged the extension using TFX. I uploaded the extension to TFS 2018 update 1. I followed the readme in the repo and did the following:

  1. Exportwitd for the bug WIT to a file (using witadmin from VS 2017)
  2. Added this code under the commented work item extension code:
<Extensions>
      <Extension Id="ms-devlabs.vsts-toggle-control-dev" />
 </Extensions>  
  1. Replaced the Priority field with the following:
<ControlContribution Label="Priority" Id="ms-devlabs.vsts-toggle-control-dev.toggle-control-contribution">
    <Inputs>
              <Input Id="FieldName" Value="Microsoft.VSTS.Common.Priority" />
    </Inputs>
</ControlContribution>

And also tried using a custom field instead. I believe the Bug WIT that I have is OOB.

When running the importwitd with the file, the error message I receive is:
VS403117: The input value "Microsoft.VSTS.Common.Priority" is not a valid input value for input "FieldName" in contribution "ms-devlabs.vsts-toggle-control-dev.toggle-control-contribution"

Is there anything that I'm missing to get this to work with TFS?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.