synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
112 lines (111 loc) • 4.62 kB
JavaScript
import { jsx as t, jsxs as s, Fragment as w } from "react/jsx-runtime";
import { EntityAnnotationKey as D } from "./EntityAnnotationKey.js";
import { useGetJson as L } from "../../../synapse-queries/entity/useEntity.js";
import { useGetSchema as E } from "../../../synapse-queries/entity/useSchema.js";
import { useGetSchemaBinding as j, useGetValidationResults as B } from "../../../synapse-queries/entity/useEntityBoundSchema.js";
import { formatDate as k } from "../../../utils/functions/DateFormatter.js";
import { isISOTimestamp as G } from "../../../utils/functions/DateTimeUtils.js";
import { entityTypeToFriendlyName as c, convertToEntityType as d } from "../../../utils/functions/EntityTypeUtils.js";
import { getEndpoint as O, BackendDestinationEnum as $ } from "../../../utils/functions/getEndpoint.js";
import { useGetAnnotatedJsonInstance as x, getDisplayedAnnotationDescription as C, getDisplayedAnnotationTitle as M } from "../../../utils/jsonschema/SchemaAnnotationUtils.js";
import m from "dayjs";
import { isEmpty as F } from "lodash-es";
import { useState as P, useCallback as J } from "react";
import H from "../../FullWidthAlert/FullWidthAlert.js";
import "@mui/material";
import "@mui/material/Skeleton";
import { SkeletonTable as W } from "../../Skeleton/SkeletonTable.js";
function b(n) {
return typeof n == "number" || typeof n == "boolean" ? n.toString() : G(n) ? k(m(n)) : n;
}
function de(n) {
const { entityId: r, versionNumber: _ } = n, [T, h] = P(!1), {
data: l,
isLoading: S,
refetch: f
} = L(r, _, !0), o = l?.entityMetadata, a = l?.annotations, { data: i, isLoading: A } = j(r), { data: N, isLoading: R } = E(i?.jsonSchemaVersionInfo.$id, {
enabled: !!i
}), { data: p, isLoading: I } = x(l?.entity, N), { data: y, refetch: u } = B(r, {
enabled: !!i
}), g = !!i, V = !!o && !!y && m(o.modifiedOn).diff(
m(y.validatedOn)
) > 0, v = J(async () => {
h(!0);
const e = [
// Refetch the annotations, which may have changed if new derived annotations have been calculated
void f(),
// Refetch the validation information, which we use to determine if derived annotations may still be pending
void u()
];
await Promise.allSettled(e), h(!1);
}, [f, u]);
return S || A || R || I || T ? /* @__PURE__ */ t(W, { numRows: 3, numCols: 2 }) : /* @__PURE__ */ s(w, { children: [
o && a && F(a) ? /* @__PURE__ */ s("div", { className: "placeholder", children: [
"This",
" ",
c(
d(o.concreteType)
),
" ",
"has no annotations."
] }) : null,
/* @__PURE__ */ t("table", { className: "AnnotationsTable", children: /* @__PURE__ */ s("tbody", { children: [
a && Object.keys(a).map((e) => /* @__PURE__ */ s("tr", { className: "AnnotationsTable__Row", children: [
/* @__PURE__ */ t("td", { className: "AnnotationsTable__Row__Key", children: /* @__PURE__ */ t(
D,
{
annotationKey: e,
title: M(
e,
p
),
description: C(
e,
p
)
}
) }),
/* @__PURE__ */ t("td", { className: "AnnotationsTable__Row__Value", children: Array.isArray(a[e]) ? a[e].map(b).join(", ") : b(
a[e]
) })
] }, e)),
g ? /* @__PURE__ */ s("tr", { className: "AnnotationsTable__Row", children: [
/* @__PURE__ */ t("td", { className: "AnnotationsTable__Row__Key Schema", children: "Validation Schema" }),
/* @__PURE__ */ t("td", { className: "AnnotationsTable__Row__Value", children: /* @__PURE__ */ t(
"a",
{
href: `${O(
$.REPO_ENDPOINT
)}/repo/v1/schema/type/registered/${i.jsonSchemaVersionInfo.$id}`,
target: "_blank",
rel: "noopener noreferrer",
children: i.jsonSchemaVersionInfo.schemaName
}
) })
] }) : null
] }) }),
o && g && V && /* @__PURE__ */ t(
H,
{
variant: "warning",
description: `This ${c(
d(o.concreteType)
)} has changed since it has been last validated. If this ${c(
d(o.concreteType)
)} is expected to have annotations derived from the Validation Schema, they may not yet be visible.`,
primaryButtonConfig: {
text: "Reload Annotations",
onClick: () => {
v();
}
},
isGlobal: !1
}
)
] });
}
export {
de as AnnotationsTable,
b as getDisplayedAnnotation
};
//# sourceMappingURL=AnnotationsTable.js.map