diff --git a/lib/src/hal-ui/InputPropertiesList.jsx b/lib/src/hal-ui/InputPropertiesList.jsx index 79dccfb..380591d 100644 --- a/lib/src/hal-ui/InputPropertiesList.jsx +++ b/lib/src/hal-ui/InputPropertiesList.jsx @@ -1,45 +1,115 @@ -import React from "react"; +import React, { Component } from "react"; import styled from "styled-components"; import InputProperty from "./InputProperty.jsx"; +import axios from "axios"; -const InputPropertiesList = ({ properties, disabled, propertyUpdateFunction }) => ( - - {properties.map((property) => ( - - - {property.key} - {property.required ? "*" : ""} - - - - - - ))} - -); +class InputPropertiesList extends Component { + constructor(props) { + super(props); + this.state = { + fetchedOptions: {}, + }; + } + + componentDidMount() { + this.fetchAllOptions(); + } + + fetchAllOptions = async () => { + const { properties } = this.props; + try { + const filteredProperties = properties.filter(property => property.options && property.options.link && property.options.link.href) + const response = await Promise.all(filteredProperties.map((property) => + axios.get(property.options.link.href) + )) + const propertyObject = {} + response.forEach((res, index) => { + propertyObject[filteredProperties[index].key] = Object.values(res.data)[0] + } + ) + this.setState({ fetchedOptions: propertyObject }) + } catch (error) { + console.error(`Error fetching data`); + } + }; + + render() { + const { properties, disabled, propertyUpdateFunction } = this.props; + const { fetchedOptions } = this.state; + return ( + + {properties.map((property) => { + const enumOptions = property.options && fetchedOptions[property.key]? fetchedOptions[property.key] : null; + return ( + + + + {property.key} + {property.required === 'true' ? " * required" : ""} + + + {`${property.type}, `} + {property.format ? property.format : '-'} + + {`min:${property.minLength <= 0 || property.minLength >= 0 ? property.minLength : '-' }, max:${property.maxLength ? property.maxLength : '-'}`} + + + {property.description ? property.description : '-'} + + + + ); + })} + + ); + } +} const PropertiesListStyled = styled.div` display: flex; flex-direction: column; `; +const PropertyWrapper = styled.span` + width: 50%; + display: flex; + flex-direction: column; +`; + +const Text = styled.span` + color: red; + font-size: 13px; +`; + const PropertyLayout = styled.div` display: flex; margin: 5px 0px; `; -const Label = styled.span` - width: 50%; - display: inline-flex; - align-items: center; +const Label = styled.div` + margin-bottom: 1px; +`; + +const Label1 = styled.div` + font-size: 12px; + font-family: monospace; +`; + +const Label2 = styled.span` + font-size: 12px; + font-style: italic; + font-weight: 600; +`; + +const Label3 = styled.span` + font-size: 12px; `; const InputPropertyLayout = styled.div` diff --git a/lib/src/hal-ui/InputProperty.jsx b/lib/src/hal-ui/InputProperty.jsx index 2db79fe..c8acaef 100644 --- a/lib/src/hal-ui/InputProperty.jsx +++ b/lib/src/hal-ui/InputProperty.jsx @@ -21,17 +21,16 @@ export default class InputProperty extends Component { handleChangeEnum(event) { const { propertyUpdateFunction, name, enumOptions } = this.props; - propertyUpdateFunction(name, enumOptions[event.target.value]); + propertyUpdateFunction(name, event.target.value); } render() { const { disabled, type, enumOptions } = this.props; - return enumOptions ? ( - {enumOptions.map((option, i) => ( - {option.toString()} + {enumOptions && enumOptions.map((option, i) => ( + {option.label} ))} ) : type === "number" ? (