diff --git a/modelina-website/src/components/contexts/PlaygroundConfigContext.ts b/modelina-website/src/components/contexts/PlaygroundConfigContext.ts index 84e15a4b40..245e262d9e 100644 --- a/modelina-website/src/components/contexts/PlaygroundConfigContext.ts +++ b/modelina-website/src/components/contexts/PlaygroundConfigContext.ts @@ -10,6 +10,7 @@ import { ModelinaPhpOptions, ModelinaPythonOptions, ModelinaRustOptions, + ModelinaScalaOptions, ModelinaTypeScriptOptions } from '@/types'; import { createContext } from 'react'; @@ -24,6 +25,8 @@ export const PlaygroundGoConfigContext = createContext(null); export const PlaygroundRustConfigContext = createContext(null); +export const PlaygroundScalaConfigContext = + createContext(null); export const PlaygroundKotlinConfigContext = createContext(null); export const PlaygroundDartConfigContext = diff --git a/modelina-website/src/components/contexts/PlaygroundContext.tsx b/modelina-website/src/components/contexts/PlaygroundContext.tsx index c513634783..9ed959ec20 100644 --- a/modelina-website/src/components/contexts/PlaygroundContext.tsx +++ b/modelina-website/src/components/contexts/PlaygroundContext.tsx @@ -88,6 +88,8 @@ export const PlaygroundContextProvider: React.FC<{ children: React.ReactNode; }> javaOverwriteToString: false, javaJavaDocs: false, javaJavaxAnnotation: false, + scalaCollectionType: 'Array', + scalaPackageName: 'asyncapi.models', goPackageName: 'asyncapi.models', kotlinPackageName: 'asyncapi.models' }; diff --git a/modelina-website/src/components/playground/OptionsNavigation.tsx b/modelina-website/src/components/playground/OptionsNavigation.tsx index e5bcaef587..899c7d0d54 100644 --- a/modelina-website/src/components/playground/OptionsNavigation.tsx +++ b/modelina-website/src/components/playground/OptionsNavigation.tsx @@ -8,6 +8,7 @@ import { PlaygroundJavaScriptConfigContext, PlaygroundKotlinConfigContext, PlaygroundPythonConfigContext, + PlaygroundScalaConfigContext, PlaygroundRustConfigContext, PlaygroundCplusplusConfigContext, PlaygroundGeneralConfigContext, @@ -35,9 +36,11 @@ export const OptionsNavigation: React.FunctionComponent - - - + + + + + diff --git a/modelina-website/src/components/playground/Playground.tsx b/modelina-website/src/components/playground/Playground.tsx index 7efb15fc00..fae6a49957 100644 --- a/modelina-website/src/components/playground/Playground.tsx +++ b/modelina-website/src/components/playground/Playground.tsx @@ -12,6 +12,7 @@ import { getJavaGeneratorCode } from '@/helpers/GeneratorCode/JavaGenerator'; import { getGoGeneratorCode } from '@/helpers/GeneratorCode/GoGenerator'; import { getCSharpGeneratorCode } from '@/helpers/GeneratorCode/CSharpGenerator'; import { getRustGeneratorCode } from '@/helpers/GeneratorCode/RustGenerator'; +import { getScalaGeneratorCode } from '@/helpers/GeneratorCode/ScalaGenerator'; import { getPythonGeneratorCode } from '@/helpers/GeneratorCode/PythonGenerator'; import { getDartGeneratorCode } from '@/helpers/GeneratorCode/DartGenerator'; import { getCplusplusGeneratorCode } from '@/helpers/GeneratorCode/CplusplusGenerator'; @@ -165,6 +166,18 @@ const Playground: React.FC = (props) => { if (query.kotlinPackageName !== undefined) { setConfig({ ...config, kotlinPackageName: query.kotlinPackageName }); } + if (query.scalaCollectionType !== undefined) { + setConfig({ + ...config, + scalaCollectionType: query.scalaCollectionType as any + }); + } + if (query.scalaPackageName !== undefined) { + setConfig({ + ...config, + scalaPackageName: query.scalaPackageName as any + }); + } if (props.router.isReady && !hasLoadedQuery) { setHasLoadedQuery(true); @@ -222,6 +235,7 @@ const Playground: React.FC = (props) => { go: getGoGeneratorCode, csharp: getCSharpGeneratorCode, rust: getRustGeneratorCode, + scala: getScalaGeneratorCode, python: getPythonGeneratorCode, dart: getDartGeneratorCode, cplusplus: getCplusplusGeneratorCode, diff --git a/modelina-website/src/components/playground/PlaygroundOptions.tsx b/modelina-website/src/components/playground/PlaygroundOptions.tsx index 804d218bb8..74bbee1130 100644 --- a/modelina-website/src/components/playground/PlaygroundOptions.tsx +++ b/modelina-website/src/components/playground/PlaygroundOptions.tsx @@ -9,6 +9,7 @@ import GoGeneratorOptions from './options/GoGeneratorOptions'; import JavaGeneratorOptions from './options/JavaGeneratorOptions'; import KotlinGeneratorOptions from './options/KotlinGeneratorOptions'; import RustGeneratorOptions from './options/RustGeneratorOptions'; +import ScalaGeneratorOptions from './options/ScalaGeneratorOptions'; import PythonGeneratorOptions from './options/PythonGeneratorOptions'; import CplusplusGeneratorOptions from './options/CplusplusGeneratorOptions'; import PhpGeneratorOptions from './options/PhpGeneratorOptions'; @@ -50,6 +51,9 @@ const PlaygroundOptions: React.FC = ({ setNewConfig }) = case 'rust': setGeneratorOptions(); break; + case 'scala': + setGeneratorOptions(); + break; case 'python': setGeneratorOptions(); break; diff --git a/modelina-website/src/components/playground/options/ScalaGeneratorOptions.tsx b/modelina-website/src/components/playground/options/ScalaGeneratorOptions.tsx new file mode 100644 index 0000000000..e5a95c78f5 --- /dev/null +++ b/modelina-website/src/components/playground/options/ScalaGeneratorOptions.tsx @@ -0,0 +1,104 @@ +import React, { useCallback, useContext, useEffect, useState } from 'react'; +import Select from '@/components/Select'; +import { PlaygroundScalaConfigContext } from '@/components/contexts/PlaygroundConfigContext'; +import InfoModal from '@/components/InfoModal'; +import { debounce } from 'lodash'; + +interface ScalaGeneratorOptionsProps { + setNewConfig?: ( + queryKey: string, + queryValue: any, + updateCode?: boolean + ) => void; +} + +interface ScalaGeneratorState { + packageName?: string; +} + +export const defaultState: ScalaGeneratorState = {}; + +const ScalaGeneratorOptions: React.FC = ({ + setNewConfig +}) => { + const context = useContext(PlaygroundScalaConfigContext); + const [state, setState] = useState(defaultState); + + useEffect(() => { + setState({ ...state, packageName: context?.scalaPackageName }); + }, [context?.scalaPackageName]); + + const debouncedSetNewConfig = debounce( + (queryKey: string, queryValue: any) => setNewConfig?.(queryKey, queryValue), + 500 + ); + + const onChangeCollectionType = (collectionType: string) => { + setNewConfig && setNewConfig('scalaCollectionType', collectionType); + }; + + const onChangePackageName = useCallback( + (event: React.ChangeEvent) => { + const packageName = event.target.value; + setState({ ...state, packageName }); + setNewConfig && debouncedSetNewConfig('scalaPackageName', packageName); + }, + [setNewConfig, debouncedSetNewConfig, state] + ); + + return ( +
    +

    + Scala Specific options +

    +
  • + +

    + In Scala, a package name is a way to organize and group related + classes, objects, and traits together. It is a naming convention + that helps prevent naming conflicts and provides a hierarchical + structure to the Scala codebase. +

    +
    + +
  • +
  • + +

    + It indicates the collection type. Its value can be either List or + Array. +

    + The default value is Array. +

    +
    +