-
Notifications
You must be signed in to change notification settings - Fork 3
List things related to a resource with a custom display #119
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
base: main
Are you sure you want to change the base?
List things related to a resource with a custom display #119
Conversation
6a40e50
to
72edc1e
Compare
if (templateElement == null) { | ||
this.error = "No template element found" | ||
} else if (templateElement.content.childElementCount != 1) { | ||
this.error = "Template element should only have one child, e.g. li" |
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 reason for this is that the component will provide resources to each child based on their index. Compared to #43 (comment) this gets rid of the intermediate pos-resource. However, it will still not be possible to have li nested directly within ul, given that pos-list lies between them.
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.
One option would be to allow pos-list to be used as a customized built-in element, i.e. <ul is="pos-list"></ul>
. I would need to look into whether/how stenciljs supports this.
Update: stenciljs does not support customized built-in elements stenciljs/core#4089 (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.
What about assigning role="list"?
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 issue I had in mind is that the only permitted parents for li are ul and ol (or menu). So if a dashboard user cares about correct HTML then I suppose they could use <div role="listitem" style="display:list-item">
I hadn't thought of 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've currently ignored correct HTML for this PR. In storybook I've used bare li
s. Let me know if it's an issue.
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 care for correct HTML and accessibility. Are you sure it would be invalid? As I understand this answer it would not
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 wasn't aware of that, and indeed I tried the pos-list-composition storybook example in https://websiteaccessibilitychecker.com/checker/index.php and it also passes.
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.
In my understanding pos-list should have role "list" and each child role "listitem" by default without additional effort by the dashboard author. pos-list is a list by definition and the created children are it's items
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.
d8624cc
to
ffc74ab
Compare
I've marked as ready for review because I'm not sure what e2e test should be included (is the integration test enough?), and I think we can maybe descope and implement rev in a separate PR - this one is probably complex enough as it is? |
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.
Good work so far! I have several comments and questions, but many of them are minor, I think this goes into a good direction.
<this.templateNodeName | ||
innerHTML={this.templateString} | ||
about={it} | ||
onPod-os:resource={ev => this.provideResource(ev)} |
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.
Why ware we doing this instead of wrapping each child in a pos-resource
?
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.
Current rationale is described at #119 (comment)
I may have made life hard for myself - I suppose the main motivation is that it's more intuitive for a dashboard creator to reason about what will will happen with the provided template - having a hidden pos-resource
inserted is a big of a surprise.
In principle it also gives the list more control over the (re-)rendering of its children, but that's a hypothetical advantage at this point, until we tackle reactive rendering.
I haven't yet experimented with how we would deal with list mutations, but I expect we will eventually want to be able to allow deleting, adding, and reordering list elements.
Edit: I should also add that I have been considering changes to the produced HTML to be breaking changes, so I didn't want to start with pos-resource and change this later.
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.
Hmm, have to think about this. I wonder if we are going to re-implement a lot of pos-resource here, especially if we want to have eager loading eventually. I would not consider changes in the HTML a breaking change as long as the observable behaviour does not change
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.
Wouldn't having an explicit pos-resource be actually less surprise, given that e.g. pos-label currently relies on having a parent pos-resource as a point of reference. The current implementation of pos-list changes this and the inner pos-label now suddenly is referencing a kind of "hidden" pos-resource implicitly.
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.
Given I'm getting rid of provideQueue, I'll switch to using pos-resource for now.
I suppose from a dashboard creator point of view I consider generated HTML as an observable behaviour, but as you note elsewhere, we are still on v0.x
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've refactored to use pos-resource. See what you think :-)
You don't need to bother with this in the PR, I will do this after merging before releasing a new version |
I am having an issue using this within another stencil component. If I paste an example directly in index.html it works, but the same example fails when I e.g. use it in pos-app-browser (just replacecing the regular pos-app content with the pos-list example). In the latter case it fails, because it does not recognize the template child (childElementCount == 0). Don't know why yet. |
It seems to be related to what is described here: https://stackoverflow.com/a/70778523 If I pass the content to |
I managed to show my bookmarks using
What is unfortunately still not possible with PodOS is actually linking to the value because I cannot use |
That's frustrating. Is that ok as a solution, or would you like to explore an approach that doesn't use the template tag? I would expect that stencil components would very rarely use pos-list - given they are written in JS they can just use Thing's methods directly and create their own list. |
Nah, I think template is the right approach, is just weired with stencil, I guess we can live with that.
Yes indeed, though I think the issue is not only with stencil but with everything that creates template programmatically, e.g. also with React and other frameworks ( |
1b4d7fb
to
c8e48d1
Compare
With the switch to I've run into two problems: I can't get pos-resource to not fetch when testing, and even when it does fetch, Storybook seems to work fine. I'm guessing I've made a mistake in mocking, but maybe it's in how I call On my system I also get warnings:
Edit: I've pushed an extra commit that implements the fetch attribute + unit tests - but this doesn't address the issue in this integration test |
cdee3bc
to
a71d7ed
Compare
*/ | ||
@Prop() fetch: boolean = false; | ||
|
||
@Element() host: HTMLDivElement; |
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 could simple be HTMLElement
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.
Please keep the filename convention *.integration.spec.tsx
. Name could be e.g. pos-list-fetch.integration.spec.tsx
}); | ||
expect(os.fetch.mock.calls).toHaveLength(0); | ||
expect(page.root?.querySelectorAll('pos-list pos-resource')).toHaveLength(2); | ||
const label1 = page.root?.querySelectorAll('pos-list pos-resource')[0] as unknown as PosResource; |
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.
Let's not repeat the querySelectorAll
here, but extract the result in a variable
when(os.store.get) | ||
.calledWith('https://video.test/video-2') | ||
.mockReturnValue({ uri: 'https://video.test/video-2', label: () => 'Video 2' }); | ||
const page = await newSpecPage({ |
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.
page
is unused
|
||
const el: HTMLElement = page.root as unknown as HTMLElement; | ||
|
||
expect(el.querySelectorAll('pos-resource')[0]?.getAttribute('about')).toEqual('https://video.test/video-1'); |
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.
same remark about repetition here
Partly addresses #43
end-to-end testintegration testarchitectural decisions are documented as an ADRKeep a Changelog
This PR descoped to exclude rev, given this will involve changes very similar to rel. Covering rev in a separate PR will hopefully make both PRs easier to review.