Fixes Default View Ordering (#6114) (#6326)

fixes #6114

Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
Faisal-imtiyaz123 2024-07-19 21:57:33 +05:30 committed by GitHub
parent 088d061b3e
commit 12c33159e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 54 deletions

View File

@ -4,18 +4,11 @@ export const getObjectMetadataItemViews = (
viewObjectMetadataId: string,
views: GraphQLView[],
) => {
const indexView = views.find(
(view) =>
view.key === 'INDEX' && view.objectMetadataId === viewObjectMetadataId,
);
return [
...views
.filter((view) => view.objectMetadataId === viewObjectMetadataId)
.filter((view) => view.key !== 'INDEX'),
...views.filter((view) => view.objectMetadataId === viewObjectMetadataId),
]
.sort((a, b) => a.position - b.position)
.concat(indexView ? [indexView] : [])
.map((view) => ({
id: view.id,
name: view.name,

View File

@ -64,9 +64,6 @@ export const ViewPickerListContent = () => {
const { getIcon } = useIcons();
const indexView = viewsOnCurrentObject.find((view) => view.key === 'INDEX');
const viewsOnCurrentObjectWithoutIndex = viewsOnCurrentObject.filter(
(view) => view.key !== 'INDEX',
);
const handleDragEnd = useCallback(
(result: DropResult) => {
@ -89,49 +86,41 @@ export const ViewPickerListContent = () => {
<DropdownMenuItemsContainer>
<DraggableList
onDragEnd={handleDragEnd}
draggableItems={viewsOnCurrentObjectWithoutIndex.map(
(view, index) => (
draggableItems={viewsOnCurrentObject.map((view, index) => (
<DraggableItem
key={view.id}
draggableId={view.id}
index={index}
isDragDisabled={viewsOnCurrentObjectWithoutIndex.length === 1}
isDragDisabled={viewsOnCurrentObject.length === 1}
itemComponent={
<MenuItemDraggable
key={view.id}
iconButtons={[
iconButtons={
indexView?.id === view.id
? [
{
Icon: IconLock,
},
]
: [
{
Icon: IconPencil,
onClick: (event: MouseEvent<HTMLButtonElement>) =>
handleEditViewButtonClick(event, view.id),
},
].filter(isDefined)}
isIconDisplayedOnHoverOnly
].filter(isDefined)
}
isIconDisplayedOnHoverOnly={
indexView?.id === view.id ? false : true
}
onClick={() => handleViewSelect(view.id)}
LeftIcon={getIcon(view.icon)}
text={view.name}
/>
}
/>
),
)}
))}
/>
{indexView && (
<MenuItemDraggable
key={indexView.id}
iconButtons={[
{
Icon: IconLock,
},
].filter(isDefined)}
isIconDisplayedOnHoverOnly={false}
onClick={() => handleViewSelect(indexView.id)}
LeftIcon={getIcon(indexView.icon)}
text={indexView.name}
accent="placeholder"
isDragDisabled
/>
)}
</DropdownMenuItemsContainer>
<DropdownMenuSeparator />
<StyledBoldDropdownMenuItemsContainer>