Skip to content

Commit

Permalink
Update grid width calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jul 27, 2022
1 parent 18fbef1 commit abb4cd0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 2 additions & 7 deletions packages/core/BaseFeatureWidget/BaseFeatureDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
measureGridWidth,
getSession,
getStr,
getUriLink,
isUriLocation,
} from '../util'
import SanitizedHTML from '../ui/SanitizedHTML'
Expand Down Expand Up @@ -320,13 +321,7 @@ export function UriLink({
}: {
value: { uri: string; baseUri?: string }
}) {
const { uri, baseUri = '' } = value
let href
try {
href = new URL(uri, baseUri).href
} catch (e) {
href = uri
}
const href = getUriLink(value)
return <SanitizedHTML html={`<a href="${href}">${href}</a>`} />
}
const DataGridDetails = ({
Expand Down
13 changes: 12 additions & 1 deletion packages/core/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1128,10 +1128,21 @@ export const useLocalStorage = (key: string, defaultValue = '') => {
return [value, setValue] as [string, (arg: string) => void]
}

export function getUriLink(value: { uri: string; baseUri?: string }) {
const { uri, baseUri = '' } = value
let href
try {
href = new URL(uri, baseUri).href
} catch (e) {
href = uri
}
return href
}

export function getStr(obj: unknown) {
return isObject(obj)
? isUriLocation(obj)
? obj.uri
? getUriLink(obj)
: JSON.stringify(obj)
: String(obj)
}
Expand Down

0 comments on commit abb4cd0

Please sign in to comment.