This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(container): render list of properties with correct type elements
- Loading branch information
Lasse Küchler
committed
Dec 11, 2017
1 parent
c738430
commit 52eb838
Showing
2 changed files
with
120 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { EnumProperty } from '../../store/pattern/property/enum_property'; | ||
import { Property } from '../../store/pattern/property/index'; | ||
import { BooleanItem } from '../../lsg/patterns/property-items/boolean-item/index'; | ||
import { StringItem } from '../../lsg/patterns/property-items/string-item/index'; | ||
import { EnumItem } from '../../lsg/patterns/property-items/enum-item/index'; | ||
import { observer } from 'mobx-react'; | ||
import * as React from 'react'; | ||
import { Store } from '../../store'; | ||
|
||
export interface PropertyListProps { | ||
store: Store; | ||
} | ||
|
||
@observer | ||
export class PropertyList extends React.Component<PropertyListProps> { | ||
public constructor(props: PropertyListProps) { | ||
super(props); | ||
} | ||
|
||
public render(): JSX.Element { | ||
const selectedElement = this.props.store.getSelectedElement(); | ||
|
||
if (!selectedElement) { | ||
return <div>No Element selected</div>; | ||
} | ||
|
||
const pattern = selectedElement.getPattern(); | ||
|
||
const properties: Property[] | undefined = pattern && pattern.getProperties(); | ||
|
||
if (!properties) { | ||
return <div>This element has no properties</div>; | ||
} | ||
|
||
return ( | ||
<div> | ||
{properties.map(property => { | ||
const id = property.getId(); | ||
const name = property.getName(); | ||
const type = property.getType(); | ||
const value = selectedElement.getPropertyValue(id); | ||
|
||
switch (type) { | ||
case 'boolean': | ||
return ( | ||
<BooleanItem | ||
key={id} | ||
label={name} | ||
checked={value as boolean} | ||
handleChange={event => { | ||
selectedElement.setPropertyValue(id, !value); | ||
}} | ||
/> | ||
); | ||
case 'string': | ||
return ( | ||
<StringItem | ||
key={id} | ||
label={name} | ||
value={value as string} | ||
handleChange={event => { | ||
selectedElement.setPropertyValue(id, event.currentTarget.value); | ||
}} | ||
/> | ||
); | ||
case 'enum': | ||
const options = (property as EnumProperty) | ||
.getOptions() | ||
.map(option => option.getName()); | ||
|
||
return ( | ||
<EnumItem | ||
key={id} | ||
label={name} | ||
selectedValue={value as string} | ||
values={options} | ||
handleChange={event => { | ||
selectedElement.setPropertyValue(id, event.currentTarget.value); | ||
}} | ||
/> | ||
); | ||
default: | ||
return <div>Unknown type: {type}</div>; | ||
} | ||
})} | ||
</div> | ||
); | ||
} | ||
} |