Skip to content

Commit

Permalink
Fix content nodes sorting take 2 (#8586)
Browse files Browse the repository at this point in the history
* Fix content nodes sorting take 2

* 📖
  • Loading branch information
flvndvd authored Nov 12, 2024
1 parent 56f988e commit c273e43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions connectors/src/api/get_content_nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
Result,
WithConnectorsAPIErrorReponse,
} from "@dust-tt/types";
import { removeNulls } from "@dust-tt/types";
import { contentNodeTypeSortOrder, removeNulls } from "@dust-tt/types";
import type { Request, Response } from "express";
import { isLeft } from "fp-ts/lib/Either";
import * as t from "io-ts";
Expand Down Expand Up @@ -92,7 +92,7 @@ const _getContentNodes = async (

const contentNodes = sortBy(
removeNulls(internalIds.map((internalId) => contentNodesMap[internalId])),
(e) => e.title.toLowerCase()
(c) => [contentNodeTypeSortOrder[c.type], c.title.toLowerCase()]
);

if (includeParents) {
Expand Down
12 changes: 12 additions & 0 deletions types/src/front/lib/connectors_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ export type ConnectorType = {
export type ConnectorPermission = "read" | "write" | "read_write" | "none";
export type ContentNodeType = "file" | "folder" | "database" | "channel";

/*
* This constant defines the priority order for sorting content nodes by their type.
* The types are sorted in the following order: folder first, then file, database, and channel.
* This mapping is used to provide a numerical value representing the priority of each content node type.
*/
export const contentNodeTypeSortOrder: Record<ContentNodeType, number> = {
folder: 1,
file: 2,
database: 3,
channel: 4,
};

/**
* A ContentNode represents a connector related node. As an example:
* - Notion: Top-level pages (possibly manually added lower level ones)
Expand Down

0 comments on commit c273e43

Please sign in to comment.