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

OBPIH-5273 Dashboard is underlined in menu on some pages #3770

Merged
merged 17 commits into from
Jan 20, 2023

Conversation

alannadolny
Copy link
Collaborator

No description provided.

@alannadolny alannadolny marked this pull request as draft January 10, 2023 20:21
const path = window.location.pathname
const menuConfigValues = $(".menu-config-value").toArray();
const matchingSection = menuConfigValues.find(it => it.value.includes(path))
function getHrefs(value) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this function seems a little too complicated which makes it very hard to read and understand what is going on.
I think that we should make it more explicit and straight forward.
My proposition on how to deal with certain pages that are not underlined in the menu for GSP pages is to add a script in eg. show.gsp for stocklists

<script type="text/javascript">
  $(document).ready(function () {
    const matchingMenuSection = $("#requisitionTemplate')
    const matchingMenuSectionCollapsable = $("#requisitionTemplate-collapsed").get(0);
    if (matchingMenuSection) matchingMenuSection.classList.add('active-section');
    if (matchingMenuSectionCollapsable) matchingMenuSectionCollapsable.classList.add('active-section');
  })
</script>

that way when this show page is going to be rendered the script is going to add an active class to the appropriate section

of course you would have to implement this script in all of the pages that require it but I don't think this will be a big problem since it's a simple logic and I would prefer some duplicate chunks of code instead of a complicated hard to read function

@@ -1340,7 +1340,7 @@ openboxes {
[label: "inventory.import.label", defaultLabel: "Import Inventory", href: "/${appName}/batch/importData?type=inventory&execution=e1s1"],
[label: "inventory.createStockTransfer.label", defaultLabel: "Create Stock Transfer", requiredActivitiesAll: ActivityCode.binTrackingList(), href: "/${appName}/stockTransfer/create"],
[label: "inventory.listStockTransfers.label", defaultLabel: "List Stock Transfers", requiredActivitiesAll: ActivityCode.binTrackingList(), href: "/${appName}/stockTransfer/list"],
[label: "inventory.createReplenishment.label", defaultLabel: "Create Replenishment", requiredActivitiesAll: ActivityCode.binTrackingList(), href: "/${appName}/replenishment/index"]
[label: "inventory.createReplenishment.label", defaultLabel: "Create Replenishment", requiredActivitiesAll: ActivityCode.binTrackingList(), href: "/${appName}/replenishment/create"]
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

[label: "order.createPurchase.label", defaultLabel: "Create Purchase Order", href: "/${appName}/purchaseOrder/index", requiredActivitiesAny: [ActivityCode.PLACE_ORDER]],

Create purchase order should also probably be fixed
from purchaseOrder/index to purchaseOrder/create

const {
direction,
...otherParams
} = mapQueryParamsToObject(search.substring(1, search.length));
Copy link
Collaborator

Choose a reason for hiding this comment

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

use query-string parse instead

import queryString from 'query-string';

const parsed = queryString.parse(search);

@@ -78,5 +78,6 @@
</div>
</div>
</div>
<g:render template="/dashboard/activeSection" model="[section: orderInstance.orderType.name == 'Putaway Order' ? 'inbound' : orderInstance.orderType.name == 'Outbound' ? 'outbound' : 'purchasing']"/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather use:

orderInstance?.orderType?.code == Constants.PUTAWAY_ORDER

or even:

orderInstance?.orderType?.isPutawayOrder()

By the way I'm also concered about comparing order to Outbound - we don't have orderType 'Outbound'.

@@ -111,5 +111,6 @@
</div>
</div>
</div>
<g:render template="/dashboard/activeSection" model="[section: orderInstance.orderType.name == 'Putaway Order' ? 'inbound' : orderInstance.orderType.name == 'Outbound' ? 'outbound' : 'purchasing']"/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

@@ -303,5 +303,6 @@
});
}
</script>
<g:render template="/dashboard/activeSection" model="[section: orderInstance.orderType.name == 'Putaway Order' ? 'inbound' : orderInstance.orderType.name == 'Outbound' ? 'outbound' : 'purchasing']"/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

