Skip to content

Commit

Permalink
Migrated details of api widget
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrik committed Nov 6, 2024
1 parent bd08ac3 commit fa94305
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 90 deletions.
2 changes: 1 addition & 1 deletion src/apim.design.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { DefaultSessionManager } from "@paperbits/common/persistence/defaultSess
import { HistoryRouteHandler } from "@paperbits/common/routing";
import { RoleBasedSecurityDesignModule } from "@paperbits/core/security/roleBasedSecurity.design.module";
import { ListOfApisDesignModule } from "./components/apis/list-of-apis/ko/listOfApisEditor.module";
import { DetailsOfApiDesignModule } from "./components/apis/details-of-api/ko/detailsOfApiEditor.module";
import { DetailsOfApiDesignModule } from "./components/apis/details-of-api/detailsOfApi.design.module";
import { HistoryOfApiEditorModule as HistoryOfApiDesignModule } from "./components/apis/history-of-api/ko/historyOfApiEditor.module";
import { SigninDesignModule } from "./components/users/signin/signin.design.module";
import { SigninSocialEditorModule as SigninSocialDesignModule } from "./components/users/signin-social/signinSocial.design.module";
Expand Down
2 changes: 1 addition & 1 deletion src/apim.publish.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RoleBasedSecurityPublishModule } from "@paperbits/core/security/roleBas
import { MapiClient } from "./services/mapiClient";
import { MapiObjectStorage, MapiBlobStorage } from "./persistence";
import { ListOfApisPublishModule } from "./components/apis/list-of-apis/ko/listOfApis.module";
import { DetailsOfApiPublishModule } from "./components/apis/details-of-api/ko/detailsOfApi.module";
import { DetailsOfApiPublishModule } from "./components/apis/details-of-api/detailsOfApi.publish.module";
import { HistoryOfApiPublishModule } from "./components/apis/history-of-api/ko/historyOfApi.module";
import { SigninPublishModule } from "./components/users/signin/signin.publish.module";
import { SigninSocialPublishModule } from "./components/users/signin-social/signinSocial.publish.module";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { IInjector, IInjectorModule } from "@paperbits/common/injection";
import { IWidgetService } from "@paperbits/common/widgets";
import { KnockoutComponentBinder } from "@paperbits/core/ko";
import { DetailsOfApiHandlers } from "../detailsOfApiHandlers";
import { DetailsOfApiModel } from "../detailsOfApiModel";
import { DetailsOfApiModelBinder } from "../detailsOfApiModelBinder";
import { DetailsOfApiEditor } from "./detailsOfApiEditor";
import { DetailsOfApiViewModel } from "./detailsOfApiViewModel";
import { DetailsOfApiHandlers } from "./detailsOfApiHandlers";
import { DetailsOfApiModel } from "./detailsOfApiModel";
import { DetailsOfApiModelBinder } from "./detailsOfApiModelBinder";
import { DetailsOfApiEditor } from "./ko/detailsOfApiEditor";
import { DetailsOfApiViewModelBinder } from "./detailsOfApiViewModelBinder";
import { ReactComponentBinder } from "@paperbits/react/bindings";
import { ApiDetailsViewModel } from "./react/ApiDetailsViewModel";

