> For the complete documentation index, see [llms.txt](https://docs.eximee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/eximee-dashboard/wlasny-web-component.md).

# Custom web component in Eximee Dashboard

Eximee Dashboard can display its own **web component**, that is, an HTML element created outside the platform. The element is a separate frontend application. Dashboard loads its JavaScript file only in the browser, so Dashboard and the web component have independent releases.

The page describes the web component shown in a tab of type `external` case view. The pattern is the tab `Notes` (element `notes-view`): views, adds, edits, and deletes case notes. The method of building, configuring, and invoking the service described below applies to every web component of the tab.

{% hint style="info" %}
The page describes the element, not the service it connects to. The element calls the service at the address entered in its code. The pattern assumes a service available in the Dashboard domain, but in another deployment the service may run under any address.
{% endhint %}

## How Dashboard shows the web component

In the script [application screen configuration](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/eximee-dashboard/konfiguracja/konfiguracja-ekranow-aplikacji.md) tab of type `external` has three elements:

* `data` - an object with data for the element,
* tab header,
* web component configuration: element tag and JavaScript file addresses ([`webComponentV1`](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/eximee-dashboard/konfiguracja/konfiguracja-ekranow-aplikacji.md#webcomponentv1)).

When the tab is opened, Dashboard:

1. Loads JavaScript files from the configuration, in the given order. On the first load on the page, it fetches them again, bypassing the browser cache.
2. Creates an element with the given tag.
3. Sets the element property `data`, before inserting it into the page.
4. Inserts the element into the tab.

Rules that result from this:

* `data` is an object whose all values are text. Dashboard does not add any data to it: case ID, user data, or token. The element receives only the data specified in the script.
* When only the data changes, Dashboard passes new `data` data to the same element. When the configuration changes, Dashboard removes the element and recreates it.
* When the user leaves the tab, Dashboard removes the element from the page and does not call any method on it. The element stops timers and removes window event listeners itself (`disconnectedCallback`).
* If the files fail to load, the element is not created. The next time the tab is opened, Dashboard retries loading them.
* Dashboard does not load the web component stylesheets. Styles must be in the JavaScript file.

## Example: Notes tab

The element `notes-view` consists of four elements registered in one file `notes-view.js`:

| Tag                  | Task                                                                  |
| -------------------- | --------------------------------------------------------------------- |
| `notes-view`         | Main tab element. Fetches data, stores view state, and saves changes. |
| `notes-view-toolbar` | Header `Notes` and buttons.                                           |
| `notes-view-list`    | Case notes list.                                                      |
| `notes-view-details` | Content of the selected note or the field for a new note.             |

Only the tag `notes-view`. The remaining elements are created by `notes-view`.

The look of the tab and its operation from the user's perspective are described on the page [Notes](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/eximee-dashboard/konfiguracja/notatki.md).

### Tab configuration in the script

The tab receives the case identifier in the object `data`. It is the only source from which the element obtains this identifier.

```javascript
function call(context) {
    return processConfigV1()
        .tab(
            processTabV1(
                "notes",
                "Notes",
                external
                "feature_browse_notes",
                externalComponentTabV1(
                    { processId: context.processId() },
                    processTabHeaderV1("Notes"),
                    webComponentV1("notes-view", [sourceV1("/biz/notes/ui/notes-view.js")])
                )
            )
        );
}
```

| Argument                                                                                                                                                                                                                                       | Meaning in the example                                             |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| `"notes"`                                                                                                                                                                                                                                      | Tab identifier in the case URL, e.g. `#/process/{caseId}/notes`.   |
| `"feature_browse_notes" Permission required to display the tab. Dashboard removes the tab for which the employee does not have permission before sending the configuration to the browser. In that case the web component file is not loaded.` | "notes-view"                                                       |
| `"notes-view"`                                                                                                                                                                                                                                 | Element tag.                                                       |
| `"/biz/notes/ui/notes-view.js"`                                                                                                                                                                                                                | Address of the JavaScript file, relative to the Dashboard address. |

Permission specified in `permission` is compared against the user's role list case-sensitively. It should be written in lowercase, according to the names `feature_*` of [role mapping](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/eximee-dashboard/konfiguracja/uprawnienia.md).

### Element structure

#### Tag registration

Tag is registered only if it has not been registered before. Thanks to this, reloading the file does not cause an error:

```javascript
const ELEMENTS = [
    ['notes-view', NotesView],
    ['notes-view-toolbar', NotesViewToolbar],
    ['notes-view-list', NotesViewList],
    ['notes-view-details', NotesViewDetails],
];

for (const [tag, element] of ELEMENTS) {
    if (!customElements.get(tag)) {
        customElements.define(tag, element);
    }
}
```

Tag starts with the abbreviation of the application name to which the web component belongs (`notes` in the example). This allows you to recognize which application the element comes from. Prefixes `rt2-`, `ui-` and `es-` are reserved for Dashboard, and `ex-` - for the form engine.

#### Receiving data

The element accepts `data` both before insertion into the page and after it. After the case identifier changes `notes-view` it fetches notes again:

```javascript
class NotesView extends LitElement {
    static properties = {
        data: {attribute: false},
    };

    willUpdate(changed) {
        const processId = this.data?.processId;
        if (changed.has('data') && processId !== this.loadedProcessId) {
            this.loadedProcessId = processId;
            this.load(processId);
        }
    }
}
```

If the object `data` does not contain `processId`, the view displays the message `Failed to load notes`.

#### Token and service calls

Dashboard does not add the token to requests sent by the web component. The element gets the token from `window.router2api.getAuthToken()` and adds it to every request in the header `Authorization`:

```javascript
const token = await window.router2api.getAuthToken();

const response = await fetch('/biz/notes/v1/process/' + encodeURIComponent(processId) + '/notes', {
    method: 'GET',
    headers: {Authorization: 'Bearer ' + token, Accept: 'application/json'},
});
```

{% hint style="warning" %}
The element calls the service using a relative address, in the Dashboard domain. Calling another domain requires CORS to be set on the service side and permission in the Content Security Policy (CSP).
{% endhint %}

Dashboard provides the object `window.router2api`, which contains two functions used in the example:

| Function                    | Action                                                                                |
| --------------------------- | ------------------------------------------------------------------------------------- |
| `getAuthToken()`            | Returns the access token of the logged-in user.                                       |
| `notify(message, duration)` | Shows a Dashboard message for `duration` milliseconds (default 3000). Notes use 5000. |

#### Notes service calls

The view sends five kinds of requests. Each carries the header `Authorization: Bearer <token>`.

| Operation             | Request                                     | Request body         | Response                                                                      |
| --------------------- | ------------------------------------------- | -------------------- | ----------------------------------------------------------------------------- |
| Logged-in user's data | `GET /biz/notes/v1/current-user`            | none                 | `username` and `permissions` (`browse`, `add`, `modify`, `delete` - booleans) |
| Case notes list       | `GET /biz/notes/v1/process/{caseId}/notes`  | none                 | notes list                                                                    |
| Create note           | `POST /biz/notes/v1/process/{caseId}/notes` | `{"content": "..."}` | created note                                                                  |
| Edit note             | `PUT /biz/notes/v1/notes/{noteId}`          | `{"content": "..."}` | edited note                                                                   |
| Delete note           | `DELETE /biz/notes/v1/notes/{noteId}`       | none                 | any 2xx response                                                              |

The note in the response has fields: `id`, `processInstanceId`, `content`, `username`, `firstName`, `lastName`, `creationDate` and `lastModificationDate` (may be empty).

The view distinguishes only two types of error:

* status `403` - no access to the notes for this case,
* other statuses outside the 2xx range - general error.

When the tab opens, the view sends the request `current-user` and the request to fetch the list of notes at the same time. If either returns status `403`, the view displays a no-access message. In case of another error, it displays a general message.

#### Permissions in the element

The element does not read roles from the token. The service passes permissions to the notes in the response `current-user`, and the element shows or hides buttons based on them. Hiding buttons concerns only the presentation of the view. With each request, the service checks whether the given operation is allowed. The case identifier sent from the browser alone does not confirm that the user has access to it.

Buttons are Dashboard controls `rt2-button`. Dashboard registers its own controls on the page `rt2-*`, so the element built from them looks like the rest of the Dashboard. The control accepts properties `color` (`primary` or `warn`), `type` (`stroked` or `flat`) and `disabled`. Click emits the event `buttonClick`:

```javascript
html`
    <rt2-button .color=${'primary'} .type=${'stroked'} @buttonClick=${() => this.save()}>
        Save note
    </rt2-button>
`
```

#### Selected note in the page URL

The view saves the identifier of the selected note in the parameter `note` in the address, e.g. `#/process/{caseId}/notes?note=15`. This makes the link point to a specific note.

* Selecting a note updates the address using `history.replaceState`. The browser does not add a new history entry, and the Dashboard router does not recreate the element.
* The view reads the parameter when loading notes and after events `hashchange` and `popstate`.
* If the parameter value is not a number or points to a note outside the list, the parameter is ignored. No note is selected, and the view does not display an error message.
* Button `Add new note` removes the parameter from the address.

```javascript
const hash = withNoteId(window.location.hash, noteId);
if (hash !== window.location.hash) {
    window.history.replaceState(window.history.state, '', hash);
}
```

#### Style

Each of the four elements has its own `shadow root`, and its styles are saved in the JavaScript file (in the example using `css` from the Lit library). The element's styles do not affect the rest of the page, and the Dashboard's styles do not affect the element.

An element without `shadow root` uses the global Dashboard styles and the styles from the file `custom/styles.css` of the given deployment. Its own styles can, however, affect the whole page, so each selector should start with the element's tag.

### View behavior

| Situation                          | What is visible                                                                                                                                                                                |
| ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Data is being fetched              | Loading indicator.                                                                                                                                                                             |
| No notes                           | Text `No notes`.                                                                                                                                                                               |
| Service denies access (`403`)      | `No access to the notes for this case.` The list and text field are not shown.                                                                                                                 |
| Another error while loading        | `Failed to load notes.` The list and text field are not shown.                                                                                                                                 |
| Note created                       | Message `The note has been created`. The note is the first item in the list and is selected.                                                                                                   |
| Note modified                      | Message `The note has been modified`.                                                                                                                                                          |
| Note deleted                       | Message `The note has been deleted`. No note is selected.                                                                                                                                      |
| Save error                         | Message `An error occurred while adding the note`, `An error occurred while modifying the note` or `An error occurred while deleting the note`. The entered content remains in the text field. |
| Access denied while saving (`403`) | Message `No access to the notes for this case`.                                                                                                                                                |

The buttons in the header depend on permissions from the response `current-user` and on the state of the view:

| Button                           | When visible                                                                   |
| -------------------------------- | ------------------------------------------------------------------------------ |
| `Save note` (new note)           | Permission `add`, no note is selected.                                         |
| `Add new note`                   | Permission `add`, a note is selected.                                          |
| `Edit note`                      | Permission `modify`, a note is selected, editing is not in progress.           |
| `Save note` and `Cancel editing` | Permission `modify`, editing of the selected note is in progress.              |
| `Delete note`                    | Permission `delete`, a note is selected, and its author is the logged-in user. |

The text field is displayed when a note is selected or the user has permission `add`. The content of the selected note remains read-only until editing starts. The button `Cancel editing` restores the original content without saving changes or displaying a message.

The list displays notes in the order returned by the service. Each item contains the content in one line (longer content is truncated), the author's first and last name together with initials, and the creation date in the format `15.10.2026, 14:05`, according to the browser's local time.

### Sharing the web component file

Dashboard loads the file from the address given in `sourceV1`. The address is used exactly as entered. The relative address is calculated from the Dashboard address.

The web component file meets the conditions:

* it is a single JavaScript file in the format `iife`, without splitting into parts, because Dashboard can run it again,
* it is available at an address without query parameters, because Dashboard appends `?_c=<time>`. If the address already contains the sign `?`, adding a second one will cause the address to stop working,
* is small, because Dashboard fetches it again on the first load on a given page. The remaining code can be loaded via `import()` from addresses for which the browser can use the cache,
* has its own tag. Dashboard remembers loaded files based on the tag, so two configurations with the same tag must point to the same files. A file defining multiple tags will be run once for each tag configured in the case.

In the example, the file `notes-view.js` is built by the esbuild tool from the Nx project. The Lit library is bundled together with the component code. The Nx tool accepts only the `esm` and `cjs`, so the `iife` format is set by a plugin in the build configuration file:

```javascript
module.exports = {
  outExtension: {'.js': '.js'},
  plugins: [
    {
      name: 'iife-format',
      setup(build) {
        build.initialOptions.format = 'iife';
      },
    },
  ],
};
```

Build: `nx build notes-webcomponent`.

#### Dashboard proxy at `/biz/<prefix>/`

In the example, the component file and service are available on the Dashboard domain at `/biz/notes/`. They are handled by a proxy created by the Dashboard backend. By default it is disabled.

<figure><img src="https://2112972046-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2CssJT0zIo4SJQLbSZ6l%2Fuploads%2Fgit-blob-52dd101c6d0985edb83693fb804ffb004d8525db%2Fprzelotka-dashboardu.png?alt=media" alt="Droga żądań web componentu przez przelotkę Dashboardu"><figcaption><p><em><strong>Figure 1.</strong> Path of web component requests through the Dashboard proxy</em></p></figcaption></figure>

The proxy routes requests according to the route. The route name is a prefix in the address and consists of lowercase letters and digits.

| Address                                   | Handling                                                                                                                                                                                                                           |
| ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/biz/<prefix>/ui/<file>` (`GET`, `HEAD`) | Response `302` to `<files-url>/<file>`, with header `Cache-Control: no-store`. The request does not require a token, because the `<script>` tag does not send one. The query (`?_c=`) is not carried over to the redirect address. |
| `/biz/<prefix>/...` (other addresses)     | Forwarding the request to the service at the route address. Requires a token.                                                                                                                                                      |

The route is described by Dashboard backend properties. The properties `url`, `files-url` and `permissions` can be provided as environment variables, for example for the prefix `notes`: `EXIMEE_DASHBOARD_BIZPROXY_ROUTES_NOTES_URL`, `EXIMEE_DASHBOARD_BIZPROXY_ROUTES_NOTES_FILESURL` and `EXIMEE_DASHBOARD_BIZPROXY_ROUTES_NOTES_PERMISSIONS`.

| Property                                                     | Meaning                                                                                        | Default value              |
| ------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- | -------------------------- |
| `eximee.dashboard.biz-proxy.enabled`                         | Enables the proxy.                                                                             | `false`                    |
| `eximee.dashboard.biz-proxy.routes.<prefix>.url`             | Service address. The path after the prefix is appended to it.                                  | none, required             |
| `eximee.dashboard.biz-proxy.routes.<prefix>.files-url`       | Address of the directory with web component files. Without it, the route does not serve files. | none                       |
| `eximee.dashboard.biz-proxy.routes.<prefix>.permissions`     | View function permissions. Any one is sufficient.                                              | none, list cannot be empty |
| `eximee.dashboard.biz-proxy.routes.<prefix>.connect-timeout` | Limit for establishing a connection to the service.                                            | `2s`                       |
| `eximee.dashboard.biz-proxy.routes.<prefix>.read-timeout`    | Limit for waiting for the service response.                                                    | `10s`                      |
| `eximee.dashboard.biz-proxy.routes.<prefix>.max-connections` | Route connection pool size.                                                                    | `20`                       |

{% hint style="warning" %}
The Dashboard backend will not start with a route that has an invalid prefix, has no address, or has no permissions.
{% endhint %}

Proxy responses for requests to the service:

| Condition                                      | Response         |
| ---------------------------------------------- | ---------------- |
| request without a valid token                  | `401`            |
| prefix without a route                         | `404`            |
| the employee has none of the route permissions | `403` no content |
| path with a segment `.` or `..`                | `400`            |
| service is unreachable                         | `502`            |
| service does not respond within the time limit | `504`            |

The proxy forwards only the following headers to the service `Content-Type`, `Accept`, `Accept-Language`, `If-Match`, `If-None-Match` and `Authorization` with the request token. From the response, it returns the status, body, and headers `Content-Type`, `Content-Disposition`, `Cache-Control`, `ETag` and `Last-Modified`. Header `Location` and cookies do not pass through the proxy, so a service responding with a redirect will not work through it.

The proxy checks only the general right to the view function. Access to a specific case or note is checked by the service with each request.

## Most common issues

| Symptom                                                | Most common cause                                                                                                                                                                                                                                      |
| ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| The tab is not in the case view                        | The employee does not have the permission from the argument `permission`, or the screen configuration script of this application does not declare the tab. Permissions are fetched on login, so after changing them you must log out and log in again. |
| The tab is there, but the element does not appear      | The JavaScript file was not loaded: the address is incorrect or contains query parameters. The tag in the script must be the same as the one registered in the file.                                                                                   |
| The view shows `Failed to load notes.`                 | Object `data` does not contain `processId`, or the service responds with an error other than `403`.                                                                                                                                                    |
| The view shows `No access to the notes for this case.` | The service responded `403`. The service may also deny access for a few seconds after creating the case. After a few seconds and refreshing the page, the notes are visible.                                                                           |
| The request to the service ends with status `401`      | The request does not carry the header `Authorization` with the token.                                                                                                                                                                                  |
| File `notes-view.js` responds `404`                    | The route has no address set for the directory with files (`files-url`) or the prefix has no route.                                                                                                                                                    |

## Related pages

* [Application screen configuration](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/eximee-dashboard/konfiguracja/konfiguracja-ekranow-aplikacji.md) - functions `externalComponentTabV1`, `webComponentV1` and `processTabHeaderV1`.
* [Notes](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/eximee-dashboard/konfiguracja/notatki.md) - Notes tab from the user's and administrator's perspective.
* [Permissions](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/eximee-dashboard/konfiguracja/uprawnienia.md) - mapping roles to Eximee Dashboard permissions.
* [External WebComponent](https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/komponenty-rozszerzone/external-webcomponent.md) - web component embedded in the form.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.eximee.com/documentation/documentation-en/budowanie-aplikacji/interfejs-uzytkownika/eximee-dashboard/wlasny-web-component.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
