Skip to content

Commit

Permalink
Require conditional rendering of modals
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 committed Oct 10, 2024
1 parent c8d7822 commit dcf71cc
Show file tree
Hide file tree
Showing 29 changed files with 262 additions and 275 deletions.
4 changes: 4 additions & 0 deletions frontend/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@
{
"selector": "Literal[value=/\\bOpen Data Hub\\b/i],JSXText[value=/\\bOpen Data Hub\\b/i]",
"message": "Do not hard code product name `Open Data Hub`. Use `~/utilities/const#ODH_PRODUCT_NAME` instead."
},
{
"selector": "JSXElement[openingElement.name.name=/Modal/]:has(> JSXOpeningElement:has(> [name.name=/(isOpen|open)/][value]))",
"message": "Do not control modals visibility with 'isOpen|open', use conditional rendering instead."
}
]
}
Expand Down
46 changes: 24 additions & 22 deletions frontend/src/app/DevFeatureFlagsBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,30 @@ const DevFeatureFlagsBanner: React.FC<Props> = ({
</SplitItem>
</Split>
</Banner>
<Modal
data-testid="dev-feature-flags-modal"
variant="large"
title="Feature flags"
isOpen={isModalOpen}
onClose={() => {
setModalOpen(false);
setDevFeatureFlagQueryVisible(false);
}}
actions={[
<Button
data-testid="reset-feature-flags-modal-button"
key="confirm"
variant="link"
onClick={() => resetDevFeatureFlags()}
>
Reset to defaults
</Button>,
]}
>
{renderDevFeatureFlags()}
</Modal>
{isModalOpen ? (
<Modal
data-testid="dev-feature-flags-modal"
variant="large"
title="Feature flags"
isOpen
onClose={() => {
setModalOpen(false);
setDevFeatureFlagQueryVisible(false);
}}
actions={[
<Button
data-testid="reset-feature-flags-modal-button"
key="confirm"
variant="link"
onClick={() => resetDevFeatureFlags()}
>
Reset to defaults
</Button>,
]}
>
{renderDevFeatureFlags()}
</Modal>
) : null}
</>
);
};
Expand Down
94 changes: 48 additions & 46 deletions frontend/src/components/EditableLabelsDescriptionListGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,52 +168,54 @@ const EditableLabelsDescriptionListGroup: React.FC<EditableTextDescriptionListGr
))}
</LabelGroup>
</DashboardDescriptionListGroup>
<Modal
variant="small"
title="Add label"
isOpen={isAddLabelModalOpen}
onClose={toggleAddLabelModal}
actions={[
<Button
key="save"
variant="primary"
form="add-label-form"
onClick={submitAddLabelModal}
isDisabled={addLabelModalSubmitDisabled}
>
Save
</Button>,
<Button key="cancel" variant="link" onClick={toggleAddLabelModal}>
Cancel
</Button>,
]}
>
<Form id="add-label-form" onSubmit={submitAddLabelModal}>
<FormGroup label="Label text" fieldId="add-label-form-label-text" isRequired>
<TextInput
type="text"
id="add-label-form-label-text"
name="add-label-form-label-text"
value={addLabelInputValue}
onChange={(_event: React.FormEvent<HTMLInputElement>, value: string) =>
setAddLabelInputValue(value)
}
ref={addLabelInputRef}
isRequired
validated={addLabelValidationError ? 'error' : 'default'}
/>
{addLabelValidationError && (
<FormHelperText>
<HelperText>
<HelperTextItem icon={<ExclamationCircleIcon />} variant="error">
{addLabelValidationError}
</HelperTextItem>
</HelperText>
</FormHelperText>
)}
</FormGroup>
</Form>
</Modal>
{isAddLabelModalOpen ? (
<Modal

Check warning on line 172 in frontend/src/components/EditableLabelsDescriptionListGroup.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/components/EditableLabelsDescriptionListGroup.tsx#L172

Added line #L172 was not covered by tests
variant="small"
title="Add label"
isOpen
onClose={toggleAddLabelModal}
actions={[
<Button
key="save"
variant="primary"
form="add-label-form"
onClick={submitAddLabelModal}
isDisabled={addLabelModalSubmitDisabled}
>
Save
</Button>,
<Button key="cancel" variant="link" onClick={toggleAddLabelModal}>
Cancel
</Button>,
]}
>
<Form id="add-label-form" onSubmit={submitAddLabelModal}>
<FormGroup label="Label text" fieldId="add-label-form-label-text" isRequired>
<TextInput
type="text"
id="add-label-form-label-text"
name="add-label-form-label-text"
value={addLabelInputValue}
onChange={(_event: React.FormEvent<HTMLInputElement>, value: string) =>

Check warning on line 199 in frontend/src/components/EditableLabelsDescriptionListGroup.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/components/EditableLabelsDescriptionListGroup.tsx#L199

Added line #L199 was not covered by tests
setAddLabelInputValue(value)
}
ref={addLabelInputRef}
isRequired
validated={addLabelValidationError ? 'error' : 'default'}

Check warning on line 204 in frontend/src/components/EditableLabelsDescriptionListGroup.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/components/EditableLabelsDescriptionListGroup.tsx#L204

Added line #L204 was not covered by tests
/>
{addLabelValidationError && (
<FormHelperText>

Check warning on line 207 in frontend/src/components/EditableLabelsDescriptionListGroup.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/components/EditableLabelsDescriptionListGroup.tsx#L206-L207

Added lines #L206 - L207 were not covered by tests
<HelperText>
<HelperTextItem icon={<ExclamationCircleIcon />} variant="error">
{addLabelValidationError}
</HelperTextItem>
</HelperText>
</FormHelperText>
)}
</FormGroup>
</Form>
</Modal>
) : null}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import DisplayedContentTabContent from './DisplayedContentTabContent';

