Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Fix an issue with the openapi editor not loading
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWittmann committed Jan 26, 2024
1 parent 8dea197 commit 1f08dd2
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 49 deletions.
8 changes: 4 additions & 4 deletions ui/ui-app/src/app/pages/EditorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
} from "@patternfly/react-core";
import { ArtifactTypes, ContentTypes, Design, DesignContent } from "@models/designs";
import { DesignsService, useDesignsService } from "@services/useDesignsService.ts";
import { UseDownloadService, useDownloadService } from "@services/useDownloadService.ts";
import { UseAlertsService, useAlertsService } from "@services/useAlertsService.tsx";
import { DownloadService, useDownloadService } from "@services/useDownloadService.ts";
import { AlertsService, useAlertsService } from "@services/useAlertsService.tsx";
import {
contentTypeForDesign,
convertToValidFilename,
Expand Down Expand Up @@ -70,9 +70,9 @@ export const EditorPage: FunctionComponent<EditorPageProps> = () => {
const params = useParams();

const designsService: DesignsService = useDesignsService();
const downloadSvc: UseDownloadService = useDownloadService();
const downloadSvc: DownloadService = useDownloadService();
const navigation: AppNavigationService = useAppNavigation();
const alerts: UseAlertsService = useAlertsService();
const alerts: AlertsService = useAlertsService();

useEffect(() => {
// Cleanup any possible event listener we might still have registered
Expand Down
4 changes: 2 additions & 2 deletions ui/ui-app/src/app/pages/components/editor/EditorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TextContent
} from "@patternfly/react-core";
import { ArtifactTypes, Design, DesignEvent } from "@models/designs";
import { UseLocalStorageService, useLocalStorageService } from "@services/useLocalStorageService.ts";
import { LocalStorageService, useLocalStorageService } from "@services/useLocalStorageService.ts";
import { DesignsService, useDesignsService } from "@services/useDesignsService.ts";
import { ArtifactTypeIcon } from "@app/components";
import { DesignDescription, NavLink } from "@app/pages";
Expand Down Expand Up @@ -47,7 +47,7 @@ type EditorContextMenuItem = {
* The context of the design when editing a design on the editor page.
*/
export const EditorContext: FunctionComponent<EditorContextProps> = (props: EditorContextProps) => {
const lss: UseLocalStorageService = useLocalStorageService();
const lss: LocalStorageService = useLocalStorageService();

const [originEvent, setOriginEvent] = useState<DesignEvent>();
const [isExpanded, setExpanded] = useState(lss.getConfigProperty("editor-context.isExpanded", "false") === "true");
Expand Down
4 changes: 2 additions & 2 deletions ui/ui-app/src/app/pages/components/home/CreateDesignModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "@patternfly/react-core";
import { ArtifactTypes, CreateDesign } from "@models/designs";
import { Template } from "@models/templates";
import { UseTemplatesService, useTemplatesService } from "@services/useTemplatesService.ts";
import { TemplatesService, useTemplatesService } from "@services/useTemplatesService.ts";
import { OPENAPI_VERSIONS, TemplateItem, TYPE_ITEMS, TypeItem } from "@app/pages";
import { If, ObjectSelect } from "@apicurio/common-ui-components";

Expand All @@ -36,7 +36,7 @@ export const CreateDesignModal: FunctionComponent<CreateDesignModalProps> = ({ i
const [templates, setTemplates] = useState<Template[]>();
const [template, setTemplate] = useState<Template>();

const templatesSvc: UseTemplatesService = useTemplatesService();
const templatesSvc: TemplatesService = useTemplatesService();

// Called when the user clicks the Create button in the modal
const doCreate = (): void => {
Expand Down
8 changes: 4 additions & 4 deletions ui/ui-app/src/app/pages/components/home/DesignsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
RenameDesign
} from "@models/designs";
import { DesignsService, useDesignsService } from "@services/useDesignsService.ts";
import { UseDownloadService, useDownloadService } from "@services/useDownloadService.ts";
import { UseAlertsService, useAlertsService } from "@services/useAlertsService.tsx";
import { DownloadService, useDownloadService } from "@services/useDownloadService.ts";
import { AlertsService, useAlertsService } from "@services/useAlertsService.tsx";
import { contentTypeForDesign, convertToValidFilename, fileExtensionForDesign } from "@utils/content.utils.ts";
import { ListWithToolbar } from "@apicurio/common-ui-components";
import { AppNavigationService, useAppNavigation } from "@services/useAppNavigation.ts";
Expand Down Expand Up @@ -56,9 +56,9 @@ export const DesignsPanel: FunctionComponent<DesignsPanelProps> = ({ selectedDes
const [ isRenameModalOpen, setRenameModalOpen ] = useState(false);

const designsSvc: DesignsService = useDesignsService();
const downloadSvc: UseDownloadService = useDownloadService();
const downloadSvc: DownloadService = useDownloadService();
const nav: AppNavigationService = useAppNavigation();
const alerts: UseAlertsService = useAlertsService();
const alerts: AlertsService = useAlertsService();

const doRefresh = (): void => {
setRefresh(refresh + 1);
Expand Down
4 changes: 2 additions & 2 deletions ui/ui-app/src/app/pages/components/home/UrlUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FunctionComponent, useState } from "react";
import "./UrlUpload.css";
import { Button, Spinner, TextArea, TextInput } from "@patternfly/react-core";
import { UseUrlService, useUrlService } from "@services/useUrlService.ts";
import { UrlService, useUrlService } from "@services/useUrlService.ts";
import { If, IfNotLoading } from "@apicurio/common-ui-components";

/**
Expand All @@ -24,7 +24,7 @@ export const UrlUpload: FunctionComponent<UrlUploadProps> = (props: UrlUploadPro
const [isLoading, setLoading] = useState<boolean>(false);
const [downloadError, setDownloadError] = useState<string>();

const urlService: UseUrlService = useUrlService();
const urlService: UrlService = useUrlService();

const onTextInputChange = (_event: any, value: string): void => {
setUrl(value);
Expand Down
8 changes: 5 additions & 3 deletions ui/ui-app/src/editors/AsyncApiEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, { RefObject, useEffect } from "react";
import "./AsyncApiEditor.css";
import { Editor as DesignEditor, EditorProps } from "./editor-types";
import { ContentTypes } from "@models/designs";
import { EditorConfig, useEditorConfig } from "./EditorConfigContext.ts";
import { parseJson, parseYaml, toJsonString, toYamlString } from "@utils/content.utils.ts";
import { ApiDesignerConfig, useApiDesignerConfig } from "@services/useApiDesignerConfig.ts";


export type AsyncApiEditorProps = {
Expand All @@ -18,7 +18,9 @@ export type AsyncApiEditorProps = {
*/
export const AsyncApiEditor: DesignEditor = ({ content, onChange, className }: AsyncApiEditorProps) => {
const ref: RefObject<any> = React.createRef();
const cfg: EditorConfig = useEditorConfig();
const config: ApiDesignerConfig = useApiDesignerConfig();

const editorsUrl: string = config.components.editors.url;

// TODO we have a lot of common functionality between the asyncapi and openapi editors. Need to share!
useEffect(() => {
Expand Down Expand Up @@ -49,7 +51,7 @@ export const AsyncApiEditor: DesignEditor = ({ content, onChange, className }: A
});

const editorAppUrl = (): string => {
return cfg.asyncApiEditorUrl;
return editorsUrl;
};

const onEditorLoaded = (): void => {
Expand Down
15 changes: 0 additions & 15 deletions ui/ui-app/src/editors/EditorConfigContext.ts

This file was deleted.

10 changes: 6 additions & 4 deletions ui/ui-app/src/editors/OpenApiEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { RefObject, useEffect } from "react";
import { Editor as DesignEditor, EditorProps } from "./editor-types";
import "./OpenApiEditor.css";
import { EditorConfig, useEditorConfig } from "./EditorConfigContext.ts";
import { ContentTypes } from "@models/designs";
import { parseJson, parseYaml, toJsonString, toYamlString } from "@utils/content.utils.ts";
import { ApiDesignerConfig, useApiDesignerConfig } from "@services/useApiDesignerConfig.ts";


export type OpenApiEditorProps = {
Expand All @@ -18,10 +18,12 @@ export type OpenApiEditorProps = {
*/
export const OpenApiEditor: DesignEditor = ({ content, onChange, className }: OpenApiEditorProps) => {
const ref: RefObject<any> = React.createRef();
const cfg: EditorConfig = useEditorConfig();
const config: ApiDesignerConfig = useApiDesignerConfig();

const editorsUrl: string = config.components.editors.url;

useEffect(() => {
console.info("[OpenApiEditor] URL location of ads-editors: ", cfg.openApiEditorUrl);
console.info("[OpenApiEditor] URL location of editors: ", editorsUrl);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

Expand Down Expand Up @@ -50,7 +52,7 @@ export const OpenApiEditor: DesignEditor = ({ content, onChange, className }: Op
});

const editorAppUrl = (): string => {
return cfg.openApiEditorUrl;
return editorsUrl;
};

const onEditorLoaded = (): void => {
Expand Down
1 change: 0 additions & 1 deletion ui/ui-app/src/editors/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from "./AsyncApiEditor";
export * from "./editor-types";
export * from "./EditorConfigContext.ts";
export * from "./OpenApiEditor";
export * from "./ProtoEditor";
export * from "./TextEditor";
6 changes: 2 additions & 4 deletions ui/ui-app/src/services/useAlertsService.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Design, RenameDesign } from "@models/designs";


export interface UseAlertsService {
export interface AlertsService {
designDeleted(design: Design): void;
designDeleteFailed(design: Design, error: any): void;
designSaved(design: Design): void;
Expand All @@ -12,9 +12,7 @@ export interface UseAlertsService {
/**
* React hook to get the Alerts service.
*/
export const useAlertsService: () => UseAlertsService = (): UseAlertsService => {
// const serviceConfig: ServiceConfig = useServiceConfig();

export const useAlertsService: () => AlertsService = (): AlertsService => {
return {
designDeleted(design: Design): void {
console.info(design);
Expand Down
4 changes: 2 additions & 2 deletions ui/ui-app/src/services/useDownloadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ async function downloadToFS(content: string, contentType: string, filename: stri
/**
* The Download Service interface.
*/
export interface UseDownloadService {
export interface DownloadService {
downloadToFS(content: string, contentType: string, filename: string): Promise<void>;
}


/**
* React hook to get the Download service.
*/
export const useDownloadService: () => UseDownloadService = (): UseDownloadService => {
export const useDownloadService: () => DownloadService = (): DownloadService => {
return {
downloadToFS
};
Expand Down
4 changes: 2 additions & 2 deletions ui/ui-app/src/services/useLocalStorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function clearConfigProperty(propertyName: string): void {
/**
* The Local Storage Service interface.
*/
export interface UseLocalStorageService {
export interface LocalStorageService {
setConfigProperty(propertyName: string, propertyValue: string | object): void;
getConfigProperty(propertyName: string, defaultValue: string | object | undefined): string | object | undefined;
clearConfigProperty(propertyName: string): void;
Expand All @@ -35,7 +35,7 @@ export interface UseLocalStorageService {
/**
* React hook to get the LocalStorage service.
*/
export const useLocalStorageService: () => UseLocalStorageService = (): UseLocalStorageService => {
export const useLocalStorageService: () => LocalStorageService = (): LocalStorageService => {
return {
setConfigProperty,
getConfigProperty,
Expand Down
4 changes: 2 additions & 2 deletions ui/ui-app/src/services/useTemplatesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ async function getTemplatesFor(type: string, version?: string): Promise<Template
/**
* The Templates Service interface.
*/
export interface UseTemplatesService {
export interface TemplatesService {
getTemplatesFor(type: string, version?: string): Promise<Template[]>;
}


/**
* React hook to get the Templates service.
*/
export const useTemplatesService: () => UseTemplatesService = (): UseTemplatesService => {
export const useTemplatesService: () => TemplatesService = (): TemplatesService => {
return {
getTemplatesFor
};
Expand Down
4 changes: 2 additions & 2 deletions ui/ui-app/src/services/useUrlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ async function fetchUrlContent(url: string): Promise<string> {
/**
* The URL Service interface.
*/
export interface UseUrlService {
export interface UrlService {
fetchUrlContent(url: string): Promise<string>;
}


/**
* React hook to get the URL service.
*/
export const useUrlService: () => UseUrlService = (): UseUrlService => {
export const useUrlService: () => UrlService = (): UrlService => {
return {
fetchUrlContent
};
Expand Down

0 comments on commit 1f08dd2

Please sign in to comment.