mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-13 17:59:48 +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 => {
|
return (fieldPath: string, record: ExtendedSchemaFields): JSX.Element => {
|
||||||
const fieldPathWithoutAnnotations = translateFieldPath(fieldPath);
|
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 the field path is too long, truncate it
|
||||||
|
if (pathToDisplay.length > MAX_FIELD_PATH_LENGTH) {
|
||||||
if (isOverflow) {
|
pathToDisplay = `..${pathToDisplay.substring(pathToDisplay.length - MAX_FIELD_PATH_LENGTH)}`;
|
||||||
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 = '..';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FieldPathContainer>
|
<FieldPathContainer>
|
||||||
<FieldPathText>{lastPath || firstPath}</FieldPathText>
|
<FieldPathText>{pathToDisplay}</FieldPathText>
|
||||||
<TypeLabel type={record.type} nativeDataType={record.nativeDataType} />
|
<TypeLabel type={record.type} nativeDataType={record.nativeDataType} />
|
||||||
{(schemaMetadata?.primaryKeys?.includes(fieldPath) || record.isPartOfKey) && <PrimaryKeyLabel />}
|
{(schemaMetadata?.primaryKeys?.includes(fieldPath) || record.isPartOfKey) && <PrimaryKeyLabel />}
|
||||||
{schemaMetadata?.foreignKeys
|
{schemaMetadata?.foreignKeys
|
||||||
|
|||||||
@ -7,6 +7,7 @@ export interface ExtendedSchemaFields extends SchemaField {
|
|||||||
pastGlobalTags?: GlobalTags | null;
|
pastGlobalTags?: GlobalTags | null;
|
||||||
isNewRow?: boolean;
|
isNewRow?: boolean;
|
||||||
isDeletedRow?: boolean;
|
isDeletedRow?: boolean;
|
||||||
|
parent?: ExtendedSchemaFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum SchemaViewType {
|
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 the parent field exists in the ouput, add the current row as a child
|
||||||
if (parentRow) {
|
if (parentRow) {
|
||||||
row.depth = (parentRow.depth || 0) + 1;
|
row.depth = (parentRow.depth || 0) + 1;
|
||||||
|
row.parent = parentRow;
|
||||||
parentRow.children = [...(parentRow.children || []), row];
|
parentRow.children = [...(parentRow.children || []), row];
|
||||||
} else {
|
} else {
|
||||||
outputRows.push(row);
|
outputRows.push(row);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user