diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a1bdb192..ff6f1559 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -21,6 +21,9 @@ jobs: - name: Install dependencies run: npm ci + - name: Lint + run: npm run lint + - name: Run Vitest Tests run: npm run test:vi diff --git a/src/components/ComponentsSelection/ComponentsSelection.tsx b/src/components/ComponentsSelection/ComponentsSelection.tsx index 99cb29b6..602602e3 100644 --- a/src/components/ComponentsSelection/ComponentsSelection.tsx +++ b/src/components/ComponentsSelection/ComponentsSelection.tsx @@ -28,23 +28,15 @@ export interface ComponentsSelectionProps { setComponentsList: (components: ComponentsListItem[]) => void; } -export const ComponentsSelection: React.FC = ({ - componentsList, - setComponentsList, -}) => { +export const ComponentsSelection: React.FC = ({ componentsList, setComponentsList }) => { const [searchTerm, setSearchTerm] = useState(''); const { t } = useTranslation(); - const selectedComponents = useMemo( - () => getSelectedComponents(componentsList), - [componentsList], - ); + const selectedComponents = useMemo(() => getSelectedComponents(componentsList), [componentsList]); const searchResults = useMemo(() => { const lowerSearch = searchTerm.toLowerCase(); - return componentsList.filter(({ name }) => - name.toLowerCase().includes(lowerSearch), - ); + return componentsList.filter(({ name }) => name.toLowerCase().includes(lowerSearch)); }, [componentsList, searchTerm]); const handleSelectionChange = useCallback( @@ -53,9 +45,7 @@ export const ComponentsSelection: React.FC = ({ if (!id) return; setComponentsList( componentsList.map((component) => - component.name === id - ? { ...component, isSelected: !component.isSelected } - : component, + component.name === id ? { ...component, isSelected: !component.isSelected } : component, ), ); }, @@ -74,9 +64,7 @@ export const ComponentsSelection: React.FC = ({ if (!name) return; setComponentsList( componentsList.map((component) => - component.name === name - ? { ...component, selectedVersion: version || '' } - : component, + component.name === name ? { ...component, selectedVersion: version || '' } : component, ), ); }, @@ -86,9 +74,7 @@ export const ComponentsSelection: React.FC = ({ const isProviderDisabled = useCallback( (component: ComponentsListItem) => { if (!component.name?.includes('provider')) return false; - const crossplane = componentsList.find( - ({ name }) => name === 'crossplane', - ); + const crossplane = componentsList.find(({ name }) => name === 'crossplane'); return crossplane?.isSelected === false; }, [componentsList], @@ -130,11 +116,7 @@ export const ComponentsSelection: React.FC = ({ aria-label={component.name} onChange={handleSelectionChange} /> - + {/* TODO: Add documentation link */} {component.documentationUrl && ( + diff --git a/src/components/ControlPlane/ManagedResources.tsx b/src/components/ControlPlane/ManagedResources.tsx index 8531f21a..851b488d 100644 --- a/src/components/ControlPlane/ManagedResources.tsx +++ b/src/components/ControlPlane/ManagedResources.tsx @@ -5,7 +5,7 @@ import { AnalyticalTableScaleWidthMode, Title, } from '@ui5/webcomponents-react'; -import useResource from '../../lib/api/useApiResource'; +import { useApiResource } from '../../lib/api/useApiResource'; import { ManagedResourcesRequest } from '../../lib/api/types/crossplane/listManagedResources'; import { timeAgo } from '../../utils/i18n/timeAgo'; import IllustratedError from '../Shared/IllustratedError'; @@ -44,7 +44,7 @@ export function ManagedResources() { data: managedResources, error, isLoading, - } = useResource(ManagedResourcesRequest, { + } = useApiResource(ManagedResourcesRequest, { refreshInterval: resourcesInterval, // Resources are quite expensive to fetch, so we refresh every 30 seconds }); @@ -102,7 +102,7 @@ export function ManagedResources() { ) : undefined, }, ], - [], + [t], ); const rows: ResourceRow[] = @@ -110,12 +110,8 @@ export function ManagedResources() { ?.filter((managedResource) => managedResource.items) .flatMap((managedResource) => managedResource.items?.map((item) => { - const conditionSynced = item.status?.conditions?.find( - (condition) => condition.type === 'Synced', - ); - const conditionReady = item.status?.conditions?.find( - (condition) => condition.type === 'Ready', - ); + const conditionSynced = item.status?.conditions?.find((condition) => condition.type === 'Synced'); + const conditionReady = item.status?.conditions?.find((condition) => condition.type === 'Ready'); return { kind: item.kind, diff --git a/src/components/ControlPlane/Providers.tsx b/src/components/ControlPlane/Providers.tsx index d9e08add..353fb017 100644 --- a/src/components/ControlPlane/Providers.tsx +++ b/src/components/ControlPlane/Providers.tsx @@ -7,7 +7,7 @@ import { Title, } from '@ui5/webcomponents-react'; -import useResource from '../../lib/api/useApiResource'; +import { useApiResource } from '../../lib/api/useApiResource'; import IllustratedError from '../Shared/IllustratedError'; import { ProvidersListRequest } from '../../lib/api/types/crossplane/listProviders'; import { resourcesInterval } from '../../lib/shared/constants'; @@ -46,7 +46,7 @@ export function Providers() { data: providers, error, isLoading, - } = useResource(ProvidersListRequest, { + } = useApiResource(ProvidersListRequest, { refreshInterval: resourcesInterval, }); @@ -75,9 +75,7 @@ export function Providers() { cellData.cell.row.original?.installed != null ? ( ) : null, }, @@ -112,12 +110,8 @@ export function Providers() { const rows: ProvidersRow[] = providers?.items?.map((item) => { - const installed = item.status?.conditions?.find( - (condition) => condition.type === 'Installed', - ); - const healthy = item.status?.conditions?.find( - (condition) => condition.type === 'Healthy', - ); + const installed = item.status?.conditions?.find((condition) => condition.type === 'Installed'); + const healthy = item.status?.conditions?.find((condition) => condition.type === 'Healthy'); return { name: item.metadata.name, created: timeAgo.format(new Date(item.metadata.creationTimestamp)), diff --git a/src/components/ControlPlane/ProvidersConfig.tsx b/src/components/ControlPlane/ProvidersConfig.tsx index a888220b..d8022962 100644 --- a/src/components/ControlPlane/ProvidersConfig.tsx +++ b/src/components/ControlPlane/ProvidersConfig.tsx @@ -79,13 +79,11 @@ export function ProvidersConfig() { disableFilters: true, Cell: (cellData: CellData) => cellData.cell.row.original?.resource ? ( - + ) : undefined, }, ], - [], + [t], ); return ( diff --git a/src/components/ControlPlanes/ConnectButton.tsx b/src/components/ControlPlanes/ConnectButton.tsx index a4f5f4f5..b31cf04e 100644 --- a/src/components/ControlPlanes/ConnectButton.tsx +++ b/src/components/ControlPlanes/ConnectButton.tsx @@ -6,7 +6,7 @@ import { GetKubeconfig } from '../../lib/api/types/crate/getKubeconfig.ts'; import yaml from 'js-yaml'; import { useRef, useState } from 'react'; import { DownloadKubeconfig } from './CopyKubeconfigButton.tsx'; -import useResource from '../../lib/api/useApiResource.ts'; +import { useApiResource } from '../../lib/api/useApiResource.ts'; import { extractWorkspaceNameFromNamespace } from '../../utils/index.ts'; import { useTranslation } from 'react-i18next'; @@ -36,9 +36,7 @@ export default function ConnectButton(props: Props) { const { t } = useTranslation(); - const res = useResource( - GetKubeconfig(props.secretKey, props.secretName, props.namespace), - ); + const res = useApiResource(GetKubeconfig(props.secretKey, props.secretName, props.namespace)); if (res.isLoading) { return <>; } @@ -72,12 +70,7 @@ export default function ConnectButton(props: Props) { return (
- ))} - +
); diff --git a/src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCard.tsx b/src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCard.tsx index 9809d8c4..19de48d8 100644 --- a/src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCard.tsx +++ b/src/components/ControlPlanes/ControlPlaneCard/ControlPlaneCard.tsx @@ -12,14 +12,9 @@ import { DeleteConfirmationDialog } from '../../Dialogs/DeleteConfirmationDialog import MCPHealthPopoverButton from '../../ControlPlane/MCPHealthPopoverButton.tsx'; import styles from './ControlPlaneCard.module.css'; import { KubectlDeleteMcp } from '../../Dialogs/KubectlCommandInfo/Controllers/KubectlDeleteMcp.tsx'; -import { - ListControlPlanesType, - ReadyStatus, -} from '../../../lib/api/types/crate/controlPlanes.ts'; +import { ListControlPlanesType, ReadyStatus } from '../../../lib/api/types/crate/controlPlanes.ts'; import { ListWorkspacesType } from '../../../lib/api/types/crate/listWorkspaces.ts'; -import { - useApiResourceMutation, -} from '../../../lib/api/useApiResource.ts'; +import { useApiResourceMutation } from '../../../lib/api/useApiResource.ts'; import { DeleteMCPResource, DeleteMCPType, @@ -38,40 +33,26 @@ interface Props { projectName: string; } -export function ControlPlaneCard({ - controlPlane, - workspace, - projectName, -}: Props) { +export function ControlPlaneCard({ controlPlane, workspace, projectName }: Props) { const [dialogDeleteMcpIsOpen, setDialogDeleteMcpIsOpen] = useState(false); const toast = useToast(); const { t } = useTranslation(); const { trigger: patchTrigger } = useApiResourceMutation( - PatchMCPResourceForDeletion( - controlPlane.metadata.namespace, - controlPlane.metadata.name, - ), + PatchMCPResourceForDeletion(controlPlane.metadata.namespace, controlPlane.metadata.name), ); const { trigger: deleteTrigger } = useApiResourceMutation( - DeleteMCPResource( - controlPlane.metadata.namespace, - controlPlane.metadata.name, - ), + DeleteMCPResource(controlPlane.metadata.namespace, controlPlane.metadata.name), ); const name = controlPlane.metadata.name; const namespace = controlPlane.metadata.namespace; - const isSystemIdentityProviderEnabled = - Boolean(controlPlane.spec?.authentication?.enableSystemIdentityProvider); + const isSystemIdentityProviderEnabled = Boolean(controlPlane.spec?.authentication?.enableSystemIdentityProvider); - const isConnectButtonEnabled = - canConnectToMCP(controlPlane) && - isSystemIdentityProviderEnabled + const isConnectButtonEnabled = canConnectToMCP(controlPlane) && isSystemIdentityProviderEnabled; - const showWarningBecauseOfDisabledSystemIdentityProvider = - !isSystemIdentityProviderEnabled; + const showWarningBecauseOfDisabledSystemIdentityProvider = !isSystemIdentityProviderEnabled; return ( <> @@ -92,28 +73,16 @@ export function ControlPlaneCard({ />
- +