export type ManageBYONImageModalProps = {
existingImage?: BYONImage;
isOpen: boolean;
onClose: (submitted: boolean) => void;
};

Expand All @@ -32,11 +31,7 @@ export enum DisplayedContentTab {
PACKAGES,
}

const ManageBYONImageModal: React.FC<ManageBYONImageModalProps> = ({
existingImage,
isOpen,
onClose,
}) => {
const ManageBYONImageModal: React.FC<ManageBYONImageModalProps> = ({ existingImage, onClose }) => {
const [activeTabKey, setActiveTabKey] = React.useState<string | number>(
DisplayedContentTab.SOFTWARE,
);
Expand Down Expand Up @@ -123,7 +118,7 @@ const ManageBYONImageModal: React.FC<ManageBYONImageModalProps> = ({
onEscapePress={(e) => e.preventDefault()}
variant={ModalVariant.medium}
title={`${existingImage ? 'Update' : 'Import'} notebook image`}
isOpen={isOpen}
isOpen
onClose={() => onBeforeClose(false)}
showClose={!isEditing}
footer={
Expand Down
21 changes: 11 additions & 10 deletions frontend/src/pages/BYONImages/BYONImagesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,17 @@ export const BYONImagesTable: React.FC<BYONImagesTableProps> = ({ images, refres
}}
/>
) : null}
<ManageBYONImageModal
isOpen={!!editImage}
onClose={(updated) => {
if (updated) {
refresh();
}
setEditImage(undefined);
}}
existingImage={editImage}
/>
{editImage ? (
<ManageBYONImageModal
onClose={(updated) => {
if (updated) {
refresh();
}
setEditImage(undefined);
}}
existingImage={editImage}
/>
) : null}
</>
);
};
19 changes: 10 additions & 9 deletions frontend/src/pages/BYONImages/ImportBYONImageButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ const ImportBYONImageButton: React.FC<ImportBYONImageButtonProps> = ({ refresh }
>
Import new image
</Button>
<ManageBYONImageModal
isOpen={isOpen}
onClose={(imported) => {
if (imported) {
refresh();
}
setOpen(false);
}}
/>
{isOpen ? (
<ManageBYONImageModal
onClose={(imported) => {
if (imported) {
refresh();
}
setOpen(false);
}}
/>
) : null}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ const AcceleratorProfileEnableToggle: React.FC<AcceleratorProfileEnableTogglePro
}
}}
/>
<DisableAcceleratorProfileModal
data-testid="disable-accelerator-profile-modal"
isOpen={isModalOpen}
onClose={(confirmStatus) => {
if (confirmStatus) {
handleChange(false);
}
setIsModalOpen(false);
}}
/>
{isModalOpen ? (
<DisableAcceleratorProfileModal
data-testid="disable-accelerator-profile-modal"
onClose={(confirmStatus) => {
if (confirmStatus) {
handleChange(false);
}
setIsModalOpen(false);
}}
/>
) : null}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import * as React from 'react';
import { Button, Modal } from '@patternfly/react-core';

type DisableAcceleratorProfileModalType = {
isOpen: boolean;
onClose: (confirmStatus: boolean) => void;
};

const DisableAcceleratorProfileModal: React.FC<DisableAcceleratorProfileModalType> = ({
isOpen,
onClose,
}) => (
<Modal
variant="small"
title="Disable accelerator profile"
isOpen={isOpen}
isOpen
onClose={() => onClose(false)}
actions={[
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ export const ManageAcceleratorProfileTolerationsSection: React.FC<
onUpdate={(newTolerations) => setTolerations(newTolerations)}
/>
</FormSection>
<ManageTolerationModal
isOpen={manageTolerationModalOpen}
onClose={() => setManageTolerationModalOpen(false)}
onSave={(toleration) => setTolerations([...tolerations, toleration])}
/>
{manageTolerationModalOpen ? (
<ManageTolerationModal
onClose={() => setManageTolerationModalOpen(false)}
onSave={(toleration) => setTolerations([...tolerations, toleration])}
/>
) : null}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import TolerationFields from './TolerationFields';
import { EMPTY_TOLERATION } from './const';

type ManageTolerationModalProps = {
isOpen: boolean;
onClose: () => void;
initialToleration?: Toleration;
onSave: (toleration: Toleration) => void;
};

const ManageTolerationModal: React.FC<ManageTolerationModalProps> = ({
isOpen,
onClose,
initialToleration,
onSave,
Expand Down Expand Up @@ -41,7 +39,7 @@ const ManageTolerationModal: React.FC<ManageTolerationModalProps> = ({
<Modal
title={initialToleration ? 'Edit toleration' : 'Add toleration'}
variant="medium"
isOpen={isOpen}
isOpen
onClose={() => {
onBeforeClose();
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,22 @@ export const TolerationsTable: React.FC<TolerationTableProps> = ({ tolerations,
/>
)}
/>
<ManageTolerationModal
isOpen={!!editToleration}
initialToleration={editToleration}
onClose={() => {
setEditToleration(undefined);
setCurrentIndex(undefined);
}}
onSave={(toleration) => {
if (currentIndex !== undefined) {
const updatedTolerations = [...tolerations];
updatedTolerations[currentIndex] = toleration;
onUpdate(updatedTolerations);
}
}}
/>
{editToleration ? (
<ManageTolerationModal
initialToleration={editToleration}
onClose={() => {
setEditToleration(undefined);
setCurrentIndex(undefined);
}}
onSave={(toleration) => {
if (currentIndex !== undefined) {
const updatedTolerations = [...tolerations];
updatedTolerations[currentIndex] = toleration;
onUpdate(updatedTolerations);
}
}}
/>
) : null}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ const NotebookAdminControl: React.FC = () => {
/>
</StackItem>
</Stack>
<StopServerModal notebooksToStop={notebooksToStop} onNotebooksStop={onNotebooksStop} />
{notebooksToStop.length ? (
<StopServerModal notebooksToStop={notebooksToStop} onNotebooksStop={onNotebooksStop} />
) : null}
</ApplicationsPage>
);
};
Expand Down
Loading

0 comments on commit dcf71cc

Please sign in to comment.