tweak data ordering

This commit is contained in:
Matthias Kretschmann 2022-10-19 18:05:19 +01:00
parent 99320cffe4
commit a9d6a68545
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 9 additions and 6 deletions

View File

@ -37,7 +37,7 @@ export default function HomePage(): ReactElement {
async function getStatuses() { async function getStatuses() {
setIsloading(true) setIsloading(true)
const data = await getData() const data = await getData()
if (!data) setError(`Could not fetch data from ${statusApiUri}`) if (!data) setError(`Could not get data from ${statusApiUri}`)
setData(data) setData(data)
setIsloading(false) setIsloading(false)
} }
@ -76,7 +76,9 @@ export default function HomePage(): ReactElement {
) : ( ) : (
Object.entries(data || {}).map(([networkName, value]) => ( Object.entries(data || {}).map(([networkName, value]) => (
<Fragment key={networkName}> <Fragment key={networkName}>
<h2 className={styles.networkName}>{networkName}</h2> <h2 className={styles.networkName}>
{networkName == 'general' ? null : networkName}
</h2>
<div className={styles.grid}> <div className={styles.grid}>
{value.components.map((component) => ( {value.components.map((component) => (
<div <div

View File

@ -8,12 +8,13 @@ export async function getData(): Promise<{ [key: string]: Status }> {
if (!response?.data || response.status !== 200) if (!response?.data || response.status !== 200)
throw Error('ERROR: no data recieved') throw Error('ERROR: no data recieved')
// transform data into object with network names as keys, // transform data into object with network names as keys
// and make sure 'general' is always the first key let output = Object.fromEntries(
const output = Object.fromEntries(
response.data?.map((item) => [item.network, item]) response.data?.map((item) => [item.network, item])
) )
console.log('Got new data', output) // make sure 'general' is always the first key
output = Object.assign({ general: output['general'] }, output)
console.log('Got new data', JSON.stringify(output))
return output return output
} catch (error) { } catch (error) {
console.error(error.message) console.error(error.message)