Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: discard changes and unnecessary scroll in Modules form #3048

Merged
merged 4 commits into from
Jul 10, 2024
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: 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 @@ -33,6 +33,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 @@ -43,6 +44,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 @@ -95,6 +97,8 @@ export function KymaModulesList(props) {
resourceUrl: resourceUrl,
},
});

setIsFormOpen({ formOpen: true });
};

const ModulesList = resource => {
Expand Down Expand Up @@ -364,6 +368,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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add comment to describe why it is here

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>
);
// }
}
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
Loading