Skip to content

Commit

Permalink
Fix status page (#883)
Browse files Browse the repository at this point in the history
* Adjust link to components, add new function for PRC component data

* Remove newline

* Utilize graphql data to load in PRC component data

* Rework function for rcs

* clean up
  • Loading branch information
TylerJDev authored Nov 14, 2024
1 parent dc369ba commit 9df0c60
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions src/components/status.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import componentMetadata from '@primer/component-metadata'
import {Box, themeGet, ActionList, ActionMenu, StyledOcticon, ThemeProvider, Spinner} from '@primer/react'
import {DotFillIcon, AccessibilityInsetIcon, ListUnorderedIcon} from '@primer/octicons-react'
import { graphql, useStaticQuery } from 'gatsby'
import React from 'react'
import styled from 'styled-components'
import StatusRows from './status-rows'
Expand Down Expand Up @@ -93,13 +94,29 @@ const statusFieldTypes = [
{type: 'Deprecated', name: 'Deprecated'},
]

function getStatusIndex(status) {
return statusFieldTypes.findIndex(({ type }) => type.toLowerCase() === status)
}

export function StatusTable() {
const [components, setComponents] = React.useState([])
const [selectedField, setSelectedField] = React.useState(initialFieldTypes[0])
const { actions: railsActions, data: railsData } = useRails()
const {allReactComponent: reactData} = useStaticQuery(graphql`
query ReactPagesQuery {
allReactComponent {
nodes {
a11yReviewed
componentId
name
status
}
}
}
`);

React.useEffect(() => {
getComponents(railsActions, railsData)
getComponents(railsActions, railsData, reactData)
.then(components => setComponents(components))
.catch(error => console.error(error))
}, [])
Expand Down Expand Up @@ -184,20 +201,38 @@ export function StatusTable() {
)
}

async function getComponents(railsActions, railsData) {
async function getComponents(railsActions, railsData, reactData) {
const handleError = error => {
console.error(error)
}

// Get component status data
const reactComponents = await fetch(`https://primer.github.io/react/components.json`)
.then(res => res.json())
.catch(handleError)
const {nodes: rcs} = reactData

const implementations = {
react: {
url: 'https://primer.style/react',
data: reactComponents,
url: 'https://primer.style/components',
data: (() => {
const components = {}

rcs.forEach((component) => {
const {a11yReviewed, componentId: id, name, status} = component
const url = `/${id.split('_').join('-')}/react/${status}`

if (components[name]) {
// Only display component closest to "stable"
const current = getStatusIndex(status)
const existing = getStatusIndex(components[name].status)

if (current > existing) {
return;
}
}

components[name] = {a11yReviewed, id, name, status, path: url}
})
return Object.values(components)
})(),
},
viewComponent: {
url: '',
Expand Down Expand Up @@ -232,7 +267,6 @@ async function getComponents(railsActions, railsData) {
}

const components = {}

for (const [implementation, {url, data}] of Object.entries(implementations)) {
if(!data) {
continue
Expand Down

0 comments on commit 9df0c60

Please sign in to comment.