-
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.
feat: Support singe-instance templates
- Loading branch information
Showing
5 changed files
with
154 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,117 @@ | ||
// Copyright DB InfraGO AG and contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React, {useEffect, useState} from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { Card } from './Card'; | ||
import React, { useEffect, useState } from "react"; | ||
import { useNavigate, useParams } from "react-router-dom"; | ||
|
||
export const TemplateDetails = ({endpoint}) => { | ||
export const TemplateDetails = ({ endpoint, onSingleInstance }) => { | ||
let { templateName, objectID } = useParams(); | ||
const [error, setError] = useState(null); | ||
const [details, setDetails] = useState([]); | ||
const navigate = useNavigate(); | ||
const [filterText, setFilterText] = useState(''); | ||
const [filterText, setFilterText] = useState(""); | ||
|
||
useEffect(() => { | ||
const fetchDetails = async () => { | ||
try { | ||
const response = await fetch(endpoint + templateName, { | ||
method: 'GET', | ||
method: "GET", | ||
headers: { | ||
'Content-Type': 'application/json' | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
const data = await response.json(); | ||
setDetails(data); | ||
} | ||
catch (error) { | ||
if (data.single) { | ||
onSingleInstance(data.objects[0].idx); | ||
} | ||
} catch (error) { | ||
setError(error.message); | ||
} finally { | ||
} | ||
finally {} | ||
}; | ||
fetchDetails(); | ||
}, [endpoint, templateName, objectID]); | ||
}, [endpoint, templateName, objectID, onSingleInstance]); | ||
if (error) { | ||
return ( | ||
<div className='bg-red-500 text-white p-4 rounded text-2xl'> | ||
{error} | ||
</div> | ||
) | ||
<div className="bg-red-500 text-white p-4 rounded text-2xl"> | ||
{error} | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div className='flex flex-col h-full'> | ||
<h5 className='mb-2 text-2xl font-bold text-gray-900 dark:text-white'> | ||
<div className="flex flex-col h-full"> | ||
<h5 className="mb-2 text-2xl font-bold text-gray-900 dark:text-white"> | ||
{details.name} | ||
</h5> | ||
<p className='mb-3 font-normal text-gray-700 dark:text-white'>{details.description}</p> | ||
{details.error ? ( | ||
<div> | ||
<p>We failed to find matching template instances due to the following error: </p> | ||
<div className='bg-red-500 py-2 px-2 text-white rounded'> | ||
{details.error} | ||
</div> | ||
</div> | ||
) : ( | ||
<> | ||
<input | ||
type="text" | ||
value={filterText} | ||
onChange={(e) => setFilterText(e.target.value)} | ||
placeholder="Filter objects" | ||
className="mb-3 p-2 border rounded" | ||
/> | ||
<div className='flex flex-wrap justify-center items-center overflow-auto'> | ||
{details.objects && details.objects.length === 0 ? ( | ||
<p>No objects found</p> | ||
) : ( | ||
details.objects && details.objects.filter(object => object.name.toLowerCase().includes(filterText.toLowerCase())).map(object => ( | ||
<div key={object.idx} | ||
onClick={() => {navigate(`/${templateName}/${object.idx}`);}} | ||
className={(objectID && object.idx === objectID ? 'bg-blue-800 dark:bg-blue-800 text-white hover:dark:text-white hover:text-blue-800' : 'text-gray-900') + ' max-w-sm rounded-lg border border-gray-200 shadow-md m-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700 dark:border-gray-700'} | ||
> | ||
<div className='p-2'> | ||
<h5 className={'text-md font-bold dark:text-white ' + (objectID && object.idx === objectID ? '' : '')}> | ||
{object.name} | ||
</h5> | ||
</h5> | ||
<p className="mb-3 font-normal text-gray-700 dark:text-white"> | ||
{details.description} | ||
</p> | ||
{details.error ? ( | ||
<div> | ||
<p> | ||
We failed to find matching template instances due to | ||
the following error:{" "} | ||
</p> | ||
<div className="bg-red-500 py-2 px-2 text-white rounded"> | ||
{details.error} | ||
</div> | ||
</div> | ||
</div> | ||
)) | ||
)} | ||
</div> | ||
</> | ||
)} | ||
|
||
</div> | ||
);} | ||
) : ( | ||
<> | ||
<input | ||
type="text" | ||
value={filterText} | ||
onChange={(e) => setFilterText(e.target.value)} | ||
placeholder="Filter objects" | ||
className="mb-3 p-2 border rounded" | ||
/> | ||
<div className="flex flex-wrap justify-center items-center overflow-auto"> | ||
{details.objects && details.objects.length === 0 ? ( | ||
<p>No objects found</p> | ||
) : ( | ||
details.objects && | ||
details.objects | ||
.filter((object) => | ||
object.name | ||
.toLowerCase() | ||
.includes(filterText.toLowerCase()) | ||
) | ||
.map((object) => ( | ||
<div | ||
key={object.idx} | ||
onClick={() => { | ||
navigate( | ||
`/${templateName}/${object.idx}` | ||
); | ||
}} | ||
className={ | ||
(objectID && | ||
object.idx === objectID | ||
? "bg-blue-800 dark:bg-blue-800 text-white hover:dark:text-white hover:text-blue-800" | ||
: "text-gray-900") + | ||
" max-w-sm rounded-lg border border-gray-200 shadow-md m-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-700 dark:border-gray-700" | ||
} | ||
> | ||
<div className="p-2"> | ||
<h5 | ||
className={ | ||
"text-md font-bold dark:text-white " + | ||
(objectID && | ||
object.idx === objectID | ||
? "" | ||
: "") | ||
} | ||
> | ||
{object.name} | ||
</h5> | ||
</div> | ||
</div> | ||
)) | ||
)} | ||
</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
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,5 @@ | ||
{# | ||
Copyright DB InfraGO AG and contributors | ||
SPDX-License-Identifier: Apache-2.0 | ||
#} | ||
<h1>{{ object.name }}</h1> |
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,14 @@ | ||
# Copyright DB InfraGO AG and contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
template: system-definition.html.j2 | ||
name: System Definition | ||
description: hi | ||
category: sa | ||
single: true | ||
variable: | ||
name: object | ||
type: SystemComponent | ||
below: sa | ||
filters: | ||
name: "System" |