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

Bugfix/navbar entries order #3334

Merged
merged 1 commit into from
Apr 28, 2021
Merged

Conversation

JBWatenbergScality
Copy link
Contributor

@JBWatenbergScality JBWatenbergScality commented Apr 28, 2021

Component:

UI

Context:

We want to provide a way for users to define a specific order of appearance for the navbar entries.

Summary:

Adding an optional order property to define the order of entries.

Acceptance criteria:

Unit tests

@bert-e
Copy link
Contributor

bert-e commented Apr 28, 2021

Hello jbwatenbergscality,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Status report is not available.

@bert-e
Copy link
Contributor

bert-e commented Apr 28, 2021

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • one peer

Peer approvals must include at least 1 approval from the following list:

@JBWatenbergScality JBWatenbergScality force-pushed the bugfix/navbar-entries-order branch from 7087508 to f2abf2e Compare April 28, 2021 17:08
@JBWatenbergScality JBWatenbergScality force-pushed the bugfix/navbar-entries-order branch from f2abf2e to 146536d Compare April 28, 2021 17:13
@JBWatenbergScality JBWatenbergScality marked this pull request as ready for review April 28, 2021 17:13
@JBWatenbergScality JBWatenbergScality requested a review from a team as a code owner April 28, 2021 17:13
@JBWatenbergScality JBWatenbergScality added the topic:ui UI-related issues label Apr 28, 2021
Comment on lines +67 to +71
throw new Error(
`[navbar][config] Invalid path specified in "options.${section}": "${path}" ` +
'(keys must be defined as fully qualified URLs, ' +
'such as "{protocol}://{host}{path}?{queryParams}")',
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Now realizing this try/catch is likely too wide for the error message it raises... Let's tackle this as debt.

expect(entries).toStrictEqual(['First', 'Second', 'Third'])
});

it('should enqueue unordered entries', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

How can this work with:

entries.sort(([_, entryA], [__, entryB]) => (entryA.order - entryB.order));

??? 🤔 Javascript is really a mistery to me...

Copy link
Contributor

Choose a reason for hiding this comment

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

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries

The order of the array returned by Object.entries() does not depend on how an object is defined. If there is a need for certain ordering, then the array should be sorted first, like Object.entries(obj).sort((a, b) => b[0].localeCompare(a[0]));.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, that was not my question actually @ChengYanJin (but it confirms that we should really not rely on default ordering).

My point was that we are sorting entries based on entryA.order - entryB.order... But we are able to handle entries for which entryC.order === undefined, and somehow they end up at the end (which this test is verifying). This part is really mystical to me.

Copy link
Contributor

@gdemonet gdemonet Apr 28, 2021

Choose a reason for hiding this comment

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

OK, tested it a bit (see https://jsfiddle.net/Loxm9ck4/2/), it's actually broken, the sort logic just doesn't move elements when faced with such a case (the comparison function returns NaN). So I think your test is somewhat broken @JBWatenbergScality 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Typically something that would have been caught immediately with typescript)

@JBWatenbergScality
Copy link
Contributor Author

/approve

@bert-e
Copy link
Contributor

bert-e commented Apr 28, 2021

In the queue

The changeset has received all authorizations and has been added to the
relevant queue(s). The queue(s) will be merged in the target development
branch(es) as soon as builds have passed.

The changeset will be merged in:

  • ✔️ development/2.9

The following branches will NOT be impacted:

  • development/1.0
  • development/1.1
  • development/1.2
  • development/1.3
  • development/2.0
  • development/2.1
  • development/2.2
  • development/2.3
  • development/2.4
  • development/2.5
  • development/2.6
  • development/2.7
  • development/2.8

There is no action required on your side. You will be notified here once
the changeset has been merged. In the unlikely event that the changeset
fails permanently on the queue, a member of the admin team will
contact you to help resolve the matter.

IMPORTANT

Please do not attempt to modify this pull request.

  • Any commit you add on the source branch will trigger a new cycle after the
    current queue is merged.
  • Any commit you add on one of the integration branches will be lost.

If you need this pull request to be removed from the queue, please contact a
member of the admin team now.

The following options are set: approve

@bert-e
Copy link
Contributor

bert-e commented Apr 28, 2021

I have successfully merged the changeset of this pull request
into targetted development branches:

  • ✔️ development/2.9

The following branches have NOT changed:

  • development/1.0
  • development/1.1
  • development/1.2
  • development/1.3
  • development/2.0
  • development/2.1
  • development/2.2
  • development/2.3
  • development/2.4
  • development/2.5
  • development/2.6
  • development/2.7
  • development/2.8

Please check the status of the associated issue None.

Goodbye jbwatenbergscality.

@bert-e bert-e merged commit 146536d into development/2.9 Apr 28, 2021
@bert-e bert-e deleted the bugfix/navbar-entries-order branch April 28, 2021 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:ui UI-related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants