Przeglądaj źródła

feat(dashboard): Automatically apply sorting based on data type

Michael Bromley 10 miesięcy temu
rodzic
commit
6d3729a4d4

+ 3 - 0
packages/dashboard/src/framework/internal/document-introspection/get-document-structure.ts

@@ -13,6 +13,7 @@ export interface FieldInfo {
     nullable: boolean;
     list: boolean;
     isPaginatedList: boolean;
+    isScalar: boolean;
 }
 
 /**
@@ -80,6 +81,7 @@ function getQueryInfo(name: string): FieldInfo {
         nullable: fieldInfo[1],
         list: fieldInfo[2],
         isPaginatedList: fieldInfo[3],
+        isScalar: schemaInfo.scalars.includes(fieldInfo[0]),
     };
 }
 
@@ -99,6 +101,7 @@ function getObjectFieldInfo(typeName: string, fieldName: string): FieldInfo {
         nullable: fieldInfo[1],
         list: fieldInfo[2],
         isPaginatedList: fieldInfo[3],
+        isScalar: schemaInfo.scalars.includes(fieldInfo[0]),
     };
 }
 

+ 3 - 2
packages/dashboard/src/framework/internal/page/list-page.tsx

@@ -108,8 +108,9 @@ export function ListPage<T extends TypedDocumentNode<U>, U extends Record<string
             },
             header: headerContext => {
                 const column = headerContext.column;
-                const isSortable = column.getCanSort();
-                console.log(`${field.name} isSortable: `, isSortable);
+                // By default, we only enable sorting on scalar type fields,
+                // unless explicitly configured otherwise.
+                const isSortable = customConfig.enableSorting || field.isScalar;
 
                 const customHeader = customConfig.header;
                 let display = field.name;