Skip to content
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

chore(website): create new playground layout #1628

Merged
merged 33 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ce2bc21
Initialised new playground file from old playground
devilkiller-ag Nov 22, 2023
83a2b66
created tooltip component for sidebar
devilkiller-ag Nov 22, 2023
0b17766
added basic navigation layout
devilkiller-ag Nov 22, 2023
2b3f6ca
added code for splitpane
devilkiller-ag Nov 25, 2023
09c4e99
added basic editor-output-explorer layout
devilkiller-ag Nov 25, 2023
d324177
added context and functionality for opening and closing of options an…
devilkiller-ag Nov 26, 2023
764ee1a
Merge branch 'master' into ag_dev
devilkiller-ag Nov 28, 2023
6f64b35
removed split-pane and created mobile responsive layout
devilkiller-ag Nov 30, 2023
8e9e8b3
added basic output file navigation layout
devilkiller-ag Dec 3, 2023
8162175
converted Playground Code from React Class to React Functional Component
devilkiller-ag Dec 3, 2023
9f7d6e8
created playground context and integrated it with playground and content
devilkiller-ag Dec 4, 2023
7d927bf
added all options
devilkiller-ag Dec 4, 2023
f584a84
rectified sidebar css and overall pading
devilkiller-ag Dec 4, 2023
1717d1f
rectified InfoModal paddings
devilkiller-ag Dec 4, 2023
2be3393
converted GeneratedModels.tsx to Functional Component from React Class
devilkiller-ag Dec 4, 2023
2c91a76
added generated models to output navigation
devilkiller-ag Dec 4, 2023
6ae7826
added show generator code functionality
devilkiller-ag Dec 4, 2023
c8e44c4
performed code cleanups
devilkiller-ag Dec 4, 2023
d2aaab0
performed code cleanups
devilkiller-ag Dec 4, 2023
b32d680
removed code smells suggested by sonarcloud
devilkiller-ag Dec 4, 2023
6d9b388
Merge branch 'master' into ag_dev
devilkiller-ag Dec 4, 2023
18ba05d
re-structured playground layout
devilkiller-ag Dec 7, 2023
a250001
rectified option bugs
devilkiller-ag Dec 7, 2023
d9595c1
rectified info-modal bug
devilkiller-ag Dec 7, 2023
9157fbf
Merge branch 'master' into ag_dev
devilkiller-ag Dec 8, 2023
2e2219b
rectified bug: option change was not visible
devilkiller-ag Dec 8, 2023
e5185b1
removed sonarcloud code smells
devilkiller-ag Dec 8, 2023
6562394
Added Seprate Display for mobile visitors to playground
devilkiller-ag Dec 9, 2023
8b51fb0
removed bugs
devilkiller-ag Dec 9, 2023
64e44b6
rectified design bugs
devilkiller-ag Dec 10, 2023
fd9af32
rectified design bugs
devilkiller-ag Dec 10, 2023
ee85954
resolved ui bugs
devilkiller-ag Dec 11, 2023
c865c37
Merge branch 'master' into ag_dev
devilkiller-ag Dec 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions modelina-website/package-lock.json

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

