import * as React from "react"; import { Link } from "react-router-dom"; import { Button, Flash, Flex, Loader, Table, Text } from "rimble-ui"; import useSWR from "swr"; import { SchemaDataResponse } from ".."; import { colors } from "../../../themes"; import { TBody, TH, TR } from "../../layouts/LayoutComponents"; import { SertoUiContext, SertoUiContextInterface } from "../../../context/SertoUiContext"; import { ViewSchemaButton } from "./ViewSchemaButton"; export interface SchemasTableProps { discover?: boolean; noSchemasElement?: JSX.Element; hideIssueVcInDetail?: boolean; onSchemaSelect?(schema: SchemaDataResponse): void; } export const SchemasTable: React.FunctionComponent = (props) => { const context = React.useContext(SertoUiContext); const { data, error, isValidating } = useSWR(["getSchemas", !props.discover], () => context.schemasService.getSchemas(!props.discover), ); const sortedData = React.useMemo( () => data?.sort((schema1, schema2) => (schema1.updated < schema2.updated ? 1 : -1)), [data], ); if (sortedData?.length) { return ( <> {!props.discover && } {props.onSchemaSelect && } {sortedData.map((schema, i) => { return ( {!props.discover && } {props.onSchemaSelect && ( )} ); })}
Name Slug VersionDiscoverableCreated
{schema.icon} {schema.name} {schema.slug} {schema.version}{(!!schema.discoverable).toString()} {schema.created && ( )} {!props.discover && !props.onSchemaSelect && ( Update )} props.onSchemaSelect?.(schema)}> Select
); } else if (error) { return ( Error loading schemas: {error.toString()} ); } else if (isValidating) { return ( ); } else { return ( props.noSchemasElement || ( {props.discover ? "There are" : "You have"} no credential schemas yet. Please first create a credential schema in order to coordinate around verified data with your customers and partners. ) ); } };