Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This plugin for Openshift installs a tab in **Projects** -> **< project name >**

To install the dynamic plugin, follow these steps:

- **Authenticate with your cluster:**, then run the following command in the directory containing your `manifest.json` file.
- **Authenticate with your cluster:**, then run the following command in the directory containing your `manifest.yaml` file.

```shell
kubectl apply -f manifest.yaml
Expand Down
48 changes: 0 additions & 48 deletions __tests__/DeploymentNetworkConsoleButton.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,6 @@ const defaultMutationMock = {
error: null
};

type ResourceOptions = { name?: string; selector?: { matchLabels?: Record<string, string> } };

const loadedResourceMock = (resourceName: string) => (options: ResourceOptions) => {
if (options.name === resourceName) {
return [{ spec: { host: 'example.com', port: { targetPort: '8080' } } }, false, undefined];
}
if (options.selector?.matchLabels?.['app.kubernetes.io/name'] === 'network-observer') {
return [{ status: { phase: 'Running' } }, false, undefined];
}

return [undefined, false, undefined];
};

const BUTTON_LABELS = {
deploy: 'Deploy the Network Console',
open: 'Open the Network Console',
Expand All @@ -72,15 +59,6 @@ describe('DeploymentNetworkConsoleButton', () => {
expect(screen.getByText(BUTTON_LABELS.deploy)).toBeInTheDocument();
});

it('renders the open and delete buttons when loaded', () => {
mockUseK8sWatchResource.mockImplementation(loadedResourceMock('network-observer'));
mockUseMutationImpl.mockReturnValue(defaultMutationMock);

render(<DeploymentNetworkConsoleButton />);
expect(screen.getByText(BUTTON_LABELS.open)).toBeInTheDocument();
expect(screen.getByText(BUTTON_LABELS.delete)).toBeInTheDocument();
});

it('calls the create mutation when the deploy button is clicked', () => {
const mutateMock = vi.fn();
mockUseK8sWatchResource.mockReturnValue([undefined, false, undefined]);
Expand All @@ -90,30 +68,4 @@ describe('DeploymentNetworkConsoleButton', () => {
fireEvent.click(screen.getByText(BUTTON_LABELS.deploy));
expect(mutateMock).toHaveBeenCalled();
});

it('calls the delete mutation when the delete button is clicked and calls onSuccess', () => {
const mutateMock = vi.fn();
let onSuccessCallback: (() => void) | undefined;

mockUseK8sWatchResource.mockImplementation(loadedResourceMock('network-observer'));
mockUseMutationImpl.mockImplementation(({ onSuccess }) => {
onSuccessCallback = onSuccess;

return { ...defaultMutationMock, mutate: mutateMock };
});

render(<DeploymentNetworkConsoleButton />);
fireEvent.click(screen.getByText(BUTTON_LABELS.delete));
expect(mutateMock).toHaveBeenCalled();

onSuccessCallback?.();
});

it('updates URL when route data changes', () => {
mockUseK8sWatchResource.mockImplementation(loadedResourceMock('network-observer'));
mockUseMutationImpl.mockReturnValue(defaultMutationMock);

render(<DeploymentNetworkConsoleButton />);
expect(screen.getByText(BUTTON_LABELS.open)).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion src/console/deployment/Deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"spec": {
"containers": [
{
"image": "quay.io/skupper/network-observer:v2-latest",
"image": "quay.io/skupper/network-observer:v2-dev",
"imagePullPolicy": "Always",
"name": "network-observer",
"args": [
Expand Down
10 changes: 6 additions & 4 deletions src/console/pages/components/DeploymentNetworkConsoleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
const watchResource = {
groupVersionKind,
namespace: NamespaceManager.getNamespace(),
isList: false,
isList: true,
name: ROUTE
};

Expand All @@ -64,7 +64,7 @@
}
};

const [data] = useK8sWatchResource<RouteResource>(watchResource);
const [route] = useK8sWatchResource<RouteResource[]>(watchResource);
const [deployment] = useK8sWatchResource<PodResource>(watchResourcePod);

const mutationCreate = useMutation({
Expand All @@ -85,13 +85,15 @@
const handleDeleteConsole = async () => {
mutationDelete.mutate();
};

useEffect(() => {
console.log('route', route);

Check warning on line 89 in src/console/pages/components/DeploymentNetworkConsoleButton.tsx

View workflow job for this annotation

GitHub Actions / build-and-deploy

Unexpected console statement
const data = route?.find((r) => r.metadata?.name?.includes(ROUTE));

if (data?.spec?.host && data?.spec?.port?.targetPort) {
const newUrl = data?.spec?.host ? `${data?.spec?.port?.targetPort}://${data?.spec?.host}` : undefined;
setUrl(newUrl);
}
}, [data?.spec?.host, data?.spec?.port?.targetPort]);
}, [route]);

