# Team Sharing

Canonical page: https://www.adaptabletools.com/docs/handbook-team-sharing

- Team Sharing promotes collaboration by allowing colleagues to share Adaptable Objects at run-time
- It is designed for use cases where the same grid-related Entity will be required by multiple users
- Each object (e.g. a Layout, Format Column, Report etc.) can be shared in one of 2 ways:
  - **Snapshot** - i.e. a one-off operation
  - **Active** - all instances stay linked
- It is also possible to share bespoke objects (not necessarily Adaptable specific ones), practically providing a shared mutable state between multiple instances

Team Sharing enables AdapTable users to share [Adaptable Objects](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md#adaptable-objects) they have created.

These can be objects created either at run-time or design time.

Once an AdapTable Object is uploaded into Team Share, it is then tagged as a "Shared Entity" and will automatically be available to colleagues to download.

- This page explains how to share Adaptable Objects like Layouts, FormatColumns, Alerts, etc.
- Advanced users are also able to share [Custom Objects](https://www.adaptabletools.com/docs/handbook-team-sharing-custom/index.md) if required

## Team Sharing Workflow

The Team Sharing workflow is straightforward but incredibly powerful:

Step 1. AdapTable User **uploads** an Adaptable Object to the Team Share (for colleagues to download):

### How to Upload an Adaptable Object To Team Share

The steps to upload an AdapTable Object to Team Share are as follows:

If [Team Sharing is enabled](#enabling-team-sharing), every Adaptable Object will display a _Share_ button in the Settings Panel

Clicking any _Share_ button will display a popup where a name for the Shared Entity must be provided

There are 2 options:

- [Snapshot](#snapshot) - a one-off operation in which the SharedEntity is uploaded to the Team Share and then disconnected from the initial Adaptable Object

- [Active](#active) - the Shared Enitty remains linked after it has been uploaded to Team Share by a user (and then subsequently downloaded by her colleagues)

The Adaptable Object will now be uploaded into Team Share.

It is ready to be downloaded by colleagues (as a Shared Entity).

Step 2. User's Colleague **downloads** the Object - known as a **Shared Entity**:

### Downloading From Team Share

The steps to download an AdapTable Object from Team Share are as follows:

Any user (with Team Sharing entitlemens) can access this Team Share Panel.

This screen displays full details of all Adaptable Objects which have been shared.

Simply choose which Shared Entity to download and AdapTable will do the rest.

Step 3. If the Shared Entity is [Active Shared](#active-sharing), AdapTable will automatically **synchronise** the team share with local changes, allowing colleagues to **update** their local copy with the latest version in the team share

Step 4. If the Shared Entity is [Snapshot Shared](#snapshot-sharing), then it is uploaded to the Team Share and then disconnected from the initial Adaptable Object

**Example: Team Sharing**

Basic Team Sharing

- This demo shows how Team Sharing works in AdapTable
- There are 2 users each with their own Initial State:
  - **Alice** - has a Format Column for `Name` Column
  - **Bob** - has a Format Column for `Language` Column and uses the Dark Theme
- Switching between users - via the custom toolbar - loads a new AdapTable instance with that User's Initial State
- Team Sharing is enabled in this demo, allowing **Alice** and **Bob** to share entities between them
- Note: this demo uses local storage to simulate an api call - but in the real world the shared entity would be stored remotely.
### Expand to see how Team Sharing is applied

We create 2 initial Initial Adaptable States - one for each user:
```ts
// Alice
{
  FormatColumn: {
    FormatColumns: [
      {
        Name: 'FormatColumn-name-266',
        Scope: {
          ColumnIds: ['name'],
        },
        Style: {
          BackColor: 'lightblue',
          ForeColor: 'var(--ab-color-palette-17)',
        },
      },
    ],
  },
  Theme: {
    CurrentTheme: 'light',
  },
}
// Bob
{
  FormatColumn: {
    FormatColumns: [
      {
        Name: 'FormatColumn-language-267',
        Scope: {
          ColumnIds: ['language'],
        },
        Style: {
          BackColor: 'var(--ab-color-palette-21)',
          ForeColor: 'var(--ab-color-palette-13)',
        },
      },
    ],
  },
  Theme: {
    CurrentTheme: 'dark',
  },
}
```
In TeamSharingOptions - which is passed into AdaptableOptions - we do 3 things:
- set `enableTeamSharing` to true
- provide an implementation for `loadSharedEntities`
- provide an implementation for `persistSharedEntities`
```ts
const teamSharingOptions: TeamSharingOptions = {
  enableTeamSharing: true,
  loadSharedEntities: async adaptableId => {
    const data = localStorage.getItem(TEAM_SHARING_STATE_KEY);
    if (!data) {
      return [];
    }
    try {
      return JSON.parse(data);
    } catch (e) {
      return [];
    }
  },
  persistSharedEntities: (adaptableId, entries) => {
    localStorage.setItem(TEAM_SHARING_ID, JSON.stringify(entries));
    return Promise.resolve();
  },
};
```

1. As **Alice** shares the Format Column for the `Name` Column
2. As **Bob** download that Format Column from the Team Share
3. Note that the new Format Column appears in the Grid for **Bob**

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {InitialState, AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

// use a common Team Sharing state key for both users
const TEAM_SHARING_STATE_KEY = 'BasicTeamSharingDemo_TeamSharingState';
export const getAdaptableOptionsForUser = (
  userName: 'Alice' | 'Bob',
  updateCurrentUser: (userName: 'Alice' | 'Bob') => void
): AdaptableOptions<WebFramework> => {
  const commonInitialState: InitialState = {
    Dashboard: {
      Revision: Date.now(),
      Tabs: [
        {
          Name: 'Select Current User',
          Toolbars: ['CurrentUser'],
        },
      ],
      ModuleButtons: ['FormatColumn', 'TeamSharing'],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'github_stars',
            'license',
            'github_watchers',
            'language',
            'open_issues_count',
            'closed_issues_count',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'description',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  };
  const userSpecificInitialState =
    userName === 'Alice'
      ? {
          FormatColumn: {
            FormatColumns: [
              {
                Name: 'formatColumn-name',
                Scope: {
                  ColumnIds: ['name'],
                },
                Style: {
                  BackColor: 'lightblue',
                  ForeColor: 'var(--ab-color-palette-17)',
                },
              },
            ],
          },
          Theme: {
            CurrentTheme: 'light',
          },
        }
      : // Bob
        {
          FormatColumn: {
            FormatColumns: [
              {
                Name: 'formatColumn-language',
                Scope: {
                  ColumnIds: ['language'],
                },
                Style: {
                  BackColor: 'var(--ab-color-palette-21)',
                  ForeColor: 'var(--ab-color-palette-13)',
                },
              },
            ],
          },
          Theme: {
            CurrentTheme: 'dark',
          },
        };

  return {
    primaryKey: 'id',
    adaptableId: 'Basic Team Sharing Demo',
    adaptableStateKey: `BasicTeamSharingDemo_${userName}`,
    userName,
    initialState: {
      ...commonInitialState,
      ...userSpecificInitialState,
    },
    teamSharingOptions: {
      enableTeamSharing: true,
      loadSharedEntities: async () => {
        const data = localStorage.getItem(TEAM_SHARING_STATE_KEY);
        if (!data) {
          return [];
        }

        try {
          return JSON.parse(data);
        } catch (e) {
          return [];
        }
      },
      persistSharedEntities: entries => {
        localStorage.setItem(TEAM_SHARING_STATE_KEY, JSON.stringify(entries));
        return Promise.resolve();
      },
    },
    dashboardOptions: {
      customToolbars: [
        {
          name: 'CurrentUser',
          title: 'Current User',
          toolbarButtons: [
            {
              label: 'Alice',
              buttonStyle: () => {
                return {
                  tone: userName === 'Alice' ? 'success' : 'neutral',
                  variant: userName === 'Alice' ? 'raised' : 'outlined',
                };
              },
              onClick: () => {
                updateCurrentUser('Alice');
              },
            },
            {
              label: 'Bob',
              buttonStyle: () => {
                return {
                  tone: userName === 'Bob' ? 'success' : 'neutral',
                  variant: userName === 'Bob' ? 'raised' : 'outlined',
                };
              },
              onClick: () => {
                updateCurrentUser('Bob');
              },
            },
          ],
        },
      ],
      customDashboardButtons: [
        {
          tooltip: 'Reset state',
          icon: {
            name: 'refresh',
          },
          buttonStyle: {
            tone: 'error',
          },
          onClick: (button, context) => {
            localStorage.removeItem(TEAM_SHARING_STATE_KEY);
            ['Alice', 'Bob'].forEach(user => {
              localStorage.removeItem(`BasicTeamSharingDemo_${user}`);
            });
            context.adaptableApi.stateApi.reloadInitialState();
          },
        },
      ],
    },
  };
};
```

**`src/index.ts`**

```ts
import {
  Adaptable,
  AdaptableApi,
  AdaptableOptions,
  AdaptableReadyInfo,
} from '@adaptabletools/adaptable';

import '@adaptabletools/adaptable/index.css';

import './styles.css';

import {gridOptions} from './gridOptions';
import {onAdaptableReady} from './onAdaptableReady';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUser} from './adaptableOptions';
import {WebFramework} from './rowData';

let currentAdaptableInstance: AdaptableApi | undefined;

let currentUser: 'Alice' | 'Bob' = 'Alice';

function updateCurrentUser(userName: 'Alice' | 'Bob') {
  currentUser = userName;
  initializeAdaptable(currentUser);
}

async function initializeAdaptable(userName: 'Alice' | 'Bob') {
  // destroy the previous instance (if existing)
  if (currentAdaptableInstance) {
    const config: any = {
      unmount: true,
      destroyApi: true,
    };
    currentAdaptableInstance.destroy(config);
  }

  currentAdaptableInstance = await Adaptable.init(
    {
      ...getAdaptableOptionsForUser(userName, updateCurrentUser),
    } as AdaptableOptions<WebFramework>,
    {gridOptions: {...gridOptions}, modules: agGridModules}
  );
  currentAdaptableInstance.eventApi.on(
    'AdaptableReady',
    (readyInfo: AdaptableReadyInfo) => {
      onAdaptableReady(readyInfo);
    }
  );
}

initializeAdaptable(currentUser);
```

**`src/App.tsx`** (React version)

```ts
import * as React from 'react';
import {useState} from 'react';
import {
  Adaptable,
  AdaptableApi,
  AdaptableReadyInfo,
} from '@adaptabletools/adaptable-react-aggrid';

// import adaptable css
import '@adaptabletools/adaptable-react-aggrid/index.css';
// import aggrid themes (using Balham theme)

import './styles.css';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUser} from './adaptableOptions';

const Grid = ({
  currentUser,
  onCurrentUserChange,
}: {
  currentUser: 'Alice' | 'Bob';
  onCurrentUserChange: (userName: 'Alice' | 'Bob') => void;
}) => {
  const adaptableApiRef = React.useRef<AdaptableApi>(null);

  const adaptableOptions = getAdaptableOptionsForUser(
    currentUser,
    onCurrentUserChange
  );

  const agGridOptions = {...gridOptions};
  return (
    <div style={{display: 'flex', flexFlow: 'column', height: '100vh'}}>
      <Adaptable.Provider
        gridOptions={agGridOptions}
        adaptableOptions={adaptableOptions}
        modules={[...agGridModules]}
        onAdaptableReady={(adaptableReadyInfo: AdaptableReadyInfo) => {
          // save a reference to adaptable api
          adaptableApiRef.current = adaptableReadyInfo.adaptableApi;
          onAdaptableReady(adaptableReadyInfo);
        }}>
        <Adaptable.UI key={`${currentUser}-ui`} style={{flex: 'none'}} />
        <Adaptable.AgGridReact />
      </Adaptable.Provider>
    </div>
  );
};

const App: React.FunctionComponent = () => {
  const [currentUser, setCurrentUser] = useState<'Alice' | 'Bob'>('Alice');

  return (
    <Grid
      key={currentUser}
      currentUser={currentUser}
      onCurrentUserChange={userName => setCurrentUser(userName)}
    />
  );
};
export default App;
```

**`src/app/app.component.ts`** (Angular version)

```ts
import {ChangeDetectorRef, Component, Inject} from '@angular/core';

import {AdaptableReadyInfo, AdaptableOptions} from '@adaptabletools/adaptable-angular-aggrid';
import {GridOptions} from 'ag-grid-enterprise';

// Adaptable styles
import '@adaptabletools/adaptable-angular-aggrid/index.css';

// AG Grid styles

import './styles.css';

// grid configuration
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {onAdaptableReady} from './onAdaptableReady';
import {getAdaptableOptionsForUser} from './adaptableOptions';
import {WebFramework} from './rowData';

@Component({
  standalone: false,
  selector: 'app-root',
  template: `
    <div id="demoOutputAbove"></div>
    <adaptable-provider
      *ngIf="isUpToDate"
      [adaptableOptions]="adaptableOpts"
      [gridOptions]="agGridOptions"
      [modules]="modules"
      (adaptableReady)="adaptableReady($event)"
      style="height: 100vh; width: 100vw;">
      <adaptable-ui style="flex: none"></adaptable-ui>
      <ag-grid-angular
        *adaptable="let adaptable"
        [gridOptions]="adaptable.gridOptions"
        [modules]="adaptable.modules"
        style="flex: 1">
      </ag-grid-angular>
    </adaptable-provider>
    <div id="demoOutputBelow"></div>
  `,
  styles: [
    `
      :host {
        height: 100vh;
        display: flex;
        flex-flow: column;
      }
    `,
  ],
})
export class AppComponent {
  adaptableOpts: AdaptableOptions<WebFramework>;
  agGridOptions: GridOptions<WebFramework>;
  modules = agGridModules;

  currentUser: 'Alice' | 'Bob';
  isUpToDate = true;

  constructor(
    @Inject(ChangeDetectorRef) private changeDetectorRef: ChangeDetectorRef
  ) {
    this.currentUser = 'Alice';
    this.adaptableOpts = getAdaptableOptionsForUser(
      this.currentUser,
      (user: 'Alice' | 'Bob') => this.setCurrentUser(user)
    );
    this.agGridOptions = {...gridOptions};
  }

  setCurrentUser(currentUser: 'Alice' | 'Bob') {
    this.isUpToDate = false;
    this.changeDetectorRef.detectChanges();

    this.currentUser = currentUser;
    this.initializeAdaptable();
    this.isUpToDate = true;
    this.changeDetectorRef.detectChanges();
  }

  initializeAdaptable() {
    this.adaptableOpts = getAdaptableOptionsForUser(
      this.currentUser,
      (user: 'Alice' | 'Bob') => this.setCurrentUser(user)
    );
    this.agGridOptions = {...gridOptions};
  }

  adaptableReady($event: AdaptableReadyInfo) {
    onAdaptableReady($event);
  }
}
```

**`src/App.vue`** (Vue version)

```ts
<template>
  <Grid
    :key="currentUser"
    :currentUser="currentUser"
    @currentUserChange="setCurrentUser" />
</template>

<script lang="ts">
import {ref, defineComponent} from 'vue';
import {
  AdaptableProvider,
  AdaptableAgGridVue,
  AdaptableUI,
} from '@adaptabletools/adaptable-vue3-aggrid';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUser} from './adaptableOptions';

const Grid = defineComponent({
  props: {
    currentUser: {
      type: String,
      required: true,
    },
  },
  emits: ['currentUserChange'],
  setup(props, {emit}) {
    const adaptableOptions = getAdaptableOptionsForUser(
      props.currentUser,
      userName => emit('currentUserChange', userName)
    );

    const agGridOptions = {...gridOptions};

    return {
      adaptableOptions,
      agGridOptions,
      agGridModules,
      onAdaptableReady,
    };
  },
  components: {
    AdaptableProvider,
    AdaptableAgGridVue,
    AdaptableUI,
  },
  template: `
    <AdaptableProvider
        :gridOptions="agGridOptions"
        :adaptableOptions="adaptableOptions"
        :modules="agGridModules"
        @onAdaptableReady="onAdaptableReady">
      <div style="display: flex; flex-direction: column; height: 100vh">
        <AdaptableUI :key="currentUser + '-ui'" style="flex: none" />
        <AdaptableAgGridVue style="flex: 1"  />
      </div>
    </AdaptableProvider>
  `,
});

export default defineComponent({
  name: 'App',
  components: {
    Grid,
  },
  setup() {
    const currentUser = ref('Alice');

    const setCurrentUser = userName => {
      currentUser.value = userName;
    };

    return {
      currentUser,
      setCurrentUser,
    };
  },
});
</script>
```

There are a few important concepts to know.

### Snapshot Sharing

The most straightforwad way in which a SharedEntity can be uploaded is by Snapshot Sharing.

This is a **one off operation** in which the SharedEntity is uploaded to the Team Share and then disconnected from the initial Adaptable Object.

This means that any changes made by the original sharer - or any colleagues who download the Shared Entity - will **not** be fed back to the other.

However, the object will remain in the team share, meaning that any user who has locally amended the initial shared object can revert to the shared version at any time by downloading it again

### Active Sharing

The other way to upload a SharedEntity is through Active Sharing.

In this scenario, the Shared Entity remains linked after it has been uploaded to Team Share by a user (and then subsequently downloaded by her colleagues).

AdapTable ensures that any local changes to a Shared Entity are automatically synchronised to TeamSharing.

See [Active Team Sharing](https://www.adaptabletools.com/docs/handbook-team-sharing-active/index.md) for full details on how Live sharing works in AdapTable

### Referenced Sharing

Sometimes a Shared Entity contains references to other objects.

Most commonly a [Layout](https://www.adaptabletools.com/docs/handbook-layouts/index.md) will reference Special Columns (ie. [Calculated](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md), [FreeText](https://www.adaptabletools.com/docs/handbook-freetext-column/index.md) or [Action](https://www.adaptabletools.com/docs/handbook-action-column/index.md)Column).

When this happens, AdapTable will find all the associated dependencies, and they will be uploaded into Team Share together with the main Shared Entity.

See [Referenced Team Sharing](https://www.adaptabletools.com/docs/handbook-team-sharing-referenced/index.md) for further information

## Multiple Teams

**Example: Team Sharing with Multiple Teams**

Team Sharing between multiple teams of users

- This example illustrates how Team Sharing can be used with multiple teams
- It is identical to the demo above (with 2 users) but in addition each user can share to 2 teams

- Share Adaptable Objects between users and distribute them between the teams
- Note that only those Shared Entities which are located to the current Team are displayed

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions, InitialState} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

// use a common Team Sharing state key for both users
export const getAdaptableOptionsForUserAndTeam = (
  userName: 'Alice' | 'Bob',
  updateCurrentUser: (userName: 'Alice' | 'Bob') => void,
  team: 'Red' | 'Blue',
  updateCurrentTeam: (userName: 'Red' | 'Blue') => void
): AdaptableOptions<WebFramework> => {
  const commonInitialState: InitialState = {
    Dashboard: {
      Revision: Date.now(),
      Tabs: [
        {
          Name: 'Select User & Team',
          Toolbars: ['CurrentUser', 'CurrentTeam'],
        },
      ],
      ModuleButtons: ['FormatColumn', 'TeamSharing'],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'has_projects',
            'has_pages',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'github_watchers',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          AutoSizeColumns: true,
        },
      ],
    },
  };
  const userSpecificInitialState =
    userName === 'Alice'
      ? {
          FormatColumn: {
            FormatColumns: [
              {
                Name: 'formatColumn-name',
                Scope: {
                  ColumnIds: ['name'],
                },
                Style: {
                  BackColor: 'lightblue',
                  ForeColor: 'var(--ab-color-palette-17)',
                },
              },
            ],
          },
          Theme: {
            CurrentTheme: 'light',
          },
        }
      : // Bob
        {
          FormatColumn: {
            FormatColumns: [
              {
                Name: 'formatColumn-language',
                Scope: {
                  ColumnIds: ['language'],
                },
                Style: {
                  BackColor: 'var(--ab-color-palette-23)',
                },
              },
            ],
          },
          Theme: {
            CurrentTheme: 'dark',
          },
        };

  return {
    primaryKey: 'id',
    adaptableId: 'Multi Team Sharing Demo',
    adaptableStateKey: `MultiTeamSharingDemo_${userName}`,
    userName,
    initialState: {
      ...commonInitialState,
      ...userSpecificInitialState,
    },
    teamSharingOptions: {
      enableTeamSharing: true,
      loadSharedEntities: async () => {
        const data = localStorage.getItem(
          `MultiTeamSharingDemo_TeamSharingState_${team}`
        );
        if (!data) {
          return [];
        }

        try {
          return JSON.parse(data);
        } catch (e) {
          return [];
        }
      },
      persistSharedEntities: entries => {
        localStorage.setItem(
          `MultiTeamSharingDemo_TeamSharingState_${team}`,
          JSON.stringify(entries)
        );
        return Promise.resolve();
      },
    },
    dashboardOptions: {
      customToolbars: [
        {
          name: 'CurrentUser',
          title: 'Current User',
          toolbarButtons: [
            {
              label: 'Alice',
              buttonStyle: () => {
                return {
                  tone: userName === 'Alice' ? 'success' : 'neutral',
                  variant: userName === 'Alice' ? 'raised' : 'outlined',
                };
              },
              onClick: () => {
                updateCurrentUser('Alice');
              },
            },
            {
              label: 'Bob',
              buttonStyle: () => {
                return {
                  tone: userName === 'Bob' ? 'success' : 'neutral',
                  variant: userName === 'Bob' ? 'raised' : 'outlined',
                };
              },
              onClick: () => {
                updateCurrentUser('Bob');
              },
            },
          ],
        },
        {
          name: 'CurrentTeam',
          title: 'Current Team',
          toolbarButtons: [
            {
              label: 'Red',
              buttonStyle: () => {
                return {
                  tone: team === 'Red' ? 'error' : 'neutral',
                  variant: team === 'Red' ? 'raised' : 'outlined',
                };
              },
              onClick: () => {
                updateCurrentTeam('Red');
              },
            },
            {
              label: 'Blue',
              buttonStyle: () => {
                return {
                  tone: team === 'Blue' ? 'accent' : 'neutral',
                  variant: team === 'Blue' ? 'raised' : 'outlined',
                };
              },
              onClick: () => {
                updateCurrentTeam('Blue');
              },
            },
          ],
        },
      ],
      customDashboardButtons: [
        {
          tooltip: 'Reset state',
          icon: {
            name: 'refresh',
          },
          buttonStyle: {
            tone: 'error',
          },
          onClick: (button, context) => {
            ['Red', 'Blue'].forEach(teamName => {
              localStorage.removeItem(
                `MultiTeamSharingDemo_TeamSharingState_${teamName}`
              );
            });
            ['Alice', 'Bob'].forEach(user => {
              localStorage.removeItem(`MultiTeamSharingDemo_${user}`);
            });
            context.adaptableApi.stateApi.reloadInitialState();
          },
        },
      ],
    },
  };
};
```

**`src/index.ts`**

```ts
import {
  Adaptable,
  AdaptableApi,
  AdaptableOptions,
  AdaptableReadyInfo,
} from '@adaptabletools/adaptable';

import '@adaptabletools/adaptable/index.css';

import './styles.css';

import {gridOptions} from './gridOptions';
import {onAdaptableReady} from './onAdaptableReady';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUserAndTeam} from './adaptableOptions';
import {WebFramework} from './rowData';

let currentAdaptableInstance: AdaptableApi | undefined;

let currentUser: 'Alice' | 'Bob' = 'Alice';
let currentTeam: 'Red' | 'Blue' = 'Red';

function updateCurrentUser(userName: 'Alice' | 'Bob') {
  currentUser = userName;
  initializeAdaptable(currentUser, currentTeam);
}

function updateCurrentTeam(team: 'Red' | 'Blue') {
  currentTeam = team;
  initializeAdaptable(currentUser, currentTeam);
}

async function initializeAdaptable(
  userName: 'Alice' | 'Bob',
  teamName: 'Red' | 'Blue'
) {
  // destroy the previous instance (if existing)
  if (currentAdaptableInstance) {
    const config: any = {
      unmount: true,
      destroyApi: true,
    };
    currentAdaptableInstance.destroy(config);
  }

  currentAdaptableInstance = await Adaptable.init(
    {
      ...getAdaptableOptionsForUserAndTeam(
        userName,
        updateCurrentUser,
        teamName,
        updateCurrentTeam
      ),
    } as AdaptableOptions<WebFramework>,
    {gridOptions: {...gridOptions}, modules: agGridModules}
  );
  currentAdaptableInstance.eventApi.on(
    'AdaptableReady',
    (readyInfo: AdaptableReadyInfo) => {
      onAdaptableReady(readyInfo);
    }
  );
}

initializeAdaptable(currentUser, currentTeam);
```

**`src/App.tsx`** (React version)

```ts
import {
  Adaptable,
  AdaptableApi,
  AdaptableReadyInfo,
} from '@adaptabletools/adaptable-react-aggrid';
import * as React from 'react';
import {useState} from 'react';

// import adaptable css
import '@adaptabletools/adaptable-react-aggrid/index.css';
// import aggrid themes (using Balham theme)

import './styles.css';

import {agGridModules} from './agGridModules';
import {gridOptions} from './gridOptions';
import {onAdaptableReady} from './onAdaptableReady';
import {getAdaptableOptionsForUserAndTeam} from './adaptableOptions';

const Grid = ({
  currentUser,
  onCurrentUserChange,
  team,
  onTeamChange,
}: {
  currentUser: 'Alice' | 'Bob';
  onCurrentUserChange: (userName: 'Alice' | 'Bob') => void;
  team: 'Red' | 'Blue';
  onTeamChange: (team: 'Red' | 'Blue') => void;
}) => {
  const adaptableApiRef = React.useRef<AdaptableApi>(null);

  const adaptableOptions = getAdaptableOptionsForUserAndTeam(
    currentUser,
    onCurrentUserChange,
    team,
    onTeamChange
  );

  const agGridOptions = {...gridOptions};
  return (
    <div style={{display: 'flex', flexFlow: 'column', height: '100vh'}}>
      <Adaptable.Provider
        gridOptions={agGridOptions}
        adaptableOptions={adaptableOptions}
        modules={[...agGridModules]}
        onAdaptableReady={(adaptableReadyInfo: AdaptableReadyInfo) => {
          // save a reference to adaptable api
          adaptableApiRef.current = adaptableReadyInfo.adaptableApi;
          onAdaptableReady(adaptableReadyInfo);
        }}>
        <Adaptable.UI style={{flex: 'none'}} />
        <Adaptable.AgGridReact />
      </Adaptable.Provider>
    </div>
  );
};

const App: React.FunctionComponent = () => {
  const [currentUser, setCurrentUser] = useState<'Alice' | 'Bob'>('Alice');
  const [team, setTeam] = useState<'Red' | 'Blue'>('Red');

  return (
    <Grid
      key={currentUser + team}
      team={team}
      onTeamChange={teamName => setTeam(teamName)}
      currentUser={currentUser}
      onCurrentUserChange={userName => setCurrentUser(userName)}
    />
  );
};
export default App;
```

**`src/app/app.component.ts`** (Angular version)

```ts
import {ChangeDetectorRef, Component, Inject} from '@angular/core';

import {AdaptableReadyInfo, AdaptableOptions} from '@adaptabletools/adaptable-angular-aggrid';
import {GridOptions} from 'ag-grid-enterprise';

// Adaptable styles
import '@adaptabletools/adaptable-angular-aggrid/index.css';

// AG Grid styles

import './styles.css';

// grid configuration
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {onAdaptableReady} from './onAdaptableReady';
import {getAdaptableOptionsForUserAndTeam} from './adaptableOptions';
import {WebFramework} from './rowData';

@Component({
  standalone: false,
  selector: 'app-root',
  template: `
    <div id="demoOutputAbove"></div>
    <adaptable-provider
      *ngIf="isUpToDate"
      [adaptableOptions]="adaptableOpts"
      [gridOptions]="agGridOptions"
      [modules]="modules"
      (adaptableReady)="adaptableReady($event)"
      style="height: 100vh; width: 100vw;">
      <adaptable-ui style="flex: none"></adaptable-ui>
      <ag-grid-angular
        *adaptable="let adaptable"
        [gridOptions]="adaptable.gridOptions"
        [modules]="adaptable.modules"
        style="flex: 1">
      </ag-grid-angular>
    </adaptable-provider>
    <div id="demoOutputBelow"></div>
  `,
  styles: [
    `
      :host {
        height: 100vh;
        display: flex;
        flex-flow: column;
      }
    `,
  ],
})
export class AppComponent {
  adaptableOpts: AdaptableOptions<WebFramework>;
  agGridOptions: GridOptions<WebFramework>;
  modules = agGridModules;

  currentUser: 'Alice' | 'Bob';
  currentTeam: 'Red' | 'Blue';
  isUpToDate = true;

  constructor(
    @Inject(ChangeDetectorRef) private changeDetectorRef: ChangeDetectorRef
  ) {
    this.currentUser = 'Alice';
    this.currentTeam = 'Red';
    this.adaptableOpts = getAdaptableOptionsForUserAndTeam(
      this.currentUser,
      (user: 'Alice' | 'Bob') => this.setCurrentUser(user),
      this.currentTeam,
      (team: 'Red' | 'Blue') => this.setCurrentTeam(team)
    );
    this.agGridOptions = {...gridOptions};
  }

  setCurrentUser(currentUser: 'Alice' | 'Bob') {
    this.isUpToDate = false;
    this.changeDetectorRef.detectChanges();

    this.currentUser = currentUser;
    this.initializeAdaptable();
    this.isUpToDate = true;
    this.changeDetectorRef.detectChanges();
  }

  setCurrentTeam(teamName: 'Red' | 'Blue') {
    this.isUpToDate = false;
    this.changeDetectorRef.detectChanges();

    this.currentTeam = teamName;
    this.initializeAdaptable();
    this.isUpToDate = true;
    this.changeDetectorRef.detectChanges();
  }

  initializeAdaptable() {
    this.adaptableOpts = getAdaptableOptionsForUserAndTeam(
      this.currentUser,
      (user: 'Alice' | 'Bob') => this.setCurrentUser(user),
      this.currentTeam,
      (team: 'Red' | 'Blue') => this.setCurrentTeam(team)
    );
    this.agGridOptions = {...gridOptions};
  }

  adaptableReady($event: AdaptableReadyInfo) {
    onAdaptableReady($event);
  }
}
```

**`src/App.vue`** (Vue version)

```ts
<template>
  <Grid
    :key="currentUser + '-' + team"
    :currentUser="currentUser"
    @currentUserChange="setCurrentUser"
    :team="team"
    @onTeamChange="setTeam" />
</template>

<script lang="ts">
import {ref, defineComponent} from 'vue';
import {
  AdaptableProvider,
  AdaptableAgGridVue,
  AdaptableUI,
} from '@adaptabletools/adaptable-vue3-aggrid';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {getAdaptableOptionsForUserAndTeam} from './adaptableOptions';

const Grid = defineComponent({
  props: {
    currentUser: {
      type: String,
      required: true,
    },
    team: {
      type: String,
      required: true,
    },
  },
  emits: ['currentUserChange', 'onTeamChange'],
  setup(props, {emit}) {
    const adaptableOptions = getAdaptableOptionsForUserAndTeam(
      props.currentUser,
      userName => emit('currentUserChange', userName),
      props.team,
      team => emit('onTeamChange', team)
    );

    const agGridOptions = {...gridOptions};

    return {
      adaptableOptions,
      agGridOptions,
      agGridModules,
      onAdaptableReady,
    };
  },
  components: {
    AdaptableProvider,
    AdaptableAgGridVue,
    AdaptableUI,
  },
  template: `
    <AdaptableProvider
        :gridOptions="agGridOptions"
        :adaptableOptions="adaptableOptions"
        :modules="agGridModules"
        @onAdaptableReady="onAdaptableReady">
      <div style="display: flex; flex-direction: column; height: 100vh">
        <AdaptableUI :key="currentUser + '-ui'" style="flex: none" />
        <AdaptableAgGridVue style="flex: 1"  />
      </div>
    </AdaptableProvider>
  `,
});

export default defineComponent({
  name: 'App',
  components: {
    Grid,
  },
  setup() {
    const currentUser = ref('Alice');
    const team = ref('Red');

    const setCurrentUser = userName => {
      currentUser.value = userName;
    };

    const setTeam = teamName => {
      team.value = teamName;
    };

    return {
      currentUser,
      setCurrentUser,
      team,
      setTeam,
    };
  },
});
</script>
```

## Custom Objects Sharing

While the primary use case for TeamSharing is to allow different AdapTable instances to share AdapTable Objects (Layouts, Format Columns, etc.), it is also __possible to share bespoke object structures and values__.

See [Custom Team Sharing](https://www.adaptabletools.com/docs/handbook-team-sharing-custom/index.md) for more information

## Downloading Existing Objects

AdapTable will warn users if they are trying to import an Object which already exists.

It does this by checking whether Uuid of the [Adaptable Object](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md#adaptable-objects) is unique.

Set `suppressOverrideConfigWarning` to true in [Team Sharing Options](https://www.adaptabletools.com/docs/technical-reference-team-sharing/index.md) to avoid seeing this warning

## Configuring Team Sharing

Team Sharing is not available or enabled by default in AdapTable; instead, it needs to be explicitly enabled and set up by developers at design time.

Once Team Sharing is enabled, AdapTable will update the UI in 2 ways:

- include the Team Sharing screen in the Settings Panel
- add a _Share_ button to every screen in the Settings Panel that displays AdapTable Objects

See [Configuring Team Sharing](https://www.adaptabletools.com/docs/handbook-team-sharing-configuring/index.md) for step by step instructions on setting up Team Sharing

### FAQ

**Can we turn off Team Sharing if we don't want to use it?**
You don't need to turn off Team Sharing as it's not available by default.
Team Sharing is only available if the `enableTeamSharing` property is set to true in [Team Sharing Options](https://www.adaptabletools.com/docs/technical-reference-team-sharing/index.md) and the Entitlement for the Team Sharing Module is 'Full'.

**Can we share Adaptable Objects between differently identified Adaptable instances?**
Strictly speaking no (but in practice it is possible).

Team Sharing is intended to be used only for instances that share the same `adaptableId`; e.g. all users of a CDS Pricer can share the same Report but it cannot also be used in a Bond Matrix Pricer.

However while we use `adaptableId` as the identifier we don't enforce this so you can - at your discretion - share objects between AdapTable instances with different Ids.

**Can we use Team Sharing to share bespoke data (i.e. not AdapTable objects)?**
Yes, [Custom Objects Sharing](#custom-objects-sharing) was introduced in [AdapTable Version 15](https://www.adaptabletools.com/support/version-15-release-note)
