-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into cc--fix-data-product-num-assets
- Loading branch information
Showing
15 changed files
with
383 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
datahub-web-react/src/app/search/filters/render/FilterRenderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { FilterRenderProps } from './types'; | ||
|
||
/** | ||
* Base interface used for custom search filter renderers | ||
* | ||
*/ | ||
export interface FilterRenderer { | ||
/** | ||
* The filter field that is rendered by this renderer | ||
*/ | ||
field: string; | ||
|
||
/** | ||
* Renders the filter | ||
*/ | ||
render: (props: FilterRenderProps) => JSX.Element; | ||
|
||
/** | ||
* Ant-design icon associated with the Entity. For a list of all candidate icons, see | ||
* https://ant.design/components/icon/ | ||
*/ | ||
icon: () => JSX.Element; | ||
|
||
/** | ||
* Returns a label for rendering the value of a particular field, e.g. for rendering the selected set of filters. | ||
* Currently only for rendering the selected value set below Search V2 top-bar. | ||
*/ | ||
valueLabel: (value: string) => JSX.Element; | ||
} |
42 changes: 42 additions & 0 deletions
42
datahub-web-react/src/app/search/filters/render/FilterRendererRegistry.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { FilterRenderer } from './FilterRenderer'; | ||
import { FilterRenderProps } from './types'; | ||
|
||
function validatedGet<K, V>(key: K, map: Map<K, V>): V { | ||
if (map.has(key)) { | ||
return map.get(key) as V; | ||
} | ||
throw new Error(`Unrecognized key ${key} provided in map ${JSON.stringify(map)}`); | ||
} | ||
|
||
/** | ||
* Serves as a singleton registry for custom filter renderers. | ||
*/ | ||
export default class FilterRendererRegistry { | ||
renderers: Array<FilterRenderer> = new Array<FilterRenderer>(); | ||
|
||
fieldNameToRenderer: Map<string, FilterRenderer> = new Map<string, FilterRenderer>(); | ||
|
||
register(renderer: FilterRenderer) { | ||
this.renderers.push(renderer); | ||
this.fieldNameToRenderer.set(renderer.field, renderer); | ||
} | ||
|
||
hasRenderer(field: string): boolean { | ||
return this.fieldNameToRenderer.has(field); | ||
} | ||
|
||
render(field: string, props: FilterRenderProps): React.ReactNode { | ||
const renderer = validatedGet(field, this.fieldNameToRenderer); | ||
return renderer.render(props); | ||
} | ||
|
||
getValueLabel(field: string, value: string): React.ReactNode { | ||
const renderer = validatedGet(field, this.fieldNameToRenderer); | ||
return renderer.valueLabel(value); | ||
} | ||
|
||
getIcon(field: string): React.ReactNode { | ||
const renderer = validatedGet(field, this.fieldNameToRenderer); | ||
return renderer.icon(); | ||
} | ||
} |
Oops, something went wrong.