synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
79 lines (78 loc) • 2.48 kB
JavaScript
import { jsx as p } from "react/jsx-runtime";
import * as u from "../../../synapse-client/SynapseClient.js";
import "@sage-bionetworks/synapse-client/generated/models/ErrorResponseCode";
import "@sage-bionetworks/synapse-client/generated/models/TwoFactorAuthErrorResponse";
import "@sage-bionetworks/synapse-client/util/SynapseClientError";
import "@sage-bionetworks/synapse-types";
import "../../../utils/functions/EntityTypeUtils.js";
import "../../../utils/SynapseConstants.js";
import "lodash-es";
import "@sage-bionetworks/synapse-client/util/synapseClientFetch";
import { useGetAccessRequirements as A } from "../../../synapse-queries/dataaccess/useAccessRequirements.js";
import { useSynapseContext as h } from "../../../utils/context/SynapseContext.js";
import { useTheme as y, Skeleton as C } from "@mui/material";
import I from "react-select/async";
function a(n, i) {
return n.toString() === i ? i : `${i} (${n})`;
}
function G(n) {
const { inputId: i, initialId: t, onChange: m, placeholder: d } = n, { palette: f } = y(), { accessToken: s } = h(), { data: c, isLoading: g } = A(t, {
enabled: !!t
});
async function S(e) {
const l = parseInt(e);
let r;
return l && (r = [
await u.getAccessRequirementById(s, l)
]), r || (r = (await u.searchAccessRequirements(s, {
nameContains: e
}))?.results), r?.map((o) => ({
id: o.id.toString(),
value: o.id.toString(),
label: a(o.id, o.name)
})) ?? [];
}
return t && g ? /* @__PURE__ */ p(C, { width: "100%" }) : /* @__PURE__ */ p(
I,
{
className: "AsyncSelect",
defaultInputValue: t ? a(
t,
c?.name ?? t.toString()
) : void 0,
defaultOptions: t ? [
{
id: t,
value: t,
label: a(
t,
c?.name ?? t.toString()
)
}
] : !0,
inputId: i,
cacheOptions: !0,
isClearable: !0,
styles: {
control: (e) => ({ ...e, backgroundColor: f.grey[200] }),
input: (e) => ({
...e,
// SWC-6327 - Adjust the input style so a right-click focuses on the input field
input: {
gridArea: "1 / 2 / 4 / 4 !important"
}
})
},
loadOptions: S,
onChange: (e) => {
m(e?.id.toString());
},
placeholder: d
}
);
}
export {
G as default,
a as getOptionLabel
};
//# sourceMappingURL=AccessRequirementSearchBox.js.map