const loaded = deployment?.status?.phase === POD_LOADED_STATUS && url;

Expand Down
6 changes: 3 additions & 3 deletions src/console/pages/components/forms/LinkForm/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ export const Footer: FC<FooterProps> = function ({ onCancel, onSubmit }) {
});

const handleSubmit = useCallback(() => {
if (!fileContent) {
if (!fileContent || !name) {
setValidated(t('Fill out all required fields before continuing'));

return;
}

try {
const JsonFile = parse(fileContent) as AccessGrantCrdResponse;
const { metadata, status } = JsonFile;
const { status } = JsonFile;

if (!status) {
setValidated(t('Invalid Grant format'));
Expand All @@ -77,7 +77,7 @@ export const Footer: FC<FooterProps> = function ({ onCancel, onSubmit }) {

const data: AccessTokenCrdParams = createAccessTokenRequest({
metadata: {
name: name || metadata.name
name
},
spec: {
linkCost: Number(cost),
Expand Down
10 changes: 9 additions & 1 deletion src/console/pages/components/forms/LinkForm/FormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { useCallback, FormEvent } from 'react';
import { I18nNamespace } from '@config/config';
import { Form, FormGroup, TextInput, FileUpload, DropEvent } from '@patternfly/react-core';
import { useTranslation } from 'react-i18next';
import { parse } from 'yaml';

import { useLinkForm } from './hooks/useLinkForm';
import { AccessGrantCrdResponse } from '../../../../interfaces/CRD_AccessGrant';

export const FormPage = function () {
const { t } = useTranslation(I18nNamespace);
Expand All @@ -22,7 +24,13 @@ export const FormPage = function () {

const handleFileContentChange = useCallback(
(_: DropEvent, value: string) => {
const JsonFile = parse(value) as AccessGrantCrdResponse;
const { metadata } = JsonFile;
dispatch({ type: 'SET_FILE_CONTENT', payload: value });

if (metadata?.name) {
dispatch({ type: 'SET_NAME', payload: metadata.name });
}
},
[dispatch]
);
Expand Down Expand Up @@ -59,7 +67,7 @@ export const FormPage = function () {
/>
</FormGroup>

<FormGroup label={t('Name')} fieldId="form-name-input">
<FormGroup isRequired label={t('Name')} fieldId="form-name-input">
<TextInput
isRequired
data-testid="simple-form-name-01"
Expand Down
33 changes: 24 additions & 9 deletions src/console/pages/components/forms/LinkForm/SummaryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const SummaryPage = function () {

const [isLoading, setIsLoading] = useState(true);

const { data: accessTokens } = useWatchedSkupperResource({
const { data: accessTokens, error: accessTokenError } = useWatchedSkupperResource({
kind: 'AccessToken',
isList: false,
name: name || fileName
Expand All @@ -36,11 +36,19 @@ export const SummaryPage = function () {
const hasError =
accessToken?.status?.status === 'Error' ||
(accessToken?.status?.status && link?.status?.status && link?.status?.status === 'Error');
const errorMessage = link?.status?.status || accessToken?.status?.status;
const errorMessage = link?.status?.status || accessToken?.status?.message;

useEffect(() => {
if (!hasStatus) {
return;
if (accessTokenError) {
setIsLoading(false);
setExternalLoading(false);
setValidated('Generic error');
}

if (hasError) {
setIsLoading(false);
setExternalLoading(false);
setValidated(errorMessage);
}

if (isConfigured) {
Expand All @@ -51,12 +59,19 @@ export const SummaryPage = function () {
return;
}

if (hasError) {
setIsLoading(false);
setExternalLoading(false);
setValidated(errorMessage);
if (!hasStatus) {
return;
}
}, [setValidated, setIsLoading, setExternalLoading, isConfigured, hasError, hasStatus, errorMessage]);
}, [
setValidated,
setIsLoading,
setExternalLoading,
accessTokenError,
isConfigured,
hasError,
hasStatus,
errorMessage
]);

if (isLoading) {
return (
Expand Down
Loading