|
@@ -18,20 +18,14 @@ import Loading from "components/Loading";
|
|
|
const Overview = () => {
|
|
const Overview = () => {
|
|
|
const {
|
|
const {
|
|
|
newStack,
|
|
newStack,
|
|
|
- clusterId,
|
|
|
|
|
namespace,
|
|
namespace,
|
|
|
setStackName,
|
|
setStackName,
|
|
|
setStackNamespace,
|
|
setStackNamespace,
|
|
|
- setStackCluster,
|
|
|
|
|
submit,
|
|
submit,
|
|
|
} = useContext(StacksLaunchContext);
|
|
} = useContext(StacksLaunchContext);
|
|
|
- const { currentProject } = useContext(Context);
|
|
|
|
|
|
|
+ const { currentProject, currentCluster } = useContext(Context);
|
|
|
const [isAuthorized] = useAuth();
|
|
const [isAuthorized] = useAuth();
|
|
|
|
|
|
|
|
- const [clusterOptions, setClusterOptions] = useState<
|
|
|
|
|
- { label: string; value: string }[]
|
|
|
|
|
- >([]);
|
|
|
|
|
-
|
|
|
|
|
const [namespaceOptions, setNamespaceOptions] = useState<
|
|
const [namespaceOptions, setNamespaceOptions] = useState<
|
|
|
{ label: string; value: string }[]
|
|
{ label: string; value: string }[]
|
|
|
>([]);
|
|
>([]);
|
|
@@ -40,31 +34,6 @@ const Overview = () => {
|
|
|
|
|
|
|
|
const { pushFiltered } = useRouting();
|
|
const { pushFiltered } = useRouting();
|
|
|
|
|
|
|
|
- const getClusters = () => {
|
|
|
|
|
- return api
|
|
|
|
|
- .getClusters("<token>", {}, { id: currentProject.id })
|
|
|
|
|
- .then((res) => {
|
|
|
|
|
- if (res.data) {
|
|
|
|
|
- let clusterOptions: {
|
|
|
|
|
- label: string;
|
|
|
|
|
- value: string;
|
|
|
|
|
- }[] = res.data.map((cluster: ClusterType, i: number) => ({
|
|
|
|
|
- label: cluster.name,
|
|
|
|
|
- value: `${cluster.id}`,
|
|
|
|
|
- }));
|
|
|
|
|
-
|
|
|
|
|
- if (res.data.length > 0) {
|
|
|
|
|
- setClusterOptions(clusterOptions);
|
|
|
|
|
- console.log({ clusterId });
|
|
|
|
|
- if (isNaN(clusterId)) {
|
|
|
|
|
- const newClusterId = res.data[0].id;
|
|
|
|
|
- setStackCluster(newClusterId);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
const updateNamespaces = (cluster_id: number) => {
|
|
const updateNamespaces = (cluster_id: number) => {
|
|
|
api
|
|
api
|
|
|
.getNamespaces(
|
|
.getNamespaces(
|
|
@@ -108,23 +77,14 @@ const Overview = () => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- getClusters();
|
|
|
|
|
- }, []);
|
|
|
|
|
-
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- if (isNaN(clusterId)) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- updateNamespaces(clusterId);
|
|
|
|
|
- }, [clusterId]);
|
|
|
|
|
|
|
+ updateNamespaces(currentCluster.id);
|
|
|
|
|
+ }, [currentCluster]);
|
|
|
|
|
|
|
|
const isValid = useMemo(() => {
|
|
const isValid = useMemo(() => {
|
|
|
if (namespace === "") {
|
|
if (namespace === "") {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- if (isNaN(clusterId)) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
if (newStack.name === "") {
|
|
if (newStack.name === "") {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -138,7 +98,7 @@ const Overview = () => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
return true;
|
|
|
- }, [namespace, clusterId, newStack.name]);
|
|
|
|
|
|
|
+ }, [namespace, newStack.name]);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div style={{ position: "relative" }}>
|
|
<div style={{ position: "relative" }}>
|
|
@@ -148,21 +108,10 @@ const Overview = () => {
|
|
|
setValue={(newName: string) => setStackName(newName)}
|
|
setValue={(newName: string) => setStackName(newName)}
|
|
|
/>
|
|
/>
|
|
|
|
|
|
|
|
- <Selector
|
|
|
|
|
- activeValue={`${clusterId}`}
|
|
|
|
|
- setActiveValue={(cluster: string) => {
|
|
|
|
|
- setStackCluster(Number(cluster));
|
|
|
|
|
- }}
|
|
|
|
|
- options={clusterOptions}
|
|
|
|
|
- width="250px"
|
|
|
|
|
- dropdownWidth="335px"
|
|
|
|
|
- closeOverlay={true}
|
|
|
|
|
- />
|
|
|
|
|
-
|
|
|
|
|
<Selector
|
|
<Selector
|
|
|
key={"namespace"}
|
|
key={"namespace"}
|
|
|
refreshOptions={() => {
|
|
refreshOptions={() => {
|
|
|
- updateNamespaces(clusterId);
|
|
|
|
|
|
|
+ updateNamespaces(currentCluster.id);
|
|
|
}}
|
|
}}
|
|
|
addButton={isAuthorized("namespace", "", ["get", "create"])}
|
|
addButton={isAuthorized("namespace", "", ["get", "create"])}
|
|
|
activeValue={namespace}
|
|
activeValue={namespace}
|