Skip to content

Ticket #IBPLIFE-36500 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 98 additions & 28 deletions lib/src/hal-ui/InputPropertiesList.jsx
Original file line number Diff line number Diff line change
@@ -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 }) => (
<PropertiesListStyled>
{properties.map((property) => (
<PropertyLayout>
<Label>
{property.key}
{property.required ? "*" : ""}
</Label>
<InputPropertyLayout>
<InputProperty
disabled={disabled}
name={property.key}
type={property.metadata.type}
format={property.metadata.format}
enumOptions={property.metadata.enum}
required={property.required}
propertyUpdateFunction={propertyUpdateFunction}
/>
</InputPropertyLayout>
</PropertyLayout>
))}
</PropertiesListStyled>
);
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 (
<PropertiesListStyled>
{properties.map((property) => {
const enumOptions = property.options && fetchedOptions[property.key]? fetchedOptions[property.key] : null;
return (
<PropertyLayout key={property.key}>
<PropertyWrapper>
<Label>
{property.key}
<Text>{property.required === 'true' ? " * required" : ""}</Text>
</Label>
<div className="inline-labels">
<Label2 className="label-italic">{`${property.type}, `}</Label2>
<Label3>{property.format ? property.format : '-'}</Label3>
</div>
<Label1>{`min:${property.minLength <= 0 || property.minLength >= 0 ? property.minLength : '-' }, max:${property.maxLength ? property.maxLength : '-'}`}</Label1>
</PropertyWrapper>
<InputPropertyLayout>
<Label>{property.description ? property.description : '-'}</Label>
<InputProperty
disabled={disabled}
name={property.key}
type={property.type}
required={property.required}
propertyUpdateFunction={propertyUpdateFunction}
enumOptions={enumOptions}
/>
</InputPropertyLayout>
</PropertyLayout>
);
})}
</PropertiesListStyled>
);
}
}

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`
Expand Down
7 changes: 3 additions & 4 deletions lib/src/hal-ui/InputProperty.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? (
<SelectStyled disabled={disabled} onChange={this.handleChangeEnum}>
<option value="" />
{enumOptions.map((option, i) => (
<option value={i}>{option.toString()}</option>
{enumOptions && enumOptions.map((option, i) => (
<option value={option.value}>{option.label}</option>
))}
</SelectStyled>
) : type === "number" ? (
Expand Down