Skip to content

Commit 91d11af

Browse files
committed
feat: add in the files iframe
1 parent 4c4d951 commit 91d11af

18 files changed

Lines changed: 179 additions & 1 deletion

File tree

api/backend/configs/commands.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def create_config_file(filename: str, config: Schema):
4141
yaml.dump(filtered_config, f, default_flow_style=False, sort_keys=False)
4242

4343

44+
def read_yaml_file(filename: str):
45+
with open(filename, "r") as f:
46+
return yaml.load(f, Loader=yaml.FullLoader)
47+
48+
4449
def get_config_file_for_read(host: str):
4550
config = utils.read(f"./configs/{host}.yml")
4651
config.host.username = "user"

api/backend/configs/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pydantic import BaseModel
2+
3+
4+
class AppConfig(BaseModel):
5+
files_url: str

api/backend/routers/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,19 @@
99
from api.backend.host_manager import HOST_MAP
1010
from api.backend.logging import LOG
1111

12+
from api.backend.configs.models import AppConfig
13+
1214
config_router = APIRouter()
1315

1416

17+
@config_router.get("/api/app-config")
18+
async def get_app_config():
19+
config = yaml_utils.read_yaml_file("./configs/app-config/app-config.yml")
20+
app_config = AppConfig(files_url=config["files_url"])
21+
22+
return JSONResponse(app_config.model_dump())
23+
24+
1525
@config_router.post("/api/config")
1626
async def create_config(build_config: BuildConfigFile):
1727
try:

src/app/store.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { configureStore } from "@reduxjs/toolkit";
22
import integrationsReducer from "@/lib/slices/integrations";
33
import settingsReducer from "@/lib/slices/settings";
4+
import appConfigReducer from "@/lib/slices/app-config";
45

56
export const store = configureStore({
67
reducer: {
8+
appConfig: appConfigReducer,
79
integrations: integrationsReducer,
810
settings: settingsReducer,
911
},
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use client";
2+
3+
import { IconButton } from "@mui/material";
4+
import React, { useState, useEffect } from "react";
5+
import FindInPageIcon from "@mui/icons-material/FindInPage";
6+
import { useRouter } from "next/navigation";
7+
import { useAppConfig } from "@/lib/hooks/use-app-config";
8+
9+
export type FilesProps = {
10+
className?: string;
11+
};
12+
13+
export const Files = ({ className }: FilesProps) => {
14+
const router = useRouter();
15+
const { appConfig } = useAppConfig();
16+
const [isClient, setIsClient] = useState(false);
17+
18+
useEffect(() => {
19+
setIsClient(true);
20+
}, []);
21+
22+
if (!isClient) return null;
23+
24+
return appConfig.filesUrl ? (
25+
<div className={className}>
26+
<IconButton component="span" onClick={() => router.push("/files")}>
27+
<FindInPageIcon />
28+
</IconButton>
29+
</div>
30+
) : null;
31+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./files";

src/components/dashboard/dashboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState, useEffect } from "react";
22
import { fetchAndSet } from "@/lib/utils";
3-
import { Container, Grid } from "@mui/material";
3+
import { Container } from "@mui/material";
44
import classes from "./dashboard.module.css";
55
import HostOverview from "@/components/shared/host-overview/host-overview";
66
import { useRouter } from "next/router";

src/lib/hooks/use-app-config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { RootState } from "@/app";
2+
import { useSelector } from "react-redux";
3+
import { AppConfig } from "../services/app-config/app-config.types";
4+
import { setAppConfig } from "../slices/app-config";
5+
import { useDispatch } from "react-redux";
6+
7+
export const useAppConfig = () => {
8+
const dispatch = useDispatch();
9+
const appConfig = useSelector((state: RootState) => state.appConfig);
10+
11+
return {
12+
appConfig,
13+
setNewAppConfig: (appConfig: AppConfig) =>
14+
dispatch(setAppConfig(appConfig)),
15+
};
16+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type ServerAppConfig = {
2+
files_url: string;
3+
};
4+
5+
export type AppConfig = {
6+
filesUrl: string;
7+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./read-config";

0 commit comments

Comments
 (0)