Skip to content

Commit

Permalink
Fix form builder sort bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kalilsn committed Feb 26, 2025
1 parent 6437e39 commit ee6700e
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 112 deletions.
30 changes: 18 additions & 12 deletions core/app/components/FormBuilder/FormBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,29 +265,35 @@ export function FormBuilder({ pubForm, id, stages }: Props) {
activeIndex !== undefined &&
overIndex !== undefined
) {
const isMovedEarlier =
activeIndex > overIndex;
const activeElem =
elements[activeIndex];
const aboveRank =
elements[overIndex + 1]
?.rank ?? "";
elements[
isMovedEarlier
? overIndex
: overIndex + 1
]?.rank ?? "";
const belowRank =
elements[overIndex - 1]
?.rank ?? "";
elements[
isMovedEarlier
? overIndex - 1
: overIndex
]?.rank ?? "";
const [rank] =
mudder.base62.mudder(
belowRank,
aboveRank,
1
);
form.setValue(
`elements.${activeIndex}`,
{
...activeElem,
rank,
updated: true,
}
);

move(activeIndex, overIndex);
update(overIndex, {
...activeElem,
rank,
updated: true,
});
}
}
}}
Expand Down
3 changes: 2 additions & 1 deletion core/lib/server/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export const getForm = (
"pub_fields.isRelation",
])
.$narrowType<FormElements>()
.orderBy("form_elements.rank")
// Use "C" collation order to ensure uppercase letters sort before lowercase to match mudder
.orderBy(sql`"rank" collate "C"`)
).as("elements")
)
);
Expand Down
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"jsonpath-plus": "^10.2.0",
"jsonwebtoken": "^9.0.0",
"katex": "^0.16.18",
"kysely": "^0.27.3",
"kysely": "^0.27.5",
"lodash.partition": "^4.6.0",
"logger": "workspace:*",
"lucia": "^3.2.2",
Expand Down
Loading

0 comments on commit ee6700e

Please sign in to comment.