Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add when property to extensions menus #3959

Merged
merged 17 commits into from Sep 25, 2023

Conversation

axel7083
Copy link
Contributor

What does this PR do?

The when property is available on a large range of options, and this PR aims to add support for conditional menus provided by extensions.

Screenshot/screencast of this PR

screenshot description
image Menu visible only on compose group actions using when: type === compose
image Only visible on running container when: state === RUNNING

What issues does this PR fix or reference?

The accessibles when properties

Depending on which type of ContainerGroup it is, different properties are accessible.

For a standalone container the following properties are accessible in addition of the global context.

standalone

name type
created number
displayPort string
engineId string
engineName string
engineType string
groupInfo object
hasPublicPort boolean
icon string
id string
image string
labels object
name string
openingUrl string
ports array
portsAsString string
selected boolean
shortId string
shortImage string
startedAt string
state string
uptime string

compose

name type
containers array
engineId string
engineType string
name string
status string
type string

pod

TODO

Implementation details

The main logic of evaluating the context is delegated to the ContributionActions.svelte component. It was too laborious to manage everything in the ContainerList.svelte.

The ComposeInfoUI and PodInfoUI interface have a new property type which allows to identify the type of ContainerGroup, this has been added since there was no other simple way to be able to distinguish them easily.

An utility context function has been created transformObjectToContext taking any object and transforming it a ContextUI object. This function is generic since, the ContributionActions component does not have any type information about the arguments it receive.

How to test this PR?

@axel7083 axel7083 marked this pull request as ready for review September 19, 2023 10:15
@axel7083 axel7083 requested review from benoitf and a team as code owners September 19, 2023 10:15
@axel7083 axel7083 requested review from dgolovin and jeffmaury and removed request for a team September 19, 2023 10:15
@benoitf
Copy link
Collaborator

benoitf commented Sep 19, 2023

hi @axel7083 thanks for this other PR

I was wondering if we should probably use prefix/suffix on the properties to avoid collisions/separate stuff

for example type and state are too generic

We should describe what is available for given contexts

For example, in container list, probably it should be containerSomething like containerType and containerState

And in image list, `imageSomething, etc.

@axel7083
Copy link
Contributor Author

axel7083 commented Sep 19, 2023

hi @axel7083 thanks for this other PR

I was wondering if we should probably use prefix/suffix on the properties to avoid collisions/separate stuff

for example type and state are too generic

We should describe what is available for given contexts

For example, in container list, probably it should be containerSomething like containerType and containerState

And in image list, `imageSomething, etc.

Other field are very generic in the ComposeInfoUI, ContainerInfoUI, ImageInfoUI and PodInfoUI.
I made the ContributionActions component to be able to take a contextPrefix, that will prefix all properties in the context of the given arguments.

For examle, in we can have

<ContributionActions
    args="{[compose]}"
    contextPrefix="ContainerGroup"
    dropdownMenu="{dropdownMenu}"
    contributions="{contributions}"
    onError="{errorCallback}" />

Then the when condition would be ContainerGroup:type === COMPOSE, what do you think ?

@benoitf
Copy link
Collaborator

benoitf commented Sep 19, 2023

I would say I'm fine with the prefix but I'm unsure if we should use the : notation like ContainerGroupType rather than ContainerGroup:type

I'm just thinking out loud.

So I'm not sure as well about the properties as well.

in the list, we display items so I'm not sure about ContainerGroup prefix

so at the end, is it like containerListItem

@benoitf
Copy link
Collaborator

benoitf commented Sep 19, 2023

or other ideas

@axel7083
Copy link
Contributor Author

I would say I'm fine with the prefix but I'm unsure if we should use the : notation like ContainerGroupType rather than ContainerGroup:type

I'm just thinking out loud.

So I'm not sure as well about the properties as well.

in the list, we display items so I'm not sure about ContainerGroup prefix

so at the end, is it like containerListItem

I implemented first the : since in the documentation we can already see it being used.

image

But if you rather have simple prefix, as you want.

@benoitf
Copy link
Collaborator

benoitf commented Sep 19, 2023

the : prefix was used for the scope of context properties. (to see properties only in a given context)

so ok why not to say that containerList is a scope, I don't know what others think.

it would mean then containerListItem:state , containerListItem:type or containerList:itemState

cc @lstocchi that added the context for the onboarding. Thoughts ?

@deboer-tim
Copy link
Collaborator

