Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mwb 274 #49

Merged
merged 6 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion infra/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG PORT

ENV PORT=$PORT

RUN apt update && apt install -y make wget
RUN apt update && apt install -y make wget git

# Create an application directory
RUN mkdir -p /app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ def download(self, result_dir_path: pathlib.Path, download_resources_filter: Lis
"""
with tempfile.TemporaryDirectory() as tmp_dir:
temp_dir_path = pathlib.Path(tmp_dir)
bash_script = f"cd {temp_dir_path} && git clone --depth=1 --branch {self.branch_or_tag_name} {self.github_repository_url}"
bash_script = f"cd {temp_dir_path} && git clone --depth=1 --single-branch --branch {self.branch_or_tag_name} {self.github_repository_url}"
subprocess.run(bash_script, shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT)
dir_contents = list(temp_dir_path.iterdir())

assert len(dir_contents) == 1
repository_name = dir_contents[0].name

repository_content_dir_path = temp_dir_path / repository_name
if download_resources_filter:
for content_path in repository_content_dir_path.iterdir():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
from typing import List

from beanie import PydanticObjectId
from fastapi import APIRouter, Depends, status
from fastapi import APIRouter, Depends, status, UploadFile, Form

from mapping_workbench.backend.core.models.api_response import APIEmptyContentWithIdResponse
from mapping_workbench.backend.fields_registry.models.field_registry import StructuralElement, \
Expand Down Expand Up @@ -35,18 +36,34 @@
response_model=APIListStructuralElementsPaginatedResponse
)
async def route_list_structural_elements(
project_id: PydanticObjectId = None
project: PydanticObjectId = None,
page: int = None,
limit: int = None,
q: str = None
):
filters: dict = {}
if project_id:
filters['project'] = Project.link_from_id(project_id)
items: List[StructuralElement] = await list_structural_elements(filters)
if project:
filters['project'] = Project.link_from_id(project)
if q is not None:
filters['q'] = q

items, total_count = await list_structural_elements(filters, page, limit)
return APIListStructuralElementsPaginatedResponse(
items=items,
count=len(items)
count=total_count
)


@router.get(
"/elements/{structural_element_id}",
description=f"Get structural element by id",
name=f"elements:get",
response_model=StructuralElement
)
async def route_get_structural_element(structural_element: StructuralElement = Depends(get_structural_element)):
return structural_element


@router.delete(
"/elements/{id}",
description=f"Delete structural element by id",
Expand Down Expand Up @@ -137,9 +154,10 @@ async def route_search_structural_elements_versioned_view_by_eforms_version(
status_code=status.HTTP_200_OK
)
async def route_import_eforms_from_github(
github_repository_url: str,
branch_or_tag_name: str,
project_id: PydanticObjectId):
github_repository_url: str = Form(...),
branch_or_tag_name: str = Form(...),
project_id: PydanticObjectId = Form(...)
):
project_link = Project.link_from_id(project_id)
await import_eforms_fields_from_github_repository(github_repository_url=github_repository_url,
branch_or_tag_name=branch_or_tag_name,
Expand Down
18 changes: 18 additions & 0 deletions mapping_workbench/backend/fields_registry/models/field_registry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import pymongo
from beanie import Link
from typing import Optional, List, Literal, Set

from pymongo import IndexModel

from mapping_workbench.backend.core.models.api_response import APIListPaginatedResponse
from mapping_workbench.backend.core.models.base_project_resource_entity import BaseProjectResourceEntity

Expand All @@ -27,6 +30,21 @@ class StructuralElement(BaseProjectResourceEntity):
class Settings(BaseProjectResourceEntity.Settings):
name = "structural_elements_registry"

indexes = [
IndexModel(
[
("eforms_sdk_element_id", pymongo.TEXT),
("absolute_xpath", pymongo.TEXT),
("relative_xpath", pymongo.TEXT),
("parent_node_id", pymongo.TEXT),
("versions", pymongo.TEXT),
("name", pymongo.TEXT),
("bt_id", pymongo.TEXT)
],
name="search_text_idx"
)
]


class StructuralElementsVersionedView(BaseProjectResourceEntity):
"""
Expand Down
2 changes: 1 addition & 1 deletion mapping_workbench/backend/fields_registry/services/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def delete_structural_elements_versioned_view(
return await structural_elements_versioned_view.delete()


async def get_structural_element(structural_element_id: PydanticObjectId) -> StructuralElement:
async def get_structural_element(structural_element_id: str) -> StructuralElement:
structural_element: StructuralElement = await StructuralElement.get(structural_element_id)
if not api_entity_is_found(structural_element):
raise ResourceNotFoundException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async def import_eforms_fields(eforms_fields_content: dict, project_link: Link[D
if old_structural_node:
old_structural_node.versions.append(eforms_sdk_version)
old_structural_node.versions = list(set(old_structural_node.versions))
await old_structural_node.save()
else:
new_structural_node.versions.append(eforms_sdk_version)
await new_structural_node.save()
Expand All @@ -71,6 +72,7 @@ async def import_eforms_fields(eforms_fields_content: dict, project_link: Link[D
if old_structural_field:
old_structural_field.versions.append(eforms_sdk_version)
old_structural_field.versions = list(set(old_structural_field.versions))
await old_structural_field.save()
else:
new_structural_field.versions.append(eforms_sdk_version)
await new_structural_field.save()
Expand Down
16 changes: 15 additions & 1 deletion mapping_workbench/frontend/src/api/fields-registry/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {SectionApi} from "../section";
import {ACTION, SectionApi} from "../section";
import {appApi} from "../app";

class FieldsRegistryApi extends SectionApi {
get SECTION_TITLE() {
Expand All @@ -9,9 +10,22 @@ class FieldsRegistryApi extends SectionApi {
return "Fields Registry";
}

get SECTION_LIST_ACTIONS() {
return [ACTION.VIEW];
}

constructor() {
super("fields_registry");
}

importEFormsFromGithub(request) {
try {
let endpoint = this.paths['import_eforms_from_github'];
const headers = {"Content-Type": "multipart/form-data"};
return appApi.post(endpoint, request, null, headers);
} catch (err) {
}
}
}

export const fieldsRegistryApi = new FieldsRegistryApi();
5 changes: 3 additions & 2 deletions mapping_workbench/frontend/src/api/section/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ export class SectionApi {
return await appApi.get(this.paths[path], filters);
}

async getItem(id) {
let endpoint = this.paths['item'].replace(':id', id);
async getItem(id, path = null) {
path = path || "item";
let endpoint = this.paths[path].replace(':id', id);
return await appApi.get(endpoint);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import {Box} from "@mui/system";
export const ListItemActions = (props) => {
const router = useRouter();

const {itemctx} = props;
const {itemctx, pathnames} = props;
const popover = usePopover();

//console.log("itemctx: ", itemctx);

const handleViewAction = useCallback(async () => {
const viewPathname = pathnames && pathnames.view || paths.app[itemctx.api.section].view;
router.push({
pathname: paths.app[itemctx.api.section].view,
pathname: viewPathname,
query: {id: itemctx.id}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export class ForItemDataState {
}
}

export const useItem = (sectionApi, id) => {
export const useItem = (sectionApi, id, path = null) => {
const isMounted = useMounted();
const [item, setItem] = useState(null);

const handleItemGet = useCallback(async () => {
try {
const response = await sectionApi.getItem(id);
const response = await sectionApi.getItem(id, path);
if (isMounted()) {
setItem(response);
}
Expand Down
10 changes: 5 additions & 5 deletions mapping_workbench/frontend/src/layouts/app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,20 @@ export const useSections = () => {
},
{
title: t(tokens.nav.fields_registry),
path: paths.app.fields_registry.index,
path: paths.app.fields_registry.elements.index,
icon: (
<SvgIcon fontSize="small">
<HiveIcon/>
</SvgIcon>
),
items: [
{
title: t(tokens.nav.list),
path: paths.app.fields_registry.index
title: t(tokens.nav.elements),
path: paths.app.fields_registry.elements.index
},
{
title: t(tokens.nav.create),
path: paths.app.fields_registry.create
title: t(tokens.nav.import),
path: paths.app.fields_registry.elements.import
}
]
});
Expand Down
Loading
Loading