feat(schema): support rendering schemas with . in field names (#5141)

This commit is contained in:
Gabe Lyons 2022-06-09 20:36:36 -07:00 committed by GitHub
parent c4650356fa
commit 1b50709e20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 16 deletions

View File

@ -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

View File

@ -7,6 +7,7 @@ export interface ExtendedSchemaFields extends SchemaField {
pastGlobalTags?: GlobalTags | null;
isNewRow?: boolean;
isDeletedRow?: boolean;
parent?: ExtendedSchemaFields;
}
export enum SchemaViewType {

View File

@ -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);