# FDC3 Context

Canonical page: https://www.adaptabletools.com/docs/handbook-fdc3-context

- This AdapTable Help Page is being actively updated
- AdapTable has just upgraded to FDC3 2.0 and we are working on updating the documentation

- AdapTable fully supports FDC3 Contexts; users can:
  - Broadcast Context
  - Listen for Context
  - Create Custom Context

AdapTable supports FDC3 Contexts through the `contexts` property in FDC3 Options.

This object is of type [`Fdc3ContextOptions`](https://www.adaptabletools.com/docs/reference/fdc3contextoptions.md) and contains these properties:

| Property | Type | Description |
| --- | --- | --- |
| [broadcasts](https://www.adaptabletools.com/docs/reference/fdc3contextoptions.md#broadcasts) | [`BroadcastConfiguration`](https://www.adaptabletools.com/docs/reference/broadcastconfiguration.md) | Broadcasts given standard Context(s) on various Grid Actions |
| [handleContext](https://www.adaptabletools.com/docs/reference/fdc3contextoptions.md#handlecontext) | `(context: `[`HandleFdc3Context`](https://www.adaptabletools.com/docs/reference/handlefdc3context.md)`) => void` | Handles incoming Contexts (standard and custom) |
| [listensFor](https://www.adaptabletools.com/docs/reference/fdc3contextoptions.md#listensfor) | `ContextType[]` | Subscribe to given standard Context(s) |

As can be seen, users are able both to **Broadcast** and **Listen For** FDC3 Context.

## Available Contexts

The FDC3 Intents supported by AdapTable (and the Intents they can raise) are as follows:

| FDC3 Context                                                                 | Available Intents                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [Chart](https://fdc3.finos.org/docs/context/ref/Chart)                       | [ViewChart](https://fdc3.finos.org/docs/intents/ref/ViewChart)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| [ChatInitSettings](https://fdc3.finos.org/docs/context/ref/ChatInitSettings) | [StartChat](https://fdc3.finos.org/docs/intents/ref/StartChat) , [StartCall](https://fdc3.finos.org/docs/intents/ref/StartCall), [ViewContact](https://fdc3.finos.org/docs/intents/ref/ViewContact)                                                                                                                                                                                                                                                                                                                                                                |
| [Contact](https://fdc3.finos.org/docs/context/ref/Contact)                   | [StartChat](https://fdc3.finos.org/docs/intents/ref/StartChat) , [StartCall](https://fdc3.finos.org/docs/intents/ref/StartCall)                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| [ContactList](https://fdc3.finos.org/docs/context/ref/ContactList)           | [StartChat](https://fdc3.finos.org/docs/intents/ref/StartChat) , [StartCall](https://fdc3.finos.org/docs/intents/ref/StartCall), [ViewProfile](https://fdc3.finos.org/docs/intents/ref/ViewProfile), [ViewResearch](https://fdc3.finos.org/docs/intents/ref/ViewResearch), [ViewInteractions](https://fdc3.finos.org/docs/intents/ref/ViewInteractions), [ViewOrders](https://fdc3.finos.org/docs/intents/ref/ViewOrders)                                                                                                                                          |
| [Country](https://fdc3.finos.org/docs/context/ref/Country)                   | [ViewAnalysis](https://fdc3.finos.org/docs/intents/ref/ViewAnalysis), [ViewNews](https://fdc3.finos.org/docs/intents/ref/ViewNews)                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| [Currency](https://fdc3.finos.org/docs/context/ref/Currency)                 |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| [Email](https://fdc3.finos.org/docs/context/ref/Chart)                       | [StartEmail](https://fdc3.finos.org/docs/intents/ref/StartEmail)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [Instrument](https://fdc3.finos.org/docs/context/ref/Instrument)             | [ViewAnalysis](https://fdc3.finos.org/docs/intents/ref/ViewAnalysis), [ViewChart](https://fdc3.finos.org/docs/intents/ref/ViewChart), [ViewInstrument](https://fdc3.finos.org/docs/intents/ref/ViewInstrument), [ViewNews](https://fdc3.finos.org/docs/intents/ref/ViewNews), [ViewQuote](https://fdc3.finos.org/docs/intents/ref/ViewQuote), [ViewResearch](https://fdc3.finos.org/docs/intents/ref/ViewResearch), [ViewInteractions](https://fdc3.finos.org/docs/intents/ref/ViewInteractions), [ViewOrders](https://fdc3.finos.org/docs/intents/ref/ViewOrders) |
| [InstrumentList](https://fdc3.finos.org/docs/context/ref/InstrumentList)     | [ViewAnalysis](https://fdc3.finos.org/docs/intents/ref/ViewAnalysis), [ViewChart](https://fdc3.finos.org/docs/intents/ref/ViewChart), [ViewInstrument](https://fdc3.finos.org/docs/intents/ref/ViewInstrument), [ViewNews](https://fdc3.finos.org/docs/intents/ref/ViewNews), [ViewQuote](https://fdc3.finos.org/docs/intents/ref/ViewQuote)                                                                                                                                                                                                                       |
| [Organization](https://fdc3.finos.org/docs/context/ref/Organization)         | [ViewAnalysis](https://fdc3.finos.org/docs/intents/ref/ViewAnalysis), [ViewNews](https://fdc3.finos.org/docs/intents/ref/ViewNews), [ViewProfile](https://fdc3.finos.org/docs/intents/ref/ViewProfile), [ViewResearch](https://fdc3.finos.org/docs/intents/ref/ViewResearch), [ViewInteractions](https://fdc3.finos.org/docs/intents/ref/ViewInteractions), [ViewOrders](https://fdc3.finos.org/docs/intents/ref/ViewOrders)                                                                                                                                       |
| [Portfolio](https://fdc3.finos.org/docs/context/ref/Portfolio)               | [ViewAnalysis](https://fdc3.finos.org/docs/intents/ref/ViewAnalysis), [ViewChart](https://fdc3.finos.org/docs/intents/ref/ViewChart), [ViewNews](https://fdc3.finos.org/docs/intents/ref/ViewNews)                                                                                                                                                                                                                                                                                                                                                                 |
| [Position](https://fdc3.finos.org/docs/context/ref/Position)                 | [ViewAnalysis](https://fdc3.finos.org/docs/intents/ref/ViewAnalysis), [ViewChart](https://fdc3.finos.org/docs/intents/ref/ViewChart), [ViewNews](https://fdc3.finos.org/docs/intents/ref/ViewNews)                                                                                                                                                                                                                                                                                                                                                                 |
| [TimeRange](https://fdc3.finos.org/docs/context/ref/TimeRange)               |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| [Valuation](https://fdc3.finos.org/docs/context/ref/Valuation)               |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |

## Broadcasting Context

FDC3 Contexts are broadcast using the `broadcasts` property in the `contexts` section of FDC3 Options.

Each Context is listed by type (e.g. `fdc3.instrument`) and details the context-broadcasting behaviour.

- Make sure **all contexts** you broadcast are referenced in the `gridDataContextMapping` property of FDC3 Options
- This is a required step which AdapTable uses to [map columns and fields to FDC3 objects](https://www.adaptabletools.com/docs/handbook-fdc3-mappings/index.md)

This context-broadcasting behaviour can take one of 2 forms:

- a [Context Menu](https://www.adaptabletools.com/docs/ui-context-menu/index.md) entry
- an [FDC3 Action Column](https://www.adaptabletools.com/docs/handbook-fdc3-ui-components/index.md) (either a button or full Column definition can be provided)

It is possible to broadcast Context using the **both** [Context Menu](https://www.adaptabletools.com/docs/ui-context-menu/index.md) and an [FDC3 Action Column](https://www.adaptabletools.com/docs/handbook-fdc3-ui-components/index.md)

### `broadcasts`

Broadcasts given standard Context(s) on various Grid Actions

  [`BroadcastConfiguration`](https://www.adaptabletools.com/docs/reference/broadcastconfiguration.md)

Property which defines which FDC3 Contexts can be broadcast.

It provides an object of type [`BroadcastConfiguration`](https://www.adaptabletools.com/docs/reference/broadcastconfiguration.md) which contains a collection of [`BroadcastConfig`](https://www.adaptabletools.com/docs/reference/broadcastconfig.md) objects.

Each has Config object has 2 elements:

- a **key** which is the Context being broadcast (e.g. `fdc3.instrument`, `fdc3.currency`).

- This context should be referenced in the `gridDataContextMapping` property of FDC3 Options
  - See [Mapping columns and fields to FDC3 objects](https://www.adaptabletools.com/docs/handbook-fdc3-mappings/index.md) for more information

- properties to define the Broadcast **behaviour**, i.e. via the [Context Menu](https://www.adaptabletools.com/docs/ui-context-menu/index.md) or using an [Action Column / Button](https://www.adaptabletools.com/docs/handbook-action-column/index.md):

See [FDC3 Action Columns and Buttons](https://www.adaptabletools.com/docs/handbook-fdc3-ui-components/index.md) for full details on how these Buttons and Action Columns are rendered

| Property | Type | Description |
| --- | --- | --- |
| [actionButton](https://www.adaptabletools.com/docs/reference/broadcastconfig.md#actionbutton) | [`Fdc3AdaptableButton`](https://www.adaptabletools.com/docs/reference/fdc3adaptablebutton.md) | Definition of Action Button (to be put in default FDC3 Action Column) |
| [actionColumn](https://www.adaptabletools.com/docs/reference/broadcastconfig.md#actioncolumn) | [`FDC3ActionColumn`](https://www.adaptabletools.com/docs/reference/fdc3actioncolumn.md) | Custom FDC3 Action Column definition to broadcast the Context |
| [contextMenu](https://www.adaptabletools.com/docs/reference/broadcastconfig.md#contextmenu) | `\{ columnIds: string[]; icon?: '_defaultFdc3' \| `[`AdaptableIcon`](https://www.adaptabletools.com/docs/reference/adaptableicon.md)`; \}` | Columns to display a &#39;Broadcast&#39; Context Menu item |
```tsx {2}
contexts: {
  broadcasts: {
    'fdc3.currency': {
      contextMenu: {
        columnIds: ['currency'],
        icon: '_defaultFdc3',
      },
      actionButton: {
        id: 'BroadCastCurrencyButton',
        icon: '_defaultFdc3',
        tooltip: '_defaultFdc3',
      },
    },
    'fdc3.email': {
      contextMenu: {
        columnIds: ['interest'],
        icon: '_defaultFdc3',
      },
    },
  },
},
```  

   
## Listening for Context
Listening for Context (that has been broadcast from external applications) is done in 2 stages:

Both steps use a property in the `contexts` section of FDC3 Options

- all Contexts to handle are listed in the `listensFor` property
- an implementation is given for the `handleContext` function property
### `listensFor`

Subscribe to given standard Context(s)

  [`FDC3 context type`](https://www.adaptabletools.com/docs/reference/fdc3contextoptions.md#listensfor)

Lists which FDC3 Contexts are listened for.
The array is a list of FDC3 context type strings (e.g. `fdc3.instrument`, `fdc3.contact`) — see [`listensFor`](https://www.adaptabletools.com/docs/reference/fdc3contextoptions.md#listensfor)
```tsx {2}
contexts: {
  listensFor: ['fdc3.instrument', 'fdc3.contact'],
},
```
These Contexts are then typically handled in the `handleContext` function property (see below).

     
## Handling Context
Incoming FDC3 Context is handled by the `handleContext` property.
### `handleContext`

 Handles incoming Contexts (standard and custom)

Property used to handle incoming FDC3 Context.

Make sure that the Context is listed in the `listensFor` property - also in the `contexts` object

```tsx
handleContext?: (context: HandleFdc3Context) => void;
```

The void function receives an object of type [`HandleFdc3Context`](https://www.adaptabletools.com/docs/reference/handlefdc3context.md) which contains two FDC3 2.0 objects:

| Property | Type | Description |
| --- | --- | --- |
| [context](https://www.adaptabletools.com/docs/reference/handlefdc3context.md#context) | `Context` | The FDC3 Context |
| [metadata](https://www.adaptabletools.com/docs/reference/handlefdc3context.md#metadata) | `ContextMetadata` | The FDC3 Context Metadata related to the context |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/handlefdc3context.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

```tsx {2}
contexts: {
  handleContext: (fdc3Context: HandleFdc3Context) => {
    console.log(`Received context: `, fdc3Context);
  },
},
```
