core icon indicating copy to clipboard operation
core copied to clipboard

dotcms lib: Get Nav Is Broken

Open rjvelazco opened this issue 2 years ago • 0 comments

Describe the bug

The latest version (v0.0.18) of our dotCMS JavaScript Library has been broken for over a year. See the npm package here.

If we try to use the dotCMS.nav.get() method, it is always returning an empty array.

const nav = await dotCMS.nav.get(String(deep), location);

// Always returns an empty array.
console.log(nav.children);

To Reproduce

We can test it in one of our custom nextJS projects or in a new one.

Let's start by reproducing the error in our Dotcms NextJS Starter project:

  1. Clone the project.
  2. Run yarn dotcms@latest (The current version in this project is v0.0.17 which is working normally)
  3. Run yarn (Install all dependencies).
  4. Start the project (Read how to do it in the README.md)
  5. See the error. Now the navigation only has one options home.
v0.0.18 v0.0.17
v0.0.18.png v0.0.17.png

We can also reproducing in a new JavaScript Project:

  1. Create a JavaScript Project using npm. Could be: NextJS, ReactJS, or Angular.
  2. Run yarn dotcms@latest
  3. Instance a dotCMS APP:
// Dependencies
import { initDotCMS } from 'dotcms'

export const dotCMS = initDotCMS({
  host: ${your_host}
  token: ${your_token}
})
  1. Try to use the await dotCMS.nav.get(String(deep), location); method.
  2. See the Error.

Expected behavior

The method should bring the navigation items as we would expect.

Additional context

It looks like it is due to a change on the params made in this PR.

As you can see in the PR, in the DotApiNavigation.ts file, the depth param was changed to deep.

issue.png

If we follow the documentation [dotcms navigation rest api], the correct param is:

.request({
   url: `/api/v1/nav/${location}`,
   params: {
      depth: deep
   }
})

Acceptance criteria

  • Should bring the navigation items as expected.
  • Try the methods and confirm that they are working normally.
  • Update the dotCMS package.

P.S: You can reach me if you have any questions about how to start our Dotcms NextJS Starter project.

rjvelazco avatar Sep 16 '22 21:09 rjvelazco