Skip to content

Commit

Permalink
fix setting states (#2625)
Browse files Browse the repository at this point in the history
* fix setting states

* bump
  • Loading branch information
mrCherry97 authored Oct 24, 2023
1 parent 7a62107 commit 77fff09
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion resources/web/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: busola
image: europe-docker.pkg.dev/kyma-project/dev/busola-web:PR-2609
image: europe-docker.pkg.dev/kyma-project/dev/busola-web:PR-2625
imagePullPolicy: Always
resources:
requests:
Expand Down
20 changes: 12 additions & 8 deletions src/hooks/usePermittedUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useUrl } from 'hooks/useUrl';

import { permittedUrlsState } from 'state/permittedUrlsAtom';
import { K8sResource } from 'types';
import { useEffect } from 'react';

const DEFAULT_TIMEOUT = 3600;

Expand Down Expand Up @@ -60,19 +61,22 @@ export function usePermittedUrl(
data: Array<K8sResource> | null;
};

const permittedUrl = error ? (namespacedError ? null : namespacedUrl) : url;
useEffect(() => {
if (!loading || !resourceNamespace || !skip)
setPermittedUrls({
[url]: {
url: permittedUrl,
timestamp: new Date(),
},
});
}, [loading, skip, resourceNamespace, setPermittedUrls, url, permittedUrl]);

if (loading) return null;
if (resourceNamespace) return namespacedUrl;
if (skip) {
return permittedUrls?.[url].url;
}

const permittedUrl = error ? (namespacedError ? null : namespacedUrl) : url;
setPermittedUrls({
[url]: {
url: permittedUrl,
timestamp: new Date(),
},
});

return permittedUrl;
}
16 changes: 9 additions & 7 deletions src/shared/ResourceForm/components/ResourceForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ export function ResourceForm({
};
}

if (!resourceRef.current) {
resourceRef.current = JSON.stringify(resource);
handleSetResetFormFn(() => () => {
setResource(JSON.parse(resourceRef.current));
if (onReset) onReset();
});
}
useEffect(() => {
if (!resourceRef.current) {
resourceRef.current = JSON.stringify(resource);
handleSetResetFormFn(() => () => {
setResource(JSON.parse(resourceRef.current));
if (onReset) onReset();
});
}
}, [handleSetResetFormFn, onReset, resource, resourceRef, setResource]);

const { t } = useTranslation();
const createResource = useCreateResource({
Expand Down
2 changes: 1 addition & 1 deletion src/shared/components/ModalWithForm/ModalWithForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const ModalWithForm = ({
}) => {
const { t } = useTranslation();
const [isOpen, setOpen] = useState(alwaysOpen || false);
const [resetFormFn, setResetFormFn] = useState(() => {});
const [resetFormFn, setResetFormFn] = useState(() => () => {});

const {
isValid,
Expand Down

0 comments on commit 77fff09

Please sign in to comment.