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

PagedResourcesAssembler should expose first and last links [DATACMNS-701] #1167

Closed
spring-projects-issues opened this issue May 18, 2015 · 5 comments
Assignees

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented May 18, 2015

Chris Georgoulis opened DATACMNS-701 and commented

Currently the default HAL representation for collections only provides next and prev rels for navigating collections. It would be nice to also add first and last rels as well since these are very common buttons / links that are used when representing data with tables client - side


Reference URL: http://stackoverflow.com/questions/30281438/spring-data-rest-hateoas-first-and-last-rels/30302068#30302068

0 votes, 5 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 18, 2015

Oliver Drotbohm commented

I wonder if we should apply some restrictions on when these links actually are supposed to appear? Should they only be rendered if more than one page is available in total? Should first link be rendered if the current one is the first page? Or the last link of we're on the last page already?

I'm currently leaning towards not rendering the link in case they "don't make sense". So not rendering first for the first page etc. and only rendering the links in case more than a single page are present. The reason for that being that based on the presence of such link the client can reason about whether the resource pointed to is a different one than the current one. So imagining a UI being rendered, it could reason that it doesn't need to render the "Go to first page" button if it already is on the first page. However, if you always want to render these kinds of buttons, you'd have to apply additional logic.

What do you think of using the adaptive behavior by default but providing a configuration option to enforce the first and last links being rendered?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 18, 2015

Greg Turnquist commented

I agree with defaulting to a dynamic set of links based on conditions, but providing a single property to switch to ALWAYS ON rendering.

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 18, 2015

Vladimir Tsukur commented

Having first and last links rendered dynamically seems to be a more natural choice to me.

Consider an alternative case when first and last links are available all the time, but client wants to enable or disable navigation controls if respective actions make sense. In this case client won't escape additional logic, but this time it is going to be more complex than just knowing about potential inclusion of first and last links.

Still, making this overall dynamism configurable is a good idea

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 18, 2015

André Schäfer commented

The default rendering behavior of first and last should be consistent with next and prev.

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 20, 2015

Oliver Drotbohm commented

That's in place now. We slightly altered the appearance rules compared to what I sketched out above: first/last links now always appear together in case a Page is navigable. This effectively means whenever next or prev or both appear, both first and last will appear, too. So here's what this will boil down to:

  • Page 1 of 1, no content -> no navigation links
  • Page 1 of 1, content -> no navigation links
  • Page 1 of 2 -> navigation links: first, next, last
  • Page 2 of 2 -> navigation links: first, prev, last

Also, PagedResourcesAssembler has a new method setForceFirstAndLastRels(…) that can be used to enforce the appearance of first and last links for the first two scenarios shown above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.