Skip to content

Commit

Permalink
Merge pull request #180 from ZACHSTRIVES/dev
Browse files Browse the repository at this point in the history
feat: add new generators
  • Loading branch information
ZACHSTRIVES authored Aug 18, 2023
2 parents cc547ae + 68fcc79 commit 69fae02
Show file tree
Hide file tree
Showing 20 changed files with 445 additions and 28 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"react-redux": "^8.0.5",
"react-reflex": "^4.1.0",
"redux-persist": "^6.0.0",
"sass": "^1.63.4",
"sass": "^1.65.1",
"tailwindcss": "^3.3.2",
"tsx": "^3.12.7",
"uuidjs": "^5.0.1"
Expand Down
12 changes: 9 additions & 3 deletions scripts/addNewGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const checkIfGeneratorExists = (generatorName: string): boolean => {

const formatFolderName = (folderName: string): string => {
const firstLetter = folderName.charAt(0).toUpperCase();
const restLetters = folderName.slice(1).toLowerCase();
const restLetters = folderName.slice(1);
return `${firstLetter}${restLetters}`;
};

Expand Down Expand Up @@ -114,19 +114,25 @@ export const generate = (options: any): GenerateResult => {
value: 'NOT IMPLEMENTED',
stringValue: 'NOT IMPLEMENTED',
type: ExportValueType.STRING
}
};
}
// -------------------------------------------------------------------------------------------------------------
// options component
export const ${generatorName}GeneratorOptionsComponent: 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 (
<div>
NOT IMPLEMENTED
</div>
)
);
}`;
}

Expand Down
7 changes: 5 additions & 2 deletions src/constants/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ export enum DataTypeCategory {
}

export enum DataType {
PERSONTITLE = "persontitle",
MIDDLENAME = "middlename",
LASTNAME = "lastname",
FIRSTNAME = "firstname",
SEX = "sex",
NUMBER = "number",
EMAIL = "email",
// DATE_TIME = "dateTime",
// ACCOUNT_NUMBER = "accountNumber",
BOOLEAN = "boolean",
FULL_NAME = "fullName",
COMPANY_NAME = "companyName",
Expand Down
19 changes: 19 additions & 0 deletions src/core/common/selectOptions/SexSelectOptions.tsx
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
}
]
58 changes: 58 additions & 0 deletions src/core/generators/FirstName/FirstName.tsx
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)}/>
</>
);
}
13 changes: 13 additions & 0 deletions src/core/generators/FirstName/index.ts
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"]
}

20 changes: 3 additions & 17 deletions src/core/generators/FullName/FullName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {FormattedMessage} from "@/locale";
import {ExportValueType, Sex} from "@/constants/enums";
import {faker} from "@faker-js/faker";
import {isNullOrWhiteSpace} from "@/utils/stringUtils";
import {SexSelectOptions} from "@/core/common/selectOptions/SexSelectOptions";


// -------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -63,7 +64,7 @@ export const FullNameGeneratorOptionsComponent: React.FunctionComponent<Generato
<>
<OptionsSelect
label={<FormattedMessage id={"dataType.fullName.sex.label"}/>}
selectOptions={sexSelectOptions}
selectOptions={SexSelectOptions}
value={fullNameOptions.sex}
style={{width: '150px'}}
onChange={(v) => handleOptionsChange("sex", v)}/>
Expand All @@ -83,19 +84,4 @@ export const FullNameGeneratorOptionsComponent: React.FunctionComponent<Generato
/>
</>
)
};

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
}
]
};
58 changes: 58 additions & 0 deletions src/core/generators/LastName/LastName.tsx
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)}/>
</>
);
}
13 changes: 13 additions & 0 deletions src/core/generators/LastName/index.ts
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"]
}

58 changes: 58 additions & 0 deletions src/core/generators/MiddleName/MiddleName.tsx
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)}/>
</>
);
}
13 changes: 13 additions & 0 deletions src/core/generators/MiddleName/index.ts
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"]
}

Loading

1 comment on commit 69fae02

@vercel
Copy link

@vercel vercel bot commented on 69fae02 Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.