Backoffice Signs: Can I add a sign to an entity without the server?

Heya :waving_hand:
Poking around with FlagProviders & Signs (Icons on the tree items) and I was wondering if I am able to add a sign/icon to the tree from clientside only without the C# FlagProvider code ?

Why?

I am currently using SignalR in the Content Lock package and I have a Global Context that receives events from the server as a SignalR hub when nodes are locked and unlocked by the current user and other users logged into the CMS. This global context stores a list of unique/keys of the current locked nodes.

So in my mind it would be good if I was able to set a sign/icon alias on a collection of nodes/uniques, in order that the sign icon can be added and removed to the tree document when nodes are locked and unlocked in realtime.

As currently the information for the tree and the flags are only sent when you are navigating the tree and only then you would get the new information back from the server that the node is locked or unlocked now.

Hi @warren

Yes, you can.. that is actually the difference between a Entity Flag and Entity Sign.
The sign is not married to the flag, its an opportunity to bind them.

Read more here

Leave out the forEntityFlags then the sign will appear everywhere, then use Conditions to control when the Sign should appear.

Ideally finetune the Docs, I see this aspect is not very clear from the reading.

Psst… As well could Flags be used for other things than Signs.. but this is just not something we have done yet.

My Solution

I was able to solve my solution with locked and unlocked nodes with Flags & Signs by doing the following.

My entity action that triggers a message via SignalR which will in turn then use the event context to trigger the tree item to be reloaded, which in turn then requests it again from the server and this then gets the latest state for the flag off the server.

Code

import { UmbControllerHost } from "@umbraco-cms/backoffice/controller-api";
import { UMB_ACTION_EVENT_CONTEXT, UmbActionEventContext } from "@umbraco-cms/backoffice/action";
import { UmbRequestReloadStructureForEntityEvent } from "@umbraco-cms/backoffice/entity-action";
import { UMB_DOCUMENT_ENTITY_TYPE } from "@umbraco-cms/backoffice/document";

#eventContext?: UmbActionEventContext;

constructor(host: UmbControllerHost) {
    super(host, CONTENTLOCK_SIGNALR_CONTEXT);

    // Action Event context - to notify about emitting event to trigger a tree reload
    this.consumeContext(UMB_ACTION_EVENT_CONTEXT, (eventContext) => {
        this.#eventContext = eventContext;
    });
}

/**
 * Send out an event to request the tree to reload the item with the given key
 * Will fetch item/s from server again and thus get the latest Locked Flag/Sign info
 * @param key The GUID/Unique/key that got updated
 */
#emitReloadTreeEvent(key: string){
    if(this.#eventContext){
        this.#eventContext.dispatchEvent(new UmbRequestReloadStructureForEntityEvent(
            {
                unique: key,
                entityType: UMB_DOCUMENT_ENTITY_TYPE
            }
        ));
    } else{
        console.warn('[Content Lock - SignalR Ctx] Unable to dispatch reload event because UMB_ACTION_EVENT_CONTEXT is not available.');
    }
}

Forgot about my own blog post :see_no_evil_monkey: