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

Add order by topo position to line list #383

Open
dorthrithil opened this issue Jun 9, 2024 · 0 comments
Open

Add order by topo position to line list #383

dorthrithil opened this issue Jun 9, 2024 · 0 comments
Labels
enhancement Improves existing features

Comments

@dorthrithil
Copy link
Contributor

The old list was fetching all lines for an area and could easily implement order by topo image order index on client side. For the new implementation, this requires some clever queries that mimic the attached order function. Somehow the order by needs to order by an attributes of the first element in a relationship list.

/**
 * Sorts an array of lines by their primary topo image and the topo images order. Lines without topo images come
 * last.
 * @param lines Lines to sort.
 */
const getSortedLines = (lines: Line[]): Line[] => {
  const sortedLines = lines.sort((l1, l2) => {
    if (l1.topoImages.length === 0 && l2.topoImages.length === 0) {
      return 0;
    }
    if (l1.topoImages.length === 0) {
      return 1;
    }
    if (l2.topoImages.length === 0) {
      return -1;
    }
    if (l1.topoImages[0].orderIndex > l2.topoImages[0].orderIndex) {
      return 1;
    }
    if (l1.topoImages[0].orderIndex < l2.topoImages[0].orderIndex) {
      return -1;
    }
    if (l1.topoImages[0].linePaths[0].orderIndex > l2.topoImages[0].linePaths[0].orderIndex) {
      return 1;
    }
    if (l1.topoImages[0].linePaths[0].orderIndex < l2.topoImages[0].linePaths[0].orderIndex) {
      return -1;
    }
    return 0;
  });
  sortedLines.map((line, orderIndex) => {
    line.blockOrderIndex = orderIndex
  })
  return sortedLines;
}
@dorthrithil dorthrithil added the enhancement Improves existing features label Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improves existing features
Projects
None yet
Development

No branches or pull requests

1 participant