Skip to content

Commit

Permalink
[#464] Improve JS
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmursa-dev committed Jan 8, 2025
1 parent 7f5fdd6 commit d3e962f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/objects/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ def get_urls(self):
return my_urls + urls

def versions_view(self, request, objecttype_id):
versions = {}
versions = {
"count": 0,
"next": None,
"previous": None,
"results": [],
}
if objecttype := self.get_object(request, objecttype_id):
client = build_client(objecttype.service)
try:
response = client.get(objecttype.versions_url)
response_data = response.json()

# TODO: remove check once API V1 is removed
if "results" in response_data:
versions = response_data["results"]

versions = response.json()
except (requests.RequestException, requests.JSONDecodeError):
pass
return JsonResponse(versions, safe=False)
Expand Down
22 changes: 12 additions & 10 deletions src/objects/js/components/admin/permissions/permission-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ const PermissionForm = ({objectFields, tokenChoices, objecttypeChoices, modeChoi
})
.then(response => response.json())
.then(response_data => {
const objecttypes = {
[objecttype_id]: response_data.reduce((acc, version) => {
const properties = Object.keys(version.jsonSchema?.properties || {});
acc[version.version] = properties.reduce((propsAcc, prop) => {
propsAcc[prop] = `record__data__${prop}`;
return propsAcc;
}, {});
return acc;
}, {})
};
if (response_data?.results?.length > 0) {
const objecttypes = {
[objecttype_id]: response_data.results.reduce((acc, version) => {
const properties = Object.keys(version?.jsonSchema?.properties || {});
acc[version.version] = properties.reduce((propsAcc, prop) => {
propsAcc[prop] = `record__data__${prop}`;
return propsAcc;
}, {});
return acc;
}, {})
};
setDataFieldChoices(objecttypes);
}
})
.catch(error => {
console.error('An error occurred while fetching the Objecttype versions endpoint:', error);
Expand Down

0 comments on commit d3e962f

Please sign in to comment.