UNPKG

@redocly/graphql-docs

Version:

Redocly GraphQL docs

2 lines (1 loc) 1.54 kB
import{Fragment as B,jsx as e,jsxs as a}from"react/jsx-runtime";import{useState as M,useMemo as p,memo as x}from"react";import{Portal as v,SecurityIcon as d,useModalScrollLock as C,useThemeHooks as j}from"@redocly/theme";import{RequiresScopesModal as k}from"./RequiresScopesModal.js";import{getRequiresScopesDirective as D,getRequiresScopesWithParent as I}from"../utils/directive-utils.js";import{RequiresScopesItemButton as T,RequiresScopesItemButtonText as b,RequiresScopesButtonItemWrapper as w,RequiresScopesSecurityHeader as O,RequiresScopesButtonTitle as W,ViewDetailsButton as _}from"./styled.js";import{useTelemetry as y}from"../../hooks/index.js";function F({type:o,field:r,parentType:s,isItem:m=!1}){const[n,i]=M(!1),{useTranslate:S}=j(),{translate:c}=S(),q=y();C(n);const t=p(()=>r&&s?I(r,s):o?D(o):null,[r,s,o]),h=p(()=>t?!(t.scopes.length===0&&(t.parentScopes??[]).length>0):!1,[t]),u=()=>{i(!0),q.sendRequiredScopesModalOpenedMessage([{id:"requiredScopesButton",object:"button",uri:"urn:redocly:redoc:ui:button:requiredScopesButton"}])},f=()=>{i(!1)},l=c("graphql.requiredScopes","Required scopes"),R=c("graphql.viewSecurityDetails","View details");if(!h)return null;const g=m?e(w,{children:a(O,{children:[e(d,{}),e(W,{children:l}),e(_,{variant:"link",onClick:u,children:R})]})}):e(T,{variant:"outlined",fullWidth:!1,icon:e(d,{}),onClick:u,children:e(b,{children:l})});return a(B,{children:[g,n&&t&&e(v,{children:e(k,{scopes:t.scopes,parentScopes:t.parentScopes,onClose:f})})]})}const G=x(F);export{G as RequiresScopesButton};