Skip to content

Commit

Permalink
added ui support to runtime
Browse files Browse the repository at this point in the history
Signed-off-by: Eneko Fernandez <eneko@weave.works>
  • Loading branch information
enekofb committed Dec 18, 2023
1 parent 813dda2 commit 2463ec5
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 7 deletions.
27 changes: 24 additions & 3 deletions ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";

Expand All @@ -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",
Expand All @@ -88,7 +108,7 @@ const navItems: NavItem[] = [
},
{
label: "Runtime",
link: { value: V2Routes.FluxRuntime },
link: { value: V2Routes.Runtime },
icon: IconType.FluxIcon,
},
{
Expand Down Expand Up @@ -143,7 +163,8 @@ const App = () => {
path={V2Routes.ImagePolicyDetails}
component={withSearchParams(ImagePolicyDetails)}
/>
<Route path={V2Routes.FluxRuntime} component={FluxRuntime} />
// TODO should be configurable based on feature flag
<Route path={V2Routes.Runtime} component={Runtime} />
<Route
path={V2Routes.GitRepo}
component={withSearchParams(GitRepositoryDetail)}
Expand Down
35 changes: 31 additions & 4 deletions ui/hooks/flux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { useContext } from "react";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { CoreClientContext } from "../contexts/CoreClientContext";
import {
ListFluxCrdsResponse,
ListFluxRuntimeObjectsResponse,
ToggleSuspendResourceRequest,
ToggleSuspendResourceResponse,
ListFluxCrdsResponse,
ListFluxRuntimeObjectsResponse, ListRuntimeObjectsResponse,
ToggleSuspendResourceRequest,
ToggleSuspendResourceResponse,
} from "../lib/api/core/core.pb";
import { GroupVersionKind, Kind } from "../lib/api/core/types.pb";
import { getChildren } from "../lib/graph";
Expand Down Expand Up @@ -44,6 +44,33 @@ export function useListFluxCrds(clusterName = DefaultCluster) {
);
}

export function useListRuntimeObjects(
clusterName = DefaultCluster,
namespace = NoNamespace,
opts: ReactQueryOptions<ListRuntimeObjectsResponse, RequestError> = {
retry: false,
refetchInterval: 5000,
}
) {
const { api } = useContext(CoreClientContext);

return useQuery<ListRuntimeObjectsResponse, RequestError>(
"runtime_objects",
() => api.ListRuntimeObjects({ namespace, clusterName }),
opts
);
}

export function useListRuntimeCrds(clusterName = DefaultCluster) {
const { api } = useContext(CoreClientContext);

return useQuery<ListFluxCrdsResponse, RequestError>(
"runtime_crds",
() => api.ListRuntimeCrds({ clusterName }),
{ retry: false, refetchInterval: 5000 }
);
}

export function flattenChildren(children: FluxObject[]) {
return children.flatMap((child) =>
[child].concat(flattenChildren(child.children))
Expand Down
1 change: 1 addition & 0 deletions ui/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum V2Routes {
Automations = "/applications",
Sources = "/sources",
FluxRuntime = "/flux_runtime",
Runtime = "/runtime",
Kustomization = "/kustomization",
HelmRelease = "/helm_release",
HelmRepo = "/helm_repo",
Expand Down
34 changes: 34 additions & 0 deletions ui/pages/v2/Runtime.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as React from "react";
import {useContext} from "react";

Check failure on line 2 in ui/pages/v2/Runtime.tsx

View workflow job for this annotation

GitHub Actions / CI Test JS (16.X)

'useContext' is defined but never used
import styled from "styled-components";
import FluxRuntimeComponent from "../../components/FluxRuntime";
import Page from "../../components/Page";
import {CoreClientContext} from "../../contexts/CoreClientContext";

Check failure on line 6 in ui/pages/v2/Runtime.tsx

View workflow job for this annotation

GitHub Actions / CI Test JS (16.X)

'CoreClientContext' is defined but never used
import { useFeatureFlags } from "../../hooks/featureflags";

Check failure on line 7 in ui/pages/v2/Runtime.tsx

View workflow job for this annotation

GitHub Actions / CI Test JS (16.X)

'useFeatureFlags' is defined but never used
import {useListFluxCrds, useListFluxRuntimeObjects, useListRuntimeCrds, useListRuntimeObjects} from "../../hooks/flux";

Check failure on line 8 in ui/pages/v2/Runtime.tsx

View workflow job for this annotation

GitHub Actions / CI Test JS (16.X)

'useListFluxCrds' is defined but never used

Check failure on line 8 in ui/pages/v2/Runtime.tsx

View workflow job for this annotation

GitHub Actions / CI Test JS (16.X)

'useListFluxRuntimeObjects' is defined but never used

type Props = {
className?: string;
};

function Runtime({ className }: Props) {
const { data, isLoading, error } = useListRuntimeObjects();
const {
data: crds,
isLoading: crdsLoading,
error: crdsError,
} = useListRuntimeCrds();
return (

<Page
loading={isLoading || crdsLoading}
error={error || crdsError}
className={className}
path={[{ label: "Runtime" }]}
>
<FluxRuntimeComponent deployments={data?.deployments} crds={crds?.crds} />
</Page>
);
}

export default styled(Runtime).attrs({ className: Runtime.name })``;

0 comments on commit 2463ec5

Please sign in to comment.