forked from VRK-YTI/yti-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from CSCfi/CSCFC4EMSCR-588_Array-values-in-no…
…de-info-box CSCFC4EMSCR-588 Show node property attribute values that are arrays
- Loading branch information
Showing
4 changed files
with
68 additions
and
29 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
30 changes: 30 additions & 0 deletions
30
mscr-ui/src/common/components/schema-info/schema-tree/node-info/render-attribute/index.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,30 @@ | ||
import { ConstantAttribute } from '@app/common/interfaces/node.interface'; | ||
import processHtmlLinks from '@app/common/utils/process-html-links'; | ||
|
||
export default function RenderAttribute({ attribute }: { attribute: ConstantAttribute }) { | ||
const valueWithLinks = processHtmlLinks(attribute.value); | ||
let valueList; | ||
// Add line breaks between values if multiple | ||
if (Array.isArray(valueWithLinks)) { | ||
valueList = [valueWithLinks[0]]; | ||
for (let i = 1; i < valueWithLinks.length; i++) { | ||
valueList.push( | ||
<span key={self.crypto.randomUUID()}> | ||
<br /> | ||
{valueWithLinks[i]} | ||
</span> | ||
); | ||
} | ||
} else { | ||
valueList = valueWithLinks; | ||
} | ||
return ( | ||
<div | ||
className="col-12" | ||
hidden={attribute.name === '@id'} | ||
> | ||
<div>{processHtmlLinks(attribute.name)}:</div> | ||
<div className="attribute-font">{valueList}</div> | ||
</div> | ||
); | ||
} |
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,4 @@ | ||
export interface ConstantAttribute { | ||
name: string; | ||
value: string | Array<string | number | boolean> | undefined; | ||
} |
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,24 @@ | ||
import { IconLinkExternal } from 'suomifi-icons'; | ||
|
||
// Takes a string or an array of primitive values and swaps urls to link elements | ||
export default function processHtmlLinks(input: string | Array<string | number | boolean> | undefined) { | ||
const inputArray = typeof input == 'string' ? [input] : input; | ||
if (!inputArray) return undefined; | ||
const output : Array<JSX.Element | string | number | boolean> = inputArray.map((inputPart) => { | ||
if (typeof inputPart == 'string' && (inputPart.startsWith('http://') || inputPart.startsWith('https://'))) { | ||
return ( | ||
<a key={inputPart} href={inputPart} target="_blank" rel="noreferrer"> | ||
{inputPart} <IconLinkExternal /> | ||
</a> | ||
); | ||
} else { | ||
return inputPart; | ||
} | ||
}); | ||
|
||
if (typeof input == 'string') { | ||
return output[0]; | ||
} else { | ||
return output; | ||
} | ||
} |