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

Enhanced navigation reducer in Volto #5817

Merged
merged 6 commits into from
Apr 4, 2024
Merged

Conversation

Hrittik20
Copy link
Contributor

Fixes: #5772

Copy link

netlify bot commented Mar 1, 2024

Deploy Preview for plone-components ready!

Name Link
🔨 Latest commit 19e49af
🔍 Latest deploy log https://app.netlify.com/sites/plone-components/deploys/660e1d565d7f6600072cbecb
😎 Deploy Preview https://deploy-preview-5817--plone-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Mar 1, 2024

Deploy Preview for volto ready!

Name Link
🔨 Latest commit 19e49af
🔍 Latest deploy log https://app.netlify.com/sites/volto/deploys/660e1d569c16210008c20b47
😎 Deploy Preview https://deploy-preview-5817--volto.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ichim-david
Copy link
Member

@Hrittik20 when you add a pull request you need to check the CI tests and find out what fails.
unit-tests
You can see that the unit tests fail for plone/volto.
this means that you need to go inside your branch to packages/volto and run:
pnpm test

jest testing will run and eventually you will get failures.
hit f key and only the failed tests will run.
From there you can make changes to the code or tests and when saving the failed tests will re-run.
This way you will know if what you changed fixed the tests or not.

@Hrittik20
Copy link
Contributor Author

@ichim-david Yes, I'm working on it. I will soon make an updated PR

@ichim-david
Copy link
Member

@ichim-david Yes, I'm working on it. I will soon make an updated PR

@Hrittik20 I think the navigation test can avoid being update as long as the id is filtered since we
have the url field.
@sneridagh what do you think, are we ok with having the id of the item added or
should we remove it?

@Hrittik20
Copy link
Contributor Author

@ichim-david How about If I update navigation.js by adding a check within the reducer logic that compares the incoming navigation items with the existing ones based on their URLs?

function isSameItem(item1, item2) {
  return item1.url === item2.url;
}
export default function navigation(state = initialState, action = {}) {
  let hasExpander;
  switch (action.type) {
    case `${GET_NAVIGATION}_PENDING`:
      return {
        ...state,
        error: null,
        loaded: false,
        loading: true,
      };
    case `${GET_CONTENT}_SUCCESS`:
      hasExpander = hasApiExpander(
        'navigation',
        getBaseUrl(flattenToAppURL(action.result['@id'])),
      );
      if (hasExpander && !action.subrequest) {
        const newItems = getRecursiveItems(
          action.result['@components'].navigation.items,
        );
        const hasSameItem = newItems.some(incomingItem =>
          state.items.some(existingItem => isSameItem(incomingItem, existingItem))
        );
        if (!hasSameItem) {
          return {
            ...state,
            error: null,
            items: newItems,
            loaded: true,
            loading: false,
          };
        }
      }
      return state;

@ichim-david
Copy link
Member

@ichim-david How about If I update navigation.js by adding a check within the reducer logic that compares the incoming navigation items with the existing ones based on their URLs?

function isSameItem(item1, item2) {
  return item1.url === item2.url;
}
export default function navigation(state = initialState, action = {}) {
  let hasExpander;
  switch (action.type) {
    case `${GET_NAVIGATION}_PENDING`:
      return {
        ...state,
        error: null,
        loaded: false,
        loading: true,
      };
    case `${GET_CONTENT}_SUCCESS`:
      hasExpander = hasApiExpander(
        'navigation',
        getBaseUrl(flattenToAppURL(action.result['@id'])),
      );
      if (hasExpander && !action.subrequest) {
        const newItems = getRecursiveItems(
          action.result['@components'].navigation.items,
        );
        const hasSameItem = newItems.some(incomingItem =>
          state.items.some(existingItem => isSameItem(incomingItem, existingItem))
        );
        if (!hasSameItem) {
          return {
            ...state,
            error: null,
            items: newItems,
            loaded: true,
            loading: false,
          };
        }
      }
      return state;

@Hrittik20 I want to hear what @davisagli or @sneridagh has to say about this change, we might be ok to have also the id present without having todo any filtering, or we can simply filter it when destructuring it here https://github.com/plone/volto/pull/5817/files#diff-c1e66aca1aa305458203941b7e7d598522bbecc56ead1841087e2393b93a57b6R37

Copy link
Member

@sneridagh sneridagh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like @tiberiuichim and @davisagli to take a final look as well.

Copy link
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a minor suggestion, but this lgtm

@davisagli davisagli merged commit 0630a6e into plone:main Apr 4, 2024
45 checks passed
sneridagh added a commit that referenced this pull request Apr 16, 2024
* main: (28 commits)
  Bump vite from 5.1.5 to 5.1.7 (#5946)
  Fix pt_BR translation of invalid email message (#5953)
  Fix markup shortcuts for bold, italic and strikethough fix (#5606)
  Release 18.0.0-alpha.27
  Release @plone/types 1.0.0-alpha.10
  Improve color widget picker and types (#5948)
  Enhanced navigation reducer in Volto (#5817)
  Release 18.0.0-alpha.26
  Rename news item
  Release @plone/slate 18.0.0-alpha.11
  Release @plone/registry 1.5.5
  Release @plone/types 1.0.0-alpha.9
  docs: Cleanup obsolete EEA projects and update info about EEA main website (#5943)
  Bump vite from 5.1.4 to 5.1.5 (#5942)
  Add a new label `needs: triage` to new bug reports (#5940)
  Fix redirect of `https://sustainability.eionet.europa.eu` to `https:/… (#5941)
  Does not show borders in addon block inputs (#5898)
  Fix edge case in search options mangling when the options are false-ish (#5869)
  Add additional parameters to ContentsUploadModal to be reusable in different scenarios (#5881)
  fix(slate): fix insert/remove element edgecase bug in slate (#5926)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Navigation reducer should keep items extra-data sent from the navigation endpoint
4 participants