mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-03 12:16:10 +00:00
feat(schema): support rendering schemas with . in field names (#5141)
This commit is contained in:
parent
c4650356fa
commit
1b50709e20
@ -37,29 +37,24 @@ export default function useSchemaTitleRenderer(
|
||||
|
||||
return (fieldPath: string, record: ExtendedSchemaFields): JSX.Element => {
|
||||
const fieldPathWithoutAnnotations = translateFieldPath(fieldPath);
|
||||
const parentPathWithoutAnnotations = translateFieldPath(record.parent?.fieldPath || '');
|
||||
let pathToDisplay = fieldPathWithoutAnnotations;
|
||||
|
||||
const isOverflow = fieldPathWithoutAnnotations.length > MAX_FIELD_PATH_LENGTH;
|
||||
// if the parent path is a prefix of the field path, remove it for display purposes
|
||||
if (parentPathWithoutAnnotations && fieldPathWithoutAnnotations.indexOf(parentPathWithoutAnnotations) === 0) {
|
||||
// parent length + 1 because of the trailing `.` of the parent
|
||||
pathToDisplay = fieldPathWithoutAnnotations.slice(parentPathWithoutAnnotations.length + 1);
|
||||
}
|
||||
|
||||
let [firstPath, lastPath] = fieldPathWithoutAnnotations.split(/\.(?=[^.]+$)/);
|
||||
|
||||
if (isOverflow) {
|
||||
if (lastPath.length >= MAX_FIELD_PATH_LENGTH) {
|
||||
lastPath = `..${lastPath.substring(lastPath.length - MAX_FIELD_PATH_LENGTH)}`;
|
||||
firstPath = '';
|
||||
} else {
|
||||
firstPath = firstPath.substring(fieldPath.length - MAX_FIELD_PATH_LENGTH);
|
||||
if (firstPath.includes('.')) {
|
||||
firstPath = `..${firstPath.substring(firstPath.indexOf('.'))}`;
|
||||
} else {
|
||||
firstPath = '..';
|
||||
}
|
||||
}
|
||||
// if the field path is too long, truncate it
|
||||
if (pathToDisplay.length > MAX_FIELD_PATH_LENGTH) {
|
||||
pathToDisplay = `..${pathToDisplay.substring(pathToDisplay.length - MAX_FIELD_PATH_LENGTH)}`;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<FieldPathContainer>
|
||||
<FieldPathText>{lastPath || firstPath}</FieldPathText>
|
||||
<FieldPathText>{pathToDisplay}</FieldPathText>
|
||||
<TypeLabel type={record.type} nativeDataType={record.nativeDataType} />
|
||||
{(schemaMetadata?.primaryKeys?.includes(fieldPath) || record.isPartOfKey) && <PrimaryKeyLabel />}
|
||||
{schemaMetadata?.foreignKeys
|
||||
|
||||
@ -7,6 +7,7 @@ export interface ExtendedSchemaFields extends SchemaField {
|
||||
pastGlobalTags?: GlobalTags | null;
|
||||
isNewRow?: boolean;
|
||||
isDeletedRow?: boolean;
|
||||
parent?: ExtendedSchemaFields;
|
||||
}
|
||||
|
||||
export enum SchemaViewType {
|
||||
|
||||
@ -121,6 +121,7 @@ export function groupByFieldPath(
|
||||
// if the parent field exists in the ouput, add the current row as a child
|
||||
if (parentRow) {
|
||||
row.depth = (parentRow.depth || 0) + 1;
|
||||
row.parent = parentRow;
|
||||
parentRow.children = [...(parentRow.children || []), row];
|
||||
} else {
|
||||
outputRows.push(row);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user