Files
outline/shared/utils/collections.ts
Apoorv Mishra ad902af52c Move tree implementation out of collections store (#4763)
* refactor: attaching emoji in tree node is unnecessary

* refactor: pass depth and hasChildren as separate props

* refactor: move tree impl into a separate hook

* refactor: separate out as DocumentExplorer for reuse

* fix: separate search and node

* fix: review comments

* fix: tsc
2023-01-27 11:33:51 +05:30

44 lines
937 B
TypeScript

import { NavigationNode } from "@shared/types";
import naturalSort from "./naturalSort";
type Sort = {
field: string;
direction: "asc" | "desc";
};
export const sortNavigationNodes = (
documents: NavigationNode[],
sort: Sort,
sortChildren = true
): NavigationNode[] => {
// "index" field is manually sorted and is represented by the documentStructure
// already saved in the database, no further sort is needed
if (sort.field === "index") {
return documents;
}
const orderedDocs = naturalSort(documents, sort.field, {
direction: sort.direction,
});
return orderedDocs.map((document) => ({
...document,
children: sortChildren
? sortNavigationNodes(document.children, sort, sortChildren)
: document.children,
}));
};
export const colorPalette = [
"#4E5C6E",
"#0366d6",
"#9E5CF7",
"#FF825C",
"#FF5C80",
"#FFBE0B",
"#42DED1",
"#00D084",
"#FF4DFA",
"#2F362F",
];