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

[Neo4j] Nested Sorting + Engagement expanded usage #3226

Merged
merged 13 commits into from
Jun 3, 2024

Conversation

CarsonF
Copy link
Member

@CarsonF CarsonF commented Jun 3, 2024

Why? Engagement sorters

This new functionality is driven by the need for the new UI to sort by deep fields.
Now the engagements list supports sorting by:

  • nameProjectFirst - project name, then language/intern name.
  • nameProjectLast - language/intern name, then project name.
    (Yes yes I hear you thinking multi sorting. Some day.)
  • sensitivity
  • project.primaryLocation.name
  • language.ethnologue.code
  • language.registryOfDialectsCode
  • currentProgressReportDue.status

sorting -> sortWith

Previously we had

query.apply(sorting(User, input, {
  ...
}))

This still works, but now it's recommended to switch to declare the matchers/sorters separately from application in a query.

// top level
export const userSorters = defineSorters(User, {
  ...
});

// in list()
query.apply(sortWith(userSorters, input))

This split allows the sorters to be referenced as sub/nested sorting in other sorting calls.

Basic sorter

Each key is the sort field string that callers can pick this is a loose string, so it can be an existing field on the type or something completely new.

const userSorters = defineSorters(User, {
  name: (query) => query
    // Do whatever to calculate the sort value.
    // `node` can be assumed to be the current type.
    // One per row.
    .match(...)
    // This "matcher" function should end with a return clause that
    // emits `sortValue`
    .return<SortCol>('x as sortValue'),

This hasn't changed from previous functionality.

Nested sorter

The ability to nest sorting into relationships is possible.
This is done by appending .* to the key.
For example, the sort field could be "parent.name"

const userSorters = defineSorters(User, {
  'name': (query) => ...

  'parent.*': (query, input) => query
    // Again match as needed
    .match(...)
    // Call sortWith with the sorters of the relationship type.
    // These matchers are also given the current sort _input_
    // (second arg above) which can be passed down like this.
    // `sortWith` understands this nesting and will remove the `parent.`
    // prefix before matching the nested sorters.
    .apply(sortWith(userSorters, input))
});

Extending other sorters

Sorters can "extend" others too.
Defined sorters have their declared matchers exposed on the matchers property.
So they can be spread/picked/etc. into a new object.
For example, say Manager extends User, and we want to add some sorters for that type but keep the User ones as well.

const managerSorters = defineSorters(Manager, {
  ...userSorters.matchers,
  // Add some new ones
});

https://seed-company-squad.monday.com/boards/5989610236/pulses/6766885746

@CarsonF CarsonF requested a review from a team June 3, 2024 14:07
Copy link
Contributor

@bryanjnelson bryanjnelson left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Contributor

@willdch willdch left a comment

Choose a reason for hiding this comment

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

LGTM!

@CarsonF CarsonF merged commit fde8ef4 into develop Jun 3, 2024
15 checks passed
@CarsonF CarsonF deleted the engagement-sorting-nested branch June 3, 2024 19:21
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.

4 participants