# Team Sharing of Custom Objects

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

- Team Sharing can be used to share any kind of data including custom objects

The primary use case for TeamSharing is to allow different AdapTable instances to share AdapTable Objects, e.g. Layouts, Format Columns, etc.

However, it is also possible to share bespoke object structures and values.

- AdapTable does not provide dedicated UI components for sharing Custom Objects
- Each user should create their own UI components optimised for their specific use case

AdapTable is very flexible and unopinionated regarding the structure of the shared data, so anything can be Team Shared if required.

### Understanding Custom Team Sharing

Shared objects in AdapTable are of type [`SharedEntity`](https://www.adaptabletools.com/docs/reference/sharedentity.md) defined as follows:

| Property | Type | Description |
| --- | --- | --- |
| [ChangedAt](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#changedat) | `number` | Last time when the object was changed |
| [ChangedBy](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#changedby) | `string` | Last User who changed the object |
| [Description](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#description) | `string` | Description of object being shared |
| [Entity](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#entity) | [`AdaptableObject`](https://www.adaptabletools.com/docs/reference/adaptableobject.md) | Actual Adaptable Object being shared |
| [EntityDependencyIds](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#entitydependencyids) | `TypeUuid[]` | Ids of direct entity dependencies |
| [EntityType](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#entitytype) | `'adaptableEntity'` | Type of shared entity (either Adaptable specific or custom object) |
| [LayoutExtensions](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#layoutextensions) | [`LayoutExtensionInfo`](https://www.adaptabletools.com/docs/reference/layoutextensioninfo.md) | Shared Layouts only: names of the objects, per Module, extended into the Layout when it was shared;<br/>applied to the importing user&#39;s Layout Extensions so the Extended Layout arrives complete |
| [Module](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#module) | [`AdaptableModule`](https://www.adaptabletools.com/docs/reference/adaptablemodule.md) | Adaptable Module to which object belongs |
| [Revision](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#revision) | `number` | Revision - incremental for &#39;Active&#39;, always 1 for &#39;Snapshot&#39; |
| [SharedAtMajorVersion](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#sharedatmajorversion) | `number` | Major AdapTable version this entity was last shared or migrated with.<br/>When it matches the running major, the upgrade chain is skipped. |
| [Timestamp](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#timestamp) | `number` | When the object was shared |
| [Type](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#type) | [`SharedEntityType`](https://www.adaptabletools.com/docs/reference/sharedentitytype.md) | &#39;Snapshot&#39; (for 1-time sharing) or &#39;Active&#39; (for continuous sharing) |
| [UserName](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#username) | `string` | User who shared the object |
| [IsReadOnly](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md#isreadonly) | `boolean` | Sets Entity to ReadOnly (overwriting a Strategy Entitlement of &#39;Full&#39;) |

The Shared Entity can be either:

- An [`AdapTable SharedEntity`](https://www.adaptabletools.com/docs/reference/adaptablesharedentity.md) (which extends an [Adaptable Object](https://www.adaptabletools.com/docs/dev-guide-adaptable-state-initial-state/index.md#adaptable-objects))
- A [`Custom Shared Entity`](https://www.adaptabletools.com/docs/reference/customsharedentity.md) - essentially of any Type

In addition, AdapTable provides several API methods that can be used when sharing custom objects:

- [`getLoadedCustomSharedEntities()`](https://www.adaptabletools.com/docs/reference/teamsharingapi.md#getloadedcustomsharedentities): returns all the locally loaded [`CustomSharedEntities`](https://www.adaptabletools.com/docs/reference/customsharedentity.md)
- [`shareCustomEntity()`](https://www.adaptabletools.com/docs/reference/teamsharingapi.md#sharecustomentity): shares the given [`CustomSharedEntities`](https://www.adaptabletools.com/docs/reference/customsharedentity.md)
- [`importSharedEntry()`](https://www.adaptabletools.com/docs/reference/teamsharingapi.md#importsharedentry): imports the given SharedEntry. In case of [`CustomSharedEntities`](https://www.adaptabletools.com/docs/reference/customsharedentity.md), the import logic will be delegated to [TeamSharingOptions.handleCustomSharedEntityImport()](https://www.adaptabletools.com/docs/technical-reference-team-sharing/index.md)

### `handleCustomSharedEntityImport`

Handles import of Custom Shared Entities

While import of shared AdaptableObjects (`AdaptableSharedEntity` flavour of the [`SharedEntity`](https://www.adaptabletools.com/docs/reference/sharedentity.md)) is automatically handled by Adaptable, the import of custom shared objects (`CustomSharedEntity` flavour of the [`SharedEntity`](https://www.adaptabletools.com/docs/reference/sharedentity.md)) needs to be handled on a case-by-case basis.

Invoking [`TeamSharingApi.importSharedEntry()`](https://www.adaptabletools.com/docs/reference/teamsharingapi.md#importsharedentry) with a [`CustomSharedEntry`](https://www.adaptabletools.com/docs/reference/customsharedentity.md) will call this function.

```ts {4}
teamSharingOptions: {
    enableTeamSharing: true,
        loadSharedEntities: async () => {
        // ...
    },
    persistSharedEntities: async (entries) => {
        // ...       
    }, 
    handleCustomSharedEntityImport: (sharedEntity: CustomSharedEntity) => {
        if (sharedEntity.Uuid === CUSTOM_SHARE_KEY || sharedEntity.Name === 'myCustomObject') {
            // implement object import
        }
    }
}
```

See the [provided demo](https://www.adaptabletools.com/docs/handbook-team-sharing/index.md#custom-objects-sharing) showcasing the import & export of custom objects.

**Example: Team Sharing with Custom Objects**

Using Team Sharing to share bespoke data

- This example illustrates how Team Sharing can be used to share custom objects
- Each user may increment/decrement their local value and choose to either:
  - push their local state value to the remote common state
  - import the remote state value and overwrite their local value
### Expand to see how custom Team Sharing is handled

1. Every second we poll the remote TeamSharing state, to ensure the [`TeamSharingApi.getCustomSharedEntities()`](https://www.adaptabletools.com/docs/reference/teamsharingapi.md#getloadedcustomsharedentities) returns up-to-date values.
```ts
export const onAdaptableReady = ({adaptableApi}: AdaptableReadyInfo) => {
  const timerId = setInterval(() => {
    // reload TeamSharing state
    adaptableApi.teamSharingApi.refreshTeamSharing();
    // re-render toolbar buttons to force the update of the remote state elements
    adaptableApi.dashboardApi.refreshDashboard();
  }, 1000);
  adaptableApi.eventApi.on('AdaptableDestroy', () => {
    clearInterval(timerId);
  });
};
```
2. Updating the remote state is done by invoking the [`shareCustomEntity()`](https://www.adaptabletools.com/docs/reference/teamsharingapi.md#sharecustomentity) method.  Notice that we have a fixed technical ID (`Uuid`) in order to be able to reference it later when re-importing it.
```ts
onClick: (button, context) => {
    const currentLocalValue = getLocalMutableShare(userName);
    context.adaptableApi.teamSharingApi.shareCustomEntity(
        currentLocalValue, 
        {
          Uuid: CUSTOM_SHARE_KEY,
          Name: 'Counter',
          Description: 'Just a simple example of a shared custom state',
        }
    );
},
```
3. Querying the remote state is done by invoking the [`getLoadedCustomSharedEntities()`](https://www.adaptabletools.com/docs/reference/teamsharingapi.md#getloadedcustomsharedentities) method (the local state is kept up-to-date, see 1. above)
```ts
const getRemoteCustomSharedEntity = (
        adaptableApi: AdaptableApi
): CustomSharedEntity | undefined => {
  // TeamSharing state is refreshed every 2 seconds, see `onAdaptableReady()` handler
  return adaptableApi.teamSharingApi
          .getLoadedCustomSharedEntities()
          .find(sharedEntity => sharedEntity.Uuid === CUSTOM_SHARE_KEY);
};
```
4. Importing a remote state value is done by invoking [`importSharedEntry()`](https://www.adaptabletools.com/docs/reference/teamsharingapi.md#importsharedentry).
The actual importing logic is provided via the [TeamSharingOptions.handleCustomSharedEntityImport()](https://www.adaptabletools.com/docs/technical-reference-team-sharing/index.md) callback.
```ts
const remoteCustomSharedEntity = getRemoteCustomSharedEntity(
    context.adaptableApi
);
if (remoteCustomSharedEntity) {
    context.adaptableApi.teamSharingApi.importSharedEntry(
        remoteCustomSharedEntity
    );
}
teamSharingOptions: {
  enableTeamSharing: true, 
  handleCustomSharedEntityImport: (sharedEntity: CustomSharedEntity) => {
    if (sharedEntity.Uuid === CUSTOM_SHARE_KEY) {
      setLocalState(userName, sharedEntity.Entity);
    }
  },
},
```

1. As Alice increment the local value from 0 to 1
2. Switch to Bob and note that his local value is still 0
3. Switch back to Alice and now click "Push to Team Sharing"
4. Switch back to Bob and note that his local value is still 0 but the next tab shows that Alice updated the value to 1
5. Click 'Import Remote Value' and note that Bob now has a local value of 1 (same as Alice)
6. Update the Local Value from 1 to 2 and then click "Push to Team Sharing"
7. Switch back to Alice and note that while the local value 1, it says 2 is available which can be fetched by clicking "Import Remote Value"

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
  rowData.ts           [template]
  styles.css           [template + shown below]
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,
  AdaptableApi,
  CustomSharedEntity,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

// use a common Team Sharing state key for both users
const TEAM_SHARING_STATE_KEY = 'CustomTeamSharingDemo_TeamSharingState';

const CUSTOM_SHARE_KEY = 'demoCustomKey';

const getLocalMutableShare = (
  userName: 'Alice' | 'Bob'
): {
  value: number;
  lastUpdatedBy: string;
} => {
  const localState = localStorage.getItem(
    `CustomTeamSharingDemo_${userName}_localState`
  );
  if (!localState) {
    return {
      value: 0,
      lastUpdatedBy: 'none',
    };
  }
  return JSON.parse(localState);
};

const mutateLocalState = (userName: 'Alice' | 'Bob', step: 1 | -1) => {
  let localState = getLocalMutableShare(userName);
  localState = {
    value: localState.value + step,
    lastUpdatedBy: userName,
  };
  localStorage.setItem(
    `CustomTeamSharingDemo_${userName}_localState`,
    JSON.stringify(localState)
  );
};

const setLocalState = (
  userName: 'Alice' | 'Bob',
  newValue: {
    value: number;
    lastUpdatedBy: string;
  }
) => {
  localStorage.setItem(
    `CustomTeamSharingDemo_${userName}_localState`,
    JSON.stringify(newValue)
  );
};

const getRemoteCustomSharedEntity = (
  adaptableApi: AdaptableApi
): CustomSharedEntity | undefined => {
  // TeamSharing state is refreshed every 2 seconds, see `onAdaptableReady()` handler
  return adaptableApi.teamSharingApi
    .getLoadedCustomSharedEntities()
    .find(sharedEntity => sharedEntity.Uuid === CUSTOM_SHARE_KEY);
};

export const getAdaptableOptionsForUser = (
  userName: 'Alice' | 'Bob',
  updateCurrentUser: (userName: 'Alice' | 'Bob') => void
): AdaptableOptions<WebFramework> => {
  const commonInitialState: InitialState = {
    Dashboard: {
      Revision: Date.now(),
      Tabs: [
        {
          Name: 'Configuration',
          Toolbars: ['CurrentUser', 'LocalCustomState', 'RemoteCustomState'],
        },
      ],
      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-21)',
                  ForeColor: 'var(--ab-color-palette-13)',
                },
              },
            ],
          },
          Theme: {
            CurrentTheme: 'dark',
          },
        };

  return {
    primaryKey: 'id',
    adaptableId: 'Custom Objects Team Sharing Demo',
    adaptableStateKey: `CustomTeamSharingDemo_${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();
      },
      handleCustomSharedEntityImport: (sharedEntity: CustomSharedEntity) => {
        if (sharedEntity.Uuid === CUSTOM_SHARE_KEY) {
          setLocalState(userName, sharedEntity.Entity);
        }
      },
    },
    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: 'LocalCustomState',
          title: 'Local Custom State',

          toolbarButtons: [
            {
              icon: {
                name: 'plus',
              },
              buttonStyle: () => {
                return {
                  tone: 'info',
                  variant: 'outlined',
                };
              },
              onClick: () => {
                mutateLocalState(userName, 1);
              },
            },
            {
              icon: {
                name: 'minus',
              },
              buttonStyle: () => {
                return {
                  tone: 'info',
                  variant: 'outlined',
                };
              },
              onClick: () => {
                mutateLocalState(userName, -1);
              },
            },
            {
              label: () => {
                return `Local value: ${getLocalMutableShare(userName).value}`;
              },
              buttonStyle: () => {
                return {
                  tone: 'neutral',
                  variant: 'text',
                  className: 'textContent',
                };
              },
              disabled: () => true,
            },
            {
              label: 'Push to Team Sharing',
              icon: {
                name: 'upload',
              },
              buttonStyle: () => {
                return {
                  tone: 'info',
                  variant: 'raised',
                };
              },
              onClick: (button, context) => {
                const currentLocalValue = getLocalMutableShare(userName);
                context.adaptableApi.teamSharingApi.shareCustomEntity(
                  currentLocalValue,
                  {
                    Uuid: CUSTOM_SHARE_KEY,
                    Name: 'Counter',
                    Description:
                      'Just a simple example of a shared custom state',
                  }
                );
              },
              disabled: (button, context) => {
                const remoteStateValue =
                  getRemoteCustomSharedEntity(context.adaptableApi)?.Entity
                    ?.value || 0;
                const localStateValue = getLocalMutableShare(userName).value;
                return remoteStateValue === localStateValue;
              },
            },
          ],
        },
        {
          name: 'RemoteCustomState',
          title: 'Remote Custom State',
          toolbarButtons: [
            {
              label: (button, context) => {
                const remoteStateEntity = getRemoteCustomSharedEntity(
                  context.adaptableApi
                )?.Entity;
                return remoteStateEntity
                  ? `${remoteStateEntity.value} (last updated by ${remoteStateEntity.lastUpdatedBy})`
                  : '<none>';
              },
              buttonStyle: () => {
                return {
                  tone: 'neutral',
                  variant: 'text',
                  className: 'textContent',
                };
              },
              disabled: () => true,
            },
            {
              label: 'Import Remote Value',
              icon: {
                name: 'import-export',
              },
              buttonStyle: () => {
                return {
                  tone: 'warning',
                  variant: 'raised',
                };
              },
              onClick: (button, context) => {
                const remoteCustomSharedEntity = getRemoteCustomSharedEntity(
                  context.adaptableApi
                );
                if (remoteCustomSharedEntity) {
                  context.adaptableApi.teamSharingApi.importSharedEntry(
                    remoteCustomSharedEntity
                  );
                }
              },
              disabled: (button, context) => {
                const remoteStateValue = getRemoteCustomSharedEntity(
                  context.adaptableApi
                )?.Entity?.value;
                const localStateValue = getLocalMutableShare(userName).value;
                return (
                  !remoteStateValue || remoteStateValue === localStateValue
                );
              },
            },
          ],
        },
      ],
      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(
                `CustomTeamSharingDemo_${user}_localState`
              );
              localStorage.removeItem(`CustomTeamSharingDemo_${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/onAdaptableReady.ts`**

```ts
import {AdaptableReadyInfo} from '@adaptabletools/adaptable';

export const onAdaptableReady = ({adaptableApi}: AdaptableReadyInfo) => {
  const timerId = setInterval(() => {
    // reload TeamSharing state
    adaptableApi.teamSharingApi.refreshTeamSharing();
    // re-render toolbar buttons to force the update of the remote state elements
    adaptableApi.dashboardApi.refreshDashboard();
  }, 1000);

  adaptableApi.eventApi.on('AdaptableDestroy', () => {
    clearInterval(timerId);
  });
};
```

**`src/styles.css`**

```css
.ab-Dashboard__toolbar
  .ab-Dashboard__toolbar-content
  .ab-SimpleButton--disabled.textContent {
  opacity: inherit;
}
```

**`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>
```
