forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sorter for distant tables (twentyhq#5546)
As title
- Loading branch information
Showing
7 changed files
with
147 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ules/remote-server/remote-table/distant-table/utils/__tests__/sort-distant-tables.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { RemoteTableStatus } from 'src/engine/metadata-modules/remote-server/remote-table/dtos/remote-table.dto'; | ||
import { sortDistantTables } from 'src/engine/metadata-modules/remote-server/remote-table/distant-table/utils/sort-distant-tables.util'; | ||
|
||
const table1 = { | ||
status: RemoteTableStatus.SYNCED, | ||
name: 'table1', | ||
}; | ||
|
||
const table2 = { | ||
status: RemoteTableStatus.NOT_SYNCED, | ||
name: 'table2', | ||
}; | ||
|
||
describe('sortDistantTables', () => { | ||
it('should return -1 when first param status is SYNCED and second param status is NOT_SYNCED', () => { | ||
const result = sortDistantTables(table1, table2); | ||
|
||
expect(result).toBe(-1); | ||
}); | ||
|
||
it('should return 1 when first param status is NOT_SYNCED and second param status is SYNCED', () => { | ||
const result = sortDistantTables(table2, table1); | ||
|
||
expect(result).toBe(1); | ||
}); | ||
|
||
it('should return -1 when same status and first param name is smaller than second param name', () => { | ||
const result = sortDistantTables( | ||
{ ...table1, status: RemoteTableStatus.NOT_SYNCED }, | ||
table2, | ||
); | ||
|
||
expect(result).toBe(-1); | ||
}); | ||
|
||
it('should return 1 when same status and second param name is smaller than first param name', () => { | ||
const result = sortDistantTables(table2, { | ||
...table1, | ||
status: RemoteTableStatus.NOT_SYNCED, | ||
}); | ||
|
||
expect(result).toBe(1); | ||
}); | ||
|
||
it('should be case insensitive', () => { | ||
const result = sortDistantTables( | ||
{ ...table1, name: 'table1', status: RemoteTableStatus.NOT_SYNCED }, | ||
{ ...table2, name: 'Table2' }, | ||
); | ||
|
||
expect(result).toBe(-1); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
...tadata-modules/remote-server/remote-table/distant-table/utils/sort-distant-tables.util.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { RemoteTableStatus } from 'src/engine/metadata-modules/remote-server/remote-table/dtos/remote-table.dto'; | ||
|
||
export const sortDistantTables = ( | ||
table1: { | ||
status: RemoteTableStatus; | ||
name: string; | ||
}, | ||
table2: { | ||
status: RemoteTableStatus; | ||
name: string; | ||
}, | ||
) => { | ||
if ( | ||
table1.status === RemoteTableStatus.SYNCED && | ||
table2.status === RemoteTableStatus.NOT_SYNCED | ||
) { | ||
return -1; | ||
} | ||
|
||
if ( | ||
table1.status === RemoteTableStatus.NOT_SYNCED && | ||
table2.status === RemoteTableStatus.SYNCED | ||
) { | ||
return 1; | ||
} | ||
|
||
return table1.name.toUpperCase() > table2.name.toUpperCase() ? 1 : -1; | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters