From 2463ec5157589ace9a962b473a060ee25ab7677b Mon Sep 17 00:00:00 2001 From: Eneko Fernandez Date: Mon, 18 Dec 2023 18:14:39 +0100 Subject: [PATCH] added ui support to runtime Signed-off-by: Eneko Fernandez --- ui/App.tsx | 27 ++++++++++++++++++++++++--- ui/hooks/flux.ts | 35 +++++++++++++++++++++++++++++++---- ui/lib/types.ts | 1 + ui/pages/v2/Runtime.tsx | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 ui/pages/v2/Runtime.tsx diff --git a/ui/App.tsx b/ui/App.tsx index 1efd6e5aa5..b0aea99e59 100644 --- a/ui/App.tsx +++ b/ui/App.tsx @@ -40,7 +40,6 @@ import Error from "./pages/Error"; import SignIn from "./pages/SignIn"; import Automations from "./pages/v2/Automations"; import BucketDetail from "./pages/v2/BucketDetail"; -import FluxRuntime from "./pages/v2/FluxRuntime"; import GitRepositoryDetail from "./pages/v2/GitRepositoryDetail"; import HelmChartDetail from "./pages/v2/HelmChartDetail"; import HelmReleasePage from "./pages/v2/HelmReleasePage"; @@ -52,6 +51,7 @@ import OCIRepositoryPage from "./pages/v2/OCIRepositoryPage"; import PoliciesList from "./pages/v2/PoliciesList"; import PolicyDetailsPage from "./pages/v2/PolicyDetailsPage"; import ProviderPage from "./pages/v2/ProviderPage"; +import Runtime from "./pages/v2/Runtime"; import Sources from "./pages/v2/Sources"; import UserInfo from "./pages/v2/UserInfo"; @@ -65,6 +65,26 @@ function withSearchParams(Cmp) { }; } +// gets the right runtime navigation item based on the feature WEAVE_GITOPS_FEATURE_GITOPS_RUNTIME +// function getRuntimeConfiguration() { +// const { isFlagEnabled } = useFeatureFlags(); +// +// if (isFlagEnabled("WEAVE_GITOPS_FEATURE_GITOPS_RUNTIME")) { +// return { +// label: "Runtime", +// route: V2Routes.Runtime, +// component: {Runtime}, +// }; +// } +// return { +// label: "Flux Runtime", +// route: V2Routes.FluxRuntime, +// component: {FluxRuntime}, +// }; +// } + +// const runtimeConfiguration = getRuntimeConfiguration(); + const navItems: NavItem[] = [ { label: "Applications", @@ -88,7 +108,7 @@ const navItems: NavItem[] = [ }, { label: "Runtime", - link: { value: V2Routes.FluxRuntime }, + link: { value: V2Routes.Runtime }, icon: IconType.FluxIcon, }, { @@ -143,7 +163,8 @@ const App = () => { path={V2Routes.ImagePolicyDetails} component={withSearchParams(ImagePolicyDetails)} /> - + // TODO should be configurable based on feature flag + = { + retry: false, + refetchInterval: 5000, + } +) { + const { api } = useContext(CoreClientContext); + + return useQuery( + "runtime_objects", + () => api.ListRuntimeObjects({ namespace, clusterName }), + opts + ); +} + +export function useListRuntimeCrds(clusterName = DefaultCluster) { + const { api } = useContext(CoreClientContext); + + return useQuery( + "runtime_crds", + () => api.ListRuntimeCrds({ clusterName }), + { retry: false, refetchInterval: 5000 } + ); +} + export function flattenChildren(children: FluxObject[]) { return children.flatMap((child) => [child].concat(flattenChildren(child.children)) diff --git a/ui/lib/types.ts b/ui/lib/types.ts index 9b7c8aaa1d..e973a662c4 100644 --- a/ui/lib/types.ts +++ b/ui/lib/types.ts @@ -28,6 +28,7 @@ export enum V2Routes { Automations = "/applications", Sources = "/sources", FluxRuntime = "/flux_runtime", + Runtime = "/runtime", Kustomization = "/kustomization", HelmRelease = "/helm_release", HelmRepo = "/helm_repo", diff --git a/ui/pages/v2/Runtime.tsx b/ui/pages/v2/Runtime.tsx new file mode 100644 index 0000000000..f628afdb74 --- /dev/null +++ b/ui/pages/v2/Runtime.tsx @@ -0,0 +1,34 @@ +import * as React from "react"; +import {useContext} from "react"; +import styled from "styled-components"; +import FluxRuntimeComponent from "../../components/FluxRuntime"; +import Page from "../../components/Page"; +import {CoreClientContext} from "../../contexts/CoreClientContext"; +import { useFeatureFlags } from "../../hooks/featureflags"; +import {useListFluxCrds, useListFluxRuntimeObjects, useListRuntimeCrds, useListRuntimeObjects} from "../../hooks/flux"; + +type Props = { + className?: string; +}; + +function Runtime({ className }: Props) { + const { data, isLoading, error } = useListRuntimeObjects(); + const { + data: crds, + isLoading: crdsLoading, + error: crdsError, + } = useListRuntimeCrds(); + return ( + + + + + ); +} + +export default styled(Runtime).attrs({ className: Runtime.name })``;