+1 to using : for scopes, but I think we need to be careful where the context is a 'view' vs an 'object'. i.e. there may be cases where we want to allow adding tabs to a specific view vs where you really want to customize a container and have an action or icon in any page where that container appears. (it may still take time for us to enable it in every view, but the intention is clear)

e.g. in this case I'm assuming we'd want to allow adding an action to type container and state running, but it would also appear in the container details page at some point.

@axel7083
Copy link
Contributor Author

axel7083 commented Sep 19, 2023

@benoitf For the naming, we have to choose for the ComposeInfoUI, ContainerInfoUI, ImageInfoUI and PodInfoUI prefix to use. Any suggestation ?

@benoitf
Copy link
Collaborator

benoitf commented Sep 21, 2023

For the naming, we have to choose for the ComposeInfoUI, ContainerInfoUI, ImageInfoUI and PodInfoUI prefix to use. Any suggestation ?

ComposeInfoUI -> composeListItem:<property>
ContainerInfoUI -> containerListItem:<property>
ImageInfoUI -> imageListItem:<property>
PodInfoUI -> podListItem:<property>

is it what you're expecting ? based on the fact that it's displayed in a list

in details page it would be

composeDetailsItem:<property>
containerDetailsItem:<property>

@axel7083
Copy link
Contributor Author

image

On a container, working fine with the prefixes.

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
…onents

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
@deboer-tim
Copy link
Collaborator

I really appreciate this contribution and haven't had a chance to test it yet, but so far it looks like prefixes like imageListItem are furthering one of our current problems that actions are only available in a specific place, e.g. you can push an image from the Images List, but not if you're actually looking at that image in Details. It requires every person contributing an action to know all the places where an object might appear and add to each of them. How many people will forget that pods appear in the containers list?

I know there will be cases where something should only appear in one place too, but that seems lower frequency so I'm hesitant to release this without the other way of contributing. Maybe we can do both, or do something to make it more generic or more obvious to know where to contribute?

Also, shouldn't docs/extensions/write/when-clause-context be updated? I'm ok with separate issue or PR, just don't want to lose this.

@benoitf
Copy link
Collaborator

benoitf commented Sep 22, 2023

I really appreciate this contribution and haven't had a chance to test it yet, but so far it looks like prefixes like imageListItem are furthering one of our current problems that actions are only available in a specific place, e.g. you can push an image from the Images List, but not if you're actually looking at that image in Details.

I think action would appear correctly in both image list and image details (or container list and container details)
as menu name that is used is dashboard/image or dashboard/container so contribution is not specifying a list or the details

It requires every person contributing an action to know all the places where an object might appear and add to each of them. How many people will forget that pods appear in the containers list?

I think person won't need to know all the places. If you need an action about pods, you will register a menu for dashboard/pod then it'll will be displayed in container list or pod details, etc.

@axel7083 last change, could you tweak the prefix as as you're sharing the same *Actions component from the ContainerList and ContainerDetails we can't have 'List' in the name of the property
so stick to containerItem, podItem, etc.

Also, shouldn't docs/extensions/write/when-clause-context be updated? I'm ok with separate issue or PR, just don't want to lose this.

@axel7083 could you open a PR against this file as well (out of this PR)

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
@benoitf
Copy link
Collaborator

benoitf commented Sep 22, 2023

Looking as like final review:

so it looks next steps (follow-up PR, etc) would be to include in containersDetails and imageDetails the inclusion of

contributedMenus = await window.getContributedMenus(MenuContext.DASHBOARD_CONTAINER);

and

contributedMenus = await window.getContributedMenus(MenuContext.DASHBOARD_IMAGE);

but it seems there is something odd here, as it looks for compose or pods we're providing the wrong contributedMenus in ContainerList

from my understanding we should have

contributedContainerMenus = await window.getContributedMenus(MenuContext.DASHBOARD_CONTAINER);
contributedPodMenus = await window.getContributedMenus(MenuContext.DASHBOARD_POD);
contributedComposeMenus = await window.getContributedMenus(MenuContext.DASHBOARD_COMPOSE);

and then for PodActions

<PodActions..

contributions="{contributedPodMenus}"

and then for ContainerActions

<ContainerActions..

contributions="{contributedContainerMenus}"

and then for ComposeActions

<ComposeActions..

contributions="{contributedComposeMenus}"

@axel7083
Copy link
Contributor Author

