Skip to content

Commit

Permalink
Add option to modify array type
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhay Garg committed Mar 23, 2023
1 parent 513e04a commit 886e297
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
11 changes: 10 additions & 1 deletion modelina-website/src/components/playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Playground extends React.Component<
tsMarshalling: false,
tsModelType: 'class',
tsEnumType: 'enum',
csharpArrayType: 'Array'
};
hasLoadedQuery: boolean = false;
constructor(props: ModelinaPlaygroundProps) {
Expand Down Expand Up @@ -179,9 +180,15 @@ class Playground extends React.Component<
if (query.tsModelType !== undefined) {
this.config.tsModelType = query.tsModelType as any;
}
if (query.tsEnumType !== undefined) {
this.config.tsEnumType = query.tsEnumType as any;
}
if (query.language !== undefined) {
this.config.language = query.language as any;
}
if (query.csharpArrayType !== undefined) {
this.config.csharpArrayType = query.csharpArrayType as any;
}
if (this.props.router.isReady && !this.hasLoadedQuery) {
this.hasLoadedQuery = true;
this.generateNewCode(this.state.input);
Expand Down Expand Up @@ -279,7 +286,9 @@ class Playground extends React.Component<
}}
>
<PlaygroundJavaScriptConfigContext.Provider value={{}}>
<PlaygroundCSharpConfigContext.Provider value={{}}>
<PlaygroundCSharpConfigContext.Provider value={{
csharpArrayType: this.config.csharpArrayType,
}}>
<PlaygroundDartConfigContext.Provider value={{}}>
<PlaygroundGoConfigContext.Provider value={{}}>
<PlaygroundJavaConfigContext.Provider value={{}}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { PlaygroundCSharpConfigContext } from '@/components/contexts/PlaygroundConfigContext';
import Select from '@/components/Select';

interface CSharpGeneratorOptionsProps {
setNewConfig?: (queryKey: string, queryValue: string) => void;
Expand All @@ -18,6 +19,13 @@ class CSharpGeneratorOptions extends React.Component<
constructor(props: any) {
super(props);
this.state = defaultState;
this.onChangeArrayType = this.onChangeArrayType.bind(this);
}

onChangeArrayType(arrayType: any) {
if (this.props.setNewConfig) {
this.props.setNewConfig('csharpArrayType', String(arrayType));
}
}

render() {
Expand All @@ -26,9 +34,22 @@ class CSharpGeneratorOptions extends React.Component<
<h3 className="text-lg font-medium leading-6 text-gray-900">
CSharp Specific options
</h3>
<span className="mt-1 max-w-2xl text-sm text-gray-500">
Currently no options are available
</span>
<li>
<label className="flex items-center py-2 justify-between cursor-pointer">
<span className="mt-1 max-w-2xl text-sm text-gray-500">
C# array type
</span>
<Select
options={[
{ value: 'List', text: 'List' },
{ value: 'Array', text: 'Array' }
]}
value={this.context?.csharpArrayType}
onChange={this.onChangeArrayType}
className="shadow-outline-blue cursor-pointer"
/>
</label>
</li>
</ul>
);
}
Expand Down
4 changes: 4 additions & 0 deletions modelina-website/src/helpers/GeneratorCode/CSharpGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export function getCSharpGeneratorCode(
const optionString: string[] = [];
const optionStringPresets: string[] = [];

if (generatorOptions.csharpArrayType) {
optionString.push(`arrayType: '${generatorOptions.csharpArrayType}'`);
}

const presetOptions =
optionStringPresets.length > 0
? `${optionString.length > 0 ? ',' : ''}
Expand Down
4 changes: 4 additions & 0 deletions modelina-website/src/pages/api/functions/CSharpGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export async function getCSharpModels(
presets: []
};

if (generatorOptions.csharpArrayType) {
options.collectionType = generatorOptions.csharpArrayType as any;
}

try {
const generator = new CSharpGenerator(options);
const generatedModels = await generator.generateCompleteModels(input, {
Expand Down
8 changes: 6 additions & 2 deletions modelina-website/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export interface ModelinaTypeScriptOptions {
export interface ModelinaJavaOptions {}
export interface ModelinaGoOptions {}
export interface ModelinaJavaScriptOptions {}
export interface ModelinaCSharpOptions {}
export interface ModelinaCSharpOptions {
csharpArrayType: 'List' | 'Array' | undefined;
}
export interface ModelinaKotlinOptions {}
export interface ModelinaRustOptions {}
export interface ModelinaPythonOptions {}
Expand All @@ -41,7 +43,9 @@ export interface ModelinaGeneralQueryOptions {
export interface ModelinaJavaQueryOptions {}
export interface ModelinaGoQueryOptions {}
export interface ModelinaJavaScriptQueryOptions {}
export interface ModelinaCSharpQueryOptions {}
export interface ModelinaCSharpQueryOptions {
csharpArrayType?: string;
}
export interface ModelinaKotlinQueryOptions {}
export interface ModelinaRustQueryOptions {}
export interface ModelinaPythonQueryOptions {}
Expand Down

0 comments on commit 886e297

Please sign in to comment.