-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1536 from flanksource/1518-add-topology-page-wizard
feat: make the add topology form wizard
- Loading branch information
Showing
12 changed files
with
533 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { TupleToUnion } from "type-fest"; | ||
import AddTopologyOptionsList, { | ||
createTopologyOptions | ||
} from "./StepsForms/AddTopologyOptionsList"; | ||
import { useEffect, useState } from "react"; | ||
import TopologyResourceForm from "./StepsForms/TopologyResourceForm"; | ||
|
||
type AddTopologyResourceProps = { | ||
onSuccess: () => void; | ||
isModal?: boolean; | ||
setModalTitle?: (title: string) => void; | ||
}; | ||
|
||
export default function AddTopologyResource({ | ||
onSuccess, | ||
isModal = false, | ||
setModalTitle = () => {} | ||
}: AddTopologyResourceProps) { | ||
const [selectedOption, setSelectedOption] = useState< | ||
TupleToUnion<typeof createTopologyOptions> | undefined | ||
>(); | ||
|
||
useEffect(() => { | ||
if (selectedOption) { | ||
setModalTitle(`Create a ${selectedOption.toLocaleLowerCase()} topology`); | ||
} else { | ||
setModalTitle("Create Topology"); | ||
} | ||
}, [selectedOption, setModalTitle]); | ||
|
||
return ( | ||
<div className="flex flex-col flex-1 gap-2"> | ||
{selectedOption ? ( | ||
<TopologyResourceForm | ||
selectedOption={selectedOption} | ||
onSuccess={onSuccess} | ||
onBack={() => setSelectedOption(undefined)} | ||
isModal={isModal} | ||
/> | ||
) : ( | ||
<AddTopologyOptionsList | ||
onSelectOption={(options) => setSelectedOption(options)} | ||
/> | ||
)} | ||
</div> | ||
); | ||
} |
56 changes: 56 additions & 0 deletions
56
src/components/Topology/Settings/AddTopologyResourceModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { AiFillPlusCircle } from "react-icons/ai"; | ||
import { useSearchParams } from "react-router-dom"; | ||
import AddTopologyResource from "./AddTopologyResource"; | ||
import { Modal } from "../../Modal"; | ||
import { useState } from "react"; | ||
|
||
type Props = { | ||
onClose?: () => void; | ||
}; | ||
|
||
export default function AddTopologyResourceModal({ | ||
onClose = () => {} | ||
}: Props) { | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
|
||
const [modalTitle, setModalTitle] = useState("Create Topology"); | ||
|
||
const isModalOpen = searchParams.get("openCreateForm") === "true"; | ||
|
||
const setModalIsOpen = (isOpen: boolean) => { | ||
if (isOpen) { | ||
searchParams.set("openCreateForm", "true"); | ||
} else { | ||
searchParams.delete("openCreateForm"); | ||
} | ||
setSearchParams(searchParams); | ||
}; | ||
|
||
return ( | ||
<> | ||
<button type="button" className="" onClick={() => setModalIsOpen(true)}> | ||
<AiFillPlusCircle size={32} className="text-blue-600" /> | ||
</button> | ||
|
||
<Modal | ||
open={isModalOpen} | ||
onClose={() => { | ||
setModalIsOpen(false); | ||
onClose(); | ||
}} | ||
bodyClass="flex flex-col flex-1 overflow-y-auto" | ||
size="full" | ||
title={modalTitle} | ||
> | ||
<AddTopologyResource | ||
isModal | ||
onSuccess={() => { | ||
setModalIsOpen(false); | ||
onClose(); | ||
}} | ||
setModalTitle={setModalTitle} | ||
/> | ||
</Modal> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import TopologyResourceForm, { | ||
TopologyResource | ||
} from "./StepsForms/TopologyResourceForm"; | ||
|
||
type EditTopologyResourceProps = { | ||
onSuccess: () => void; | ||
topologyResource: TopologyResource; | ||
isModal?: boolean; | ||
}; | ||
|
||
export default function EditTopologyResource({ | ||
onSuccess, | ||
topologyResource, | ||
isModal = false | ||
}: EditTopologyResourceProps) { | ||
return ( | ||
<div className="flex flex-col flex-1 p-2"> | ||
<TopologyResourceForm | ||
isModal={isModal} | ||
onSuccess={onSuccess} | ||
topology={topologyResource} | ||
footerClassName="p-4" | ||
/> | ||
</div> | ||
); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/components/Topology/Settings/StepsForms/AddTopologyOptionsList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { TupleToUnion } from "type-fest"; | ||
import { Icon } from "../../../Icon"; | ||
|
||
export const createTopologyOptions = [ | ||
"Kubernetes", | ||
"Flux", | ||
"Prometheus", | ||
"Custom" | ||
] as const; | ||
|
||
type AddTopologyOptionsListProps = { | ||
onSelectOption: (options: TupleToUnion<typeof createTopologyOptions>) => void; | ||
}; | ||
|
||
export default function AddTopologyOptionsList({ | ||
onSelectOption | ||
}: AddTopologyOptionsListProps) { | ||
return ( | ||
<div className="flex flex-col gap-2"> | ||
<div className="flex flex-wrap p-2"> | ||
{createTopologyOptions.map((item) => { | ||
return ( | ||
<div className="flex flex-col w-1/4 p-2" key={item}> | ||
<div | ||
role="button" | ||
className="flex flex-col items-center space-y-2 justify-center p-2 border border-gray-300 hover:border-blue-200 hover:bg-gray-100 rounded-md text-center h-20" | ||
onClick={(e) => { | ||
onSelectOption(item); | ||
}} | ||
> | ||
<Icon name={item.toLowerCase()} /> | ||
<div>{item}</div> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.