@bigbinary/neeto-assist-frontend 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"NeetoAssistButton.js","sources":["../app/javascript/src/components/NeetoAssistButton/index.jsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\nimport { Button } from \"neetoatoms\";\nimport { useTranslation } from \"react-i18next\";\n\nimport Sparkle from \"components/commons/Sparkle\";\nimport { useFetchRuns } from \"hooks/reactQuery/useRunsApi\";\nimport useNeetoAssistStore from \"stores/useNeetoAssistStore\";\nimport { latestDraftId } from \"utils/runs\";\n\nconst NeetoAssistIcon = props => (\n <Sparkle {...props} className=\"text-purple-600\" />\n);\n\n// Goes on the ticket: it opens the pane, and tells the pane which ticket it is\n// about for as long as the button is on screen. A dot says a suggested reply is\n// waiting, since the pane is closed until the rep asks for it.\nconst NeetoAssistButton = ({ conversationId, onUseReply }) => {\n const { t } = useTranslation();\n const isOpen = useNeetoAssistStore(state => state.isOpen);\n const toggle = useNeetoAssistStore(state => state.toggle);\n const setConversation = useNeetoAssistStore(state => state.setConversation);\n const clearConversation = useNeetoAssistStore(\n state => state.clearConversation\n );\n\n const seenDraftId = useNeetoAssistStore(\n state => state.seenDrafts[conversationId]\n );\n\n const { data: { runs = [] } = {} } = useFetchRuns(conversationId);\n const draftId = latestDraftId(runs);\n const hasUnseenDraft = !isOpen && !!draftId && draftId !== seenDraftId;\n\n // The host's handler changes on every render, and only whether there is one\n // matters to the pane.\n const useReplyRef = useRef(onUseReply);\n const canUseReply = !!onUseReply;\n useEffect(() => {\n useReplyRef.current = onUseReply;\n });\n\n useEffect(() => {\n setConversation({\n id: conversationId,\n onUseReply: canUseReply\n ? (text, html) => useReplyRef.current?.(text, html)\n : undefined,\n });\n\n return () => clearConversation(conversationId);\n }, [canUseReply, clearConversation, conversationId, setConversation]);\n\n return (\n <span className=\"relative inline-flex\">\n <Button\n aria-pressed={isOpen}\n data-testid=\"neeto-assist-button\"\n icon={NeetoAssistIcon}\n iconPosition=\"left\"\n label={t(\"neetoAssist.askButton\")}\n size=\"sm\"\n variant={isOpen ? \"secondary\" : \"outline\"}\n tooltipProps={\n hasUnseenDraft ? { content: t(\"neetoAssist.draftReady\") } : undefined\n }\n onClick={toggle}\n />\n {hasUnseenDraft && (\n <span\n aria-label={t(\"neetoAssist.draftReady\")}\n className=\"ring-background absolute -end-0.5 -top-0.5 size-2.5 rounded-full bg-purple-600 ring-2\"\n data-testid=\"neeto-assist-draft-dot\"\n role=\"status\"\n />\n )}\n </span>\n );\n};\n\nexport default NeetoAssistButton;\n"],"names":["NeetoAssistIcon","props","_jsx","Sparkle","_objectSpread","className","NeetoAssistButton","_ref","conversationId","onUseReply","_useTranslation","useTranslation","t","isOpen","useNeetoAssistStore","state","toggle","setConversation","clearConversation","seenDraftId","seenDrafts","_useFetchRuns","useFetchRuns","_useFetchRuns$data","data","_useFetchRuns$data2","_useFetchRuns$data2$r","runs","draftId","latestDraftId","hasUnseenDraft","useReplyRef","useRef","canUseReply","useEffect","current","id","text","html","_useReplyRef$current","call","undefined","_jsxs","children","Button","icon","iconPosition","label","size","variant","tooltipProps","content","onClick","role"],"mappings":";;;;;;;;;;;;;;;;;AAUA,IAAMA,eAAe,GAAG,SAAlBA,eAAeA,CAAGC,KAAK,EAAA;EAAA,oBAC3BC,GAAA,CAACC,OAAO,EAAAC,aAAA,CAAAA,aAAA,KAAKH,KAAK,CAAA,EAAA,EAAA,EAAA;AAAEI,IAAAA,SAAS,EAAC;AAAiB,GAAA,CAAE,CAAC;AAAA,CACnD;;AAED;AACA;AACA;AACA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAAC,IAAA,EAAuC;AAAA,EAAA,IAAjCC,cAAc,GAAAD,IAAA,CAAdC,cAAc;IAAEC,UAAU,GAAAF,IAAA,CAAVE,UAAU;AACrD,EAAA,IAAAC,eAAA,GAAcC,cAAc,EAA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b5B,GAAA,CAAA,MAAA,EAAA;MACE,YAAA,EAAYU,CAAC,CAAC,wBAAwB,CAAE;AACxCP,MAAAA,SAAS,EAAC,uFAAuF;AACjG,MAAA,aAAA,EAAY,wBAAwB;AACpCgD,MAAAA,IAAI,EAAC;AAAQ,KACd,CACF;AAAA,GACG,CAAC;AAEX;;;;"}
1
+ {"version":3,"file":"NeetoAssistButton.js","sources":["../app/javascript/src/components/NeetoAssistButton/index.jsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\n\nimport { Button } from \"neetoatoms\";\nimport { useTranslation } from \"react-i18next\";\n\nimport Sparkle from \"components/commons/Sparkle\";\nimport { useFetchRuns } from \"hooks/reactQuery/useRunsApi\";\nimport useNeetoAssistStore from \"stores/useNeetoAssistStore\";\nimport { latestDraftId } from \"utils/runs\";\n\nconst NeetoAssistIcon = props => (\n <Sparkle {...props} className=\"text-purple-600\" />\n);\n\n// Goes on the ticket: it opens the pane, and tells the pane which ticket it is\n// about for as long as the button is on screen, along with the host's words\n// for what the rep is looking at. A dot says a suggested reply is waiting,\n// since the pane is closed until the rep asks for it.\nconst NeetoAssistButton = ({\n conversationId,\n contextLabel,\n onActionApplied,\n onUseReply,\n}) => {\n const { t } = useTranslation();\n const isOpen = useNeetoAssistStore(state => state.isOpen);\n const toggle = useNeetoAssistStore(state => state.toggle);\n const setConversation = useNeetoAssistStore(state => state.setConversation);\n const clearConversation = useNeetoAssistStore(\n state => state.clearConversation\n );\n\n const seenDraftId = useNeetoAssistStore(\n state => state.seenDrafts[conversationId]\n );\n\n const { data: { runs = [] } = {} } = useFetchRuns(conversationId);\n const draftId = latestDraftId(runs);\n const hasUnseenDraft = !isOpen && !!draftId && draftId !== seenDraftId;\n\n // The host's handlers change on every render. Only whether there is one for\n // \"Use reply\" matters to the pane, and one for an applied action changes\n // nothing it shows, so the pane gets stand-ins that call the latest.\n const useReplyRef = useRef(onUseReply);\n const actionAppliedRef = useRef(onActionApplied);\n const canUseReply = !!onUseReply;\n useEffect(() => {\n useReplyRef.current = onUseReply;\n actionAppliedRef.current = onActionApplied;\n });\n\n useEffect(() => {\n // The answer to a click on Apply can arrive after the button has moved on\n // to another ticket. It then goes to the handler the host last gave for\n // this ticket, not to the one for the ticket now on screen.\n let handlerOnLeaving;\n let hasLeft = false;\n\n setConversation({\n id: conversationId,\n contextLabel,\n onUseReply: canUseReply\n ? (text, html) => useReplyRef.current?.(text, html)\n : undefined,\n onActionApplied: action =>\n (hasLeft ? handlerOnLeaving : actionAppliedRef.current)?.(action),\n });\n\n return () => {\n handlerOnLeaving = actionAppliedRef.current;\n hasLeft = true;\n clearConversation(conversationId);\n };\n }, [\n canUseReply,\n clearConversation,\n contextLabel,\n conversationId,\n setConversation,\n ]);\n\n return (\n <span className=\"relative inline-flex\">\n <Button\n aria-pressed={isOpen}\n data-testid=\"neeto-assist-button\"\n icon={NeetoAssistIcon}\n iconPosition=\"left\"\n label={t(\"neetoAssist.askButton\")}\n size=\"sm\"\n variant={isOpen ? \"secondary\" : \"outline\"}\n tooltipProps={\n hasUnseenDraft ? { content: t(\"neetoAssist.draftReady\") } : undefined\n }\n onClick={toggle}\n />\n {hasUnseenDraft && (\n <span\n aria-label={t(\"neetoAssist.draftReady\")}\n className=\"ring-background absolute -end-0.5 -top-0.5 size-2.5 rounded-full bg-purple-600 ring-2\"\n data-testid=\"neeto-assist-draft-dot\"\n role=\"status\"\n />\n )}\n </span>\n );\n};\n\nexport default NeetoAssistButton;\n"],"names":["NeetoAssistIcon","props","_jsx","Sparkle","_objectSpread","className","NeetoAssistButton","_ref","conversationId","contextLabel","onActionApplied","onUseReply","_useTranslation","useTranslation","t","isOpen","useNeetoAssistStore","state","toggle","setConversation","clearConversation","seenDraftId","seenDrafts","_useFetchRuns","useFetchRuns","_useFetchRuns$data","data","_useFetchRuns$data2","_useFetchRuns$data2$r","runs","draftId","latestDraftId","hasUnseenDraft","useReplyRef","useRef","actionAppliedRef","canUseReply","useEffect","current","handlerOnLeaving","hasLeft","id","text","html","_useReplyRef$current","call","undefined","action","_ref2","_jsxs","children","Button","icon","iconPosition","label","size","variant","tooltipProps","content","onClick","role"],"mappings":";;;;;;;;;;;;;;;;;AAUA,IAAMA,eAAe,GAAG,SAAlBA,eAAeA,CAAGC,KAAK,EAAA;EAAA,oBAC3BC,GAAA,CAACC,OAAO,EAAAC,aAAA,CAAAA,aAAA,KAAKH,KAAK,CAAA,EAAA,EAAA,EAAA;AAAEI,IAAAA,SAAS,EAAC;AAAiB,GAAA,CAAE,CAAC;AAAA,CACnD;;AAED;AACA;AACA;AACA;AACA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAiBA,CAAAC,IAAA,EAKjB;AAAA,EAAA,IAJJC,cAAc,GAAAD,IAAA,CAAdC,cAAc;IACdC,YAAY,GAAAF,IAAA,CAAZE,YAAY;IACZC,eAAe,GAAAH,IAAA,CAAfG,eAAe;IACfC,UAAU,GAAAJ,IAAA,CAAVI,UAAU;AAEV,EAAA,IAAAC,eAAA,GAAcC,cAAc,EAAE;IAAtBC,CAAC,GAAAF,eAAA,CAADE,CAAC;AACT,EAAA,IAAMC,MAAM,GAAGC,mBAAmB,CAAC,UAAAC,KAAK,EAAA;IAAA,OAAIA,KAAK,CAACF,MAAM;EAAA,CAAA,CAAC;AACzD,EAAA,IAAMG,MAAM,GAAGF,mBAAmB,CAAC,UAAAC,KAAK,EAAA;IAAA,OAAIA,KAAK,CAACC,MAAM;EAAA,CAAA,CAAC;AACzD,EAAA,IAAMC,eAAe,GAAGH,mBAAmB,CAAC,UAAAC,KAAK,EAAA;IAAA,OAAIA,KAAK,CAACE,eAAe;EAAA,CAAA,CAAC;AAC3E,EAAA,IAAMC,iBAAiB,GAAGJ,mBAAmB,CAC3C,UAAAC,KAAK,EAAA;IAAA,OAAIA,KAAK,CAACG,iBAAiB;AAAA,EAAA,CAClC,CAAC;AAED,EAAA,IAAMC,WAAW,GAAGL,mBAAmB,CACrC,UAAAC,KAAK,EAAA;AAAA,IAAA,OAAIA,KAAK,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