@alannadolny alannadolny changed the base branch from develop to release/0.8.21 January 12, 2023 09:49
@@ -32,7 +35,7 @@ const Menu = ({ menuConfig, location }) => {
<MenuSection
section={section}
key={`${section.label}-menu-section`}
active={activeSection === section.label}
active={activeSection === section.id}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice catch

@jmiranda
Copy link
Member

I need a bit more time on this one.

Copy link
Member

@jmiranda jmiranda left a comment

Choose a reason for hiding this comment

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

I don't think we want to be passing in this section information on every GSP when we already have it available in the Config (i.e. search href by the current URL to get the active section). Let's discuss this one on the tech huddle.

@jmiranda
Copy link
Member

jmiranda commented Jan 18, 2023

Tech Huddle discussion

  • Make as many work implicitly without having to inject the active section
    • inventoryItem -> inventory
    • product -> product
    • order -> purchasing
  • Stock movement can be hard-coded / injected for now
  • All other exceptions can wait to another release
  • activeSection.gsp should be included in megamenu.gsp or custom.gsp
  • Consider using sitemesh to handle the active section value

When you need to override, use the following convention
stockMovement/show.gsp (add to head)

<g:set var="activeSection">$stockMovement?.stockMovementType?.toLowecase()</g:set>
<content tag="activeSection">${activeSection?:controllerName}</content>

Copy link
Collaborator

@kchelstowski kchelstowski left a comment

Choose a reason for hiding this comment

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

Don't do any changes until @awalkowiak approves my requests

if (matchingMenuSection) matchingMenuSection.classList.add('active-section');
if (matchingMenuSectionCollapsable) matchingMenuSectionCollapsable.classList.add('active-section');
}
const urlPartsWithSectionConfig = "${(grailsApplication.config.openboxes.menuSectionsUrlParts as JSON)}";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like it could be better to return it from the backend, from the def megamenu just adding another property to return after menu, configurationSection, megamenuConfig:

menuSectionsUrlParts: grailsApplication.config.openboxes.menuSectionsUrlParts as JSON

and to create a hidden field with id/class, that would allow you to access it from the js script side

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kchelstowski Yup, good suggestion

Copy link
Collaborator

@awalkowiak awalkowiak left a comment

Choose a reason for hiding this comment

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

One question about the util on the react side plus take a look at Kacpers suggestion

import _ from 'lodash';
import queryString from 'query-string';

export const checkActiveSection = ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

@alannadolny could this util also be simplified to use the new sections config?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so, because this util has to compare sectionSearch, not only sectionPath. There are some tricky places where the sectionSearch can change the section which should be underlined.

// check if current section exists in object with wrongly underlined urls
const sectionFromJson = Object.keys(parsedUrlPartsWithSection).find(sectionName => {
return !!parsedUrlPartsWithSection[sectionName].some(section => path.includes(section));
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Alternatively if we want to avoid this parsing of LinkedHasMap to JSON we can do everything using groovy.
By everything I mean finding the matched section based on config.openboxes.menuSectionUrlParts

So instead of doing it with javascript we can do it with groovy

      <g:set
        var="matchedSection"
        value="${grailsApplication.config.openboxes.menuSectionsUrlParts.find{ key, val -> val.any{ request?.forwardURI?.contains(it)} }}"
     />
      return menuConfigValues.find(it => it.name === "${matchedSection?.key}");

@alannadolny @kchelstowski @awalkowiak what do you think ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The solution that Kacper propsed, fixed the problem with replacing &quotes to ".
So now it looks like:
const urlPartsWithSection = $("#menuSectionUrlParts").val();
const parsedUrlPartsWithSection = JSON.parse(urlPartsWithSection);
I think it is much cleaner than doing it in groovy

Copy link
Collaborator

Choose a reason for hiding this comment

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

@drodzewicz I love that idea, but it depends on if we want Alan to spend some more time on this one

@awalkowiak awalkowiak merged commit 08523e8 into release/0.8.21 Jan 20, 2023
@awalkowiak awalkowiak deleted the OBPIH-5273 branch January 20, 2023 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants