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(actions): standardize contexts #1124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

skjnldsv
Copy link
Contributor

@skjnldsv skjnldsv commented Nov 20, 2024

Following discussion on #1113

This would be a breaking change unless we add a conversion layer to support the old legacy way.
BUT, the cleanest way, imho, is to quickly update server and communicate to devs asap

// Before
action.exec(node, view, '/path/to/node')

// After
action.exec({
	nodes: [node],
	view: View,
	context: Folder
})

@skjnldsv skjnldsv added type: enhancement 🚀 New feature or request 3. to review 3️⃣ Waiting for reviews type: breaking 💥 changes that require a new major version labels Nov 20, 2024
@skjnldsv skjnldsv requested review from susnux and Pytal November 20, 2024 08:15
@skjnldsv skjnldsv self-assigned this Nov 20, 2024
Copy link

codecov bot commented Nov 20, 2024

Bundle Report

Bundle size has no change ✅

Copy link

codecov bot commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.62%. Comparing base (f1d1a84) to head (d994eb4).
Report is 33 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1124   +/-   ##
=======================================
  Coverage   91.62%   91.62%           
=======================================
  Files          23       23           
  Lines         633      633           
  Branches      166      166           
=======================================
  Hits          580      580           
  Misses         46       46           
  Partials        7        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@susnux
Copy link
Contributor

susnux commented Nov 25, 2024

BUT, the cleanest way, imho, is to quickly update server and communicate to devs asap

I would try to make the library to work with all supported Nextcloud versions.
This makes it hard to impossible to maintain multi-version apps (e.g. things like groupware).
So I think we should make sure this works with 30, 29, and 28.

What I mean is we can do it like in this PR, which would be breaking and a v4 of the library.
But it would then only be a breaking change of this library we should not break the server API which we should support as of our deprecation rules (at least 3 version, I do not want to go the 9 versions 3 years way 🙈 )

So how to do it while not breaking server API?
Change the registerFileAction function in this PR to use a new _nc_fileactions_v2 to store them.
And in getFileActions we return a proxy over the real v1 actions emulating a v2 action (to simplify the server code).

This way an app using files v3 work with 28,29,30,31 as per our deprecation rules (we had this discussion with management at the Nextcloud conference).
Apps using v4 will only work with 31+ but that is ok as long as v3 also works with 31,32 and 33. With 34 we can drop v3 support.


Context:
There is no reason to not support a server version, features can be conditionally using capabilities.
Binding a library to a server version removes all benefits from using a library.
I think we can do breaking changes like this and release a new major, but should make sure it still works with the other Nextcloud versions by having so

Copy link
Contributor

@Pytal Pytal left a comment

Choose a reason for hiding this comment

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

Using 1 or 2 parameters before a context object in a function declaration does not seem that bad to me IMHO, any reason why we should never do this @skjnldsv?

import { View } from './navigation'

type ActionContextSingle = {
nodes: [Node],
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not simply

Suggested change
nodes: [Node],
node: Node,

?

type ActionContextSingle = {
nodes: [Node],
view: View,
context: Folder,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
context: Folder,
folder: Folder,

Calling the folder context inside the context object seems confusing to me 😵

We should use "context" only for context objects

Copy link
Contributor Author

@skjnldsv skjnldsv Dec 5, 2024

Choose a reason for hiding this comment

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

it's to do a clear separation between the nodes. So we know folder isn't the subject of this action

@skjnldsv
Copy link
Contributor Author

skjnldsv commented Dec 5, 2024

Using 1 or 2 parameters before a context object in a function declaration does not seem that bad to me IMHO, any reason why we should never do this @skjnldsv?

Because it just looks weird to me.
It's like mixing two syntaxes that have nothing in common, like spaces and tabs 😁

From a clean declaration perspective, I would agree with
function(path, options = {})
function(path, folder, view...)
function(options = {})

But mixing something like function(path, view, dir, options = {}) seems incoherent to me.
To prove my point, and assuming there is no issue with mixing both, then why do this feels worse? function(options = {}, path, dir) or even worse: function(path, options = {}, view, dir) 🙈

But more importantly, I like to be consistent across our APIs here, and considering we have multiple APIs that do similar approaches, like FileAction, NewFileMenu, Views..., I think we should stick to one type of pattern here. That way it's easy to know what to expect when you work with the @nextcloud/files library.

This is why I was really against #1113
PS: #1135

@skjnldsv skjnldsv added 2. developing 2️⃣ Work in progress and removed 3. to review 3️⃣ Waiting for reviews labels Dec 12, 2024
@susnux susnux added this to the v4.0.0 milestone Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing 2️⃣ Work in progress type: breaking 💥 changes that require a new major version type: enhancement 🚀 New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants