-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'storybook' of github.com:DSD-DBS/capella-model-explorer…
… into storybook
- Loading branch information
Showing
7 changed files
with
137 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,73 @@ | ||
import React, {useEffect, useState, useRef} from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { Spinner } from './Spinner'; | ||
import { SVGDisplay } from './SVGDisplay'; | ||
import React, { useEffect, useRef, useState } from "react"; | ||
import { SVGDisplay } from "./SVGDisplay"; | ||
import { Spinner } from "./Spinner"; | ||
|
||
|
||
export const InstanceView = ({templateName, objectID, endpoint}) => { | ||
export const InstanceView = ({ templateName, objectID, endpoint }) => { | ||
const [details, setDetails] = useState([]); | ||
const [loading, setLoading] = useState(true); | ||
const contentRef = useRef(null); | ||
|
||
useEffect(() => { | ||
setLoading(true); | ||
const url = endpoint + `${templateName}/${objectID}`; | ||
fetch(url, { | ||
method: 'GET', | ||
method: "GET", | ||
headers: { | ||
'Content-Type': 'text/html' | ||
} | ||
"Content-Type": "text/html", | ||
}, | ||
}) | ||
.then(response => response.text()) | ||
.then(data => { | ||
const parser = new DOMParser(); | ||
const doc = parser.parseFromString(data, 'text/html'); | ||
const contentItems = []; | ||
doc.body.childNodes.forEach((node) => { | ||
if (node.nodeType === Node.ELEMENT_NODE) { | ||
if (node.tagName === 'svg') { | ||
contentItems.push({type: "SVGDisplay", content: node.outerHTML}); | ||
} else { | ||
contentItems.push({type: "HTML", content: node.outerHTML}); | ||
.then((response) => response.text()) | ||
.then((data) => { | ||
const parser = new DOMParser(); | ||
const doc = parser.parseFromString(data, "text/html"); | ||
const contentItems = []; | ||
doc.body.childNodes.forEach((node) => { | ||
if (node.nodeType === Node.ELEMENT_NODE) { | ||
if (node.tagName === "svg") { | ||
contentItems.push({ | ||
type: "SVGDisplay", | ||
content: node.outerHTML, | ||
}); | ||
} else { | ||
contentItems.push({ | ||
type: "HTML", | ||
content: node.outerHTML, | ||
}); | ||
} | ||
} | ||
} | ||
}); | ||
setDetails(contentItems); | ||
setLoading(false); | ||
if (contentRef.current) contentRef.current.scrollIntoView(); | ||
}) | ||
.catch((error) => { | ||
setLoading(false); | ||
setDetails("Error fetching data ", error); | ||
}); | ||
setDetails(contentItems); | ||
setLoading(false); | ||
if (contentRef.current) contentRef.current.scrollIntoView(); | ||
}) | ||
.catch((error) => { | ||
setLoading(false); | ||
setDetails("Error fetching data ", error); | ||
}); | ||
}, [endpoint, objectID, templateName]); | ||
if (loading) return (<div><Spinner />;</div>) | ||
if (loading) | ||
return ( | ||
<div> | ||
<Spinner />; | ||
</div> | ||
); | ||
return ( | ||
<div ref={contentRef} className='html-content bg-white shadow-lg dark:shadow-white text-gray-700 mx-auto md:my-8 p-8 md:w-[210mm] max-w-full overflow-auto print:shadow-none print:m-0 print:p-0 print:bg-transparent'> | ||
{details.map((item, idx) => { | ||
if (item.type === "SVGDisplay") { | ||
return ( | ||
<SVGDisplay key={idx} content={item.content} /> | ||
); | ||
} else { | ||
return ( | ||
<div key={idx} dangerouslySetInnerHTML={{__html: item.content}} /> | ||
); | ||
} | ||
})} | ||
</div> | ||
);} | ||
<div | ||
ref={contentRef} | ||
className="html-content bg-white shadow-lg dark:shadow-white text-gray-700 mx-auto md:my-8 p-8 md:w-[210mm] max-w-full overflow-auto print:shadow-none print:m-0 print:p-0 print:bg-transparent min-w-full" | ||
> | ||
{details.map((item, idx) => { | ||
if (item.type === "SVGDisplay") { | ||
return <SVGDisplay key={idx} content={item.content} />; | ||
} else { | ||
return ( | ||
<div | ||
key={idx} | ||
dangerouslySetInnerHTML={{ __html: item.content }} | ||
/> | ||
); | ||
} | ||
})} | ||
</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
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,17 @@ | ||
// Spinner.stories.js | ||
import React from 'react'; | ||
import { Spinner } from '../components/Spinner'; | ||
|
||
export default { | ||
title: 'Components/Spinner', | ||
component: Spinner, | ||
}; | ||
export const Demo = { | ||
args: { | ||
template: { | ||
name: "Spinner", | ||
description: "Spins and looks cool.", | ||
}, | ||
}, | ||
}; | ||
|
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