-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add some generators under the "person" directory
- Loading branch information
1 parent
dc43e69
commit 68fcc79
Showing
17 changed files
with
379 additions
and
25 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
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,19 @@ | ||
import {SelectOption} from "@/components/Utils"; | ||
import {FormattedMessage} from "@/locale"; | ||
import {Sex} from "@/constants/enums"; | ||
import React from "react"; | ||
|
||
export const SexSelectOptions: SelectOption[] = [ | ||
{ | ||
label: <FormattedMessage id={"dataType.fullName.sex.selectOptions.all"}/>, | ||
value: Sex.ALL | ||
}, | ||
{ | ||
label: <FormattedMessage id={"dataType.fullName.sex.selectOptions.male"}/>, | ||
value: Sex.MALE, | ||
}, | ||
{ | ||
label: <FormattedMessage id={"dataType.fullName.sex.selectOptions.female"}/>, | ||
value: Sex.FEMALE | ||
} | ||
] |
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,58 @@ | ||
import React from "react"; | ||
import {GenerateResult, GeneratorOptionsComponentInterface} from "@/types/generator"; | ||
import {ExportValueType, Sex} from "@/constants/enums"; | ||
import {faker} from "@faker-js/faker"; | ||
import {FormattedMessage} from "@/locale"; | ||
import {OptionsSelect} from "@/components/Utils"; | ||
import {SexSelectOptions} from "@/core/common/selectOptions/SexSelectOptions"; | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// types | ||
export interface FirstNameGeneratorOptions { | ||
sex: Sex; | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// default options | ||
export const FirstNameGeneratorDefaultOptions:FirstNameGeneratorOptions = { | ||
sex: Sex.ALL | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// generate method | ||
export const generate = (options: any): GenerateResult => { | ||
let config = null; | ||
if(options.sex !== Sex.ALL ){ | ||
config = options.sex; | ||
} | ||
|
||
const value = faker.person.firstName(config); | ||
|
||
return { | ||
value: value, | ||
stringValue: value, | ||
type: ExportValueType.STRING | ||
}; | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// options component | ||
export const FirstNameGeneratorOptionsComponent: React.FunctionComponent<GeneratorOptionsComponentInterface> = ({...props}) => { | ||
const {options, onOptionsChange} = props; | ||
|
||
const handleOptionsChange = (changedFieldName: string, value: any) => { | ||
let newOptions = {...options, [changedFieldName]: value}; | ||
onOptionsChange(newOptions); | ||
}; | ||
|
||
return ( | ||
<> | ||
<OptionsSelect | ||
label={<FormattedMessage id={"dataType.fullName.sex.label"}/>} | ||
selectOptions={SexSelectOptions} | ||
value={options.sex} | ||
style={{width: '150px'}} | ||
onChange={(v) => handleOptionsChange("sex", v)}/> | ||
</> | ||
); | ||
} |
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,13 @@ | ||
import {Generator} from "@/types/generator"; | ||
import {DataType, DataTypeCategory} from "@/constants/enums"; | ||
import {FirstNameGeneratorDefaultOptions, FirstNameGeneratorOptionsComponent, generate} from "./FirstName"; | ||
|
||
export const FirstNameGenerator: Generator = { | ||
type: DataType.FIRSTNAME, | ||
category: DataTypeCategory.PERSON, | ||
generate: generate, | ||
optionsComponent: FirstNameGeneratorOptionsComponent, | ||
defaultOptions: FirstNameGeneratorDefaultOptions, | ||
exampleLines: ["Javier", "Luis", "Tom"] | ||
} | ||
|
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,58 @@ | ||
import React from "react"; | ||
import {GenerateResult, GeneratorOptionsComponentInterface} from "@/types/generator"; | ||
import {ExportValueType, Sex} from "@/constants/enums"; | ||
import {faker} from "@faker-js/faker"; | ||
import {OptionsSelect} from "@/components/Utils"; | ||
import {FormattedMessage} from "@/locale"; | ||
import {SexSelectOptions} from "@/core/common/selectOptions/SexSelectOptions"; | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// types | ||
export interface LastNameGeneratorOptions { | ||
sex: Sex; | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// default options | ||
export const LastNameGeneratorDefaultOptions:LastNameGeneratorOptions = { | ||
sex: Sex.ALL | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// generate method | ||
export const generate = (options: any): GenerateResult => { | ||
let config = null; | ||
if(options.sex !== Sex.ALL ){ | ||
config = options.sex; | ||
} | ||
|
||
const value = faker.person.lastName(config); | ||
|
||
return { | ||
value: value, | ||
stringValue: value, | ||
type: ExportValueType.STRING | ||
}; | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// options component | ||
export const LastNameGeneratorOptionsComponent: React.FunctionComponent<GeneratorOptionsComponentInterface> = ({...props}) => { | ||
const {options, onOptionsChange} = props; | ||
|
||
const handleOptionsChange = (changedFieldName: string, value: any) => { | ||
let newOptions = {...options, [changedFieldName]: value}; | ||
onOptionsChange(newOptions); | ||
} | ||
|
||
return ( | ||
<> | ||
<OptionsSelect | ||
label={<FormattedMessage id={"dataType.fullName.sex.label"}/>} | ||
selectOptions={SexSelectOptions} | ||
value={options.sex} | ||
style={{width: '150px'}} | ||
onChange={(v) => handleOptionsChange("sex", v)}/> | ||
</> | ||
); | ||
} |
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,13 @@ | ||
import {Generator} from "@/types/generator"; | ||
import {DataType, DataTypeCategory} from "@/constants/enums"; | ||
import {LastNameGeneratorDefaultOptions, LastNameGeneratorOptionsComponent, generate} from "./LastName"; | ||
|
||
export const LastNameGenerator: Generator = { | ||
type: DataType.LASTNAME, | ||
category: DataTypeCategory.PERSON, | ||
generate: generate, | ||
optionsComponent: LastNameGeneratorOptionsComponent, | ||
defaultOptions: LastNameGeneratorDefaultOptions, | ||
exampleLines: ["Hegmann", "Parker", "Wang"] | ||
} | ||
|
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,58 @@ | ||
import React from "react"; | ||
import {GenerateResult, GeneratorOptionsComponentInterface} from "@/types/generator"; | ||
import {ExportValueType, Sex} from "@/constants/enums"; | ||
import {faker} from "@faker-js/faker"; | ||
import {OptionsSelect} from "@/components/Utils"; | ||
import {FormattedMessage} from "@/locale"; | ||
import {SexSelectOptions} from "@/core/common/selectOptions/SexSelectOptions"; | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// types | ||
export interface MiddleNameGeneratorOptions { | ||
sex: Sex; | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// default options | ||
export const MiddleNameGeneratorDefaultOptions:MiddleNameGeneratorOptions = { | ||
sex: Sex.ALL | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// generate method | ||
export const generate = (options: any): GenerateResult => { | ||
let config = null; | ||
if(options.sex !== Sex.ALL ){ | ||
config = options.sex; | ||
} | ||
|
||
const value = faker.person.middleName(config); | ||
|
||
return { | ||
value: value, | ||
stringValue: value, | ||
type: ExportValueType.STRING | ||
}; | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// options component | ||
export const MiddleNameGeneratorOptionsComponent: React.FunctionComponent<GeneratorOptionsComponentInterface> = ({...props}) => { | ||
const {options, onOptionsChange} = props; | ||
|
||
const handleOptionsChange = (changedFieldName: string, value: any) => { | ||
let newOptions = {...options, [changedFieldName]: value}; | ||
onOptionsChange(newOptions); | ||
}; | ||
|
||
return ( | ||
<> | ||
<OptionsSelect | ||
label={<FormattedMessage id={"dataType.fullName.sex.label"}/>} | ||
selectOptions={SexSelectOptions} | ||
value={options.sex} | ||
style={{width: '150px'}} | ||
onChange={(v) => handleOptionsChange("sex", v)}/> | ||
</> | ||
); | ||
} |
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,13 @@ | ||
import {Generator} from "@/types/generator"; | ||
import {DataType, DataTypeCategory} from "@/constants/enums"; | ||
import {MiddleNameGeneratorDefaultOptions, MiddleNameGeneratorOptionsComponent, generate} from "./MiddleName"; | ||
|
||
export const MiddleNameGenerator: Generator = { | ||
type: DataType.MIDDLENAME, | ||
category: DataTypeCategory.PERSON, | ||
generate: generate, | ||
optionsComponent: MiddleNameGeneratorOptionsComponent, | ||
defaultOptions: MiddleNameGeneratorDefaultOptions, | ||
exampleLines: ["Elliott", "Taylor", "Bailey"] | ||
} | ||
|
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,59 @@ | ||
import React from "react"; | ||
import {GenerateResult, GeneratorOptionsComponentInterface} from "@/types/generator"; | ||
import {ExportValueType, Sex} from "@/constants/enums"; | ||
import {faker} from "@faker-js/faker"; | ||
import {OptionsSelect} from "@/components/Utils"; | ||
import {FormattedMessage} from "@/locale"; | ||
import {SexSelectOptions} from "@/core/common/selectOptions/SexSelectOptions"; | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// types | ||
export interface PersonTitleGeneratorOptions { | ||
sex: Sex; | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// default options | ||
export const PersonTitleGeneratorDefaultOptions:PersonTitleGeneratorOptions = { | ||
sex: Sex.ALL | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// generate method | ||
export const generate = (options: any): GenerateResult => { | ||
let config = null; | ||
if(options.sex !== Sex.ALL ){ | ||
config = options.sex; | ||
} | ||
|
||
const value = faker.person.prefix(config); | ||
|
||
return { | ||
value: value, | ||
stringValue: value, | ||
type: ExportValueType.STRING | ||
}; | ||
} | ||
|
||
// ------------------------------------------------------------------------------------------------------------- | ||
// options component | ||
export const PersonTitleGeneratorOptionsComponent: React.FunctionComponent<GeneratorOptionsComponentInterface> = ({...props}) => { | ||
const {options, onOptionsChange} = props; | ||
|
||
const handleOptionsChange = (changedFieldName: string, value: any) => { | ||
let newOptions = {...options, [changedFieldName]: value}; | ||
onOptionsChange(newOptions); | ||
}; | ||
|
||
// TODO: implement your own options component here | ||
return ( | ||
<> | ||
<OptionsSelect | ||
label={<FormattedMessage id={"dataType.fullName.sex.label"}/>} | ||
selectOptions={SexSelectOptions} | ||
value={options.sex} | ||
style={{width: '150px'}} | ||
onChange={(v) => handleOptionsChange("sex", v)}/> | ||
</> | ||
); | ||
} |
Oops, something went wrong.