-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Credit Class Page "Additional Info" improvements (#1980)
* feat: add custom label for measuredGHGs and coBenefits * feat: add support for boolean unknown fields * refactor: avoid null return * feat: add support for ISO8601 formatted durations * fix: duration value formatting * fix: rm offset gen method from additional info since already displayed above * fix: add spacing between items if metadata value is a list * feat: add support for bufferPoolAccounts * feat: add BufferPoolAccounts component * refactor: use LinkWithArrow in BufferPoolAccounts and ApprovedMethodologiesList
- Loading branch information
Showing
8 changed files
with
172 additions
and
76 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
20 changes: 20 additions & 0 deletions
20
web-registry/src/components/molecules/MetaDetail/MetaDetail.utils.ts
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,20 @@ | ||
import { formatDuration } from 'date-fns'; | ||
|
||
export function fromISO8601(iso8601Duration: string) { | ||
const iso8601DurationRegex = | ||
/(-)?P(-)?(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?(?:T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?)?/; | ||
var matches = iso8601Duration.match(iso8601DurationRegex); | ||
const duration = { | ||
years: matches?.[3] ? Number(matches?.[3]) : 0, | ||
months: matches?.[4] ? Number(matches?.[4]) : 0, | ||
weeks: matches?.[5] ? Number(matches?.[5]) : 0, | ||
days: matches?.[6] ? Number(matches?.[6]) : 0, | ||
hours: matches?.[7] ? Number(matches?.[7]) : 0, | ||
minutes: matches?.[8] ? Number(matches?.[8]) : 0, | ||
seconds: matches?.[9] ? Number(matches?.[9]) : 0, | ||
}; | ||
if (Object.values(duration).findIndex(v => v !== 0) > -1) | ||
return `${ | ||
matches?.[1] === '-' || matches?.[2] === '-' ? 'Previous ' : '' | ||
}${formatDuration(duration)}`; | ||
} |
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
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
43 changes: 43 additions & 0 deletions
43
web-registry/src/pages/CreditClassDetails/CreditClassDetails.BufferPoolAccounts.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,43 @@ | ||
import { Flex } from 'web-components/lib/components/box'; | ||
import { Body } from 'web-components/lib/components/typography'; | ||
|
||
import { getAccountUrl } from 'lib/block-explorer'; | ||
import { BufferPoolAccount } from 'lib/db/types/json-ld/credit-class-metadata'; | ||
|
||
import { LinkWithArrow } from 'components/atoms'; | ||
import { MetaDetail } from 'components/molecules'; | ||
|
||
type Props = { | ||
bufferPoolAccounts?: BufferPoolAccount[]; | ||
}; | ||
|
||
const BufferPoolAccounts: React.FC<Props> = ({ bufferPoolAccounts }) => { | ||
if (!bufferPoolAccounts) return null; | ||
|
||
const count = bufferPoolAccounts?.length; | ||
|
||
if (!count || count < 1) return null; | ||
|
||
return ( | ||
<MetaDetail | ||
label="buffer pool accounts" | ||
customContent={ | ||
<Flex flexDirection="column"> | ||
{bufferPoolAccounts.map(account => ( | ||
<Body key={account?.['schema:name']} size="xl" styleLinks={false}> | ||
<LinkWithArrow | ||
href={getAccountUrl( | ||
account?.['regen:walletAddress'] || | ||
account?.['regen:address'], | ||
)} | ||
label={account?.['schema:name']} | ||
/> | ||
</Body> | ||
))} | ||
</Flex> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export { BufferPoolAccounts }; |