-
Notifications
You must be signed in to change notification settings - Fork 12
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: make possible for the service to specify the size of the intent modale #175
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me 👍
Can't this be achieved by styling the |
@y-lohse We are styling the element wrapping the iframe which is the one showing the modale in the case of the onboarding at least. |
Ah, I see. That's interesting, and not really something we considered when we did the spec. I'm taking note of it :) |
I think this may open a way to personalization for intent modals later, but restricted the list of authorized css properties at the moment to no wory too much. |
Actually I feel that the way to do it is too much complicated. I suggest to do something like the following code, but maybe I am missing a point and it is not possible: cozy.client.intents.createService(intent, window, {
dimensions: {
with: 400,
height: 400
}
}) 1/ The signature of 2/ As the 3/ Also I think we should not pass a string because the integer values cannot be used without being parsed, and maybe the client will not use it directly for styling with CSS. If we give an integer value directly, it is still easy to generate a string like '400px' client-side. 4/ Did you try to pass an element instead dimensions and let cozy-client detect its width and height ? What do you think @doubleface, @y-lohse ? |
Regarding 1 & 2 : I'm always a bit cautious when it comes to a
|
@gregorylegarec |
@doubleface Thanks, you're right I did not get the fact that we needed the connector before being able to first. So yes, we have to use a new method in the service object. 👍 However I still have a doubt about passing to much specificity about the size or units. For several reasons:
I am going to look at the code. |
@gregorylegarec I think I understand your point. The fact is that I only pass px for the account intent anyway and the dom property only generates size with px also. Then it would be coherent. Then ok, let's go for the px unit. It is still possible to extend it easily in the futur anyway. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I am a little late, the whole thing is really good but I have some micro-feedback (naming and so), I'll end my review tonight.
src/intents.js
Outdated
@@ -46,6 +46,14 @@ function injectService (url, element, intent, data) { | |||
return event.source.postMessage(data, event.origin) | |||
} | |||
|
|||
if (handshaken && event.data.type === `intent-${intent._id}:size`) { | |||
['width', 'height', 'maxWidth', 'maxHeight', 'minWidth', 'minHeight'].forEach(prop => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not care about properties which we don't use or need for now, so keep only width
and height
. It is more code to maintain and to keep tested. What do you think ? What are @CPatchane and @y-lohse opinions about this point ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really mind it tbh. I can see how they would be useful even in the current use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could be useful for later without adding complications here so I would prefer to keep it 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally disagree because we will have code which is not used, but if I am alone let's go with it. (Just brace yourself for the day someone will ask "May I change maxHeight
? Where is it used ? What the difference with height
? 😄 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then @gregorylegarec you will have the right to laugh at us if that may comfort you a little 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking @doubleface, I can't see any cases when we will need max and min css properties here. I was first thinking about responsive behaviour but, even that, if we use the service from cozy-collect, the app which handle the inter-app view will the provide a responsive width and height. So I think we would just need width and height here. What do you think? And @y-lohse ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're allowing the service to control the size of it's container, I think min and max sizing are a valid part of that and are ok here. But ultimately I haven't seen the mockups or anything, so it's hard for me to say if they will ever be used or not. You guys are working this app, you know this better than me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CPatchane I actually use maxHeight and maxWidth in https://github.com/doubleface/cozy-client-js/blob/389578a203c7152e9e239b55db2a6e3843c852ad/src/intents.js#L158 since it allows the modale to adapt it's size if the resolution lower than expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't see it like that, so we just need the max properties? If we don't need the min properties we can skip them for now. It's just better to not handle not used yet properties to avoid useless maintenance 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then let's just remove min properties and I merge
src/intents.js
Outdated
if (event.data.document[prop]) element.style[prop] = event.data.document[prop] | ||
}) | ||
|
||
return true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it is just an early return, I think we should not return true
or another value. When we read this part, it feels that the true
value has some kind of importance, but it is not the case.
src/intents.js
Outdated
if (terminated) throw new Error('Intent service has already been terminated') | ||
|
||
// if a dom element is passed, calculate its size and convert it in css properties | ||
if (message.document.dom) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By renaming the dom
attribute to element
, we can avoid the previous comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually hesitating between dom and element
src/intents.js
Outdated
@@ -142,6 +150,19 @@ export function createService (cozy, intentId, serviceWindow) { | |||
serviceWindow.parent.postMessage(message, intent.attributes.client) | |||
} | |||
|
|||
const setSize = (message) => { | |||
if (terminated) throw new Error('Intent service has already been terminated') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/has already been/has been/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am really sorry, a lot of comments, much about tiny details. I feel like an evil perfectionnist so please @CPatchane and @y-lohse give us your opinion about my comments. This PR needs discussion because what is done in Cozy Client is done for a looong time, if not forever. 😄
src/intents.js
Outdated
@@ -165,6 +186,10 @@ export function createService (cozy, intentId, serviceWindow) { | |||
type: `intent-${intent._id}:error`, | |||
error: errorSerializer.serialize(error) | |||
}), | |||
setSize: (doc) => setSize({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setSize()
signature should not have a document as parameter, but something like dimensions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with that one, dimensions is more explicit.
src/intents.js
Outdated
@@ -46,6 +46,14 @@ function injectService (url, element, intent, data) { | |||
return event.source.postMessage(data, event.origin) | |||
} | |||
|
|||
if (handshaken && event.data.type === `intent-${intent._id}:size`) { | |||
['width', 'height', 'maxWidth', 'maxHeight', 'minWidth', 'minHeight'].forEach(prop => { | |||
if (event.data.document[prop]) element.style[prop] = event.data.document[prop] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok now I understand what is done here and why CSS values are directly transmitted. Again, I am not a big fan of letting the service do whatever he wants with client's iframe CSS values. It should limit its role to transmit width and height. Nothing more is needed. Again, if @CPatchane and @y-lohse agree with this, let's keep it.
Summary of what I suggest:
['width', 'height'].forEach(property => {
element.style[property] = `${event.data.dimensions[property]}px` || element.style[property]
}
It is reeeeaaaally difficult for me to consider passing directly a CSS value as a string containing px
, sorry about that.
src/intents.js
Outdated
@@ -165,6 +186,10 @@ export function createService (cozy, intentId, serviceWindow) { | |||
type: `intent-${intent._id}:error`, | |||
error: errorSerializer.serialize(error) | |||
}), | |||
setSize: (doc) => setSize({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more I think about this method name the more I feel that it is not explicit enough. Calling intentService.setSize()
give the idea that we are setting the service own size. I suggest something like setClientDimensions(dimensions)
or resizeClient(dimensions)
. What's your opinion about that ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not like setSize a lot. Let's go for resizeClient.
This dom propertie allows to automatically adapt the size of the modal to a given dom element
@@ -137,11 +145,24 @@ export function createService (cozy, intentId, serviceWindow) { | |||
let terminated = false | |||
|
|||
const terminate = (message) => { | |||
if (terminated) throw new Error('Intent service has already been terminated') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My remark was just for resizeClient()
: it is the only method which does not terminate the service.
The service can make a call to service to set the size of its modale :
The service is responsible to make the modale displayable on screen in different possible resolutions (mobile, desktop). The client application requesting the intent is still responsible for the display of the modal and the default size of it, if the service does not request any special modale size.