-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve bugs tied to record creations on table #4011
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { atom } from 'recoil'; | ||
|
||
import { ViewType } from '@/views/types/ViewType'; | ||
|
||
export const recordIndexViewTypeState = atom<ViewType | undefined>({ | ||
key: 'recordIndexViewTypeState', | ||
default: undefined, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
import { useParams } from 'react-router-dom'; | ||
import styled from '@emotion/styled'; | ||
|
||
import { useObjectMetadataItemForSettings } from '@/object-metadata/hooks/useObjectMetadataItemForSettings'; | ||
import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObjectNameSingularFromPlural'; | ||
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord'; | ||
import { RecordIndexContainer } from '@/object-record/record-index/components/RecordIndexContainer'; | ||
import { DEFAULT_CELL_SCOPE } from '@/object-record/record-table/record-table-cell/hooks/useOpenRecordTableCell'; | ||
import { useSelectedTableCellEditMode } from '@/object-record/record-table/record-table-cell/hooks/useSelectedTableCellEditMode'; | ||
import { useIcons } from '@/ui/display/icon/hooks/useIcons'; | ||
import { PageAddButton } from '@/ui/layout/page/PageAddButton'; | ||
import { PageBody } from '@/ui/layout/page/PageBody'; | ||
import { PageContainer } from '@/ui/layout/page/PageContainer'; | ||
import { PageHeader } from '@/ui/layout/page/PageHeader'; | ||
import { PageHotkeysEffect } from '@/ui/layout/page/PageHotkeysEffect'; | ||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope'; | ||
import { RecordIndexPageHeader } from '~/pages/object-record/RecordIndexPageHeader'; | ||
|
||
const StyledIndexContainer = styled.div` | ||
display: flex; | ||
|
@@ -28,44 +24,29 @@ export const RecordIndexPage = () => { | |
objectNamePlural, | ||
}); | ||
|
||
const { findObjectMetadataItemByNamePlural } = | ||
useObjectMetadataItemForSettings(); | ||
|
||
const { getIcon } = useIcons(); | ||
const Icon = getIcon( | ||
findObjectMetadataItemByNamePlural(objectNamePlural)?.icon, | ||
); | ||
|
||
const { createOneRecord: createOneObject } = useCreateOneRecord({ | ||
objectNameSingular, | ||
}); | ||
|
||
const recordIndexId = objectNamePlural ?? ''; | ||
|
||
const setHotkeyScope = useSetHotkeyScope(); | ||
|
||
const { setSelectedTableCellEditMode } = useSelectedTableCellEditMode({ | ||
scopeId: recordIndexId, | ||
}); | ||
|
||
const handleAddButtonClick = async () => { | ||
await createOneObject?.({}); | ||
await createOneObject?.({ | ||
position: 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @martmull this is actually tied to another behavior: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok then go |
||
}); | ||
|
||
setSelectedTableCellEditMode(0, 0); | ||
setHotkeyScope(DEFAULT_CELL_SCOPE.scope, DEFAULT_CELL_SCOPE.customScopes); | ||
}; | ||
|
||
return ( | ||
<PageContainer> | ||
<PageHeader | ||
title={ | ||
objectNamePlural.charAt(0).toUpperCase() + objectNamePlural.slice(1) | ||
} | ||
Icon={Icon} | ||
> | ||
<PageHotkeysEffect onAddButtonClick={handleAddButtonClick} /> | ||
<PageAddButton onClick={handleAddButtonClick} /> | ||
</PageHeader> | ||
<RecordIndexPageHeader createRecord={handleAddButtonClick} /> | ||
<PageBody> | ||
<StyledIndexContainer> | ||
<RecordIndexContainer | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useParams } from 'react-router-dom'; | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
import { useObjectMetadataItemForSettings } from '@/object-metadata/hooks/useObjectMetadataItemForSettings'; | ||
import { recordIndexViewTypeState } from '@/object-record/record-index/states/recordIndexViewTypeState'; | ||
import { useIcons } from '@/ui/display/icon/hooks/useIcons'; | ||
import { PageAddButton } from '@/ui/layout/page/PageAddButton'; | ||
import { PageHeader } from '@/ui/layout/page/PageHeader'; | ||
import { PageHotkeysEffect } from '@/ui/layout/page/PageHotkeysEffect'; | ||
import { ViewType } from '@/views/types/ViewType'; | ||
|
||
type RecordIndexPageHeaderProps = { | ||
createRecord: () => void; | ||
}; | ||
|
||
export const RecordIndexPageHeader = ({ | ||
createRecord, | ||
}: RecordIndexPageHeaderProps) => { | ||
const objectNamePlural = useParams().objectNamePlural ?? ''; | ||
|
||
const { findObjectMetadataItemByNamePlural } = | ||
useObjectMetadataItemForSettings(); | ||
|
||
const { getIcon } = useIcons(); | ||
const Icon = getIcon( | ||
findObjectMetadataItemByNamePlural(objectNamePlural)?.icon, | ||
); | ||
|
||
const recordIndexViewType = useRecoilValue(recordIndexViewTypeState); | ||
|
||
return ( | ||
<PageHeader | ||
title={ | ||
objectNamePlural.charAt(0).toUpperCase() + objectNamePlural.slice(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @charlesBochet there is a capitalize util function in packages/twenty-front/src/utils/string/capitalize.ts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've split a file in two so I missed it, but I'll use capitalize, thank you for pointing it |
||
} | ||
Icon={Icon} | ||
> | ||
<PageHotkeysEffect onAddButtonClick={createRecord} /> | ||
{recordIndexViewType === ViewType.Table && ( | ||
<PageAddButton onClick={createRecord} /> | ||
)} | ||
</PageHeader> | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming there is already one element at position 0 when you load the page right? Will it still work? @charlesBochet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works but it's a hack. We will need to do a better job but this is fixing the current erratic component. I'll create a follow up ticket to properly implement the position that should be first / 2