Skip to content

Commit

Permalink
fix: discard changes and unnecessary scroll in Modules form (#3048)
Browse files Browse the repository at this point in the history
* fix form height & discard

* remove unused imports

* add comment

* fix comment
  • Loading branch information
OliwiaGowor authored Jul 10, 2024
1 parent 135b992 commit 3561fa4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/components/KymaModules/KymaModulesCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState } from 'react';
import { useTranslation } from 'react-i18next';

import { ResourceForm } from 'shared/ResourceForm';
import './KymaModulesCreate.scss';

export default function KymaModulesCreate({ resource, ...props }) {
const { t } = useTranslation();
Expand All @@ -13,6 +14,7 @@ export default function KymaModulesCreate({ resource, ...props }) {
return (
<ResourceForm
{...props}
className="kyma-modules-create"
pluralKind="kymas"
singularName={t('kyma-modules.kyma')}
resource={kymaResource}
Expand Down
20 changes: 20 additions & 0 deletions src/components/KymaModules/KymaModulesCreate.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.kyma-modules {
.edit-form {
min-height: calc(100vh - 17rem);
}

.kyma-modules-create {
.resource-form--panel,
.resource-form--panel::part(content) {
min-height: calc(100vh - 20rem);
}

.resource-form--panel {
margin-bottom: 0 !important;
}

.yaml-form {
height: calc(100vh - 20rem);
}
}
}
5 changes: 5 additions & 0 deletions src/components/KymaModules/KymaModulesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { cloneDeep } from 'lodash';
import { useCreateResource } from 'shared/ResourceForm/useCreateResource';
import { useNotification } from 'shared/contexts/NotificationContext';
import { PopoverBadge } from 'shared/components/PopoverBadge/PopoverBadge';
import { isFormOpenState } from 'state/formOpenAtom';

export function KymaModulesList(props) {
const { t } = useTranslation();
Expand All @@ -46,6 +47,7 @@ export function KymaModulesList(props) {
setShowReleaseChannelTitleDescription,
] = useState(false);
const setLayoutColumn = useSetRecoilState(columnLayoutState);
const setIsFormOpen = useSetRecoilState(isFormOpenState);
const { clusterUrl } = useUrl();

const { data: kymaResources, loading: kymaResourcesLoading } = useGet(
Expand Down Expand Up @@ -98,6 +100,8 @@ export function KymaModulesList(props) {
resourceUrl: resourceUrl,
},
});

setIsFormOpen({ formOpen: true });
};

const ModulesList = resource => {
Expand Down Expand Up @@ -407,6 +411,7 @@ export function KymaModulesList(props) {

return (
<ResourceDetails
className="kyma-modules"
layoutNumber="StartColumn"
windowTitle={t('kyma-modules.title')}
headerContent={
Expand Down
4 changes: 2 additions & 2 deletions src/shared/ResourceForm/components/ResourceForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export function ResourceForm({
const [editorError, setEditorError] = useState(null);

useEffect(() => {
if (leavingForm) {
// Check if form is opened based on width
if (leavingForm && formElementRef.current?.clientWidth > 0) {
if (
JSON.stringify(excludeStatus(resource)) !==
JSON.stringify(excludeStatus(initialResource)) ||
Expand Down Expand Up @@ -324,5 +325,4 @@ export function ResourceForm({
{createPortal(<UnsavedMessageBox />, document.body)}
</section>
);
// }
}
29 changes: 16 additions & 13 deletions src/shared/components/DynamicPageComponent/DynamicPageComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const DynamicPageComponent = ({
showYamlTab,
protectedResource,
protectedResourceWarning,
className,
}) => {
const [showTitleDescription, setShowTitleDescription] = useState(false);
const [layoutColumn, setLayoutColumn] = useRecoilState(columnLayoutState);
Expand Down Expand Up @@ -241,7 +242,7 @@ export const DynamicPageComponent = ({
return (
<ObjectPage
mode="IconTabBar"
className="page-header"
className={`page-header ${className}`}
alwaysShowContentHeader
showHideHeaderButton={false}
headerContentPinnable={false}
Expand All @@ -251,19 +252,21 @@ export const DynamicPageComponent = ({
onBeforeNavigate={e => {
if (isFormOpen.formOpen) {
e.preventDefault();
setIsResourceEdited({
...isResourceEdited,
discardAction: () => {
setSelectedSectionIdState(e.detail.sectionId);
setIsResourceEdited({
isEdited: false,
});
},
});
setIsFormOpen({ formOpen: true, leavingForm: true });
return;
}
setSelectedSectionIdState(e.detail.sectionId);

handleActionIfFormOpen(
isResourceEdited,
setIsResourceEdited,
isFormOpen,
setIsFormOpen,
() => {
setSelectedSectionIdState(e.detail.sectionId);
setIsResourceEdited({
isEdited: false,
});
},
);

if (e.detail.sectionId === 'edit') {
setIsFormOpen({ formOpen: true });
}
Expand Down
2 changes: 2 additions & 0 deletions src/shared/components/ResourceDetails/ResourceDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ function Resource({
showHealthCardsTitle,
statusConditions,
headerContent,
className,
}) {
useVersionWarning({ resourceUrl, resourceType });
const { t } = useTranslation();
Expand Down Expand Up @@ -401,6 +402,7 @@ function Resource({
return (
<ResourceDetailContext.Provider value={true}>
<DynamicPageComponent
className={className}
headerContent={headerContent}
showYamlTab={showYamlTab || disableEdit}
layoutNumber={layoutNumber ?? 'MidColumn'}
Expand Down

0 comments on commit 3561fa4

Please sign in to comment.