components#CompareApiBreadcrumbs TypeScript Examples

The following examples show how to use components#CompareApiBreadcrumbs. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Category.tsx    From substrate-api-explorer with Apache License 2.0 6 votes vote down vote up
Category = ({ api, apiDiff, match }: Props) => {
  const { category } = match.params

  return (
    <S.Wrapper>
      <S.Title>
        <S.CategoryName>{category}</S.CategoryName>
        <CompareApiBreadcrumbs apiName={api.compare.url} match={match} />
      </S.Title>
      {_isEmpty(api.compare.description[category]) ? (
        <S.Empty>There&apos;s nothing in here ?</S.Empty>
      ) : (
        Object.entries(api.compare.description[category].categories)
          .sort((a: [string, Method], b: [string, Method]) => {
            return a[0] < b[0] ? -1 : 1
          })
          .map((item: [string, Method], idx) => {
            const added = !!apiDiff.added[category]?.categories[item[0]]
            const deleted = !!apiDiff.deleted[category]?.categories[item[0]]
            const updated = !!apiDiff.updated[category]?.categories[item[0]]
            const isNew =
              added && !api.current.description[category]?.categories[item[0]]

            return (
              (added || deleted || updated) && (
                <CompareApiLink
                  key={`compareApi-subcategory-${idx}`}
                  to={`${match.url}/${item[0]}`}
                  name={item[0]}
                  description={item[1].description}
                  states={{ added, deleted, updated, isNew }}
                />
              )
            )
          })
      )}
    </S.Wrapper>
  )
}
Example #2
Source File: CompareApiBreadcrumbs.stories.tsx    From substrate-api-explorer with Apache License 2.0 6 votes vote down vote up
storiesOf('COMPONENTS|CompareApiBreadcrumbs', module)
  .addDecorator(story => (
    <MemoryRouter initialEntries={['/']}>{story()}</MemoryRouter>
  ))
  .add('default', () => {
    const apiNameKnob = text(
      'apiName',
      'wss://kusama-rpc.polkadot.io/',
      'props'
    )
    const urlKnob = text(
      'apiexplorer.polkalert.com/compare-api/',
      'query/staking',
      'other'
    )

    return (
      <div style={{ padding: '24px' }}>
        <CompareApiBreadcrumbs
          apiName={apiNameKnob}
          match={{ url: `/compare-api/${urlKnob}` }}
        />
      </div>
    )
  })
Example #3
Source File: Subcategory.tsx    From substrate-api-explorer with Apache License 2.0 4 votes vote down vote up
Subcategory = ({ api, apiDiff, match }: Props) => {
  const { category, subcategory } = match.params

  return (
    <S.Wrapper>
      <S.Title>
        <S.CategoryName>{subcategory}</S.CategoryName>
        <CompareApiBreadcrumbs apiName={api.compare.url} match={match} />
      </S.Title>
      {/* We have to disable ESLint here because it doesn't
      play nicely with Prettier */}
      {/* eslint-disable indent */}
      {_isEmpty(
        api.compare.description[category]?.categories[subcategory]?.methods
      ) ? (
        <S.Empty>There&apos;s nothing in here ?</S.Empty>
      ) : (
        Object.entries(
          api.compare.description[category]?.categories[subcategory]?.methods
        )
          .sort((a: [string, Method], b: [string, Method]) => {
            return a[0] < b[0] ? -1 : 1
          })
          .map((item: [string, Method], idx) => {
            const main =
              api.current.description[category]?.categories[subcategory]
                ?.methods[item[0]]
            const comparison =
              api.compare.description[category]?.categories[subcategory]
                ?.methods[item[0]]
            const isNew = !main
            const isAltered = !!apiDiff.updated[category]?.categories[
              subcategory
            ]?.methods[item[0]]

            return (
              <CompareApiCard
                key={`compareApi-${subcategory}-method-${idx}`}
                name={item[0]}
                path={`api.${category}.${subcategory}.${item[0]}`}
                exists={{ main: !!main, comparison: !!comparison }}
                mainApiParams={main?.params}
                comparisonApiParams={comparison?.params}
                mainApiType={main?.type}
                comparisonApiType={comparison?.type}
                description={item[1].description}
                states={{ isNew, isAltered }}
              />
            )
          })
      )}
      {!_isEmpty(
        apiDiff.deleted[category]?.categories[subcategory]?.methods
      ) && (
        <>
          <S.DividerTitle>Missing in the comparison API</S.DividerTitle>
          {Object.keys(
            apiDiff.deleted[category]?.categories[subcategory]?.methods
          )
            .sort((a: string, b: string) => {
              return a < b ? -1 : 1
            })
            .map((item: string, idx) => {
              const main =
                api.current.description[category]?.categories[subcategory]
                  ?.methods[item]

              return (
                <CompareApiCard
                  key={`compareApi-${subcategory}-missing-${idx}`}
                  name={item}
                  path={`api.${category}.${subcategory}.${item}`}
                  exists={{ main: !!main, comparison: false }}
                  mainApiParams={main?.params}
                  mainApiType={main?.type}
                  description={main?.description}
                />
              )
            })}
        </>
      )}
      {/* eslint-enable indent */}
    </S.Wrapper>
  )
}