diff --git a/libs/ansible/.npmignore b/libs/ansible/.npmignore deleted file mode 100644 index b512c09d..00000000 --- a/libs/ansible/.npmignore +++ /dev/null @@ -1 +0,0 @@ -node_modules \ No newline at end of file diff --git a/libs/ansible/package.json b/libs/ansible/package.json deleted file mode 100644 index fe72160d..00000000 --- a/libs/ansible/package.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "@flightctl/ansible", - "version": "0.0.0", - "description": "Flightctl UI for Ansible", - "repository": "https://github.com/flightctl/flightctl-ui.git", - "homepage": "https://github.com/flightctl/flightctl-ui.git", - "license": "MIT", - "files": [ - "dist", - "src" - ], - "exports": { - ".": { - "source": "./src/index.js", - "types": "./dist/src/index.d.ts", - "default": "./dist/src/index.js" - }, - "./*": { - "source": "./src/*", - "types": "./dist/src/*.d.ts", - "default": "./dist/src/*.js" - } - }, - "private": false, - "scripts": { - "prebuild": "tsc --noEmit && rimraf dist", - "build": "tsc --build && npm run copy:css", - "copy:css": "rsync -Rurv --include '*/' --include '*.css' --exclude '*' src dist", - "dev": "tsc -w", - "ts-node": "ts-node -O '{\"module\":\"commonjs\"}'" - }, - "dependencies": { - "react-router-dom": "^6.22.0" - } -} diff --git a/libs/ansible/src/components/AppContext/AppContext.tsx b/libs/ansible/src/components/AppContext/AppContext.tsx deleted file mode 100644 index c2d35440..00000000 --- a/libs/ansible/src/components/AppContext/AppContext.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import * as React from 'react'; -import { AppContext, AppContextProps, FlightCtlApp, NavLinkFC } from '@flightctl/ui-components/src/hooks/useAppContext'; -import { - Link, - NavLink, - Navigate, - Route, - Routes, - useBlocker, - useLocation, - useNavigate, - useParams, - useSearchParams, -} from 'react-router-dom'; -import { useFetch } from '../../hooks/useFetch'; - -import { appRoutes } from '../../const'; - -export const AnsibleAppContext = AppContext.Provider; - -type GetCookie = (cookieName: string) => string | undefined; - -export const useValuesAppContext = (getCookie: GetCookie, serviceUrl: string | undefined): AppContextProps => { - const fetch = useFetch(getCookie, serviceUrl); - - return { - appType: FlightCtlApp.AAP, - settings: {}, - user: '', - router: { - useNavigate, - Link, - appRoutes, - NavLink: NavLink as NavLinkFC, - Navigate, - Route, - useBlocker, - useParams, - useSearchParams, - Routes, - useLocation, - }, - i18n: { - transNamespace: 'plugin__flightctl-plugin', - }, - fetch, - }; -}; - -export const FctlAppContext = ({ - getCookie, - serviceUrl, - children, -}: React.PropsWithChildren<{ getCookie: GetCookie; serviceUrl: string | undefined }>) => { - const value = useValuesAppContext(getCookie, serviceUrl); - return {children}; -}; diff --git a/libs/ansible/src/components/ScrollablePage/ScrollablePage.css b/libs/ansible/src/components/ScrollablePage/ScrollablePage.css deleted file mode 100644 index 5e4b46dd..00000000 --- a/libs/ansible/src/components/ScrollablePage/ScrollablePage.css +++ /dev/null @@ -1,6 +0,0 @@ -.fctl-scrollable-page { - height: 100%; - overflow: auto; - display: flex; - flex-direction: column; -} diff --git a/libs/ansible/src/components/ScrollablePage/ScrollablePage.tsx b/libs/ansible/src/components/ScrollablePage/ScrollablePage.tsx deleted file mode 100644 index 96818cab..00000000 --- a/libs/ansible/src/components/ScrollablePage/ScrollablePage.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import * as React from 'react'; - -import './ScrollablePage.css'; - -const ScrollablePage = ({ children }: React.PropsWithChildren) => { - return
{children}
; -}; - -export default ScrollablePage; diff --git a/libs/ansible/src/const.ts b/libs/ansible/src/const.ts deleted file mode 100644 index e2513483..00000000 --- a/libs/ansible/src/const.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { ROUTE } from '@flightctl/ui-components/src/hooks/useNavigate'; - -export const appRoutes = { - [ROUTE.ROOT]: '/edge/overview', - [ROUTE.FLEETS]: '/edge/fleets', - [ROUTE.FLEET_DETAILS]: '/edge/fleets', - [ROUTE.FLEET_CREATE]: '/edge/fleets/create', - [ROUTE.FLEET_EDIT]: '/edge/fleets/edit', - [ROUTE.FLEET_IMPORT]: '/edge/fleets/import', - [ROUTE.DEVICES]: '/edge/devices', - [ROUTE.DEVICE_DETAILS]: '/edge/devices', - [ROUTE.DEVICE_EDIT]: '/edge/devices/edit', - [ROUTE.REPO_CREATE]: '/edge/repositories/create', - [ROUTE.REPO_EDIT]: '/edge/repositories/edit', - [ROUTE.REPO_DETAILS]: '/edge/repositories', - [ROUTE.REPOSITORIES]: '/edge/repositories', - [ROUTE.RESOURCE_SYNC_DETAILS]: '/edge/resourcesyncs', - [ROUTE.ENROLLMENT_REQUESTS]: '/edge/enrollmentrequests', - [ROUTE.ENROLLMENT_REQUEST_DETAILS]: '/edge/enrollmentrequests', - [ROUTE.IMAGE_BUILDS]: '/edge/imagebuilds', - [ROUTE.IMAGE_BUILD_CREATE]: '/edge/imagebuilds/create', - [ROUTE.IMAGE_BUILD_DETAILS]: '/edge/imagebuilds', - [ROUTE.IMAGE_BUILD_EDIT]: '/edge/imagebuilds/edit', - // Unimplemented UI routes - [ROUTE.COMMAND_LINE_TOOLS]: '/', - [ROUTE.AUTH_PROVIDERS]: '/', - [ROUTE.AUTH_PROVIDER_CREATE]: '/', - [ROUTE.AUTH_PROVIDER_EDIT]: '/', - [ROUTE.AUTH_PROVIDER_DETAILS]: '/', -}; diff --git a/libs/ansible/src/hooks/useFctlNavigation.tsx b/libs/ansible/src/hooks/useFctlNavigation.tsx deleted file mode 100644 index da3859d3..00000000 --- a/libs/ansible/src/hooks/useFctlNavigation.tsx +++ /dev/null @@ -1,207 +0,0 @@ -import * as React from 'react'; -import { ROUTE } from '@flightctl/ui-components/src/hooks/useNavigate'; - -import { appRoutes } from '../const'; -import ScrollablePage from '../components/ScrollablePage/ScrollablePage'; - -const EnrollmentRequestDetails = React.lazy( - () => - import( - '@flightctl/ui-components/src/components/EnrollmentRequest/EnrollmentRequestDetails/EnrollmentRequestDetails' - ), -); -const DevicesPage = React.lazy(() => import('@flightctl/ui-components/src/components/Device/DevicesPage/DevicesPage')); -const DeviceDetails = React.lazy( - () => import('@flightctl/ui-components/src/components/Device/DeviceDetails/DeviceDetailsPage'), -); -const EditDeviceWizard = React.lazy( - () => import('@flightctl/ui-components/src/components/Device/EditDeviceWizard/EditDeviceWizard'), -); -const CreateRepository = React.lazy( - () => import('@flightctl/ui-components/src/components/Repository/CreateRepository/CreateRepository'), -); -const RepositoryList = React.lazy(() => import('@flightctl/ui-components/src/components/Repository/RepositoryList')); -const RepositoryDetails = React.lazy( - () => import('@flightctl/ui-components/src/components/Repository/RepositoryDetails/RepositoryDetails'), -); -const ResourceSyncToRepository = React.lazy( - () => import('@flightctl/ui-components/src/components/ResourceSync/ResourceSyncToRepository'), -); - -const ImportFleetWizard = React.lazy( - () => import('@flightctl/ui-components/src/components/Fleet/ImportFleetWizard/ImportFleetWizard'), -); -const CreateFleetWizard = React.lazy( - () => import('@flightctl/ui-components/src/components/Fleet/CreateFleet/CreateFleetWizard'), -); - -const FleetsPage = React.lazy(() => import('@flightctl/ui-components/src/components/Fleet/FleetsPage')); -const FleetDetails = React.lazy( - () => import('@flightctl/ui-components/src/components/Fleet/FleetDetails/FleetDetailsPage'), -); - -const OverviewPage = React.lazy(() => import('@flightctl/ui-components/src/components/OverviewPage/OverviewPage')); - -const getNavRoute = (route: string) => route.replace('/edge/', ''); - -export const useFctlNavigation = () => { - const navigationItems = React.useMemo( - () => [ - { - id: 'overview', - label: 'Overview', - path: getNavRoute(appRoutes[ROUTE.ROOT]), - element: ( - - - - ), - }, - { - id: 'fleets', - label: 'Fleets', - path: 'fleets', - children: [ - { - path: '', - element: ( - - - - ), - }, - { - id: 'fleet-details', - path: ':fleetId', - element: ( - - - - ), - }, - { - id: 'create', - path: 'create', - element: ( - - - - ), - }, - { - id: 'import', - path: 'import', - element: ( - - - - ), - }, - { - id: 'edit', - path: 'edit/:fleetId', - element: ( - - - - ), - }, - ], - }, - { - id: 'devices', - label: 'Devices', - path: getNavRoute(appRoutes[ROUTE.DEVICES]), - children: [ - { - path: '', - element: ( - - - - ), - }, - { - id: 'details', - path: ':deviceId/*', - element: ( - - - - ), - }, - { - id: 'edit', - path: 'edit/:deviceId', - element: ( - - - - ), - }, - ], - }, - { - id: 'repositories', - label: 'Repositories', - path: getNavRoute(appRoutes[ROUTE.REPOSITORIES]), - children: [ - { - path: '', - element: ( - - - - ), - }, - { - id: 'create', - path: 'create', - element: ( - - - - ), - }, - { - id: 'edit', - path: 'edit/:repositoryId', - element: ( - - - - ), - }, - { - id: 'details', - path: ':repositoryId/*', - element: ( - - - - ), - }, - ], - }, - { - path: 'resourcesyncs/:rsId', - // Fetches the RS from its ID and redirects to the repository page - element: ( - - - - ), - }, - { - path: 'enrollmentrequests/:enrollmentRequestId', - element: ( - - - - ), - }, - ], - [], - ); - return navigationItems; -}; diff --git a/libs/ansible/src/hooks/useFetch.ts b/libs/ansible/src/hooks/useFetch.ts deleted file mode 100644 index 0e039fc1..00000000 --- a/libs/ansible/src/hooks/useFetch.ts +++ /dev/null @@ -1,71 +0,0 @@ -import * as React from 'react'; -import { deleteData, fetchData, fetchUiProxy, patchData, postData, putData } from '../utils/apiCalls'; -import { PatchRequest } from '@flightctl/types'; - -export const useFetch = (getCookie: (name: string) => string | undefined, serviceUrl = '') => { - const applyHeaders = React.useCallback( - (options: RequestInit) => { - const token = getCookie('csrftoken'); - if (token) { - const headers = new Headers(options.headers || {}); - headers.set('X-CSRFToken', token); - return { - ...options, - headers, - }; - } - return options; - }, - [getCookie], - ); - - const get = React.useCallback( - async (kind: string, abortSignal?: AbortSignal): Promise => fetchData(kind, serviceUrl, abortSignal), - [serviceUrl], - ); - - const post = React.useCallback( - async (kind: string, data: TRequest): Promise => - postData(kind, data, serviceUrl, applyHeaders), - [serviceUrl, applyHeaders], - ); - - const put = React.useCallback( - async (kind: string, data: TRequest): Promise => putData(kind, data, serviceUrl, applyHeaders), - [serviceUrl, applyHeaders], - ); - - const remove = React.useCallback( - async (kind: string, abortSignal?: AbortSignal): Promise => - deleteData(kind, serviceUrl, applyHeaders, abortSignal), - [serviceUrl, applyHeaders], - ); - - const patch = React.useCallback( - async (kind: string, obj: PatchRequest, abortSignal?: AbortSignal): Promise => - patchData(kind, obj, serviceUrl, applyHeaders, abortSignal), - [serviceUrl, applyHeaders], - ); - - const getWsEndpoint = React.useCallback( - (deviceId: string) => `${serviceUrl}/ws/v1/devices/${deviceId}/console`, - [serviceUrl], - ); - - const proxyFetch = React.useCallback( - async (endpoint: string, requestInit: RequestInit): Promise => { - return fetchUiProxy(endpoint, serviceUrl, applyHeaders, requestInit); - }, - [serviceUrl, applyHeaders], - ); - - return { - getWsEndpoint, - get, - post, - put, - remove, - patch, - proxyFetch, - }; -}; diff --git a/libs/ansible/src/index.ts b/libs/ansible/src/index.ts deleted file mode 100644 index 757b3b31..00000000 --- a/libs/ansible/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { FctlAppContext } from './components/AppContext/AppContext'; -import DevicesPage from '@flightctl/ui-components/src/components/Device/DevicesPage/DevicesPage'; - -export { FctlAppContext, DevicesPage }; diff --git a/libs/ansible/src/utils/apiCalls.ts b/libs/ansible/src/utils/apiCalls.ts deleted file mode 100644 index 0cc42a87..00000000 --- a/libs/ansible/src/utils/apiCalls.ts +++ /dev/null @@ -1,124 +0,0 @@ -/* eslint-disable no-console */ - -import { PatchRequest } from '@flightctl/types'; -import { getErrorMsgFromApiResponse } from '@flightctl/ui-components/src/utils/apiCalls'; - -const handleApiJSONResponse = async (response: Response): Promise => { - if (response.ok) { - const data = (await response.json()) as R; - return data; - } - - if (response.status === 404) { - // We skip the response message for 404 errors, which is { message: '' } - throw new Error(`Error ${response.status}: ${response.statusText}`); - } - - throw new Error(await getErrorMsgFromApiResponse(response)); -}; - -export const fetchUiProxy = async ( - endpoint: string, - serviceUrl: string, - applyOptions: (options: RequestInit) => RequestInit, - requestInit: RequestInit, -): Promise => { - const options = applyOptions(requestInit); - - return await fetch(`${serviceUrl}/api/${endpoint}`, options); -}; - -const putOrPostData = async ( - kind: string, - data: TRequest, - serviceUrl: string, - applyOptions: (options: RequestInit) => RequestInit, - method: 'PUT' | 'POST', -): Promise => { - const options: RequestInit = { - headers: { - 'Content-Type': 'application/json', - }, - method, - body: JSON.stringify(data), - }; - const updatedOptions = applyOptions(options); - try { - const response = await fetch(`${serviceUrl}/api/v1/${kind}`, updatedOptions); - return handleApiJSONResponse(response); - } catch (error) { - console.error(`Error making ${method} request for ${kind}:`, error); - throw error; - } -}; - -export const postData = async ( - kind: string, - data: TRequest, - serviceUrl: string, - applyOptions: (options: RequestInit) => RequestInit, -): Promise => putOrPostData(kind, data, serviceUrl, applyOptions, 'POST'); - -export const putData = async ( - kind: string, - data: TRequest, - serviceUrl: string, - applyOptions: (options: RequestInit) => RequestInit, -): Promise => putOrPostData(kind, data, serviceUrl, applyOptions, 'PUT'); - -export const deleteData = async ( - kind: string, - serviceUrl: string, - applyOptions: (options: RequestInit) => RequestInit, - abortSignal?: AbortSignal, -): Promise => { - const options: RequestInit = { - method: 'DELETE', - signal: abortSignal, - }; - const updatedOptions = applyOptions(options); - try { - const response = await fetch(`${serviceUrl}/api/v1/${kind}`, updatedOptions); - return handleApiJSONResponse(response); - } catch (error) { - console.error('Error making DELETE request:', error); - throw error; - } -}; - -export const patchData = async ( - kind: string, - data: PatchRequest, - serviceUrl: string, - applyOptions: (options: RequestInit) => RequestInit, - abortSignal?: AbortSignal, -): Promise => { - const options: RequestInit = { - headers: { - 'Content-Type': 'application/json-patch+json', - }, - method: 'PATCH', - body: JSON.stringify(data), - signal: abortSignal, - }; - const updatedOptions = applyOptions(options); - try { - const response = await fetch(`${serviceUrl}/api/v1/${kind}`, updatedOptions); - return handleApiJSONResponse(response); - } catch (error) { - console.error('Error making PATCH request:', error); - throw error; - } -}; - -export const fetchData = async (kind: string, serviceUrl: string, abortSignal?: AbortSignal): Promise => { - try { - const response = await fetch(`${serviceUrl}/api/v1/${kind}`, { - signal: abortSignal, - }); - return handleApiJSONResponse(response); - } catch (error) { - console.error('Error making GET request:', error); - throw error; - } -}; diff --git a/libs/ansible/tsconfig.json b/libs/ansible/tsconfig.json deleted file mode 100644 index c7ef4314..00000000 --- a/libs/ansible/tsconfig.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "baseUrl": ".", - "rootDir": ".", - "outDir": "dist", - "module": "CommonJS", - "target": "es2015", - "lib": ["es6", "dom"], - "sourceMap": true, - "jsx": "react", - "moduleResolution": "node", - "forceConsistentCasingInFileNames": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "noImplicitAny": false, - "allowJs": true, - "useUnknownInCatchVariables": false, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "importHelpers": true, - "skipLibCheck": true, - "declaration": true, - "declarationMap": true, - }, - "include": ["**/*.ts", "**/*.tsx", "**/*.jsx", "**/*.js", "**/*.json"], - "exclude": ["node_modules", "dist"], -} diff --git a/package-lock.json b/package-lock.json index 35006f46..d938be82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,6 @@ "./libs/ui-components", "./libs/types", "./libs/i18n", - "./libs/ansible", "./apps/ocp-plugin", "./apps/standalone" ], @@ -246,49 +245,12 @@ "libs/ansible": { "name": "@flightctl/ansible", "version": "0.0.0", + "extraneous": true, "license": "MIT", "dependencies": { "react-router-dom": "^6.22.0" } }, - "libs/ansible/node_modules/@remix-run/router": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.21.0.tgz", - "integrity": "sha512-xfSkCAchbdG5PnbrKqFWwia4Bi61nH+wm8wLEqfHDyp7Y3dZzgqS2itV8i4gAq9pC2HsTpwyBC6Ds8VHZ96JlA==", - "engines": { - "node": ">=14.0.0" - } - }, - "libs/ansible/node_modules/react-router": { - "version": "6.28.1", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.28.1.tgz", - "integrity": "sha512-2omQTA3rkMljmrvvo6WtewGdVh45SpL9hGiCI9uUrwGGfNFDIvGK4gYJsKlJoNVi6AQZcopSCballL+QGOm7fA==", - "dependencies": { - "@remix-run/router": "1.21.0" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "react": ">=16.8" - } - }, - "libs/ansible/node_modules/react-router-dom": { - "version": "6.28.1", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.28.1.tgz", - "integrity": "sha512-YraE27C/RdjcZwl5UCqF/ffXnZDxpJdk9Q6jw38SZHjXs7NNdpViq2l2c7fO7+4uWaEfcwfGCv3RSg4e1By/fQ==", - "dependencies": { - "@remix-run/router": "1.21.0", - "react-router": "6.28.1" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "react": ">=16.8", - "react-dom": ">=16.8" - } - }, "libs/cypress": { "name": "@flightctl/ui-tests-cypress", "version": "0.0.0", @@ -2587,10 +2549,6 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, - "node_modules/@flightctl/ansible": { - "resolved": "libs/ansible", - "link": true - }, "node_modules/@flightctl/i18n": { "resolved": "libs/i18n", "link": true diff --git a/package.json b/package.json index c7601e92..3de98a02 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "./libs/ui-components", "./libs/types", "./libs/i18n", - "./libs/ansible", "./apps/ocp-plugin", "./apps/standalone" ], @@ -21,7 +20,7 @@ "dev:kind": "npm run -w @flightctl/standalone dev:kind", "build": "npm run -w @flightctl/standalone build", "build:ocp": "npm run -w @flightctl/ocp-plugin build", - "build:libs": "npm run -w @flightctl/types build && npm run -w @flightctl/ui-components build && npm run -w @flightctl/ansible build", + "build:libs": "npm run -w @flightctl/types build && npm run -w @flightctl/ui-components build", "gen-types": "npm run -w @flightctl/types gen-types", "integration-tests:ci": "npm run build:libs && npm run -w @flightctl/standalone start-prod", "integration-tests:open": "cd libs/cypress && cypress open --config-file cypress.config.ts",