Skip to content

Commit

Permalink
Apply prettier to carbon-addons-devenv
Browse files Browse the repository at this point in the history
  • Loading branch information
folkforms committed Apr 25, 2024
1 parent 0ac7ce4 commit b783db9
Show file tree
Hide file tree
Showing 25 changed files with 373 additions and 411 deletions.
51 changes: 28 additions & 23 deletions packages/carbon-addons-devenv/sample_renderers/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @namespace Renderer
*/
export default class Renderer {

/**
* Creates a renderer.
*
Expand All @@ -18,28 +17,34 @@ export default class Renderer {
* @private
*/
static create = async (containerId, config, specifiedApolloClientHook) => {
window.spmcustom.requireCustomCarbonAddons()
.then(async (CustomCarbonAddonModule) => {

let apolloClientDataProvider;
let apolloClientHookList;
try {
const apolloClientHookListName = 'ApolloClientHooks';
apolloClientHookList = CustomCarbonAddonModule[apolloClientHookListName];
apolloClientDataProvider = apolloClientHookList[specifiedApolloClientHook];
} catch (e) {
throw new Error(`The apollo data provider : ${ specifiedApolloClientHook } does not exist. This is the list of available ones: ${ JSON.stringify(apolloClientHookList)}`);
}
if (!apolloClientDataProvider) {
throw new Error(`The apollo data provider : ${ specifiedApolloClientHook } does not exist. This is the list of available ones: ${ JSON.stringify(apolloClientHookList)}`);
}
apolloClientDataProvider(document.getElementById(containerId), {
...config,
labels: {
...config.labels,
...config.messages,
window.spmcustom
.requireCustomCarbonAddons()
.then(async (CustomCarbonAddonModule) => {
let apolloClientDataProvider;
let apolloClientHookList;
try {
const apolloClientHookListName = "ApolloClientHooks";
apolloClientHookList =
CustomCarbonAddonModule[apolloClientHookListName];
apolloClientDataProvider =
apolloClientHookList[specifiedApolloClientHook];
} catch (e) {
throw new Error(
`The apollo data provider : ${specifiedApolloClientHook} does not exist. This is the list of available ones: ${JSON.stringify(apolloClientHookList)}`,
);
}
if (!apolloClientDataProvider) {
throw new Error(
`The apollo data provider : ${specifiedApolloClientHook} does not exist. This is the list of available ones: ${JSON.stringify(apolloClientHookList)}`,
);
}
apolloClientDataProvider(document.getElementById(containerId), {
...config,
labels: {
...config.labels,
...config.messages,
},
});
});
});
}
};
}
4 changes: 2 additions & 2 deletions packages/carbon-addons-devenv/sample_renderers/logo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Copyright Merative US L.P. 2020
*/

import LogoRenderer from './LogoRenderer';
import LogoRenderer from "./LogoRenderer";

export default {
LogoRenderer
LogoRenderer,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Copyright Merative US L.P. 2020
*/

import PersonFolioRenderer from './PersonFolioRenderer';
import PersonFolioRenderer from "./PersonFolioRenderer";

export default {
PersonFolioRenderer
PersonFolioRenderer,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* Copyright Merative US L.P. 2021
*/

import { ApolloClient, createHttpLink, InMemoryCache } from '@apollo/client';
import { setContext } from '@apollo/client/link/context';
import { ApolloClient, createHttpLink, InMemoryCache } from "@apollo/client";
import { setContext } from "@apollo/client/link/context";

let csrfToken;

class ApolloClientConfig {
static serverURL = process.env.GRAPHQL_SERVER_URL || '/Rest/graphql';
static serverURL = process.env.GRAPHQL_SERVER_URL || "/Rest/graphql";

static csrfTokenHeader = process.env.CSRF_TOKEN_REQUEST_HEADER;

Expand All @@ -24,23 +24,23 @@ class ApolloClientConfig {
*/
static getCSRFRequestHeaderName = () => {
return process.env.CSRF_TOKEN_REQUEST_HEADER;
}
/**
};

/**
* Gets the CSRF token by making a call to the configured REST endpoint.
*
* @static
* @returns {String} The CSRF token.
* @memberof ApolloClientConfig
* @private
*/
static getCSRFToken = async () => {
static getCSRFToken = async () => {
const response = await fetch(this.csrfTokenEndpoint, {});
const token = await response.headers.get(this.csrfTokenHeader);
return token;
}
};

/**
/**
* Gets the http endpoint for GraphQL with basic configuration.
*
* @static
Expand All @@ -67,8 +67,8 @@ class ApolloClientConfig {
headers: {
...headers,
[this.csrfTokenHeader]: crfToken ? `${crfToken}` : "",
}
}
},
};
};

/**
Expand All @@ -79,8 +79,8 @@ class ApolloClientConfig {
* @memberof ApolloClientConfig
* @private
*/
static getCSRFLink = () => {
return setContext(async(_, { headers }) => {
static getCSRFLink = () => {
return setContext(async (_, { headers }) => {
// return the headers to the context so httpLink can read them
if (!csrfToken) {
csrfToken = await this.getCSRFToken();
Expand All @@ -89,8 +89,7 @@ class ApolloClientConfig {
});
};


/**
/**
* Gets the Apollo Client configuration depdending on the configuration from the renderers.
*
* @static
Expand All @@ -100,15 +99,16 @@ class ApolloClientConfig {
*/
static getConfig = (configuration) => {
const { security } = configuration;
const isCsrfEnabled = security && security.csrf && security.csrf.enabled === 'true';
const isCsrfEnabled =
security && security.csrf && security.csrf.enabled === "true";
const httpLink = this.getHttpLink();
return new ApolloClient({
link: isCsrfEnabled ? this.getCSRFLink().concat(httpLink) : httpLink,
headers: {
'Accept-Language': configuration.locale,
},
cache: new InMemoryCache()
});
}
return new ApolloClient({
link: isCsrfEnabled ? this.getCSRFLink().concat(httpLink) : httpLink,
headers: {
"Accept-Language": configuration.locale,
},
cache: new InMemoryCache(),
});
};
}
export default ApolloClientConfig;
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@
* Copyright Merative US L.P. 2020
*/

import React from 'react';
import PropTypes from 'prop-types';
import { ApolloProvider } from '@apollo/client';
import React from "react";
import PropTypes from "prop-types";
import { ApolloProvider } from "@apollo/client";

const ApolloClientDataProvider = ({ apolloClient, children }) => {
return (
<ApolloProvider client={apolloClient}>
{children}
</ApolloProvider>
);
return <ApolloProvider client={apolloClient}>{children}</ApolloProvider>;
};

ApolloClientDataProvider.propTypes = {
apolloClient: PropTypes.object.isRequired,
children: PropTypes.element.isRequired
}

children: PropTypes.element.isRequired,
};

export default ApolloClientDataProvider;
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,28 @@
* Copyright Merative US L.P. 2020
*/

import React from 'react';
import PropTypes from 'prop-types';
import InlContext from '../../react/core/InlContext';

const ApolloClientQueryProvider = ({configuration, children}) => {
import React from "react";
import PropTypes from "prop-types";
import InlContext from "../../react/core/InlContext";

const ApolloClientQueryProvider = ({ configuration, children }) => {
const { locale, dateFormat, labels } = configuration;
return (
<InlContext.Provider
value={{
locale,
labels,
dateFormat: dateFormat.toUpperCase()
dateFormat: dateFormat.toUpperCase(),
}}
>
{children}
{children}
</InlContext.Provider>
);

};

ApolloClientQueryProvider.propTypes = {
configuration: PropTypes.object.isRequired,
children: PropTypes.node.isRequired,
};



export default ApolloClientQueryProvider;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Copyright Merative US L.P. 2021
*/
import { gql, useQuery } from '@apollo/client';
import { gql, useQuery } from "@apollo/client";

const GetLogo = gql`
query GetLogo($logoId: String!) {
query GetLogo($logoId: String!) {
logo(logoId: $logoId) {
name
}
Expand All @@ -15,9 +15,6 @@ const useGetLogo = (logoIdValue) => {
return useQuery(GetLogo, {
variables: { logoId: logoIdValue },
});
}

export {
GetLogo,
useGetLogo,
};

export { GetLogo, useGetLogo };
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright Merative US L.P. 2021
*/

import { gql, useQuery } from '@apollo/client';
import { gql, useQuery } from "@apollo/client";

const GetPersons = gql`
query GetPerson {
Expand All @@ -11,15 +11,12 @@ const GetPersons = gql`
firstname
surname
age
}
}
}
`;

const useGetPersons = () => {
return useQuery(GetPersons);
}

export {
GetPersons,
useGetPersons,
};

export { GetPersons, useGetPersons };
13 changes: 4 additions & 9 deletions packages/carbon-addons-devenv/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@

import "../../custom-carbon-addons/src/scss/index.scss";
import 'regenerator-runtime/runtime';
import { renderers, sampleRenderers } from './staticExports';

import {
requireCustomCarbonAddons,
} from './dynamicExports';
import "regenerator-runtime/runtime";
import { renderers, sampleRenderers } from "./staticExports";

export default { requireCustomCarbonAddons, renderers, sampleRenderers };
import { requireCustomCarbonAddons } from "./dynamicExports";

export default { requireCustomCarbonAddons, renderers, sampleRenderers };
Loading

0 comments on commit b783db9

Please sign in to comment.