Skip to content

Commit

Permalink
added demo config section
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolea PLESCO authored and Kolea PLESCO committed Jan 16, 2025
1 parent fcebbda commit 492eac5
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 4 deletions.
8 changes: 5 additions & 3 deletions mapping_workbench/backend/core/entrypoints/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
routes_for_specific as specific_triple_map_fragment_routes
from mapping_workbench.backend.triple_map_registry.entrypoints.api import routes as triple_map_registry_routes
from mapping_workbench.backend.user.entrypoints.api import routes as user_routes
from mapping_workbench.backend.xsd_schema.entrypoints.api import routes as xsd_schema_router
from mapping_workbench.backend.xsd_schema.entrypoints.api import routes as xsd_schema_routes
from mapping_workbench.backend.demo.entrypoints.api import routes as demo_routes

ROOT_API_PATH = "/api/v1"

Expand Down Expand Up @@ -95,8 +96,9 @@ async def on_startup():
task_manager_routes.router,
tasks_routes.router, # Deprecated
fields_registry.router,
xsd_schema_router.router,
cm_groups_routes.router
xsd_schema_routes.router,
cm_groups_routes.router,
demo_routes.router
]

for secured_router in secured_routers:
Expand Down
Empty file.
22 changes: 22 additions & 0 deletions mapping_workbench/backend/demo/entrypoints/api/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from fastapi import APIRouter
from fastapi.responses import JSONResponse
from mapping_workbench.backend.config import settings

ROUTE_PREFIX = "/demo"
TAG = "demo"

sub_router = APIRouter()


@sub_router.post(
"/reset",
name="demo:reset"
)
async def metadata() -> JSONResponse:
return JSONResponse(content={
"message": "Resetting the demo data"
})


router = APIRouter()
router.include_router(sub_router, prefix=ROUTE_PREFIX, tags=[TAG])
21 changes: 21 additions & 0 deletions mapping_workbench/frontend/src/api/demo-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {apiPaths} from "../../paths";
import {appApi} from "../app";

class DemoConfigApi {
get SECTION_TITLE() {
return "Demo Config";
}

constructor() {
this.section = "demoConfig";
this.paths = apiPaths[this.section];
}

async reset() {
const endpoint = this.paths.reset;
return appApi.post(endpoint);
}

}

export const demoConfigApi = new DemoConfigApi();
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Popover from '@mui/material/Popover';
import SvgIcon from '@mui/material/SvgIcon';
import Typography from '@mui/material/Typography';
import ManageAccountsIcon from '@mui/icons-material/ManageAccounts';
import DemoConfigIcon from '@mui/icons-material/Tune';

import {RouterLink} from 'src/components/router-link';
import {useAuth} from 'src/hooks/use-auth';
Expand Down Expand Up @@ -143,6 +144,30 @@ export const AccountPopover = (props) => {
)}
/>
</ListItemButton>}
{securityApi.isUserAdmin(auth.user) && <ListItemButton
id='authorization_button'
component={RouterLink}
href={paths.app.demoConfig.index}
onClick={onClose}
sx={{
borderRadius: 1,
px: 1,
py: 0.5
}}
>
<ListItemIcon>
<SvgIcon fontSize="small">
<DemoConfigIcon/>
</SvgIcon>
</ListItemIcon>
<ListItemText
primary={(
<Typography variant="body1">
Demo Config
</Typography>
)}
/>
</ListItemButton>}
</Box>
<Divider sx={{my: '0 !important'}}/>
<Box
Expand Down
65 changes: 65 additions & 0 deletions mapping_workbench/frontend/src/pages/app/demo-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {useEffect} from 'react';

import Card from '@mui/material/Card';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
import {Seo} from 'src/components/seo';
import {usePageView} from 'src/hooks/use-page-view';
import {Layout as AppLayout} from 'src/layouts/app';
import {securityApi} from "../../../api/security";
import {useRouter} from "next/router";
import {useAuth} from "../../../hooks/use-auth";
import {paths} from "../../../paths";
import Button from "@mui/material/Button";
import ResetDemoIcon from "@mui/icons-material/RestartAlt";
import Paper from "@mui/material/Paper";
import {demoConfigApi} from "../../../api/demo-config";


const Page = () => {

const auth = useAuth();
const router = useRouter();

useEffect(
() => {
if (!securityApi.isUserAdmin(auth?.user)) {
router.replace(paths.notFound);
}
}, []);

usePageView();

return (
<>
<Seo title="Demo Config"/>

<Stack spacing={4}>
<Stack
direction="row"
justifyContent="space-between"
spacing={4}
>
<Stack spacing={1}>
<Typography variant="h4">Demo Config</Typography>
</Stack>
</Stack>
<Card>
<Paper sx={{p: 2}}>
<Button variant='contained'
color="warning"
onClick={() => demoConfigApi.reset()}
startIcon={<ResetDemoIcon/>}>
Reset Demo Data
</Button>

</Paper>
</Card>
</Stack>
</>
);
};

Page.getLayout = (page) => <AppLayout>{page}</AppLayout>;

export default Page;
7 changes: 6 additions & 1 deletion mapping_workbench/frontend/src/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ export const paths = {
},
authorization: {
index: '/app/authorization'
},
demoConfig: {
index: '/app/demo-config'
}
},
docs: 'https://material-kit-pro-react-docs.devias.io',
Expand Down Expand Up @@ -425,7 +428,9 @@ export const apiPaths = {
generate_cm_assertions_queries: '/tasks/generate_cm_assertions_queries',
transform_test_data: '/tasks/transform_test_data'
},

demoConfig: {
reset: "/demo/reset"
},
app: {
settings: '/app/settings'
}
Expand Down

0 comments on commit 492eac5

Please sign in to comment.