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

fix: Disable unsupported generators for AsyncAPI V3 (#979) #982

Merged
merged 7 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
22 changes: 18 additions & 4 deletions apps/studio/src/components/Modals/ConfirmModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import type { ReactNode, FunctionComponent, PropsWithChildren } from 'react';
interface ConfirmModalProps {
title: ReactNode;
description?: ReactNode;
warning?: ReactNode;
link?: string;
confirmText?: ReactNode;
cancelText?: ReactNode;
confirmDisabled?: boolean;
cancelDisabled?: boolean;
containerClassName? : string;
containerClassName?: string;
closeAfterSumbit?: boolean;
onSubmit?: () => void;
onCancel?: () => void;
Expand All @@ -20,6 +22,8 @@ interface ConfirmModalProps {
export const ConfirmModal: FunctionComponent<PropsWithChildren<ConfirmModalProps>> = ({
title,
description,
warning,
link,
confirmText = 'Save',
cancelText = 'Cancel',
confirmDisabled = true,
Expand Down Expand Up @@ -103,16 +107,26 @@ export const ConfirmModal: FunctionComponent<PropsWithChildren<ConfirmModalProps
{description && (
<p className="text-gray-500 text-xs">{description}</p>
)}
{warning && (
<p className="text-red-500 text-xs">{warning} {' '}
<a
href={link}
className='hover:underline'
target="_blank"
rel="noreferrer"
>
[TRACKING_LINK]
kalpesh-d marked this conversation as resolved.
Show resolved Hide resolved
</a></p>
)}
<div className="my-8 space-y-4">{children}</div>
</div>
</div>
<div className={`mt-5 sm:mt-6 sm:grid sm:gap-3 sm:grid-flow-row-dense ${onSubmit ? 'sm:grid-cols-2' : ''}`}>
{onSubmit && (
<button
type="button"
className={`w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-pink-600 text-base font-medium text-white hover:bg-pink-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-pink-500 sm:col-start-2 sm:text-sm ${
confirmDisabled ? 'opacity-10' : 'opacity-100'
}`}
className={`w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-pink-600 text-base font-medium text-white hover:bg-pink-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-pink-500 sm:col-start-2 sm:text-sm ${confirmDisabled ? 'opacity-10' : 'opacity-100'
}`}
disabled={confirmDisabled}
onClick={handleOnSubmit}
>
Expand Down
37 changes: 31 additions & 6 deletions apps/studio/src/components/Modals/Generator/GeneratorModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ import { filesState } from '../../../state';

import templates from './template-parameters.json';

const unsupportedGenerators = [
'@asyncapi/dotnet-nats-template',
'@asyncapi/ts-nats-template',
'@asyncapi/python-paho-template',
'@asyncapi/nodejs-ws-template',
'@asyncapi/java-spring-cloud-stream-template',
'@asyncapi/go-watermill-template',
'@asyncapi/java-spring-template',
'@asyncapi/nodejs-template',
'@asyncapi/java-template',
'@asyncapi/php-template'
];

export const GeneratorModal = create(() => {
const modal = useModal();
const [template, setTemplate] = useState('');
Expand Down Expand Up @@ -76,6 +89,8 @@ export const GeneratorModal = create(() => {
return (
<ConfirmModal
title="Generate code/docs based on your AsyncAPI Document"
warning="Not all generators currently offer support for AsyncAPI V3."
link='https://github.com/asyncapi/studio/issues/980'
confirmText="Generate"
confirmDisabled={confirmDisabled}
onSubmit={onSubmit}
Expand All @@ -99,11 +114,21 @@ export const GeneratorModal = create(() => {
value={template}
>
<option value="">Please Select</option>
{Object.keys(templates).map(templateItem => (
<option key={templateItem} value={templateItem}>
{(templates as Record<string, any>)[String(templateItem)]?.title}
</option>
))}
{Object.keys(templates).map(templateItem => {
if (!unsupportedGenerators.includes(templateItem)) {
return (
<option key={templateItem} value={templateItem}>
{(templates as Record<string, any>)[String(templateItem)]?.title}
</option>
);
} else {
return (
<option key={templateItem} value={templateItem} disabled>
{(templates as Record<string, any>)[String(templateItem)]?.title}
</option>
);
}
})}
</select>
</div>
{template && (
Expand Down Expand Up @@ -154,7 +179,7 @@ export const GeneratorModal = create(() => {
</div>
{problem.validationErrors &&
problem.validationErrors.length &&
problem.validationErrors.filter(error => error.message).length
problem.validationErrors.filter(error => error.message).length
? (
<ul className='text-xs mt-2 list-disc pl-7'>
{problem.validationErrors.map(error => (
Expand Down
Loading