Dynamic conditions
# package-development
m
Question: I need to load a workspaceView in the content section but I only want it to show up for certain document types - this used to be possible with some C# magic in pre v14. I know about the conditions array
Copy code
typescript
conditions : [
  {
      alias : 'Umb.Condition.WorkspaceAlias',
      match : 'Umb.Workspace.Document'
  }
]
In this scenario I would need to fetch from the server before I know which doc types to mount the element for. Anyone done anything similar or have any pointers/ideas?
m
So I am yet to do any 14. So I might be super wrong ๐Ÿ™‚ But you could use a JS entry point and then import Umbraco services to figure out your conditions https://docs.umbraco.com/umbraco-cms/v/14.latest-beta/extending-backoffice/extension-types/extension-types/entry-point
j
You can use an entrypoint like Matt says, or you can make your own condition, which allows you to run some javascript logic such as checking for certain things
m
Thanks guys! My code sample is from the custom entryPoint, but I'm really asking if there is a "out of the box" condition for what type of content type that is loading? If not that might be a good core candidate I guess? I could either build it internally for my package but it feels like something that would be valuable for other extensions as well - any toughts @Jacob Overgaard ?
p
@User May I suggest โ€œpeopleโ€ instead of "guys"? We use gender inclusive language in this Discord. ๐Ÿ˜€
w
Think a list of available conditions to date would be useful
m
I think that there is only 1-2 more than the once listed here
w
These are the ones I found
Copy code
Umb.Condition.User.AllowEnableAction
Umb.Condition.User.AllowUnlockAction
Umb.Condition.User.AllowDeleteAction
Umb.Condition.User.AllowDisableAction
Umb.Condition.User.AllowResendInviteAction
Umb.Condition.UserPermission

Umb.Condition.WorkspaceAlias
Umb.Condition.WorkspaceEntityType
Umb.Condition.WorkspaceHasCollection

Umb.Condition.MenuAlias

Umb.Condition.CollectionBulkActionPermission

Umb.Condition.SectionAlias
Umb.Condition.SectionUserPermission

Umb.Condition.Switch

Umb.Condition.BlockWorkspaceHasSettings
Umb.Condition.BlockEntryShowContentEdit
h
Hey Warren, I added an RSS feed to my site, I'm guessing you were asking because it can get added to an Umbraco news feed? https://harrygordon.co.uk/rss.xml
m
Ups... ๐Ÿ˜„ There is another 15-20 conditions ๐Ÿ˜„ I was wrong ๐Ÿ˜„ hahaha sorry!
h
Sorry, this was meant to be a DM! ๐Ÿ˜‚
m
@Jacob Overgaard ๐Ÿ˜„ Since you're writing ๐Ÿ˜„ Can I bump this one? Do you think that the "ContentTypeAlias" condition is something that would benefit others (and a good PR candicate) or should I keep it inside my package?
j
Sure, let me read
m
Hmmm... maybe this is not possible? Looks like the workspaceView is loaded before the content-workspace knows the content type alias?
j
yeah, well, looks like we have another way of doing this for some of the extension types --
forEntityTypes
directly on the manifest
it runs before the condition system
works for entity actions for example
maybe we should just let that work for workspace views... I think it's a good idea to have something
m
It would indeed be useful to be able to only how the workspaceView for certain content (and also media) types
Is "entityType" the same as "content type"? Sounds more like content = entity type, startpage, blogpage, article = content type alias
j
"content" covers everything -- documents, media, and members ๐Ÿ™‚
m
okej ๐Ÿ˜„
j
entity is even broader
like "language" is an entity type
m
yeeh,, thats why I was wondering about the "forEntityType" example, but I guess you talked about the reusing the concept and not the exact name?
j
yeah
but unfortunately you are right, the workspace editor currently has no idea what it is loading
m
But is the result of the condition observed in any way?
essentially you just need to consume the generic workspace context and use the
filter
argument of the initializer
of course you would need to add
forEntityTypes
as a property to the workspace view manifest model
would you be willing to do that and test it out, @Markus Johansson ?
m
Absolutely!
Just need to find the places in the code that you refer to ๐Ÿ˜„
j
awesome! the file is here: "src/packages/core/workspace/components/workspace-editor/workspace-editor.element.ts"
m
found it ๐Ÿ˜„
j
and the code:
Copy code
this.consumeContext(UMB_WORKSPACE_CONTEXT, (workspaceContext) => {
            const entityType = workspaceContext.getEntityType();
            new UmbExtensionsManifestInitializer(
                this,
                umbExtensionsRegistry,
                'workspaceView',
                (manifest) => !manifest.forEntityTypes?.length || manifest.forEntityTypes.includes(entityType),
                (workspaceViews) => {
                    this._workspaceViews = workspaceViews.map((view) => view.manifest);
                    this._createRoutes();
                },
            );
        });