axel7083 commented Sep 22, 2023

Looking as like final review:

so it looks next steps (follow-up PR, etc) would be to include in containersDetails and imageDetails the inclusion of

contributedMenus = await window.getContributedMenus(MenuContext.DASHBOARD_CONTAINER);

and

contributedMenus = await window.getContributedMenus(MenuContext.DASHBOARD_IMAGE);

but it seems there is something odd here, as it looks for compose or pods we're providing the wrong contributedMenus in ContainerList

from my understanding we should have

contributedContainerMenus = await window.getContributedMenus(MenuContext.DASHBOARD_CONTAINER);
contributedPodMenus = await window.getContributedMenus(MenuContext.DASHBOARD_POD);
contributedComposeMenus = await window.getContributedMenus(MenuContext.DASHBOARD_COMPOSE);

I see, but in the curent implementation, we do not distinguish with MenuContext.DASHBOARD_CONTAINER, MenuContext.DASHBOARD_COMPOSE etc.. This is evaluated at runtime using the when condition.

We register all the menus to the ContainerList and then they are using the when condition to choose where they should be displayed.

@benoitf
Copy link
Collaborator

benoitf commented Sep 22, 2023

I see, but in the curent implementation, we do not distinguish with MenuContext.DASHBOARD_CONTAINER, MenuContext.DASHBOARD_COMPOSE etc.. This is evaluated at runtime using the when condition.

We register all the menus to the ContainerList and then they are using the when condition to choose where they should be displayed.

yes but this is not the expected behavior

b/c you register a command to be displayed for a condition for different purpose, like for an image, for a pod or for a compose object.

then, in your when clause, you'll use containerItem or composeItem

when a fine grained object, but default is that it's added.

so if you say, I want to bind an action for a CONTAINER, you don't expect to see the action for a POD or for a Compose object

@axel7083
Copy link
Contributor Author

axel7083 commented Sep 22, 2023

I see, but in the curent implementation, we do not distinguish with MenuContext.DASHBOARD_CONTAINER, MenuContext.DASHBOARD_COMPOSE etc.. This is evaluated at runtime using the when condition.

We register all the menus to the ContainerList and then they are using the when condition to choose where they should be displayed.

yes but this is not the expected behavior

b/c you register a command to be displayed for a condition for different purpose, like for an image, for a pod or for a compose object.

then, in your when clause, you'll use containerItem or composeItem

when a fine grained object, but default is that it's added.

so if you say, I want to bind an action for a CONTAINER, you don't expect to see the action for a POD or for a Compose object

The following change is more relevant to the previous PR about adding the DASHBOARD_CONTAINER than the when condition, should I include the change in this PR ?

The change would include

  • adding await window.getContributedMenus(MenuContext.DASHBOARD_POD); to the <PodActionss>
  • adding await window.getContributedMenus(MenuContext.DASHBOARD_COMPOSE); to the <ComposeActions>
  • adding await window.getContributedMenus(MenuContext.DASHBOARD_CONTAINER); to the <ContainerActions>
  • adding await window.getContributedMenus(MenuContext.DASHBOARD_IMAGE); to the <ImageActions>
  • deleting the await window.getContributedMenus from ListImage and ListContainer

@benoitf
Copy link
Collaborator

benoitf commented Sep 22, 2023

I'm fine with your proposal

@benoitf
Copy link
Collaborator

benoitf commented Sep 22, 2023

and if it helps, you can merge some commits together and separate changes with different commits having a meaningful set of changes

@axel7083
Copy link
Contributor Author

I'm fine with your proposal

Perfect then

and if it helps, you can merge some commits together and separate changes with different commits having a meaningful set of changes

I will do everything here

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
Copy link
Collaborator

@benoitf benoitf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not related to this PR but I think we should have contributedMenus being in a store as new items/deletion of items should refresh the UI on the fly

#4039

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
@benoitf
Copy link
Collaborator

benoitf commented Sep 22, 2023

@axel7083 we still have unit tests failing

I'll probably merge on monday as never merge big chunks on friday :-)

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
@benoitf benoitf changed the title feat: adding when property to extensions menus feat: add when property to extensions menus Sep 25, 2023
@benoitf benoitf merged commit 37e99c1 into containers:main Sep 25, 2023
8 checks passed
@podman-desktop-bot podman-desktop-bot added this to the 1.5.0 milestone Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants