-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(schema) Add search filter to Schema tab #5845
Changes from all commits
25f88d7
6d48215
54a41a5
cdd8f37
47e9e76
d1f400c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import React, { useState } from 'react'; | ||
import { Typography } from 'antd'; | ||
import styled from 'styled-components'; | ||
import Highlight from 'react-highlighter'; | ||
import translateFieldPath from './translateFieldPath'; | ||
import { ExtendedSchemaFields } from './types'; | ||
import TypeLabel from '../../../../shared/tabs/Dataset/Schema/components/TypeLabel'; | ||
|
@@ -32,6 +33,7 @@ const FieldPathText = styled(Typography.Text)` | |
export default function useSchemaTitleRenderer( | ||
schemaMetadata: SchemaMetadata | undefined | null, | ||
setSelectedFkFieldPath: (params: { fieldPath: string; constraint?: ForeignKeyConstraint | null } | null) => void, | ||
filterText: string, | ||
) { | ||
const [highlightedConstraint, setHighlightedConstraint] = useState<string | null>(null); | ||
|
||
|
@@ -54,7 +56,9 @@ export default function useSchemaTitleRenderer( | |
return ( | ||
<> | ||
<FieldPathContainer> | ||
<FieldPathText>{pathToDisplay}</FieldPathText> | ||
<FieldPathText> | ||
<Highlight search={filterText}>{pathToDisplay}</Highlight> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fancy! bummer that it doesn't work on nested components though :/ i think we'll need to build that for our search cards otherwise we'll need to render like a zillion of these. |
||
</FieldPathText> | ||
<TypeLabel type={record.type} nativeDataType={record.nativeDataType} /> | ||
{(schemaMetadata?.primaryKeys?.includes(fieldPath) || record.isPartOfKey) && <PrimaryKeyLabel />} | ||
{schemaMetadata?.foreignKeys | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, { useMemo, useState } from 'react'; | ||
import React, { useEffect, useMemo, useState } from 'react'; | ||
import { ColumnsType } from 'antd/es/table'; | ||
import styled from 'styled-components'; | ||
import {} from 'antd'; | ||
|
@@ -45,6 +45,8 @@ export type Props = { | |
usageStats?: UsageQueryResult | null; | ||
schemaFieldBlameList?: Array<SchemaFieldBlame> | null; | ||
showSchemaAuditView: boolean; | ||
expandedRowsFromFilter?: Set<string>; | ||
filterText?: string; | ||
}; | ||
export default function SchemaTable({ | ||
rows, | ||
|
@@ -54,6 +56,8 @@ export default function SchemaTable({ | |
editMode = true, | ||
schemaFieldBlameList, | ||
showSchemaAuditView, | ||
expandedRowsFromFilter = new Set(), | ||
filterText = '', | ||
}: Props): JSX.Element { | ||
const hasUsageStats = useMemo(() => (usageStats?.aggregations?.fields?.length || 0) > 0, [usageStats]); | ||
|
||
|
@@ -63,15 +67,27 @@ export default function SchemaTable({ | |
|
||
const descriptionRender = useDescriptionRenderer(editableSchemaMetadata); | ||
const usageStatsRenderer = useUsageStatsRenderer(usageStats); | ||
const tagRenderer = useTagsAndTermsRenderer(editableSchemaMetadata, tagHoveredIndex, setTagHoveredIndex, { | ||
showTags: true, | ||
showTerms: false, | ||
}); | ||
const termRenderer = useTagsAndTermsRenderer(editableSchemaMetadata, tagHoveredIndex, setTagHoveredIndex, { | ||
showTags: false, | ||
showTerms: true, | ||
}); | ||
const schemaTitleRenderer = useSchemaTitleRenderer(schemaMetadata, setSelectedFkFieldPath); | ||
const tagRenderer = useTagsAndTermsRenderer( | ||
editableSchemaMetadata, | ||
tagHoveredIndex, | ||
setTagHoveredIndex, | ||
{ | ||
showTags: true, | ||
showTerms: false, | ||
}, | ||
filterText, | ||
); | ||
const termRenderer = useTagsAndTermsRenderer( | ||
editableSchemaMetadata, | ||
tagHoveredIndex, | ||
setTagHoveredIndex, | ||
{ | ||
showTags: false, | ||
showTerms: true, | ||
}, | ||
filterText, | ||
); | ||
const schemaTitleRenderer = useSchemaTitleRenderer(schemaMetadata, setSelectedFkFieldPath, filterText); | ||
const schemaBlameRenderer = useSchemaBlameRenderer(schemaFieldBlameList); | ||
|
||
const onTagTermCell = (record: SchemaField, rowIndex: number | undefined) => ({ | ||
|
@@ -153,6 +169,17 @@ export default function SchemaTable({ | |
allColumns = [...allColumns, blameColumn]; | ||
} | ||
|
||
const [expandedRows, setExpandedRows] = useState<Set<string>>(new Set()); | ||
|
||
useEffect(() => { | ||
setExpandedRows((previousRows) => { | ||
const finalRowsSet = new Set(); | ||
expandedRowsFromFilter.forEach((row) => finalRowsSet.add(row)); | ||
previousRows.forEach((row) => finalRowsSet.add(row)); | ||
return finalRowsSet as Set<string>; | ||
}); | ||
}, [expandedRowsFromFilter]); | ||
|
||
return ( | ||
<FkContext.Provider value={selectedFkFieldPath}> | ||
<TableContainer> | ||
|
@@ -169,9 +196,20 @@ export default function SchemaTable({ | |
}, | ||
}} | ||
expandable={{ | ||
expandedRowKeys: [...Array.from(expandedRows)], | ||
defaultExpandAllRows: false, | ||
expandRowByClick: false, | ||
expandIcon: ExpandIcon, | ||
onExpand: (expanded, record) => { | ||
if (expanded) { | ||
setExpandedRows((previousRows) => new Set(previousRows.add(record.fieldPath))); | ||
} else { | ||
setExpandedRows((previousRows) => { | ||
previousRows.delete(record.fieldPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tricky! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ugh i know - updating Sets in state isn't as simple as you'd want it to be |
||
return new Set(previousRows); | ||
}); | ||
} | ||
}, | ||
indentSize: 0, | ||
}} | ||
pagination={false} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats up with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is what I mentioned to you some time back where if you import from
/macro
and look in the browser dev tools and check out the html, styled component names are shown, making it much easier to find what styled component is whatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aahhh right! gotta start doing this myself