m
so the "forEntityType" is something that already exists right, just thinking that the name might be confused with the meta.entityType for a workspace manifest
j
the name exists for other models, yeah
sorry, updated the code with a controller alias, so we can overwrite it when the workspace changes:
Copy code
ts

        this.consumeContext(UMB_WORKSPACE_CONTEXT, (workspaceContext) => {
            const entityType = workspaceContext.getEntityType();
            new UmbExtensionsManifestInitializer(
                this,
                umbExtensionsRegistry,
                'workspaceView',
                (manifest) => !manifest.forEntityTypes?.length || manifest.forEntityTypes.includes(entityType),
                (workspaceViews) => {
                    this._workspaceViews = workspaceViews.map((view) => view.manifest);
                    this._createRoutes();
                },
                '_workspaceViews',
            );
        });
the workspace context gives you an entity type, so I would say it makes sense to call the property
forEntityTypes
or what do you say?
the code is basically copied from the entity-action-list
m
Hmm, I sounds like that, if the workspaceContext.getEntityType() returns the "Content Type Alias"
then it probably make sense
j
ohh, you know, it's late on a Friday afternoon, you are right
the entity type in this case would be "document" or "media" and not the content type alias
I guess it doesn't make sense to add forEntityTypes on the views, since you bind those to a workspace which is designated to an entity type anyway
m
I understand the problem the workspaceView is on a higher level so ideally it should not know what its hosting
j
If you made it as a condition instead, you could probably consume some kind of context and type cast it depending on what entity type you loaded
m
I'll give it a try to see what happens ๐Ÿ˜„
If I come up with something useful I'll let you know ๐Ÿ˜„
j
Haha great
Try and stay generic and let whatever context you consume be concerned about the alias, and if whatever entity that loaded didn't have an alias, it just wouldn't set that value to anything for example
m
I think I get it ๐Ÿ˜„ I'll probably start with something that works for content type alias and they refactor towards more generic - need to explore the contexts avalible on the content/media/member section to see where to get the alias from ๐Ÿ˜„ Like you say - could probably be the same conition that checks any of these
j
hint: we already have the
UmbEntityWorkspaceContext
which is an interface that holds the "unique" value of the loaded entity, could probably make something similar to that
m
UmbEntityWithAliasThatCanBeFilteredWithMarkusConditionWorkspaceContext ?
๐Ÿ˜„
j
๐Ÿ˜„
m
I guess that one possible solution could be to extend that with a optional alias EntityAlias or something that this contiion could look for - then the implementing "thing" could set it or not
w
Can I suggest threads where possible please @Jacob Overgaard & @Markus Johansson Makes it easier for anyone else to come along and learn about a specific topic/question/areas
j
this is a thread, Warren ๐Ÿ˜ฎ
w
God dammn it
j
๐Ÿ˜„
w
Too tired is it the weekend yet?!
And yes @Markus Johansson feel free to do the docs PR to list the conditions and what they do
j
Weekend for me now, have a good one everyone ๐Ÿ™‚
m
Thanks for the chat!! Have a great weekend! ๐Ÿ˜„
10 Views