Skip to content

Commit

Permalink
686: task: make properties inside model movable und deletable
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kuhlmay committed Jan 10, 2024
1 parent 1a3e076 commit 0d1b345
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
52 changes: 50 additions & 2 deletions Build/Sources/components/ReactFlow/CustomModelNode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import SelectComponent from "../forms/select/SelectComponent";
import { Handle, Position } from 'reactflow';
import propertyTypes from "./customModelNode/propertyTypes";
import relationTypes from "./customModelNode/relationTypes";
import { faArrowUp, faArrowDown, faTrash } from '@fortawesome/free-solid-svg-icons'


export const CustomModelNode = (props) => {
const [properties, setProperties] = useState(props.data.properties);
Expand Down Expand Up @@ -85,6 +87,24 @@ export const CustomModelNode = (props) => {
props.data.properties = properties;
}

const removeProperty = (propertyIndex) => {
properties.splice(propertyIndex, 1);
setProperties([...properties]);
props.data.properties = properties;
}

const moveProperty = (propertyIndex, direction) => {
const newIndex = propertyIndex + direction;
if (newIndex < 0 || newIndex >= properties.length) {
return;
}
const property = properties[propertyIndex];
properties.splice(propertyIndex, 1);
properties.splice(newIndex, 0, property);
setProperties([...properties]);
props.data.properties = properties;
}

const updateRelation = (index, property, value) => {
relations[index][property] = value;
setRelations([...relations]);
Expand Down Expand Up @@ -362,7 +382,7 @@ export const CustomModelNode = (props) => {
label="is nullable?"
checked={property.isNullable}
onChange={(value) => {
updateProperty(index, "isNullable", value);
updateProperty(index, "isNullable", value);
}}
/>
<CheckboxComponent
Expand All @@ -381,6 +401,34 @@ export const CustomModelNode = (props) => {
updateProperty(index, "isl10nModeExlude", value);
}}
/>
<div className="d-flex">
<button
className="btn btn-danger me-auto"
onClick={() => {
removeProperty(index);
}}
>
<FontAwesomeIcon icon={faTrash}/>
</button>
<button
className="btn btn-info me-1"
onClick={
() => moveProperty(index, -1)
}
disabled={index === 0}
>
<FontAwesomeIcon icon={faArrowUp}/>
</button>
<button
className="btn btn-info"
onClick={
() => moveProperty(index, 1)
}
disabled={index === properties.length - 1}
>
<FontAwesomeIcon icon={faArrowDown}/>
</button>
</div>
</div>
</TYPO3StyledAccordion>
)
Expand All @@ -395,7 +443,7 @@ export const CustomModelNode = (props) => {
title="Add relation"
onClick={addEmptyRelation}
>
<FontAwesomeIcon className="font-awesome-icon" icon="fa-solid fa-plus" />
<FontAwesomeIcon className="font-awesome-icon" icon="fa-solid fa-plus"/>
</button>
</div>
{
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/JavaScript/main.js

Large diffs are not rendered by default.

0 comments on commit 0d1b345

Please sign in to comment.