Skip to content

Commit

Permalink
New: Add positional-array-sorter
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Oct 29, 2024
1 parent 31ddddb commit 7267637
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Create property with type `reapeatable`.
# ...
properties:
field0:
# The order of the fields can be altered by setting position. It is the same logic as @position in Fusion
# https://neos.readthedocs.io/en/stable/References/NeosFusionReference.html#neos-fusion-join
position: 10
editorOptions:
placeholder: 'default field editor'
field1:
Expand Down
13 changes: 11 additions & 2 deletions Resources/Private/Editor/Repeatable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { selectors } from "@neos-project/neos-ui-redux-store";
import { neos } from "@neos-project/neos-ui-decorators";
import { IconButton, Button, Label } from "@neos-project/react-ui-components";
import backend from "@neos-project/neos-ui-backend-connector";
import positionalArraySorter from "@neos-project/positional-array-sorter";
import Loading from "carbon-neos-loadinganimation/LoadingWithStyles";
import { Sortable, DragHandle } from "./Sortable";
import Envelope from "./Envelope";
Expand Down Expand Up @@ -112,9 +113,15 @@ function Repeatable(props) {
let group = {};
const properties = options.properties;
if (properties) {
Object.entries(properties).forEach(([property, item]) => {
// Create array to enable sorting
const array = [];
for (const key in properties) {
const item = properties[key];
array.push({ key, position: item?.position ?? null, item });
}
positionalArraySorter(array).forEach(({ key, item }) => {
const defaultValue = item && item.defaultValue;
group[property] = returnValueIfSet(defaultValue, "");
group[key] = returnValueIfSet(defaultValue, "");
});
}
return group;
Expand Down Expand Up @@ -293,6 +300,8 @@ function Repeatable(props) {
properties.push(getProperty(property, idx));
});

// positionalArraySorter

return (
<div className={style.group}>
{groupLabel && <span dangerouslySetInnerHTML={{ __html: groupLabel }} />}
Expand Down
6 changes: 3 additions & 3 deletions Resources/Public/Plugin.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Resources/Public/Plugin.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"devDependencies": {
"@formkit/auto-animate": "^0.8.2",
"@neos-project/neos-ui-extensibility": "~8.3.11",
"@neos-project/positional-array-sorter": "^8.3.11",
"array-move": "^4.0.0",
"carbon-neos-loadinganimation": "^1.1.1",
"clsx": "^2.1.1",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7267637

Please sign in to comment.