Skip to content
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

fix(react): url encoding urns and tag profile fix #2623

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion datahub-web-react/src/app/entity/EntityPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ interface Props {
* Responsible for rendering an Entity Profile
*/
export const EntityPage = ({ entityType }: Props) => {
const { urn } = useParams<RouteParams>();
const { urn: encodedUrn } = useParams<RouteParams>();
const urn = decodeURIComponent(encodedUrn);
const entityRegistry = useEntityRegistry();
const isBrowsable = entityRegistry.getEntity(entityType).isBrowseEnabled();
const isLineageSupported = entityRegistry.getEntity(entityType).isLineageEnabled();
Expand Down
5 changes: 5 additions & 0 deletions datahub-web-react/src/app/entity/EntityRegistry.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EntityType, SearchResult } from '../../types.generated';
import { FetchedEntity } from '../lineage/types';
import { Entity, IconStyleType, PreviewType } from './Entity';
import { urlEncodeUrn } from './shared/utils';

function validatedGet<K, V>(key: K, map: Map<K, V>): V {
if (map.has(key)) {
Expand Down Expand Up @@ -71,6 +72,10 @@ export default class EntityRegistry {
return entity.getPathName();
}

getEntityUrl(type: EntityType, urn: string): string {
return `/${this.getPathName(type)}/${urlEncodeUrn(urn)}`;
}

getTypeFromPathName(pathName: string): EntityType {
return validatedGet(pathName, this.pathNameToEntityType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const ChartPreview = ({

return (
<DefaultPreviewCard
url={`/${entityRegistry.getPathName(EntityType.Chart)}/${urn}`}
url={entityRegistry.getEntityUrl(EntityType.Chart, urn)}
name={name || ''}
description={description || ''}
type="Chart"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const DashboardPreview = ({

return (
<DefaultPreviewCard
url={`/${entityRegistry.getPathName(EntityType.Dashboard)}/${urn}`}
url={entityRegistry.getEntityUrl(EntityType.Dashboard, urn)}
name={name || ''}
description={description || ''}
type="Dashboard"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Preview = ({
const capitalizedPlatform = capitalizeFirstLetter(platformName);
return (
<DefaultPreviewCard
url={`/${entityRegistry.getPathName(EntityType.DataFlow)}/${urn}`}
url={entityRegistry.getEntityUrl(EntityType.DataFlow, urn)}
name={name}
description={description || ''}
type="Data Pipeline"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Preview = ({
const capitalizedPlatform = capitalizeFirstLetter(platformName);
return (
<DefaultPreviewCard
url={`/${entityRegistry.getPathName(EntityType.DataJob)}/${urn}`}
url={entityRegistry.getEntityUrl(EntityType.DataJob, urn)}
name={name}
description={description || ''}
type="Data Task"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const Preview = ({
const capitalPlatformName = capitalizeFirstLetter(platformName);
return (
<DefaultPreviewCard
url={`/${entityRegistry.getPathName(EntityType.Dataset)}/${urn}`}
url={entityRegistry.getEntityUrl(EntityType.Dataset, urn)}
name={name || ''}
description={description || ''}
type="Dataset"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Preview = ({
const entityRegistry = useEntityRegistry();
return (
<DefaultPreviewCard
url={`/${entityRegistry.getPathName(EntityType.GlossaryTerm)}/${urn}`}
url={entityRegistry.getEntityUrl(EntityType.GlossaryTerm, urn)}
name={name || ''}
description={definition || ''}
owners={owners}
Expand Down
3 changes: 3 additions & 0 deletions datahub-web-react/src/app/entity/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function urlEncodeUrn(urn: string) {
return urn && urn.replace(/%/g, '%25').replace(/\//g, '%2F').replace(/\?/g, '%3F').replace(/#/g, '%23');
}
2 changes: 1 addition & 1 deletion datahub-web-react/src/app/entity/tag/TagProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default function TagProfile() {
onClick={() =>
navigateToSearchUrl({
type: type as EntityType,
query: `tags:${data?.tag?.name}`,
query: `tags:"${data?.tag?.name}"`,
history,
entityRegistry,
})
Expand Down
2 changes: 1 addition & 1 deletion datahub-web-react/src/app/entity/user/preview/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Preview = ({
const entityRegistry = useEntityRegistry();

return (
<Link to={`/${entityRegistry.getPathName(EntityType.CorpUser)}/${urn}`}>
<Link to={entityRegistry.getEntityUrl(EntityType.CorpUser, urn)}>
<Space size={28}>
<CustomAvatar size={60} photoUrl={photoUrl} name={name} />
<Space direction="vertical" size={4}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const Preview = ({
const entityRegistry = useEntityRegistry();

return (
<Link to={`/${entityRegistry.getPathName(EntityType.CorpGroup)}/${urn}`}>
<Link to={entityRegistry.getEntityUrl(EntityType.CorpGroup, urn)}>
<Space size={28}>
<CustomAvatar size={60} photoUrl={photoUrl} name={name} isGroup />
<Space direction="vertical" size={4}>
Expand Down
4 changes: 2 additions & 2 deletions datahub-web-react/src/app/lineage/LineageExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function LineageExplorer({ urn, type }: Props) {
}}
onEntityCenter={(params: EntitySelectParams) => {
history.push(
`/${entityRegistry.getPathName(params.type)}/${params.urn}/?is_lineage_mode=true`,
`${entityRegistry.getEntityUrl(params.type, params.urn)}/?is_lineage_mode=true`,
);
}}
onLineageExpand={(params: LineageExpandParams) => {
Expand All @@ -121,7 +121,7 @@ export default function LineageExplorer({ urn, type }: Props) {
<Col span={8} offset={8}>
<Button
type="primary"
href={`/${entityRegistry.getPathName(selectedEntity.type)}/${selectedEntity.urn}/`}
href={entityRegistry.getEntityUrl(selectedEntity.type, selectedEntity.urn)}
>
View Profile
</Button>
Expand Down