Fix drag-and-drop reordering for custom fields in content type editor (#108)
Wire up @dnd-kit sortable integration in ContentTypeEditor and connect the existing reorderFields API. The grab handle icon was visual-only with no drag functionality attached. Closes #43 Co-authored-by: Matt Kane <mkane@cloudflare.com>
This commit is contained in:
@@ -75,6 +75,7 @@ import {
|
||||
createField,
|
||||
updateField,
|
||||
deleteField,
|
||||
reorderFields,
|
||||
fetchOrphanedTables,
|
||||
registerOrphanedTable,
|
||||
fetchUsers,
|
||||
@@ -1456,6 +1457,16 @@ function ContentTypesEditPage() {
|
||||
},
|
||||
});
|
||||
|
||||
const reorderFieldsMutation = useMutation({
|
||||
mutationFn: (fieldSlugs: string[]) => reorderFields(slug, fieldSlugs),
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey: ["schema", "collections", slug],
|
||||
});
|
||||
void queryClient.invalidateQueries({ queryKey: ["manifest"] });
|
||||
},
|
||||
});
|
||||
|
||||
if (error) {
|
||||
return <ErrorScreen error={error.message} />;
|
||||
}
|
||||
@@ -1472,6 +1483,7 @@ function ContentTypesEditPage() {
|
||||
onAddField={(input) => addFieldMutation.mutateAsync(input)}
|
||||
onUpdateField={(fieldSlug, input) => updateFieldMutation.mutateAsync({ fieldSlug, input })}
|
||||
onDeleteField={(fieldSlug) => deleteFieldMutation.mutate(fieldSlug)}
|
||||
onReorderFields={(fieldSlugs) => reorderFieldsMutation.mutate(fieldSlugs)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user