-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add publiccode.yml crawl status to software pages (#1003)
Add a status badge to every software page, displaying if the publiccode.yml was crawled correctly.
- Loading branch information
Showing
5 changed files
with
141 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { Spinner } from './Spinner'; | ||
|
||
const stateClass = { | ||
loading: 'secondary', | ||
good: 'success', | ||
error: 'danger', | ||
}; | ||
|
||
export const PubliccodeBadge = React.memo(({ id }) => { | ||
const [publiccodeState, setPubliccodeState] = useState('loading'); | ||
const logUrl = `https://api.developers.italia.it/v1/software/${id}/logs`; | ||
|
||
useEffect(() => { | ||
async function fetchLogs() { | ||
const res = await fetch(logUrl); | ||
|
||
if (res.status >= 200 || res.status <= 299) { | ||
const data = await res.json(); | ||
const good = data.data[0]?.message.includes('GOOD publiccode.yml'); | ||
|
||
setPubliccodeState(good ? 'good' : 'error'); | ||
} else { | ||
setPubliccodeState('error'); | ||
} | ||
} | ||
|
||
fetchLogs(); | ||
}, [logUrl]); | ||
|
||
return ( | ||
<> | ||
<div className="lead"> | ||
{publiccodeState === 'loading' && <Spinner />} | ||
<span className={`badge badge-${stateClass[publiccodeState]}`}> | ||
{publiccodeState !== 'loading' && publiccodeState} | ||
</span> | ||
</div> | ||
|
||
<a | ||
className="x-small" | ||
href={logUrl} | ||
target="_blank" | ||
aria-label="Log results of the latest publiccode.yml crawling" | ||
rel="noreferrer" | ||
> | ||
(log) | ||
</a> | ||
</> | ||
); | ||
}); | ||
|
||
PubliccodeBadge.propTypes = { | ||
id: PropTypes.string.isRequired, | ||
}; | ||
|
||
PubliccodeBadge.displayName = 'PubliccodeBadge'; |
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,56 @@ | ||
.lds-ellipsis { | ||
display: inline-block; | ||
position: relative; | ||
width: 80px; | ||
height: 80px; | ||
margin-bottom: 1rem; | ||
} | ||
.lds-ellipsis div { | ||
position: absolute; | ||
width: 6px; | ||
height: 6px; | ||
border-radius: 50%; | ||
background: gray; | ||
top: 0.5rem; | ||
animation-timing-function: cubic-bezier(0, 1, 1, 0); | ||
} | ||
.lds-ellipsis div:nth-child(1) { | ||
left: 8px; | ||
animation: lds-ellipsis1 0.6s infinite; | ||
} | ||
.lds-ellipsis div:nth-child(2) { | ||
left: 8px; | ||
animation: lds-ellipsis2 0.6s infinite; | ||
} | ||
.lds-ellipsis div:nth-child(3) { | ||
left: 32px; | ||
animation: lds-ellipsis2 0.6s infinite; | ||
} | ||
.lds-ellipsis div:nth-child(4) { | ||
left: 56px; | ||
animation: lds-ellipsis3 0.6s infinite; | ||
} | ||
@keyframes lds-ellipsis1 { | ||
0% { | ||
transform: scale(0); | ||
} | ||
100% { | ||
transform: scale(1); | ||
} | ||
} | ||
@keyframes lds-ellipsis3 { | ||
0% { | ||
transform: scale(1); | ||
} | ||
100% { | ||
transform: scale(0); | ||
} | ||
} | ||
@keyframes lds-ellipsis2 { | ||
0% { | ||
transform: translate(0, 0); | ||
} | ||
100% { | ||
transform: translate(24px, 0); | ||
} | ||
} |
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,16 @@ | ||
import React from 'react'; | ||
|
||
import './Spinner.css'; | ||
|
||
export const Spinner = React.memo(() => ( | ||
<> | ||
<div className="lds-ellipsis"> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
<div></div> | ||
</div> | ||
</> | ||
)); | ||
|
||
Spinner.displayName = 'Spinner'; |