2 changes: 2 additions & 0 deletions modelina-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@tailwindcss/forms": "^0.5.2",
"@tailwindcss/line-clamp": "^0.4.0",
"@tailwindcss/typography": "^0.5.9",
"@tippyjs/react": "^4.2.6",
"cssnano": "^5.1.14",
"js-base64": "^3.7.4",
"lodash": "^4.17.21",
Expand All @@ -28,6 +29,7 @@
"postcss": "^8.4.31",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-icons": "^4.12.0",
"react-markdown": "^8.0.7",
"react-syntax-highlighter": "15.5.0",
"rehype-raw": "^6.1.1",
Expand Down
2 changes: 1 addition & 1 deletion modelina-website/src/components/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export default function CodeBlock({
className: 'pl-2 float-left left-0 sticky bg-code-editor-dark',
style: {}
}}
lineNumberProps={(lineNumber: any) => {
linenumberprops={(lineNumber: any) => {
const isHighlighted = highlightedLines?.includes(lineNumber) || false;
return {
className: `${
Expand Down
18 changes: 9 additions & 9 deletions modelina-website/src/components/InfoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface InfoModalProps {
children: React.ReactNode;
}

export default function InfoModal(props: InfoModalProps){
export default function InfoModal(props: InfoModalProps) {

const [showModal, setShowModal] = useState(false);

Expand All @@ -21,24 +21,24 @@ export default function InfoModal(props: InfoModalProps){

const MyModal = () => {
return (
<>
<div className='fixed inset-0 bg-black bg-opacity-10' onClick={onCloseModal}></div>
<div className='fixed max-w-[45rem] top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-white p-2 rounded-md'>
<div className=' px-3 py-2 text-sm font-mono'>
<>
<div className='fixed inset-0 bg-black bg-opacity-10' onClick={onCloseModal} style={{ zIndex: 1000 }}></div>
<div className='fixed max-w-[45rem] top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-white text-black p-2 rounded-md' style={{ zIndex: 1001 }}>
<div className='px-3 py-2 text-sm font-mono'>
<div className=' flex justify-between mb-3'><h2>{props.text}</h2><button onClick={onCloseModal} className='p-1 px-2 -mt-1 -mr-2 border-2 border-slate-200 items-center justify-center aspect-1 text-xs rounded-full'><p>X</p></button></div>
<div className="max-h-64 overflow-y-auto min-w-40">
{props.children}
</div>
</div>
</div>
</div>
</>
)
}

return(
return (
<>
<button onClick={onOpenModal}>
<div className=' p-1 bg-slate-50 -ml-6 mr-2 rounded-full'>
<div className='p-1 bg-slate-50 rounded-full'>
<svg
className=" "
width="7"
Expand All @@ -54,7 +54,7 @@ export default function InfoModal(props: InfoModalProps){
</svg>
</div>
</button>
{showModal && <MyModal/>}
{showModal && <MyModal />}
</>
)

Expand Down
185 changes: 185 additions & 0 deletions modelina-website/src/components/contexts/PlaygroundContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
'use client';
import React, {
createContext,
useContext,
Dispatch,
SetStateAction,
useState,
useMemo
} from 'react';
import { defaultAsyncapiDocument, ModelinaOptions } from '@/types';

interface ModelsGeneratorProps {
code: string;
name: string;
}

interface LoadedState {
editorLoaded: boolean;
hasReceivedCode: boolean;
}

interface PlaygroundContextProps {
showOptions: boolean;
setShowOptions: Dispatch<SetStateAction<boolean>>;
showOutputNavigation: boolean;
setShowOutputNavigation: Dispatch<SetStateAction<boolean>>;
config: ModelinaOptions;
setConfig: Dispatch<SetStateAction<ModelinaOptions>>;
input: string;
setInput: Dispatch<SetStateAction<string>>;
models: ModelsGeneratorProps[];
setModels: Dispatch<SetStateAction<ModelsGeneratorProps[]>>;
generatorCode: string;
setGeneratorCode: Dispatch<SetStateAction<string>>;
loaded: LoadedState;
setLoaded: Dispatch<SetStateAction<LoadedState>>;
showGeneratorCode: boolean;
setShowGeneratorCode: Dispatch<SetStateAction<boolean>>;
error: boolean;
setError: Dispatch<SetStateAction<boolean>>;
statusCode: number;
setStatusCode: Dispatch<SetStateAction<number>>;
errorMessage: string;
setErrorMessage: Dispatch<SetStateAction<string>>;
isLoaded: boolean;
setIsLoaded: Dispatch<SetStateAction<boolean>>;
hasLoadedQuery: boolean;
setHasLoadedQuery: Dispatch<SetStateAction<boolean>>;
renderModels: React.ReactNode | null;
setRenderModels: (models: React.ReactNode) => void;
}

const PlaygroundContext = createContext<PlaygroundContextProps | undefined>(undefined);

export const PlaygroundContextProvider: React.FC<{ children: React.ReactNode; }> = ({ children }) => {
const defaultConfig: ModelinaOptions = {
language: 'typescript',
propertyNamingFormat: 'default',
modelNamingFormat: 'default',
enumKeyNamingFormat: 'default',
indentationType: 'spaces',
showTypeMappingExample: false,
tsMarshalling: false,
tsModelType: 'class',
tsEnumType: 'enum',
tsModuleSystem: 'CJS',
tsIncludeDescriptions: false,
tsIncludeExampleFunction: false,
tsIncludeJsonBinPack: false,
csharpArrayType: 'Array',
csharpAutoImplemented: false,
csharpOverwriteHashcode: false,
csharpIncludeJson: false,
csharpOverwriteEqual: false,
csharpIncludeNewtonsoft: false,
csharpNamespace: 'asyncapi.models',
csharpNullable: false,
phpIncludeDescriptions: false,
phpNamespace: 'AsyncAPI/Models',
cplusplusNamespace: 'AsyncapiModels',
javaPackageName: 'asyncapi.models',
javaIncludeJackson: false,
javaIncludeMarshaling: false,
javaArrayType: 'Array',
javaOverwriteHashcode: false,
javaOverwriteEqual: false,
javaOverwriteToString: false,
javaJavaDocs: false,
javaJavaxAnnotation: false,
goPackageName: 'asyncapi.models',
kotlinPackageName: 'asyncapi.models'
};

const [showOptions, setShowOptions] = useState(true);
const [showOutputNavigation, setShowOutputNavigation] = useState(true);
const [config, setConfig] = useState<ModelinaOptions>(defaultConfig);
const [input, setInput] = useState(JSON.stringify(defaultAsyncapiDocument, null, 4));
const [models, setModels] = useState<ModelsGeneratorProps[]>([]);
const [generatorCode, setGeneratorCode] = useState('');
const [loaded, setLoaded] = useState({
editorLoaded: false,
hasReceivedCode: false,
});
const [showGeneratorCode, setShowGeneratorCode] = useState(false);
const [error, setError] = useState(false);
const [statusCode, setStatusCode] = useState(400);
const [errorMessage, setErrorMessage] = useState('Bad Request');
const [isLoaded, setIsLoaded] = useState(false);
const [hasLoadedQuery, setHasLoadedQuery] = useState(false);
const [renderModels, setRenderModels] = React.useState<React.ReactNode | null>(null);

const contextValue = useMemo(() => ({
showOptions,
setShowOptions,
showOutputNavigation,
setShowOutputNavigation,
config,
setConfig,
input,
setInput,
models,
setModels,
generatorCode,
setGeneratorCode,
loaded,
setLoaded,
showGeneratorCode,
setShowGeneratorCode,
error,
setError,
statusCode,
setStatusCode,
errorMessage,
setErrorMessage,
isLoaded,
setIsLoaded,
hasLoadedQuery,
setHasLoadedQuery,
renderModels,
setRenderModels
}), [
showOptions,
setShowOptions,
showOutputNavigation,
setShowOutputNavigation,
config,
setConfig,
input,
setInput,
models,
setModels,
generatorCode,
setGeneratorCode,
loaded,
setLoaded,
showGeneratorCode,
setShowGeneratorCode,
error,
setError,
statusCode,
setStatusCode,
errorMessage,
setErrorMessage,
isLoaded,
setIsLoaded,
hasLoadedQuery,
setHasLoadedQuery,
renderModels,
setRenderModels,
]);

return (
<PlaygroundContext.Provider value={contextValue}>
{children}
</PlaygroundContext.Provider>
);
}

export const usePlaygroundContext = () => {
const context = useContext(PlaygroundContext);
if (!context) {
throw new Error('usePlaygroundContext must be used within a PlaygroundContextProvider');
devilkiller-ag marked this conversation as resolved.
Show resolved Hide resolved
}
return context;
};
Loading
Loading