From 13ef45685174817944f10a5938ac47aa35fa9829 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Tue, 7 Nov 2023 12:01:00 +0200 Subject: [PATCH] connect new tool --- editors/demo/src/HHMI/config/config.js | 75 +------------------ .../NumericalAnswerDropDown.js | 23 ++++++ .../NumericalAnswerDropDownService.js | 13 ++++ .../NumericalAnswerService.js | 3 +- .../NumericalAnswer.js | 4 +- .../NumericalAnswerContainerComponent.js | 4 +- 6 files changed, 46 insertions(+), 76 deletions(-) create mode 100644 wax-questions-service/src/NumericalAnswerService/NumericalAnswerDropDownService/NumericalAnswerDropDown.js create mode 100644 wax-questions-service/src/NumericalAnswerService/NumericalAnswerDropDownService/NumericalAnswerDropDownService.js diff --git a/editors/demo/src/HHMI/config/config.js b/editors/demo/src/HHMI/config/config.js index 7fc649f31..d4f24e412 100644 --- a/editors/demo/src/HHMI/config/config.js +++ b/editors/demo/src/HHMI/config/config.js @@ -13,7 +13,6 @@ import { MathService, FullScreenService, FullScreenToolGroupService, - // ExternalAPIContentService, } from 'wax-prosemirror-services'; import { QuestionsService } from 'wax-questions-service'; @@ -21,71 +20,6 @@ import { TablesService, tableEditing, columnResizing } from 'wax-table-service'; import { DefaultSchema } from 'wax-prosemirror-core'; import invisibles, { hardBreak } from '@guardian/prosemirror-invisibles'; -const API_KEY = ''; - -async function ExternalAPIContentTransformation(prompt) { - const response = await fetch('https://api.openai.com/v1/chat/completions', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${API_KEY}`, - }, - body: JSON.stringify({ - model: 'gpt-3.5-turbo', - messages: [ - { - role: 'user', - content: prompt, - }, - ], - temperature: 0, - // max_tokens: 400, - // n: 1, - // stop: null, - }), - }); - - try { - const data = await response.json(); - console.log(data); - return data.choices[0].message.content; - } catch (e) { - console.error(e); - alert( - 'That model is currently overloaded with other requests. You can retry your request.', - ); - } finally { - } - return prompt; -} - -// async function ExternalAPIContentTransformation(prompt) { -// const response = await fetch('https://api.openai.com/v1/completions', { -// method: 'POST', -// headers: { -// 'Content-Type': 'application/json', -// Authorization: `Bearer ${API_KEY}`, -// }, -// body: JSON.stringify({ -// model: 'text-davinci-003', -// prompt: prompt, -// max_tokens: 1400, -// n: 1, -// stop: null, -// temperature: 0.5, -// }), -// }); - -// try { -// const data = await response.json(); -// console.log(data); -// return data.choices[0].text.trim(); -// } catch (e) { -// console.error(e); -// } finally { -// } -// return prompt; -// } export default { MenuService: [ @@ -107,7 +41,6 @@ export default { 'Lists', 'Images', 'Tables', - // 'ExternalAPIContent', 'QuestionsDropDown', 'FullScreen', ], @@ -120,10 +53,11 @@ export default { templateArea: 'MultipleDropDown', toolGroups: ['MultipleDropDown'], }, + { + templateArea: 'NumericalAnswer', + toolGroups: ['NumericalAnswer'], + }, ], - // ExternalAPIContentService: { - // ExternalAPIContentTransformation: ExternalAPIContentTransformation, - // }, SchemaService: DefaultSchema, RulesService: [emDash, ellipsis], @@ -131,7 +65,6 @@ export default { PmPlugins: [invisibles([hardBreak()])], services: [ - // new ExternalAPIContentService(), new QuestionsService(), new ListsService(), new LinkService(), diff --git a/wax-questions-service/src/NumericalAnswerService/NumericalAnswerDropDownService/NumericalAnswerDropDown.js b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerDropDownService/NumericalAnswerDropDown.js new file mode 100644 index 000000000..bb77410dd --- /dev/null +++ b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerDropDownService/NumericalAnswerDropDown.js @@ -0,0 +1,23 @@ +import { injectable } from 'inversify'; +import { Fragment } from 'prosemirror-model'; +import { v4 as uuidv4 } from 'uuid'; +import { Tools } from 'wax-prosemirror-core'; + +@injectable() +class NumericalAnswerDropDown extends Tools { + title = 'Select Numerical Answer Option'; + icon = ''; + name = 'Select Numerical Answer'; + label = 'Select Numerical Answer'; + + get run() {} + + select = (state, activeViewId, activeView) => { + if (activeView.props.type && activeView.props.type === 'filltheGapContaier') + return true; + + return false; + }; +} + +export default NumericalAnswerDropDown; diff --git a/wax-questions-service/src/NumericalAnswerService/NumericalAnswerDropDownService/NumericalAnswerDropDownService.js b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerDropDownService/NumericalAnswerDropDownService.js new file mode 100644 index 000000000..3ac405e5b --- /dev/null +++ b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerDropDownService/NumericalAnswerDropDownService.js @@ -0,0 +1,13 @@ +import { Service } from 'wax-prosemirror-core'; +import NumericalAnswerDropDown from './NumericalAnswerDropDown'; +import NumericalAnswerToolGroupService from '../NumericalAnswerToolGroupService/NumericalAnswerToolGroupService'; + +class NumericalAnswerDropDownService extends Service { + register() { + this.container.bind('NumericalAnswerDropDown').to(NumericalAnswerDropDown); + } + + dependencies = [new NumericalAnswerToolGroupService()]; +} + +export default NumericalAnswerDropDownService; diff --git a/wax-questions-service/src/NumericalAnswerService/NumericalAnswerService.js b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerService.js index f9a9dee89..a2c348072 100644 --- a/wax-questions-service/src/NumericalAnswerService/NumericalAnswerService.js +++ b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerService.js @@ -3,6 +3,7 @@ import NumericalAnswerContainerNode from './schema/NumericalAnswerContainerNode' import NumericalAnswerQuestion from './NumericalAnswerQuestion'; import NumericalAnswerContainerNodeView from './NumericalAnswerContainerNodeView'; import NumericalAnswerContainerComponent from './components/NumericalAnswerContainerComponent'; +import NumericalAnswerDropDownService from './NumericalAnswerDropDownService/NumericalAnswerDropDownService'; import './numericalAnswer.css'; class NumericalAnswerService extends Service { @@ -22,7 +23,7 @@ class NumericalAnswerService extends Service { }); } - dependencies = []; + dependencies = [new NumericalAnswerDropDownService()]; } export default NumericalAnswerService; diff --git a/wax-questions-service/src/NumericalAnswerService/NumericalAnswerToolGroupService/NumericalAnswer.js b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerToolGroupService/NumericalAnswer.js index 7c57f06f2..210dc52f2 100644 --- a/wax-questions-service/src/NumericalAnswerService/NumericalAnswerToolGroupService/NumericalAnswer.js +++ b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerToolGroupService/NumericalAnswer.js @@ -4,9 +4,9 @@ import { ToolGroup } from 'wax-prosemirror-core'; @injectable() class NumericalAnswer extends ToolGroup { tools = []; - constructor() { + constructor(@inject('NumericalAnswerDropDown') NumericalAnswerDropDown) { super(); - this.tools = []; + this.tools = [NumericalAnswerDropDown]; } } diff --git a/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js b/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js index 301951a86..93d3b6230 100644 --- a/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js +++ b/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js @@ -53,7 +53,7 @@ export default ({ node, view, getPos }) => { pmViews: { main }, } = context; - const FillTheGapTool = ComponentPlugin('fillTheGap'); + const NumericalAnswerTool = ComponentPlugin('NumericalAnswer'); const customProps = main.props.customValues; const { testMode } = customProps; @@ -84,7 +84,7 @@ export default ({ node, view, getPos }) => { <div> {!testMode && !readOnly && ( <NumericalAnswerContainerTool> - <FillTheGapTool /> + <NumericalAnswerTool /> <ActionButton aria-label="delete this question" onClick={removeQuestion} -- GitLab