-
Notifications
You must be signed in to change notification settings - Fork 30
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
Feature/normalizr/add country entity and students that belongs to contry #36
base: feature/normalizer_implementation
Are you sure you want to change the base?
Changes from 12 commits
ee76103
78527b1
79abc3c
ae14bf5
67033b5
acd0450
257bf67
7a8e2cc
1337a88
99a4007
4e45c7a
673f885
d74d20c
a0ba826
fa7e81a
1cfac97
2d884fc
0a1368a
9aff8ee
47952c6
4f86276
9a1be3b
10249d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as React from "react"; | ||
import {ValidationFieldComponent} from './validationFieldComponent'; | ||
|
||
interface Props { | ||
name: string; | ||
label: string; | ||
onChange: any; | ||
onBlur?: any; | ||
value: any; | ||
error?: string; | ||
option: any; | ||
} | ||
|
||
export const Select = (props: Props) => { | ||
|
||
return ( | ||
<ValidationFieldComponent | ||
name={props.name} label={props.label} error={props.error}> | ||
<select | ||
name={props.name} | ||
className="form-control" | ||
value={props.value} | ||
onChange={props.onChange} | ||
onBlur={props.onBlur} > | ||
{props.option} | ||
</select> | ||
</ValidationFieldComponent> | ||
|
||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {Input} from './Input'; | ||
import {Select} from './Select'; | ||
|
||
export { | ||
Input, | ||
Select | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as React from "react"; | ||
|
||
interface Props { | ||
name: string; | ||
label: string; | ||
error?: string; | ||
} | ||
|
||
export class ValidationFieldComponent extends React.Component<Props, {}> { | ||
constructor(props: Props) { | ||
super(props); | ||
} | ||
|
||
public render() { | ||
let wrapperClass: string = "form-group"; | ||
if (this.props.error && this.props.error.length > 0) { | ||
wrapperClass += " " + "has-error"; | ||
} | ||
return ( | ||
<div className={wrapperClass}> | ||
<label htmlFor={this.props.name}> | ||
{this.props.label} | ||
</label> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This label should not be included in this component |
||
<div className="field"> | ||
{this.props.children} | ||
|
||
<div className="help-block"> | ||
{this.props.error} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { FieldValidationResult } from "lc-form-validation"; | ||
import { validationsEnums } from "../validationsEnums"; | ||
|
||
export const requiredIdValidationHandler = (vm: any, value: {id: number}): FieldValidationResult => { | ||
const isFieldInformed: boolean = (value != null && value.id && value.id > 0); | ||
const errorInfo: string = (isFieldInformed) ? "" : validationsEnums.REQUIRED.FIELD.MESSAGE; | ||
|
||
const fieldValidationResult: FieldValidationResult = new FieldValidationResult(); | ||
fieldValidationResult.type = validationsEnums.REQUIRED.FIELD.TYPE; | ||
fieldValidationResult.succeeded = isFieldInformed; | ||
fieldValidationResult.errorMessage = errorInfo; | ||
|
||
return fieldValidationResult; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class Country { | ||
id: number; | ||
name: string; | ||
|
||
constructor() { | ||
this.id = -1; | ||
this.name = ""; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,14 @@ export class Student { | |
gotActiveTraining: boolean; | ||
fullname: string; | ||
email: string; | ||
countryId: number; | ||
|
||
public constructor() { | ||
this.id = -1; | ||
this.gotActiveTraining = false; | ||
this.fullname = ""; | ||
this.email = ""; | ||
this.countryId = -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think null can be a good value, on the other hand is it a good idea to define this as a class or should it be an interface? Should we add a factory to initialize a new instance? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we are using this value because Uncontrolled input warning (If you initialize input value to null, it means that is uncontrolled component) But I think that this initialization has to be component liability and it doesn't delegate to class constructor used in reducer default value state. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, if it's a component problem, let the component to deal with it. |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Country } from '../api/country'; | ||
import { CountryView } from '../view/countryView'; | ||
|
||
class CountryMapper { | ||
mapCountryToCountryView(country: Country): CountryView { | ||
return { | ||
id: country.id, | ||
name: country.name | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need a new object? Is not just an interface? In TS, any Country is a CountryView because of structural typing, so just use the original object, even when it has extra props, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, we can return original object and in the future, map additional props or some format |
||
} | ||
|
||
mapCountryListToCountryViewList(countrys: Country[]): CountryView[] { | ||
return countrys.map((country) => { | ||
return this.mapCountryToCountryView(country) | ||
}); | ||
} | ||
} | ||
|
||
export const countryMapper = new CountryMapper(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,11 @@ class StudentMapper { | |
id: student.id, | ||
gotActiveTraining: student.gotActiveTraining, | ||
fullname: student.fullname, | ||
email: student.email | ||
email: student.email, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make trailing comma a convention to avoid this in PRs. It can be set up in TSLint. |
||
country: { | ||
id: student.countryId, | ||
name: '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems wrong (before looking more code). |
||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class CountryView { | ||
id: number; | ||
name: string; | ||
|
||
constructor() { | ||
this.id = -1; | ||
this.name = ""; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import { CountryView } from './countryView'; | ||
|
||
export class StudentView { | ||
id: number; | ||
gotActiveTraining: boolean; | ||
fullname: string; | ||
email: string; | ||
country: CountryView; | ||
|
||
public constructor() { | ||
this.id = -1; | ||
this.gotActiveTraining = false; | ||
this.fullname = ""; | ||
this.email = ""; | ||
this.country = new CountryView(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also seems wrong. Either leave country undefined, or use a CountryView.Empty like with the Null Object pattern. Otherwise it seems you're creating a brand new country for each student. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, or we could assign a default country entry. Thinking now about pros adding a factory to create then StudentView |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this action is covered by a thunk function