Fix tests + implement radio buttons for XPositionReference
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
8759c77042
commit
9ce184df26
12 changed files with 111 additions and 30 deletions
|
@ -4,6 +4,7 @@ import { ContainerModel } from '../../Interfaces/IContainerModel';
|
||||||
import { fetchConfiguration } from '../API/api';
|
import { fetchConfiguration } from '../API/api';
|
||||||
import { IEditorState } from '../../Interfaces/IEditorState';
|
import { IEditorState } from '../../Interfaces/IEditorState';
|
||||||
import { LoadState } from './Load';
|
import { LoadState } from './Load';
|
||||||
|
import { XPositionReference } from '../../Enums/XPositionReference';
|
||||||
|
|
||||||
export function NewEditor(
|
export function NewEditor(
|
||||||
setEditorState: Dispatch<SetStateAction<IEditorState>>,
|
setEditorState: Dispatch<SetStateAction<IEditorState>>,
|
||||||
|
@ -24,6 +25,7 @@ export function NewEditor(
|
||||||
height: Number(configuration.MainContainer.Height),
|
height: Number(configuration.MainContainer.Height),
|
||||||
isRigidBody: false,
|
isRigidBody: false,
|
||||||
isAnchor: false,
|
isAnchor: false,
|
||||||
|
XPositionReference: XPositionReference.Left,
|
||||||
style: {
|
style: {
|
||||||
fillOpacity: 0,
|
fillOpacity: 0,
|
||||||
stroke: 'black'
|
stroke: 'black'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { Dispatch, SetStateAction } from 'react';
|
import { Dispatch, SetStateAction } from 'react';
|
||||||
import { IHistoryState } from '../../Interfaces/IHistoryState';
|
import { IHistoryState } from '../../Interfaces/IHistoryState';
|
||||||
import { IConfiguration } from '../../Interfaces/IConfiguration';
|
import { IConfiguration } from '../../Interfaces/IConfiguration';
|
||||||
import { ContainerModel, IContainerModel } from '../../Interfaces/IContainerModel';
|
import { ContainerModel, IContainerModel } from '../../Interfaces/IContainerModel';
|
||||||
|
@ -8,6 +8,7 @@ import IProperties from '../../Interfaces/IProperties';
|
||||||
import { AddMethod } from '../../Enums/AddMethod';
|
import { AddMethod } from '../../Enums/AddMethod';
|
||||||
import { IAvailableContainer } from '../../Interfaces/IAvailableContainer';
|
import { IAvailableContainer } from '../../Interfaces/IAvailableContainer';
|
||||||
import { transformPosition } from '../SVG/Elements/Container';
|
import { transformPosition } from '../SVG/Elements/Container';
|
||||||
|
import { XPositionReference } from '../../Enums/XPositionReference';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select a container
|
* Select a container
|
||||||
|
@ -217,7 +218,7 @@ export function AddContainer(
|
||||||
height,
|
height,
|
||||||
isRigidBody: false,
|
isRigidBody: false,
|
||||||
isAnchor: false,
|
isAnchor: false,
|
||||||
xPositionReference: containerConfig.XPositionReference,
|
XPositionReference: containerConfig.XPositionReference ?? XPositionReference.Left,
|
||||||
style: containerConfig.Style
|
style: containerConfig.Style
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -270,7 +271,7 @@ function ApplyAddMethod(index: number, containerConfig: IAvailableContainer, par
|
||||||
lastChild.properties.x,
|
lastChild.properties.x,
|
||||||
lastChild.properties.y,
|
lastChild.properties.y,
|
||||||
lastChild.properties.width,
|
lastChild.properties.width,
|
||||||
lastChild.properties.xPositionReference
|
lastChild.properties.XPositionReference
|
||||||
);
|
);
|
||||||
|
|
||||||
x += transformedX + lastChild.properties.width;
|
x += transformedX + lastChild.properties.width;
|
||||||
|
|
|
@ -97,15 +97,28 @@ export function OnPropertiesSubmit(
|
||||||
|
|
||||||
// Assign container properties
|
// Assign container properties
|
||||||
for (const property in container.properties) {
|
for (const property in container.properties) {
|
||||||
const input: HTMLInputElement | null = (event.target as HTMLFormElement).querySelector(`#${property}`);
|
const input: HTMLInputElement | HTMLDivElement | null = (event.target as HTMLFormElement).querySelector(`#${property}`);
|
||||||
|
|
||||||
if (input === null) {
|
if (input === null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
(container.properties as any)[property] = input.value;
|
if (input instanceof HTMLInputElement) {
|
||||||
if (INPUT_TYPES[property] === 'number') {
|
(container.properties as any)[property] = input.value;
|
||||||
(container.properties as any)[property] = Number(input.value);
|
if (INPUT_TYPES[property] === 'number') {
|
||||||
|
(container.properties as any)[property] = Number(input.value);
|
||||||
|
}
|
||||||
|
} else if (input instanceof HTMLDivElement) {
|
||||||
|
const radiobutton: HTMLInputElement | null = input.querySelector(`input[name="${property}"]:checked`);
|
||||||
|
|
||||||
|
if (radiobutton === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
(container.properties as any)[property] = radiobutton.value;
|
||||||
|
if (INPUT_TYPES[property] === 'number') {
|
||||||
|
(container.properties as any)[property] = Number(radiobutton.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import * as React from 'react';
|
||||||
import { fireEvent, render, screen } from '../../utils/test-utils';
|
import { fireEvent, render, screen } from '../../utils/test-utils';
|
||||||
import { ElementsSidebar } from './ElementsSidebar';
|
import { ElementsSidebar } from './ElementsSidebar';
|
||||||
import { IContainerModel } from '../../Interfaces/IContainerModel';
|
import { IContainerModel } from '../../Interfaces/IContainerModel';
|
||||||
|
import { XPositionReference } from '../../Enums/XPositionReference';
|
||||||
|
|
||||||
describe.concurrent('Elements sidebar', () => {
|
describe.concurrent('Elements sidebar', () => {
|
||||||
it('With a MainContainer', () => {
|
it('With a MainContainer', () => {
|
||||||
|
@ -17,6 +18,7 @@ describe.concurrent('Elements sidebar', () => {
|
||||||
y: 0,
|
y: 0,
|
||||||
width: 2000,
|
width: 2000,
|
||||||
height: 100,
|
height: 100,
|
||||||
|
XPositionReference: XPositionReference.Left,
|
||||||
isRigidBody: false,
|
isRigidBody: false,
|
||||||
isAnchor: false
|
isAnchor: false
|
||||||
},
|
},
|
||||||
|
@ -49,7 +51,8 @@ describe.concurrent('Elements sidebar', () => {
|
||||||
width: 2000,
|
width: 2000,
|
||||||
height: 100,
|
height: 100,
|
||||||
isRigidBody: false,
|
isRigidBody: false,
|
||||||
isAnchor: false
|
isAnchor: false,
|
||||||
|
XPositionReference: XPositionReference.Left
|
||||||
},
|
},
|
||||||
userData: {}
|
userData: {}
|
||||||
};
|
};
|
||||||
|
@ -105,6 +108,7 @@ describe.concurrent('Elements sidebar', () => {
|
||||||
y: 0,
|
y: 0,
|
||||||
width: 2000,
|
width: 2000,
|
||||||
height: 100,
|
height: 100,
|
||||||
|
XPositionReference: XPositionReference.Left,
|
||||||
isRigidBody: false,
|
isRigidBody: false,
|
||||||
isAnchor: false
|
isAnchor: false
|
||||||
},
|
},
|
||||||
|
@ -123,7 +127,8 @@ describe.concurrent('Elements sidebar', () => {
|
||||||
width: 0,
|
width: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
isRigidBody: false,
|
isRigidBody: false,
|
||||||
isAnchor: false
|
isAnchor: false,
|
||||||
|
XPositionReference: XPositionReference.Left
|
||||||
},
|
},
|
||||||
userData: {}
|
userData: {}
|
||||||
}
|
}
|
||||||
|
@ -140,6 +145,7 @@ describe.concurrent('Elements sidebar', () => {
|
||||||
y: 0,
|
y: 0,
|
||||||
width: 0,
|
width: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
|
XPositionReference: XPositionReference.Left,
|
||||||
isRigidBody: false,
|
isRigidBody: false,
|
||||||
isAnchor: false
|
isAnchor: false
|
||||||
},
|
},
|
||||||
|
@ -178,6 +184,7 @@ describe.concurrent('Elements sidebar', () => {
|
||||||
y: 0,
|
y: 0,
|
||||||
width: 2000,
|
width: 2000,
|
||||||
height: 100,
|
height: 100,
|
||||||
|
XPositionReference: XPositionReference.Left,
|
||||||
isRigidBody: false,
|
isRigidBody: false,
|
||||||
isAnchor: false
|
isAnchor: false
|
||||||
},
|
},
|
||||||
|
@ -194,6 +201,7 @@ describe.concurrent('Elements sidebar', () => {
|
||||||
y: 0,
|
y: 0,
|
||||||
width: 0,
|
width: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
|
XPositionReference: XPositionReference.Left,
|
||||||
isRigidBody: false,
|
isRigidBody: false,
|
||||||
isAnchor: false
|
isAnchor: false
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { XPositionReference } from '../../Enums/XPositionReference';
|
||||||
import IProperties from '../../Interfaces/IProperties';
|
import IProperties from '../../Interfaces/IProperties';
|
||||||
import { InputGroup } from '../InputGroup/InputGroup';
|
import { InputGroup } from '../InputGroup/InputGroup';
|
||||||
|
|
||||||
|
@ -102,15 +103,41 @@ const DynamicForm: React.FunctionComponent<IDynamicFormProps> = (props) => {
|
||||||
checked={props.properties.isAnchor}
|
checked={props.properties.isAnchor}
|
||||||
onChange={(event) => props.onChange('isAnchor', event.target.checked)}
|
onChange={(event) => props.onChange('isAnchor', event.target.checked)}
|
||||||
/>
|
/>
|
||||||
<InputGroup
|
<label>
|
||||||
labelText='Horizontal alignment'
|
Horizontal alignment
|
||||||
inputKey='xPositionReference'
|
</label>
|
||||||
labelClassName=''
|
<div id='XPositionReference'>
|
||||||
inputClassName=''
|
<label>
|
||||||
type='number'
|
<input
|
||||||
checked={props.properties.isRigidBody}
|
type='radio'
|
||||||
onChange={(event) => props.onChange('xPositionReference', event.target.value)}
|
name='XPositionReference'
|
||||||
/>
|
value={XPositionReference.Left}
|
||||||
|
checked={props.properties.XPositionReference === XPositionReference.Left}
|
||||||
|
onChange={(event) => props.onChange('XPositionReference', (event.target as HTMLInputElement).value)}
|
||||||
|
/>
|
||||||
|
Left
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type='radio'
|
||||||
|
name='XPositionReference'
|
||||||
|
value={XPositionReference.Center}
|
||||||
|
checked={props.properties.XPositionReference === XPositionReference.Center}
|
||||||
|
onChange={(event) => props.onChange('XPositionReference', (event.target as HTMLInputElement).value)}
|
||||||
|
/>
|
||||||
|
Center
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type='radio'
|
||||||
|
name='XPositionReference'
|
||||||
|
value={XPositionReference.Right}
|
||||||
|
checked={props.properties.XPositionReference === XPositionReference.Right}
|
||||||
|
onChange={(event) => props.onChange('XPositionReference', (event.target as HTMLInputElement).value)}
|
||||||
|
/>
|
||||||
|
Right
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
{ getCSSInputs(props.properties, props.onChange) }
|
{ getCSSInputs(props.properties, props.onChange) }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { fireEvent, render, screen } from '@testing-library/react';
|
import { fireEvent, render, screen } from '@testing-library/react';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { expect, describe, it, vi } from 'vitest';
|
import { expect, describe, it, vi } from 'vitest';
|
||||||
|
import { XPositionReference } from '../../Enums/XPositionReference';
|
||||||
import IProperties from '../../Interfaces/IProperties';
|
import IProperties from '../../Interfaces/IProperties';
|
||||||
import { Properties } from './Properties';
|
import { Properties } from './Properties';
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ describe.concurrent('Properties', () => {
|
||||||
y: 1,
|
y: 1,
|
||||||
width: 1,
|
width: 1,
|
||||||
height: 1,
|
height: 1,
|
||||||
|
XPositionReference: XPositionReference.Left,
|
||||||
isRigidBody: false,
|
isRigidBody: false,
|
||||||
isAnchor: false
|
isAnchor: false
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,4 +33,4 @@ export const Properties: React.FC<IPropertiesProps> = (props: IPropertiesProps)
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { XPositionReference } from '../../Enums/XPositionReference';
|
||||||
import IProperties from '../../Interfaces/IProperties';
|
import IProperties from '../../Interfaces/IProperties';
|
||||||
import { InputGroup } from '../InputGroup/InputGroup';
|
import { InputGroup } from '../InputGroup/InputGroup';
|
||||||
|
|
||||||
|
@ -96,14 +97,39 @@ const StaticForm: React.FunctionComponent<IStaticFormProps> = (props) => {
|
||||||
type='checkbox'
|
type='checkbox'
|
||||||
defaultChecked={props.properties.isAnchor}
|
defaultChecked={props.properties.isAnchor}
|
||||||
/>
|
/>
|
||||||
<InputGroup
|
<label>
|
||||||
labelText='Horizontal alignment'
|
Horizontal alignment
|
||||||
inputKey='xPositionReference'
|
</label>
|
||||||
labelClassName=''
|
<div id='XPositionReference'>
|
||||||
inputClassName=''
|
<label>
|
||||||
type='number'
|
<input
|
||||||
defaultChecked={props.properties.isRigidBody}
|
type='radio'
|
||||||
/>
|
name='XPositionReference'
|
||||||
|
value={XPositionReference.Left}
|
||||||
|
defaultChecked={props.properties.XPositionReference === XPositionReference.Left}
|
||||||
|
/>
|
||||||
|
Left
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type='radio'
|
||||||
|
name='XPositionReference'
|
||||||
|
value={XPositionReference.Center}
|
||||||
|
defaultChecked={props.properties.XPositionReference === XPositionReference.Center}
|
||||||
|
/>
|
||||||
|
Center
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type='radio'
|
||||||
|
name='XPositionReference'
|
||||||
|
value={XPositionReference.Right}
|
||||||
|
defaultChecked={props.properties.XPositionReference === XPositionReference.Right}
|
||||||
|
/>
|
||||||
|
Right
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
{ getCSSInputs(props.properties) }
|
{ getCSSInputs(props.properties) }
|
||||||
</div>
|
</div>
|
||||||
</form>);
|
</form>);
|
||||||
|
|
|
@ -22,7 +22,7 @@ export const Container: React.FC<IContainerProps> = (props: IContainerProps) =>
|
||||||
props.model.properties.x,
|
props.model.properties.x,
|
||||||
props.model.properties.y,
|
props.model.properties.y,
|
||||||
props.model.properties.width,
|
props.model.properties.width,
|
||||||
props.model.properties.xPositionReference
|
props.model.properties.XPositionReference
|
||||||
);
|
);
|
||||||
const transform = `translate(${transformedX}, ${transformedY})`;
|
const transform = `translate(${transformedX}, ${transformedY})`;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ export const Selector: React.FC<ISelectorProps> = (props) => {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
props.selected.properties.width,
|
props.selected.properties.width,
|
||||||
props.selected.properties.xPositionReference
|
props.selected.properties.XPositionReference
|
||||||
);
|
);
|
||||||
const [width, height] = [
|
const [width, height] = [
|
||||||
props.selected.properties.width,
|
props.selected.properties.width,
|
||||||
|
|
|
@ -19,6 +19,6 @@ export default interface IProperties {
|
||||||
height: number
|
height: number
|
||||||
isRigidBody: boolean
|
isRigidBody: boolean
|
||||||
isAnchor: boolean
|
isAnchor: boolean
|
||||||
xPositionReference?: XPositionReference
|
XPositionReference: XPositionReference
|
||||||
style?: React.CSSProperties
|
style?: React.CSSProperties
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { XPositionReference } from '../Enums/XPositionReference';
|
||||||
import { IConfiguration } from '../Interfaces/IConfiguration';
|
import { IConfiguration } from '../Interfaces/IConfiguration';
|
||||||
import IProperties from '../Interfaces/IProperties';
|
import IProperties from '../Interfaces/IProperties';
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ export const DEFAULT_MAINCONTAINER_PROPS: IProperties = {
|
||||||
height: Number(DEFAULT_CONFIG.MainContainer.Height),
|
height: Number(DEFAULT_CONFIG.MainContainer.Height),
|
||||||
isRigidBody: false,
|
isRigidBody: false,
|
||||||
isAnchor: false,
|
isAnchor: false,
|
||||||
|
XPositionReference: XPositionReference.Left,
|
||||||
style: {
|
style: {
|
||||||
stroke: 'black',
|
stroke: 'black',
|
||||||
fillOpacity: 0
|
fillOpacity: 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue