Skip to content

Commit

Permalink
Conditionally render pipeline modals (#3300)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 authored Oct 4, 2024
1 parent 3c4f40d commit 1fd4f18
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 134 deletions.
4 changes: 1 addition & 3 deletions frontend/src/concepts/pipelines/content/ArchiveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ interface ArchiveModalProps {
onCancel: () => void;
onSubmit: () => Promise<void[]>;
children: React.ReactNode;
isOpen: boolean;
testId: string;
}

Expand All @@ -21,7 +20,6 @@ export const ArchiveModal: React.FC<ArchiveModalProps> = ({
title,
alertTitle,
children,
isOpen,
testId,
}) => {
const { refreshAllAPI } = usePipelinesAPI();
Expand Down Expand Up @@ -53,7 +51,7 @@ export const ArchiveModal: React.FC<ArchiveModalProps> = ({

return (
<Modal
isOpen={isOpen}
isOpen
title={title}
titleIconVariant="warning"
variant="small"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const PipelineServerActions: React.FC<PipelineServerActionsProps> = ({ variant,
}}
/>
) : null}
<ViewServerModal isOpen={viewOpen} onClose={() => setViewOpen(false)} />
{viewOpen ? <ViewServerModal onClose={() => setViewOpen(false)} /> : null}
{deletePipelinesOpen ? (
<DeletePipelinesModal
toDeletePipelines={pipelines}
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/concepts/pipelines/content/RestoreModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ interface RestoreModalProps {
title: string;
alertTitle: string;
children: React.ReactNode;
isOpen: boolean;
testId: string;
}

Expand All @@ -18,7 +17,6 @@ export const RestoreModal: React.FC<RestoreModalProps> = ({
onSubmit,
title,
children,
isOpen,
testId,
alertTitle,
}) => {
Expand All @@ -43,7 +41,7 @@ export const RestoreModal: React.FC<RestoreModalProps> = ({

return (
<Modal
isOpen={isOpen}
isOpen
title={title}
variant="small"
onClose={onCancel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import { ExternalDatabaseSecret } from '~/concepts/pipelines/content/configurePi
import { DSPipelineKind } from '~/k8sTypes';

type ViewPipelineServerModalProps = {
isOpen: boolean;
onClose: () => void;
pipelineNamespaceCR: DSPipelineKind | null;
};

const ViewPipelineServerModal: React.FC<ViewPipelineServerModalProps> = ({
isOpen,
onClose,
pipelineNamespaceCR,
}) => {
Expand All @@ -35,7 +33,7 @@ const ViewPipelineServerModal: React.FC<ViewPipelineServerModalProps> = ({
const databaseSecret = dataEntryToRecord(result?.values?.data ?? []);

return (
<Modal title="View pipeline server" isOpen={isOpen} onClose={onClose} variant="small">
<Modal title="View pipeline server" isOpen onClose={onClose} variant="small">
{pipelineNamespaceCR && (
<DescriptionList termWidth="20ch" isHorizontal>
{!!pipelineNamespaceCR.spec.objectStorage.externalStorage?.s3CredentialsSecret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { configureDSPipelineResourceSpec, objectStorageIsValid } from './utils';
import { PipelineServerConfigType } from './types';

type ConfigurePipelinesServerModalProps = {
open: boolean;
onClose: () => void;
};

Expand All @@ -27,20 +26,13 @@ const FORM_DEFAULTS: PipelineServerConfigType = {

export const ConfigurePipelinesServerModal: React.FC<ConfigurePipelinesServerModalProps> = ({
onClose,
open,
}) => {
const { project, namespace } = usePipelinesAPI();
const [dataConnections, loaded, , refresh] = useDataConnections(namespace);
const [dataConnections, loaded] = useDataConnections(namespace);
const [fetching, setFetching] = React.useState(false);
const [error, setError] = React.useState<Error>();
const [config, setConfig] = React.useState<PipelineServerConfigType>(FORM_DEFAULTS);

React.useEffect(() => {
if (open) {
refresh();
}
}, [open, refresh]);

const databaseIsValid = config.database.useDefault
? true
: config.database.value.every(({ key, value }) =>
Expand Down Expand Up @@ -101,7 +93,7 @@ export const ConfigurePipelinesServerModal: React.FC<ConfigurePipelinesServerMod
title="Configure pipeline server"
variant="medium"
description="Configuring a pipeline server enables you to create and manage pipelines."
isOpen={open}
isOpen
onClose={onBeforeClose}
footer={
<DashboardModalFooter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ const CreateExperimentButton: React.FC<CreateExperimentButtonProps> = ({
>
{children || 'Create experiment'}
</Button>
<CreateExperimentModal
isOpen={open}
onClose={(experiment) => {
setOpen(false);
if (experiment) {
if (onCreate) {
onCreate(experiment);
{open ? (
<CreateExperimentModal
onClose={(experiment) => {
setOpen(false);
if (experiment) {
if (onCreate) {
onCreate(experiment);
}
refreshAllAPI();
}
refreshAllAPI();
}
}}
/>
}}
/>
) : null}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import {
import { CharLimitHelperText } from '~/components/CharLimitHelperText';

type CreateExperimentModalProps = {
isOpen: boolean;
onClose: (experiment?: ExperimentKFv2) => void;
};

const CreateExperimentModal: React.FC<CreateExperimentModalProps> = ({ isOpen, onClose }) => {
const CreateExperimentModal: React.FC<CreateExperimentModalProps> = ({ onClose }) => {
const { project, api, apiAvailable } = usePipelinesAPI();
const [submitting, setSubmitting] = React.useState(false);
const [error, setError] = React.useState<Error | undefined>();
Expand All @@ -41,7 +40,7 @@ const CreateExperimentModal: React.FC<CreateExperimentModalProps> = ({ isOpen, o

return (
<Modal
isOpen={isOpen}
isOpen
title="Create experiment"
onClose={() => onBeforeClose()}
actions={[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ const ImportPipelineButton: React.FC<ImportPipelineButtonProps> = ({
>
{children || 'Import pipeline'}
</Button>
<PipelineImportModal
isOpen={open}
redirectAfterImport={redirectAfterImport}
onClose={(pipeline) => {
setOpen(false);
if (pipeline) {
if (onCreate) {
onCreate(pipeline);
{open ? (
<PipelineImportModal
redirectAfterImport={redirectAfterImport}
onClose={(pipeline) => {
setOpen(false);
if (pipeline) {
if (onCreate) {
onCreate(pipeline);
}
refreshAllAPI();
}
refreshAllAPI();
}
}}
/>
}}
/>
) : null}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,19 @@ const ImportPipelineSplitButton: React.FC<ImportPipelineSplitButtonProps> = ({
</DropdownItem>
</DropdownList>
</Dropdown>
<PipelineImportModal
isOpen={isPipelineModalOpen}
onClose={(pipeline) => {
setPipelineModalOpen(false);
if (pipeline) {
if (onImportPipeline) {
onImportPipeline(pipeline);
{isPipelineModalOpen ? (
<PipelineImportModal
onClose={(pipeline) => {
setPipelineModalOpen(false);
if (pipeline) {
if (onImportPipeline) {
onImportPipeline(pipeline);
}
refreshAllAPI();
}
refreshAllAPI();
}
}}
/>
}}
/>
) : null}
{isPipelineVersionModalOpen && (
<PipelineVersionImportModal
onClose={(pipelineVersion) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ import PipelineUploadRadio from './PipelineUploadRadio';
import { PipelineUploadOption, extractKindFromPipelineYAML } from './utils';

type PipelineImportModalProps = {
isOpen: boolean;
onClose: (pipeline?: PipelineKFv2) => void;
redirectAfterImport?: boolean;
};

const PipelineImportModal: React.FC<PipelineImportModalProps> = ({
isOpen,
redirectAfterImport = true,
onClose,
}) => {
Expand Down Expand Up @@ -152,7 +150,7 @@ const PipelineImportModal: React.FC<PipelineImportModalProps> = ({
return (
<Modal
title="Import pipeline"
isOpen={isOpen}
isOpen
onClose={() => onBeforeClose()}
actions={[
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,9 @@ const PipelineRunDetails: React.FC<
}
}}
/>
<ArchiveRunModal
isOpen={archiving}
runs={run ? [run] : []}
onCancel={() => setArchiving(false)}
/>
{archiving ? (
<ArchiveRunModal runs={run ? [run] : []} onCancel={() => setArchiving(false)} />
) : null}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ const ActiveExperimentTable: React.FC<ActiveExperimentTableProps> = ({ ...baseTa
/>
)}
/>
<ArchiveExperimentModal
isOpen={isArchiveModalOpen}
experiments={archiveExperiments}
onCancel={() => setIsArchiveModalOpen(false)}
/>
{isArchiveModalOpen ? (
<ArchiveExperimentModal
experiments={archiveExperiments}
onCancel={() => setIsArchiveModalOpen(false)}
/>
) : null}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ const ArchivedExperimentTable: React.FC<ArchivedExperimentTableProps> = ({ ...ba
/>
)}
/>
<RestoreExperimentModal
isOpen={isRestoreModalOpen}
experiments={restoreExperiments}
onCancel={() => setIsRestoreModalOpen(false)}
/>
{isRestoreModalOpen ? (
<RestoreExperimentModal
experiments={restoreExperiments}
onCancel={() => setIsRestoreModalOpen(false)}
/>
) : null}
{deleteExperiment ? (
<DeleteExperimentModal
onCancel={() => setDeleteExperiment(undefined)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,22 +295,24 @@ const PipelineRunTableInternal: React.FC<PipelineRunTableInternalProps> = ({
data-testid={`${runType}-runs-table`}
id={`${runType}-runs-table`}
/>
<ArchiveRunModal
isOpen={isArchiveModalOpen}
runs={selectedRuns}
onCancel={() => {
setIsArchiveModalOpen(false);
setSelectedIds([]);
}}
/>
<RestoreRunModal
isOpen={isRestoreModalOpen}
runs={selectedRuns}
onCancel={() => {
setIsRestoreModalOpen(false);
setSelectedIds([]);
}}
/>
{isArchiveModalOpen ? (
<ArchiveRunModal
runs={selectedRuns}
onCancel={() => {
setIsArchiveModalOpen(false);
setSelectedIds([]);
}}
/>
) : null}
{isRestoreModalOpen ? (
<RestoreRunModal
runs={selectedRuns}
onCancel={() => {
setIsRestoreModalOpen(false);
setSelectedIds([]);
}}
/>
) : null}
{isDeleteModalOpen && (
<DeletePipelineRunsModal
toDeleteResources={selectedRuns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,12 @@ const PipelineRunTableRow: React.FC<PipelineRunTableRowProps> = ({
items={actions}
popperProps={{ appendTo: getDashboardMainContainer, position: 'right' }}
/>
<RestoreRunModal
isOpen={isRestoreModalOpen}
runs={[run]}
onCancel={() => setIsRestoreModalOpen(false)}
/>
<ArchiveRunModal
isOpen={isArchiveModalOpen}
runs={[run]}
onCancel={() => setIsArchiveModalOpen(false)}
/>
{isRestoreModalOpen ? (
<RestoreRunModal runs={[run]} onCancel={() => setIsRestoreModalOpen(false)} />
) : null}
{isArchiveModalOpen ? (
<ArchiveRunModal runs={[run]} onCancel={() => setIsArchiveModalOpen(false)} />
) : null}
</Td>
)}
</Tr>
Expand Down
Loading

0 comments on commit 1fd4f18

Please sign in to comment.