diff --git a/editors/demo/src/HHMI/config/config.js b/editors/demo/src/HHMI/config/config.js index 7fc649f31ced9483756acb011a2040eceeaa1626..d4f24e412fb6e0790b6a56a60aa597238790e546 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 0000000000000000000000000000000000000000..bb77410dddeefe507a902da27eca800220372fc4 --- /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 0000000000000000000000000000000000000000..3ac405e5b3324326e678d9cb6a4b8f5feddd1462 --- /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 f9a9dee8967a7d43a090cecc107c629a2c872f74..a2c3480724a85530aa19ba07998e39958d46d36b 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 7c57f06f2b8638bfca34b2cf00db6fb60ef90e44..210dc52f247b0af6e4c9e8a9f88c9c75ebbce42d 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 301951a86920be8123da0ef20fe2de53cc4c3b05..93d3b62300c2deb6c30f014a0eaec20a13152812 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}