Skip to content

Commit 0a9a94d

Browse files
authored
fix collapsing labels if user has read-only access (#133)
1 parent 0686aa6 commit 0a9a94d

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

ui/src/components/pages/parts/Table.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// (C) Copyright 2024-2025 Dassault Systemes SE. All Rights Reserved.
1+
// (C) Copyright 2024-2026 Dassault Systemes SE. All Rights Reserved.
22

33
import { useNavigate } from 'react-router-dom';
44
import { withTranslation } from "react-i18next";
55
import { TableBody, TableTh, TableCell, Table as TableCustom, TableHead, TableRow } from '../../controls/Table';
6-
import { getResourceByPath, getCreatePath, getChild, replaceVariables, getSchemaPath, hasMonitoredPath } from "../../../utils/schema";
6+
import { getResourceByPath, getChild, getSchemaPath, hasMonitoredPath, getEntryPath } from "../../../utils/schema";
77
import { Rest } from "./Rest";
88
import Dialog from "./Dialog";
99
import { MenuItemProps, PageProps, TempAny } from "../../../utils/types";
@@ -174,7 +174,7 @@ function Table(props: TableProps) {
174174
If the field is hierarchical, it will find the schema of the right most field.
175175
Returns defaults if not found. */
176176
function getFieldSchema(fieldName: string) {
177-
const fieldsSchema = getChild(getResourceByPath(schema, getCreatePath(schema, path) || path), ["get", "responses", "200", "content", "application/json", "schema", "properties"]);
177+
const fieldsSchema = getChild(getResourceByPath(schema, getEntryPath(schema, path) || path), ["get", "responses", "200", "content", "application/json", "schema", "properties"]);
178178
let fs = fieldsSchema;
179179
let fn = fieldName;
180180
while (fs && fn.includes(".") && fn.split(".")[0] in fs) {

ui/src/utils/schema.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,42 @@ export function getCreatePath(rootSchema: TempAny, path: string) : string|null {
244244
}
245245
}
246246

247+
/**
248+
* finds path which can be used to view a single entry. It finds the subpath having the longest path
249+
* in a GET request and ending with a placeholder (i.e. {})
250+
* @param {*} rootSchema
251+
* @param {*} path
252+
* @returns full path or null if not found
253+
*/
254+
export function getEntryPath(rootSchema: TempAny, path: string) : string|null {
255+
if(!rootSchema) {
256+
return null;
257+
}
258+
259+
let retPath = "";
260+
const parts = path.split("/");
261+
Object.keys(rootSchema).forEach(sPath => {
262+
const sParts = sPath.split("/");
263+
if(parts.length >= sParts.length) {
264+
return;
265+
}
266+
for (let i = 0; i < parts.length; i++) {
267+
if(parts[i] !== sParts[i] && !sParts[i].startsWith("{")) {
268+
return;
269+
}
270+
}
271+
if(retPath.length < sPath.length && ("get" in rootSchema[sPath]) && sPath[sPath.length-1].endsWith("}")) {
272+
retPath = sPath;
273+
}
274+
});
275+
if(!retPath) {
276+
return null;
277+
}
278+
else {
279+
return retPath;
280+
}
281+
}
282+
247283
/**
248284
* returns field name which can be used as filter for this list
249285
* @param {*} rootSchema

0 commit comments

Comments
 (0)