export class DetailsOfApiDesignModule implements IInjectorModule {
public register(injector: IInjector): void {
injector.bind("detailsOfApiEditor", DetailsOfApiViewModel);
injector.bind("detailsOfApiEditor", DetailsOfApiEditor);
injector.bindSingleton("detailsOfApiModelBinder", DetailsOfApiModelBinder);
injector.bindSingleton("detailsOfApiViewModelBinder", DetailsOfApiViewModelBinder)
injector.bindSingleton("detailsOfApiHandlers", DetailsOfApiHandlers);
Expand All @@ -19,8 +20,8 @@ export class DetailsOfApiDesignModule implements IInjectorModule {

widgetService.registerWidget("detailsOfApi", {
modelDefinition: DetailsOfApiModel,
componentBinder: KnockoutComponentBinder,
componentDefinition: DetailsOfApiViewModel,
componentBinder: ReactComponentBinder,
componentDefinition: ApiDetailsViewModel,
modelBinder: DetailsOfApiModelBinder,
viewModelBinder: DetailsOfApiViewModelBinder
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IInjectorModule, IInjector } from "@paperbits/common/injection";
import { DetailsOfApiModelBinder } from "../detailsOfApiModelBinder";
import { DetailsOfApiModelBinder } from "./detailsOfApiModelBinder";
import { DetailsOfApiViewModelBinder } from "./detailsOfApiViewModelBinder";
import { DetailsOfApiViewModel } from "./detailsOfApiViewModel";
import { DetailsOfApiModel } from "../detailsOfApiModel";
import { KnockoutComponentBinder } from "@paperbits/core/ko";
import { ApiDetailsViewModel } from "./react/ApiDetailsViewModel";
import { DetailsOfApiModel } from "./detailsOfApiModel";
import { ReactComponentBinder } from "@paperbits/react/bindings";
import { IWidgetService } from "@paperbits/common/widgets";


Expand All @@ -16,8 +16,8 @@ export class DetailsOfApiPublishModule implements IInjectorModule {

widgetService.registerWidget("detailsOfApi", {
modelDefinition: DetailsOfApiModel,
componentBinder: KnockoutComponentBinder,
componentDefinition: DetailsOfApiViewModel,
componentBinder: ReactComponentBinder,
componentDefinition: ApiDetailsViewModel,
modelBinder: DetailsOfApiModelBinder,
viewModelBinder: DetailsOfApiViewModelBinder
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IInjector, IInjectorModule } from "@paperbits/common/injection";
import { registerCustomElement } from "@paperbits/react/customElements";
import { ApiDetails } from "./react/runtime/ApiDetails";
import { ApiDetails } from "./react/ApiDetails";

export class DetailsOfApiRuntimeModule implements IInjectorModule {
public register(injector: IInjector): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { StyleCompiler } from "@paperbits/common/styles";
import { ViewModelBinder, WidgetState } from "@paperbits/common/widgets";
import { ISiteService } from "@paperbits/common/sites";
import { DetailsOfApiModel } from "../detailsOfApiModel";
import { DetailsOfApiViewModel } from "./detailsOfApiViewModel";
import { isRedesignEnabledSetting } from "../../../../constants";
import { DetailsOfApiModel } from "./detailsOfApiModel";
import { isRedesignEnabledSetting } from "../../../constants";
import { ApiDetailsViewModel } from "./react/ApiDetailsViewModel";


export class DetailsOfApiViewModelBinder implements ViewModelBinder<DetailsOfApiModel, DetailsOfApiViewModel> {
export class DetailsOfApiViewModelBinder implements ViewModelBinder<DetailsOfApiModel, ApiDetailsViewModel> {
constructor(
private readonly styleCompiler: StyleCompiler,
private readonly siteService: ISiteService,
) { }

public stateToInstance(state: WidgetState, componentInstance: DetailsOfApiViewModel): void {
componentInstance.styles(state.styles);
componentInstance.isRedesignEnabled(state.isRedesignEnabled);

componentInstance.runtimeConfig(JSON.stringify({
changeLogPageUrl: state.changeLogPageHyperlink
? state.changeLogPageHyperlink.href
: undefined
public stateToInstance(state: WidgetState, componentInstance: ApiDetailsViewModel): void {
componentInstance.setState(prevState => ({
styles: state.styles,
isRedesignEnabled: state.isRedesignEnabled,
changeLogPageUrl: state.changeLogPageHyperlink?.href
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { Resolve } from "@paperbits/react/decorators";
import { Router } from "@paperbits/common/routing";
import { Stack } from "@fluentui/react";
import { Badge, Body1, Body1Strong, Dropdown, FluentProvider, Link, Option, Spinner, Title1 } from "@fluentui/react-components";
import { Api } from "../../../../../models/api";
import { KnownMimeTypes } from "../../../../../models/knownMimeTypes"
import { ApiService } from "../../../../../services/apiService";
import { RouteHelper } from "../../../../../routing/routeHelper";
import { TypeOfApi, fuiTheme } from "../../../../../constants";
import { MarkdownProcessor } from "../../../../utils/react/MarkdownProcessor";
import { Api } from "../../../../models/api";
import { KnownMimeTypes } from "../../../../models/knownMimeTypes"
import { ApiService } from "../../../../services/apiService";
import { RouteHelper } from "../../../../routing/routeHelper";
import { TypeOfApi, fuiTheme } from "../../../../constants";
import { MarkdownProcessor } from "../../../utils/react/MarkdownProcessor";

interface ApiDetailsProps {
changeLogPageUrl?: string
Expand Down Expand Up @@ -55,7 +55,7 @@ const ApiDetailsFC = ({
const loadApis = async (): Promise<{api: Api, versionedApis: Api[]}> => {
let api: Api;
let versionedApis: Api[];

try {
api = await apiService.getApi(`apis/${apiName}`);

Expand All @@ -66,7 +66,7 @@ const ApiDetailsFC = ({
} catch (error) {
throw new Error(`Unable to load the API. Error: ${error.message}`);
}

return {api, versionedApis};
}

Expand Down Expand Up @@ -111,6 +111,7 @@ const ApiDetailsFC = ({
window.URL.revokeObjectURL(url);
}

const isRestApi = api && (api.type !== TypeOfApi.graphQL && api.type !== TypeOfApi.webSocket);
return (
<div className={"api-details-container"}>
{working
Expand All @@ -119,18 +120,18 @@ const ApiDetailsFC = ({
? <>
<Stack horizontal horizontalAlign="space-between" verticalAlign="center">
<Stack horizontal verticalAlign="center">
<Title1 className={"api-title"}>{api.displayName}</Title1>
<h1 className={"api-title"}>{api.displayName}</h1>
{api.typeName && api.typeName !== "REST" && <Badge appearance="outline">{api.typeName}</Badge>}
</Stack>
{changeLogPageUrl && api.type !== TypeOfApi.graphQL && api.type !== TypeOfApi.webSocket &&
<Link href={routeHelper.getApiReferenceUrl(apiName, changeLogPageUrl)}>View changelog</Link>
{changeLogPageUrl && isRestApi &&
<a href={routeHelper.getApiReferenceUrl(apiName, changeLogPageUrl)}>View changelog</a>
}
</Stack>
{(versionedApis?.length > 0 || (api.type !== TypeOfApi.graphQL && api.type !== TypeOfApi.webSocket)) &&
{(versionedApis?.length > 0 || isRestApi) &&
<Stack horizontal verticalAlign="center" className={"api-details-dropdowns"}>
{versionedApis?.length > 0 &&
{versionedApis?.length > 0 &&
<Stack horizontal verticalAlign="center">
<Body1Strong>Version</Body1Strong>
<span>Version</span>
<Dropdown
defaultSelectedOptions={[api.name]}
value={api.apiVersion ?? originalVersion}
Expand All @@ -145,9 +146,9 @@ const ApiDetailsFC = ({
</Dropdown>
</Stack>
}
{api.type !== TypeOfApi.graphQL && api.type !== TypeOfApi.webSocket &&
{isRestApi &&
<Stack horizontal verticalAlign="center">
<Body1Strong>Download definition</Body1Strong>
<span>Download definition</span>
<Dropdown
placeholder="Select definition type"
className={"api-details-dropdown"}
Expand All @@ -164,34 +165,34 @@ const ApiDetailsFC = ({
</Stack>
}
{api.description &&
<Body1 block><MarkdownProcessor markdownToDisplay={api.description} /></Body1>
<span style={{display: "block"}}><MarkdownProcessor markdownToDisplay={api.description} /></span>
}
{(api.contact || api.license || api.termsOfServiceUrl) &&
<div className={"api-additional-info"}>
{api.contact &&
{api.contact &&
<div className={"api-additional-info-block"}>
<Body1 block>Contact:</Body1>
{api.contact.name && <Body1 block>{api.contact.name}</Body1>}
{api.contact.email && <Body1 block><Link href={`mailto:${api.contact.email}`}>{api.contact.email}</Link></Body1>}
{api.contact.url && <Link href={api.contact.url}>{api.contact.url}</Link>}
<span style={{display: "block"}}>Contact:</span>
{api.contact.name && <span style={{display: "block"}}>{api.contact.name}</span>}
{api.contact.email && <span style={{display: "block"}}><a href={`mailto:${api.contact.email}`}>{api.contact.email}</a></span>}
{api.contact.url && <a href={api.contact.url}>{api.contact.url}</a>}
</div>
}
{api.license &&
<div className={"api-additional-info-block"}>
<Body1 block>License:</Body1>
{api.license.url ? <Link href={api.license.url}>{api.license.name}</Link> : <Body1>{api.license.name}</Body1>}
<span style={{display: "block"}}>License:</span>
{api.license.url ? <a href={api.license.url}>{api.license.name}</a> : <span>{api.license.name}</span>}
</div>
}
{api.termsOfServiceUrl &&
<div className={"api-additional-info-block"}>
<Body1 block>Additional resources:</Body1>
<Link href={api.termsOfServiceUrl}>Terms and conditions</Link>
<span style={{display: "block"}}>Additional resources:</span>
<a href={api.termsOfServiceUrl}>Terms and conditions</a>
</div>
}
</div>
}
</>
: <Body1>No API found.</Body1>
: <span>No API found.</span>
}

</div>
Expand All @@ -204,7 +205,7 @@ export class ApiDetails extends React.Component<ApiDetailsProps, ApiDetailsState

@Resolve("routeHelper")
public routeHelper: RouteHelper;

@Resolve("router")
public router: Router;

Expand Down
27 changes: 27 additions & 0 deletions src/components/apis/details-of-api/react/ApiDetailsViewModel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from "react";
import { StyleModel } from "@paperbits/common/styles";

export class ApiDetailsViewModel extends React.Component {
public state: {
isRedesignEnabled: boolean;
styles: StyleModel;
changeLogPageUrl: string;
};

constructor(props) {
super(props);

this.state = {
isRedesignEnabled: props.isRedesignEnabled,
styles: props.styles,
changeLogPageUrl: props.changeLogPageUrl
};
}

public render(): JSX.Element {
const data = JSON.stringify(this.state);
return this.state.isRedesignEnabled
? <fui-api-details key={data} props={data}></fui-api-details>
: <api-details params={data}></api-details>;
}
}
2 changes: 2 additions & 0 deletions src/components/react.components.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
declare namespace JSX {
interface IntrinsicElements {
"fui-api-details": any;
"api-details": any;
"fui-signin-aad-runtime": any;
"signin-aad": any;
"fui-signin-aadb2c-runtime": any;
Expand Down
30 changes: 0 additions & 30 deletions src/components/users/signin-social/ko/signinSocial.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IInjector, IInjectorModule } from "@paperbits/common/injection";
import { IWidgetService } from "@paperbits/common/widgets";
import { KnockoutComponentBinder } from "@paperbits/core/ko";
import { SignInSocialEditor } from "./ko/signinSocialEditor";
import { SignInSocialViewModel } from "./react/SigninSocialViewModel";
import { SignInSocialViewModel } from "./react/SignInSocialViewModel";
import { SigninSocialViewModelBinder } from "./signinSocialViewModelBinder";
import { SigninSocialHandlers } from "./signinSocialHandlers";
import { SigninSocialModel } from "./signinSocialModel";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IInjector, IInjectorModule } from "@paperbits/common/injection";
import { IWidgetService } from "@paperbits/common/widgets";
import { ReactComponentBinder } from "@paperbits/react/bindings";
import { SignInSocialViewModel } from "./react/SigninSocialViewModel";
import { SignInSocialViewModel } from "./react/SignInSocialViewModel";
import { SigninSocialViewModelBinder } from "./signinSocialViewModelBinder";
import { SigninSocialModel } from "./signinSocialModel";
import { SigninSocialModelBinder } from "./signinSocialModelBinder";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TermsOfService } from "../../../contracts/identitySettings";
import { IdentityService } from "../../../services/identityService";
import { isRedesignEnabledSetting } from "../../../constants";
import { SigninSocialModel } from "./signinSocialModel";
import { SignInSocialViewModel } from "./react/SigninSocialViewModel";
import { SignInSocialViewModel } from "./react/SignInSocialViewModel";


export class SigninSocialViewModelBinder implements ViewModelBinder<SigninSocialModel, SignInSocialViewModel> {
Expand Down

0 comments on commit fa94305

Please sign in to comment.