-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4087 refactor object metadata item hooks and utils (#4861)
- Extracted each exported element from useObjectMetadataItem into its own hook.
- Loading branch information
1 parent
651af1c
commit b1242bb
Showing
89 changed files
with
699 additions
and
622 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
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
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
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
21 changes: 0 additions & 21 deletions
21
...twenty-front/src/modules/object-metadata/hooks/__tests__/useGetObjectOrderByField.test.ts
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
...wenty-front/src/modules/object-metadata/hooks/__tests__/useGetObjectOrderByField.test.tsx
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,33 @@ | ||
import { ReactNode } from 'react'; | ||
import { MockedProvider } from '@apollo/client/testing'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { RecoilRoot } from 'recoil'; | ||
|
||
import { useGetObjectOrderByField } from '@/object-metadata/hooks/useGetObjectOrderByField'; | ||
|
||
const Wrapper = ({ children }: { children: ReactNode }) => ( | ||
<RecoilRoot> | ||
<MockedProvider addTypename={false}>{children}</MockedProvider> | ||
</RecoilRoot> | ||
); | ||
|
||
describe('useGetObjectOrderByField', () => { | ||
it('should work as expected', () => { | ||
const { result } = renderHook( | ||
() => { | ||
const { getObjectOrderByField } = useGetObjectOrderByField({ | ||
objectNameSingular: 'person', | ||
}); | ||
|
||
return getObjectOrderByField('AscNullsLast'); | ||
}, | ||
{ | ||
wrapper: Wrapper, | ||
}, | ||
); | ||
|
||
expect(result.current).toEqual({ | ||
name: { firstName: 'AscNullsLast', lastName: 'AscNullsLast' }, | ||
}); | ||
}); | ||
}); |
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
18 changes: 12 additions & 6 deletions
18
packages/twenty-front/src/modules/object-metadata/hooks/useGetObjectOrderByField.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 |
---|---|---|
@@ -1,14 +1,20 @@ | ||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; | ||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; | ||
import { OrderBy } from '@/object-metadata/types/OrderBy'; | ||
import { OrderByField } from '@/object-metadata/types/OrderByField'; | ||
import { getObjectOrderByField } from '@/object-metadata/utils/getObjectOrderByField'; | ||
import { getOrderByFieldForObjectMetadataItem } from '@/object-metadata/utils/getObjectOrderByField'; | ||
|
||
export const useGetObjectOrderByField = ({ | ||
objectMetadataItem, | ||
objectNameSingular, | ||
}: { | ||
objectMetadataItem: ObjectMetadataItem; | ||
objectNameSingular: string; | ||
}) => { | ||
return (orderBy: OrderBy): OrderByField => { | ||
return getObjectOrderByField(objectMetadataItem, orderBy); | ||
const { objectMetadataItem } = useObjectMetadataItem({ | ||
objectNameSingular, | ||
}); | ||
|
||
const getObjectOrderByField = (orderBy: OrderBy): OrderByField => { | ||
return getOrderByFieldForObjectMetadataItem(objectMetadataItem, orderBy); | ||
}; | ||
|
||
return { getObjectOrderByField }; | ||
}; |
17 changes: 17 additions & 0 deletions
17
...ges/twenty-front/src/modules/object-metadata/hooks/useLabelIdentifierFieldMetadataItem.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,17 @@ | ||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; | ||
import { getLabelIdentifierFieldMetadataItem } from '@/object-metadata/utils/getLabelIdentifierFieldMetadataItem'; | ||
|
||
export const useLabelIdentifierFieldMetadataItem = ({ | ||
objectNameSingular, | ||
}: { | ||
objectNameSingular: string; | ||
}) => { | ||
const { objectMetadataItem } = useObjectMetadataItem({ | ||
objectNameSingular, | ||
}); | ||
|
||
const labelIdentifierFieldMetadataItem = | ||
getLabelIdentifierFieldMetadataItem(objectMetadataItem); | ||
|
||
return { labelIdentifierFieldMetadataItem }; | ||
}; |
21 changes: 16 additions & 5 deletions
21
packages/twenty-front/src/modules/object-metadata/hooks/useMapToObjectRecordIdentifier.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 |
---|---|---|
@@ -1,8 +1,19 @@ | ||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; | ||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; | ||
import { getObjectRecordIdentifier } from '@/object-metadata/utils/getObjectRecordIdentifier'; | ||
import { ObjectRecord } from '@/object-record/types/ObjectRecord'; | ||
|
||
export const useMapToObjectRecordIdentifier = | ||
({ objectMetadataItem }: { objectMetadataItem: ObjectMetadataItem }) => | ||
(record: ObjectRecord) => | ||
getObjectRecordIdentifier({ objectMetadataItem, record }); | ||
export const useMapToObjectRecordIdentifier = ({ | ||
objectNameSingular, | ||
}: { | ||
objectNameSingular: string; | ||
}) => { | ||
const { objectMetadataItem } = useObjectMetadataItem({ | ||
objectNameSingular, | ||
}); | ||
|
||
const mapToObjectRecordIdentifier = (record: ObjectRecord) => { | ||
return getObjectRecordIdentifier({ objectMetadataItem, record }); | ||
}; | ||
|
||
return { mapToObjectRecordIdentifier }; | ||
}; |
Oops, something went wrong.