Skip to content

Commit f3174bc

Browse files
changes
1 parent fa77bbb commit f3174bc

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

packages/compass-crud/src/stores/crud-store.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,7 @@ class CrudStoreImpl
15441544
});
15451545
}
15461546

1547+
// so this thing
15471548
/**
15481549
* This function is called when the collection filter changes.
15491550
*/
@@ -1572,6 +1573,7 @@ class CrudStoreImpl
15721573
has_projection:
15731574
!!query.project && Object.keys(query.project).length > 0,
15741575
has_skip: (query.skip ?? 0) > 0,
1576+
// here's your has sort
15751577
has_sort: !!query.sort && Object.keys(query.sort).length > 0,
15761578
has_limit: (query.limit ?? 0) > 0,
15771579
has_collation: !!query.collation,
@@ -1615,7 +1617,14 @@ class CrudStoreImpl
16151617
countOptions.hint = '_id_';
16161618
}
16171619

1620+
// ok so this is half your battle
1621+
const sort =
1622+
query.sort ||
1623+
(this.preferences.getPreferences().showRecentDocumentsFirst &&
1624+
'natural: -1');
1625+
16181626
const findOptions = {
1627+
// and here
16191628
sort: query.sort,
16201629
projection: query.project,
16211630
skip: query.skip,

packages/compass-preferences-model/src/preferences-schema.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export type UserConfigurablePreferences = PermanentFeatureFlags &
6969
enableGenAISampleDocumentPassing: boolean;
7070
enablePerformanceAdvisorBanner: boolean;
7171
maximumNumberOfActiveConnections?: number;
72+
showRecentDocumentsFirst: boolean;
7273
enableShowDialogOnQuit: boolean;
7374
enableCreatingNewConnections: boolean;
7475
enableProxySupport: boolean;
@@ -537,6 +538,21 @@ export const storedUserPreferencesProps: Required<{
537538
validator: z.boolean().default(false),
538539
type: 'boolean',
539540
},
541+
/**
542+
* Set the default sort.
543+
*/
544+
showRecentDocumentsFirst: {
545+
ui: true,
546+
cli: true,
547+
global: true,
548+
description: {
549+
short: 'Show recent documents first',
550+
long: "If true, queries without a sort order will use '$natural: -1' as the sort order, which generally shows recently inserted documents first.",
551+
},
552+
validator: z.boolean().default(false),
553+
type: 'boolean',
554+
},
555+
540556
/**
541557
* Switch to enable DevTools in Electron.
542558
*/

packages/compass-settings/src/components/settings/general.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const generalFields = [
55
'readOnly',
66
'enableShell',
77
'protectConnectionStrings',
8+
'showRecentDocumentsFirst',
89
'showKerberosPasswordField',
910
'maxTimeMS',
1011
'enableDevTools',

packages/compass-web/sandbox/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ const App = () => {
130130
enablePerformanceAdvisorBanner: isAtlas,
131131
enableAtlasSearchIndexes: !isAtlas,
132132
maximumNumberOfActiveConnections: isAtlas ? 10 : undefined,
133+
showRecentDocumentsFirst: false,
133134
atlasServiceBackendPreset: atlasServiceSandboxBackendVariant,
134135
enableCreatingNewConnections: !isAtlas,
135136
enableGlobalWrites: isAtlas,

0 commit comments

Comments
 (0)