Skip to content
Snippets Groups Projects
Commit eca714b2 authored by Max Frederiksen's avatar Max Frederiksen Committed by Max Frederiksen
Browse files

Remove legacy APIProvider (used for useAPIMethod etc)

parent 4e420a35
No related branches found
No related tags found
2 merge requests!612Release 5.0.0,!590CE-3429: Convert to typescript
......@@ -23,7 +23,6 @@ import { TestErrorView } from "./views/TestErrorView";
import { applicationTitle } from "./components/common/Helper";
import { CreateIOCAccessControl } from "./views/IOC/CreateIOCAccessControl";
import { UserDetailsAccessControl } from "./views/UserPage/UserDetailsAccessControl";
import { DeployAPIProvider } from "./api/APIProvider";
import { ReduxProvider } from "./store/ReduxProvider";
import env from "./config/env";
......@@ -43,88 +42,86 @@ function App() {
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>
<CssBaseline />
<DeployAPIProvider>
<UserProvider>
<TokenRenew />
<NavigationMenu>
<Routes>
<Route
path="/"
element={<Navigate to="/iocs" />}
exact
/>
<Route
path="/records"
element={<RecordListView />}
exact
/>
<Route
path="/records/:name"
element={<RecordDetailsView />}
exact
/>
<Route
path="/iocs/create"
element={<CreateIOCAccessControl />}
exact
/>
<Route
path="/iocs/:id"
element={<IOCDetailsAccessControl exact />}
/>
<Route
path="/iocs"
element={<IOCListView />}
exact
/>
<Route
path="/jobs"
element={<JobLogAccessControl />}
exact
/>
<Route
path="/jobs/:id"
element={<JobDetailsAccessControl exact />}
/>
<Route
path="/hosts/:id"
element={<HostDetailsAccessControl />}
exact
/>
<Route
path="/hosts"
element={<HostListView />}
exact
/>
<Route
path="/help"
element={<HelpView />}
exact
/>
<Route
path="/login"
element={<LoginView />}
exact
/>
<Route
path="/error-test"
element={<TestErrorView />}
exact
/>
<Route
path="/user/:userName"
element={<UserDetailsAccessControl />}
exact
/>
<Route
path="*"
element={<NotFoundView />}
exact
/>
</Routes>
</NavigationMenu>
</UserProvider>
</DeployAPIProvider>
<UserProvider>
<TokenRenew />
<NavigationMenu>
<Routes>
<Route
path="/"
element={<Navigate to="/iocs" />}
exact
/>
<Route
path="/records"
element={<RecordListView />}
exact
/>
<Route
path="/records/:name"
element={<RecordDetailsView />}
exact
/>
<Route
path="/iocs/create"
element={<CreateIOCAccessControl />}
exact
/>
<Route
path="/iocs/:id"
element={<IOCDetailsAccessControl exact />}
/>
<Route
path="/iocs"
element={<IOCListView />}
exact
/>
<Route
path="/jobs"
element={<JobLogAccessControl />}
exact
/>
<Route
path="/jobs/:id"
element={<JobDetailsAccessControl exact />}
/>
<Route
path="/hosts/:id"
element={<HostDetailsAccessControl />}
exact
/>
<Route
path="/hosts"
element={<HostListView />}
exact
/>
<Route
path="/help"
element={<HelpView />}
exact
/>
<Route
path="/login"
element={<LoginView />}
exact
/>
<Route
path="/error-test"
element={<TestErrorView />}
exact
/>
<Route
path="/user/:userName"
element={<UserDetailsAccessControl />}
exact
/>
<Route
path="*"
element={<NotFoundView />}
exact
/>
</Routes>
</NavigationMenu>
</UserProvider>
</ThemeProvider>
</StyledEngineProvider>
</SnackbarProvider>
......
import { useContext } from "react";
import { SnackbarProvider } from "notistack";
import { apiContext } from "./DeployApi";
import { DeployAPIProvider } from "./APIProvider";
function AppHarness({ children }) {
return (
<SnackbarProvider
preventDuplicate
maxSnack="5"
>
{children}
</SnackbarProvider>
);
}
function mountIntoHarness(children) {
cy.mount(<AppHarness>{children}</AppHarness>);
}
function checkAPIDisplayed() {
cy.get("#api").contains("CE deploy & monitor backend");
}
function DisplayAPISpecification({ api }) {
return <pre id="api">{JSON.stringify(api, null, 2)}</pre>;
}
context("API", () => {
describe("ApiProvider", () => {
it("makes the API available via context", () => {
const Glue = () => {
const api = useContext(apiContext);
return <DisplayAPISpecification api={api} />;
};
mountIntoHarness(
<DeployAPIProvider>
<Glue />
</DeployAPIProvider>
);
checkAPIDisplayed();
});
});
});
/**
* DeployAPIProvider
* Provide CE Deploy Backend API
*/
import { APIProvider } from "@ess-ics/ce-ui-common";
import { node, arrayOf, oneOfType } from "prop-types";
import { apiContext } from "./DeployApi";
import env from "../config/env";
const propTypes = {
/** Elements used as children */
children: oneOfType([
/** Array of elements. */
arrayOf(node),
/** One or more elements without array. */
node
])
};
const apiOptions = {
url: `${env.API_BASE_ENDPOINT}`,
server: `${env.SERVER_ADDRESS}`,
// Workaround for https://github.com/swagger-api/swagger-js/issues/1022
// Empty body POST requests are sent with Content-Type text/plaintext
// instead of no content type, or application/json
requestInterceptor: (req) => {
req.headers["Content-Type"] = "application/json";
req.headers.accept = "application/json";
window.req = req;
return req;
},
responseInterceptor: (res) => {
return res;
}
};
export function DeployAPIProvider({ children }) {
return (
<APIProvider
context={apiContext}
options={apiOptions}
>
{children}
</APIProvider>
);
}
DeployAPIProvider.propTypes = propTypes;
import { createContext } from "react";
export const apiContext = createContext(null);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment