-
Notifications
You must be signed in to change notification settings - Fork 2
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
Adjust collapse and display templates' html. Was intended for plans I… #174
Conversation
… have for ALKiln to more easily see these elements, but I found that to make those changes other changes were needed, and along the way I made the html a bit more robust and accessible to manipulation (like for CSS). The collapse template title can no longer appear to sit inline with the text surrounding it, but that's probably not a terrible thing because that feature only works when the element is at the very end of text. If it's in the middle of some text, the template content will end up pushing the rest of the text down unexpectedly. I also noticed that the copy button template didn't show the subject of the template unless it was also being collapsed. I think we should also remove the `h3` tag from the display template and I can add that to this set of changes if we want.
Not sure what information |
|
||
the_id = re.sub(r"[^A-Za-z0-9]", "", template.instanceName) | ||
actual_container_id_tag = container_id_tag or f"{ the_id }_container" |
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.
What's the movitation for allowing people to set the container id directly, or why can't it just always be { the_id }_container
?
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.
Because that way they can use the id in ALKiln to detect elements (in a future feature) without worrying about changing their variable's instance name.
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'm not sure that would be useful, IMO, given that it doesn't hold for any other time you change variable names in an interview. I think it's more straight forward to say "if you change variable names in your interview, you'll need to change those variable names in your tests as well", instead of trying to give tools that help you avoid it in some (relatively small cases) but not others.
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.
Another reason is so that someone can use the id for styling or js consistently and not worry about instance name changes.
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.
See lower down for more responses to this.
Sorry, I tried to explain, but obviously didn't manage to describe clearly. Since |
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.
Actually had time to fully review:
I like most of this PR! Fully support adding container divs and classes to more things, and +1 on migrating to classname
as a param over class_name
.
I am hesitant to add a lot of parameters to customize the classes and ids though. You mentioned your reasons for doing so, but I'm afraid the complexity isn't likely to be used, and isn't the right tool for the job; they'll already have unique ids and classes, and if people want to style the same widget different ways (something I'd discourage people from doing, since it would be confusing visually to see two differently styled elements that have the exact some functionality), then I'd suggest they customize it based in the already unique id.
docassemble/ALToolbox/misc.py
Outdated
return f"""\ | ||
<a class="collapsed" data-bs-toggle="collapse" href="#{ the_id }" role="button" aria-expanded="false" aria-controls="{ the_id }"><span class="pdcaretopen">{ fa_icon(open_icon) }</span><span class="pdcaretclosed">{ fa_icon(closed_icon) }</span> { template.subject_as_html(trim=True) }</a> | ||
<div class="collapse" id="{ the_id }"><div class="card card-body pb-1{ classname }">{ template.content_as_html() }</div></div>\ | ||
<p id="{ container_id }" class="{ container_classes_plus }"> |
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.
<p>
isn't allowed to contain <div>
s, it's not valid HTML (https://stackoverflow.com/a/9852381). I'd change this to be a div
.
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.
[Yeah, that occurred to me, but there was a styling issue (which is a dumb reason, but maintenance cost is a thing.)] If we change the p
to be a div
then the markdown paragraph spacing disappears and we have to handle the spacing ourselves. Thoughts?
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.
Isn't it already there? You give al_display_template
a bottom margin of 1rem, which is the same spacing we give to paragraphs?
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.
This is for the collapse template, not the display template.
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.
Gotcha, missed that. Should there be a difference between collapse and display template (when collapsed) though? I don't see any problem with adding the same 1 rem
bottom margin to al_collapse_template
.
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.
Thinking about it more, I think you're right about p
, but I will add this note:
Trying to style the spacing ourselves (including the way I'm doing display_template
now come to think of it) can set up complications for our users later. If our users decide they want different spacing for their paragraphs, they then have to notice our elements are behaving differently and then make special rules for them.
I'm not sure how to solve it, though. I couldn't find anything using a css variable for the p
spacing that we could also use for the div
spacing. I can't think of any systemic way to handle it.
return text | ||
return f""" | ||
<div id="{actual_container_id_tag}" class="{container_classname_plus}"> | ||
<div class="panel-heading"><h3 class="subject">{template.subject_as_html(trim=True)}</h3></div> |
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.
A thing that was already present, and just being expanded on: if there's no subject, there will be an empty h3. We should instead just not generate a subject element, or maybe make it a div instead.
The current unique id is only on the content, it won't be able to control the style of any of the other elements. |
If you don't pass in the |
Sorry I'm not expressing things clearly.
"making a container id that's completely independent of the content's id" - Are you saying we should reduce to one id instead of both and just put it on the container? If so, I'm not sure what people are currently using the contents id for. Will it break their stuff to move it to the new container? If not, I'm not sure what you're referring to here. Maybe better to have a real-time conversation.
I think connecting the variable name and the id name is too coupled and too fragile. If I were using it that way, I couldn't rely on that id for anything, like css or js, unless everyone editing the code was aware that they can't change that variable name. I think the options are to either remove the
New thoughts on this:
Related question: Do templates always just have a simple variable name? That is, they're never something like |
[Unrelatedly,] We probably want to try to, at some point, see if we can have [Other thoughts: Abstract some of these pieces so both |
These do all seem like good changes.
|
Do you want me to
|
It appears to me that we can add a new |
Content id tag: unfortunately it looks like the content id tag is, at least in display template, being used to connect the subject to the content. Right now as the Having two ids in there isn't terrible, I think, since if we do end up concluding that they both have uses. |
Also, I'm reluctant to say it, but instead of transitioning to |
I suspect some things got lost in the shuffle. Still would appreciate thoughts on the new id and on the validity of the current id creation. Also on the length of the names of the new params as I'm unclear if I've addressed those sufficiently. |
Sorry for the long one, there were a lot of questions, trying to answer them as comprehensively as I can here;
I'm suggesting that you should not have to pass in an id. Inside the function, the code to make the content id and the container id then looks like this: the_id = re.sub(r"[^A-Za-z0-9]", "", template.instanceName)
actual_container_id_tag = f"{ the_id }_container" Nothing gets broken, because nothing about the content id changes. The container id is brand new, and will always be different than the content id, so it won't break anything either.
Changing my views on this is a small way after reading all of the discussion here; I now agree that using the variable name as an id for CSS styling is too fragile. However, like Quinten said, "people can always use their own bootstrap component directly". They could even wrap the collapse template in a div with whatever class they want in the markdown, since you can use HTML in markdown. And all this is only for when people want to style the toggle two different ways in the same interview, which I don't think we want to encourage. I still don't think linking the ids to the variable name is too coupled and fragile for the ALKiln tests. I forgot, but you are right; we are already doing this for tabs, and actually we have a step that clicks on a arbitrary element on the page found with an element selector, which might be really similar to your "And an element with the id "blah" is on the page" step. The tab elements is actually setting it with subject strings (even worse!), but I haven't had any particular troubles with it. We can document the step "the id name will be <variable_name_with_underscores>_container", etc. And I don't think it's that bad to be coupled to variable names, when every other step in the tests are still coupled to variable names. Removing the coupling here doesn't practically help testers when they change a lot of variables names; they'll always have to change the tests as well.
They can be anything; I have a few templates attached to DAObjects in the EFSP stuff. I think the way we turn them into ids is probably fine; MDN suggests that they stick to ASCII and numbers only. Dots still work, but they have to be escaped when using in selector query stings so they're not parsed as classes by the selector query. It's very unlikely (and probably discouraged) to have two different variable names that get turned into the same id, like |
This auto-id making with processing means that ALKiln has to also process the ids in the same way, but only for display templates as other ids on the page could have other characters like dashes or underscores. |
As per deep dive notes:
Reasons for replacing our current method of encoding with base64 encoding: it will be less likely to run into name conflicts and will match up with how docassemble handles this. I think that's what needs to be done now, but it was so long ago I'm not sure if there were other items that we discussed earlier that weren't captured during that conversation. |
Actually, what did we decide about |
|
||
# 3. If not copiable, generate the whole output | ||
else: | ||
if not collapse: | ||
return f'<div class="{scroll_class} card card-body {class_name} pb-1" id="{the_id}"><div class="panel-heading"><h3>{template.subject_as_html(trim=True)}</h3></div>{template.content_as_html()}</div>' | ||
return f'<div id="{container_id}" class="{container_classname_plus} {scroll_class} card card-body {class_name} pb-1" id="{contents_id}">{subject_html}<div>{template.content_as_html()}</div></div>' |
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.
Does class_name
belong around the content as opposed to surrounding both the title and the content? The element currently using class_name
has the container classname already.
My recollection was that we didn't need them at all. Mostly because we thought that if some one wanted very specific CSS control over their collapse / display templates, they can use their own bootstrap components, and don't need to use our function to make that bootstrap. An earlier note in the deep dive notes says:
|
Somehow I merged by [force] pushing a rebased version [- I was resolving conflicts]. Let me know if we need further changes. |
Or maybe I didn't merge. I'm a bit confused now. |
Closing, replaced by #187 |
… have for ALKiln to more easily test these elements (using a container with an id), but I found that to make those changes other changes were needed, and along the way I ended up changing the html a bit more than I expected. I hope it's more robust and accessible to manipulation (like for CSS). The most "breaking" change is that the collapse template title can no longer appear to sit inline with the text surrounding it, but that's probably not a terrible thing because that feature only works when the element is at the very end of text. If it's in the middle of some text, the template content will end up pushing the rest of the text down unexpectedly. I also noticed that the copy button template didn't show the subject of the template unless it was also being collapsed, so I adjusted that too.
This was really supposed to be just a quick tweak and has dragged out a bit. Some justification for changes:
When I have sibling elements that belong to the same functionality, it has helped me to have a container with a class and an id for access by css and js. It's really the most helpful place I've found for a class or id because everything in it can then be accessed. For that reason, if we ever get a chance to re-do this or run into similar situations, I'd rather reserve
classname
for the outer-most element.Similarly, I've found it helpful to avoid loose text. Loose text has at times made css and js access complicated or impossible. I prefer it in a container (span or div usually) when possible.
class_name
vsclassname
: the display and collapse template functions each had their own spelling. I want to reconcile them and stay backwards compatible. I went withclassname
because that let me docontainer_classname
which looks better to me for some reason, but we can switch it up if folks want. I went withcontainer_id_tag
to be consistent withcontainer_classname
. [I had to usecontainer_
in one function becauseclassname
already existed, so I used it in both functions for consistency.]Icon class: The expanding/collapsing icons can end up being different sizes. To let users style them to be a consistent width, I gave them a shared class.
subject
class: I wanted to have a way to access the subject text without relying on tags (theh3
, which I want to change - #173 - though I'm not sure what useful semantics would be).Additional css for display template: It also seemed that fields were being used to create spacing, not to set variables. Without a container, I can see why that was needed. Now it's handled with css.