Skip to content

Commit

Permalink
helm shared component
Browse files Browse the repository at this point in the history
  • Loading branch information
petar-cvit committed Dec 9, 2024
1 parent 749fa81 commit b313198
Show file tree
Hide file tree
Showing 25 changed files with 740 additions and 617 deletions.
4 changes: 2 additions & 2 deletions cyclops-ui/src/components/k8s-resources/ClusterRole.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useEffect, useState } from "react";
import { Col, Divider, Row, Alert, Table, Tag } from "antd";
import { mapResponseError } from "../../utils/api/errors";
import { useModuleDetailsActions } from "../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "./ResourceList/ResourceListActionsContext";

interface Props {
name: string;
Expand All @@ -19,7 +19,7 @@ interface ClusterRoleData {
}

const ClusterRole = ({ name }: Props) => {
const { fetchResource } = useModuleDetailsActions();
const { fetchResource } = useResourceListActions();

const [clusterRole, setClusterRole] = useState<ClusterRoleData>({
rules: [],
Expand Down
4 changes: 2 additions & 2 deletions cyclops-ui/src/components/k8s-resources/ConfigMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React, { useCallback, useEffect, useState } from "react";
import { Divider, Row, Alert, Descriptions } from "antd";
import ReactAce from "react-ace";
import { mapResponseError } from "../../utils/api/errors";
import { useModuleDetailsActions } from "../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "./ResourceList/ResourceListActionsContext";

interface Props {
name: string;
namespace: string;
}

const ConfigMap = ({ name, namespace }: Props) => {
const { fetchResource } = useModuleDetailsActions();
const { fetchResource } = useResourceListActions();

const [configMap, setConfigMap] = useState({});
const [error, setError] = useState({
Expand Down
4 changes: 2 additions & 2 deletions cyclops-ui/src/components/k8s-resources/CronJob.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React, { useCallback, useEffect, useState } from "react";
import { Col, Divider, Row, Alert } from "antd";
import { mapResponseError } from "../../utils/api/errors";
import PodTable from "./common/PodTable/PodTable";
import { useModuleDetailsActions } from "../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "./ResourceList/ResourceListActionsContext";

interface Props {
name: string;
namespace: string;
}

const CronJob = ({ name, namespace }: Props) => {
const { fetchResource } = useModuleDetailsActions();
const { fetchResource } = useResourceListActions();

const [cronjob, setCronjob] = useState({
status: "",
Expand Down
4 changes: 2 additions & 2 deletions cyclops-ui/src/components/k8s-resources/DaemonSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Col, Divider, Row, Alert } from "antd";
import { mapResponseError } from "../../utils/api/errors";
import PodTable from "./common/PodTable/PodTable";
import { isStreamingEnabled } from "../../utils/api/common";
import { useModuleDetailsActions } from "../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "./ResourceList/ResourceListActionsContext";

interface Props {
name: string;
Expand All @@ -12,7 +12,7 @@ interface Props {
}

const DaemonSet = ({ name, namespace, workload }: Props) => {
const { fetchResource, streamingDisabled } = useModuleDetailsActions();
const { fetchResource, streamingDisabled } = useResourceListActions();

const [daemonSet, setDaemonSet] = useState({
status: "",
Expand Down
4 changes: 2 additions & 2 deletions cyclops-ui/src/components/k8s-resources/Deployment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Col, Divider, Row, Alert } from "antd";
import { mapResponseError } from "../../utils/api/errors";
import PodTable from "./common/PodTable/PodTable";
import { isStreamingEnabled } from "../../utils/api/common";
import { useModuleDetailsActions } from "../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "./ResourceList/ResourceListActionsContext";

interface Props {
name: string;
Expand All @@ -12,7 +12,7 @@ interface Props {
}

const Deployment = ({ name, namespace, workload }: Props) => {
const { fetchResource, streamingDisabled } = useModuleDetailsActions();
const { fetchResource, streamingDisabled } = useResourceListActions();

const [deployment, setDeployment] = useState({
status: "",
Expand Down
4 changes: 2 additions & 2 deletions cyclops-ui/src/components/k8s-resources/Job.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React, { useCallback, useEffect, useState } from "react";
import { Col, Divider, Row, Alert } from "antd";
import { mapResponseError } from "../../utils/api/errors";
import PodTable from "./common/PodTable/PodTable";
import { useModuleDetailsActions } from "../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "./ResourceList/ResourceListActionsContext";

interface Props {
name: string;
namespace: string;
}

const Job = ({ name, namespace }: Props) => {
const { fetchResource } = useModuleDetailsActions();
const { fetchResource } = useResourceListActions();

const [job, setJob] = useState({
status: "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useState } from "react";
import { mapResponseError } from "../../utils/api/errors";
import { Alert, Descriptions, Divider } from "antd";
import { useModuleDetailsActions } from "../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "./ResourceList/ResourceListActionsContext";

interface Props {
name: string;
Expand All @@ -14,7 +14,7 @@ interface pvc {
}

const PersistentVolumeClaim = ({ name, namespace }: Props) => {
const { fetchResource } = useModuleDetailsActions();
const { fetchResource } = useResourceListActions();

const [pvc, setPvc] = useState<pvc>({
size: "",
Expand Down
4 changes: 2 additions & 2 deletions cyclops-ui/src/components/k8s-resources/Pod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
import ReactAce from "react-ace";
import { formatPodAge } from "../../utils/pods";
import { mapResponseError } from "../../utils/api/errors";
import { useModuleDetailsActions } from "../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { logStream } from "../../utils/api/sse/logs";
import { DownloadOutlined } from "@ant-design/icons";
import { useResourceListActions } from "./ResourceList/ResourceListActionsContext";
const { Title } = Typography;

interface Props {
Expand Down Expand Up @@ -51,7 +51,7 @@ const Pod = ({ name, namespace }: Props) => {
getPodLogs,
downloadPodLogs,
streamPodLogs,
} = useModuleDetailsActions();
} = useResourceListActions();
const logsSignalControllerRef = useRef<AbortController | null>(null);

const [pod, setPod] = useState<pod>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import Title from "antd/es/typography/Title";
import { mapResponseError } from "../../../utils/api/errors";
import { CheckboxChangeEvent } from "antd/es/checkbox";
import { Workload } from "../../../utils/k8s/workload";
import { useModuleDetailsActions } from "../../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "./ResourceListActionsContext";

interface Props {
loadResources: boolean;
Expand All @@ -66,7 +66,7 @@ const ResourceList = ({
fetchResourceManifest,
restartResource,
deleteResource,
} = useModuleDetailsActions();
} = useResourceListActions();

const [error, setError] = useState({
message: "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import React, { createContext, ReactNode, useContext } from "react";

interface ModuleDetailsActionsContextType {
name: string;
interface ResourceListActionsContextType {
streamingDisabled: boolean;
fetchModule: (moduleName: string) => Promise<any>;
fetchModuleRawManifest: (moduleName: string) => Promise<string>;
fetchModuleRenderedManifest: (moduleName: string) => Promise<string>;
reconcileModule: (moduleName: string) => Promise<any>;
deleteModule: (moduleName: string) => Promise<any>;
fetchModuleResources: (moduleName: string) => Promise<any[]>;
fetchResource: (
group: string,
version: string,
Expand Down Expand Up @@ -62,19 +55,12 @@ interface ModuleDetailsActionsContextType {
) => void;
}

const ModuleDetailsActionsContext = createContext<
ModuleDetailsActionsContextType | undefined
const ResourceListActionsContext = createContext<
ResourceListActionsContextType | undefined
>(undefined);

interface ModuleDetailsActionsProviderProps {
name: string;
interface ResourceListActionsProviderProps {
streamingDisabled: boolean;
fetchModule: (moduleName: string) => Promise<any>;
fetchModuleRawManifest: (moduleName: string) => Promise<string>;
fetchModuleRenderedManifest: (moduleName: string) => Promise<string>;
reconcileModule: (moduleName: string) => Promise<any>;
deleteModule: (moduleName: string) => Promise<any>;
fetchModuleResources: (moduleName: string) => Promise<any[]>;
fetchResource: (
group: string,
version: string,
Expand Down Expand Up @@ -129,17 +115,10 @@ interface ModuleDetailsActionsProviderProps {
children: ReactNode;
}

export const ModuleDetailsActionsProvider: React.FC<
ModuleDetailsActionsProviderProps
export const ResourceListActionsProvider: React.FC<
ResourceListActionsProviderProps
> = ({
name,
streamingDisabled,
fetchModule,
fetchModuleRawManifest,
fetchModuleRenderedManifest,
reconcileModule,
deleteModule,
fetchModuleResources,
fetchResource,
fetchResourceManifest,
resourceStreamImplementation,
Expand All @@ -151,16 +130,9 @@ export const ModuleDetailsActionsProvider: React.FC<
children,
}) => {
return (
<ModuleDetailsActionsContext.Provider
<ResourceListActionsContext.Provider
value={{
name,
streamingDisabled,
fetchModule,
fetchModuleRawManifest,
fetchModuleRenderedManifest,
reconcileModule,
deleteModule,
fetchModuleResources,
fetchResource,
fetchResourceManifest,
resourceStreamImplementation,
Expand All @@ -172,15 +144,15 @@ export const ModuleDetailsActionsProvider: React.FC<
}}
>
{children}
</ModuleDetailsActionsContext.Provider>
</ResourceListActionsContext.Provider>
);
};

export const useModuleDetailsActions = (): ModuleDetailsActionsContextType => {
const context = useContext(ModuleDetailsActionsContext);
export const useResourceListActions = (): ResourceListActionsContextType => {
const context = useContext(ResourceListActionsContext);
if (!context) {
throw new Error(
"useModuleDetailsActions must be used within a FetchFunctionsProvider",
"useResourceListActions must be used within a ResourceListActionsProvider",
);
}
return context;
Expand Down
4 changes: 2 additions & 2 deletions cyclops-ui/src/components/k8s-resources/Secret.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useEffect, useState } from "react";
import { mapResponseError } from "../../utils/api/errors";
import { Alert, Descriptions, Divider } from "antd";
import { useModuleDetailsActions } from "../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "./ResourceList/ResourceListActionsContext";

interface Props {
name: string;
Expand All @@ -14,7 +14,7 @@ interface secret {
}

const Secret = ({ name, namespace }: Props) => {
const { fetchResource } = useModuleDetailsActions();
const { fetchResource } = useResourceListActions();

const [secret, setSecret] = useState<secret>({
type: "",
Expand Down
4 changes: 2 additions & 2 deletions cyclops-ui/src/components/k8s-resources/Service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useState } from "react";
import { Col, Divider, Row, Table, Alert, Descriptions, Button } from "antd";
import { mapResponseError } from "../../utils/api/errors";
import { CopyOutlined } from "@ant-design/icons";
import { useModuleDetailsActions } from "../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "./ResourceList/ResourceListActionsContext";

interface Props {
name: string;
Expand All @@ -28,7 +28,7 @@ interface service {
}

const Service = ({ name, namespace }: Props) => {
const { fetchResource } = useModuleDetailsActions();
const { fetchResource } = useResourceListActions();

const [service, setService] = useState<service>({
externalIPs: [],
Expand Down
4 changes: 2 additions & 2 deletions cyclops-ui/src/components/k8s-resources/StatefulSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Col, Divider, Row, Alert } from "antd";
import { mapResponseError } from "../../utils/api/errors";
import PodTable from "./common/PodTable/PodTable";
import { isStreamingEnabled } from "../../utils/api/common";
import { useModuleDetailsActions } from "../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "./ResourceList/ResourceListActionsContext";

interface Props {
name: string;
Expand All @@ -12,7 +12,7 @@ interface Props {
}

const StatefulSet = ({ name, namespace, workload }: Props) => {
const { fetchResource, streamingDisabled } = useModuleDetailsActions();
const { fetchResource, streamingDisabled } = useResourceListActions();

const [statefulSet, setStatefulSet] = useState({
status: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import ReactAce from "react-ace/lib/ace";
import { mapResponseError } from "../../../../utils/api/errors";
import { logStream } from "../../../../utils/api/sse/logs";
import "ace-builds/src-noconflict/ext-searchbox";
import { useModuleDetailsActions } from "../../../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "../../ResourceList/ResourceListActionsContext";

interface PodLogsProps {
pod: any;
}

const PodLogs = ({ pod }: PodLogsProps) => {
const { streamingDisabled, getPodLogs, downloadPodLogs, streamPodLogs } =
useModuleDetailsActions();
useResourceListActions();
const [logs, setLogs] = useState<string[]>([]);
const [logsModal, setLogsModal] = useState({
on: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { Alert, Button, Checkbox, Modal, Tooltip } from "antd";
import { CheckboxChangeEvent } from "antd/es/checkbox";
import { useCallback, useEffect, useState } from "react";
import ReactAce from "react-ace/lib/ace";
import { useModuleDetailsActions } from "../../../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "../../ResourceList/ResourceListActionsContext";

interface PodManifestProps {
pod: any;
}

const PodManifest = ({ pod }: PodManifestProps) => {
const { fetchResourceManifest } = useModuleDetailsActions();
const { fetchResourceManifest } = useResourceListActions();

const [manifest, setManifest] = useState("");
const [showManagedFields, setShowManagedFields] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { mapResponseError } from "../../../../utils/api/errors";
import { formatPodAge } from "../../../../utils/pods";
import PodLogs from "./PodLogs";
import PodManifest from "./PodManifest";
import { useModuleDetailsActions } from "../../../shared/ModuleResourceDetails/ModuleDetailsActionsContext";
import { useResourceListActions } from "../../ResourceList/ResourceListActionsContext";

interface Props {
namespace: string;
Expand All @@ -33,7 +33,7 @@ interface Pod {
}

const PodTable = ({ pods, namespace, updateResourceData }: Props) => {
const { deleteResource } = useModuleDetailsActions();
const { deleteResource } = useResourceListActions();
const [deletePodRef, setDeletePodRef] = useState<{
on: boolean;
podDetails: Pod;
Expand Down
Loading

0 comments on commit b313198

Please sign in to comment.