From b2413a6b7e08fccd4d3e0a99f52fcb5a01d96bd3 Mon Sep 17 00:00:00 2001 From: Brandon Stull Date: Wed, 11 Oct 2023 11:50:52 -0400 Subject: [PATCH] #554 Fixed variables only being applicable on the module and pages. Fixed variables owned by other nodes reading as 'undefined' in the viewer when used. Need to add variables to all node converters, add variable name validation and fix tests. --- .../__snapshots__/more-info-box.test.js.snap | 2 ++ .../components/navigation/more-info-box.js | 20 +++++++++---------- .../variables/variable-list-modal.js | 10 +++++----- .../scripts/viewer/components/viewer-app.js | 2 +- .../obonode/obojobo-chunks-break/converter.js | 1 + .../obonode/obojobo-chunks-text/converter.js | 1 + 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/packages/app/obojobo-document-engine/__tests__/oboeditor/components/navigation/__snapshots__/more-info-box.test.js.snap b/packages/app/obojobo-document-engine/__tests__/oboeditor/components/navigation/__snapshots__/more-info-box.test.js.snap index 34703ed1b8..2439a2e8cb 100644 --- a/packages/app/obojobo-document-engine/__tests__/oboeditor/components/navigation/__snapshots__/more-info-box.test.js.snap +++ b/packages/app/obojobo-document-engine/__tests__/oboeditor/components/navigation/__snapshots__/more-info-box.test.js.snap @@ -82,3 +82,5 @@ exports[`MoreInfoBox More Info Box with no button bar 1`] = `"
Objectives:
Triggers:
"`; exports[`MoreInfoBox More Info Box with triggers 1`] = `"
Objectives:
Triggers:mockTrigger, mockSecondTrigger
"`; + +exports[`MoreInfoBox More Info Box with variables 1`] = `"
Objectives:
Triggers:
"`; diff --git a/packages/app/obojobo-document-engine/src/scripts/oboeditor/components/navigation/more-info-box.js b/packages/app/obojobo-document-engine/src/scripts/oboeditor/components/navigation/more-info-box.js index 46daf0bf9c..22b5fb7392 100644 --- a/packages/app/obojobo-document-engine/src/scripts/oboeditor/components/navigation/more-info-box.js +++ b/packages/app/obojobo-document-engine/src/scripts/oboeditor/components/navigation/more-info-box.js @@ -146,8 +146,7 @@ class MoreInfoBox extends React.Component { this.setState(prevState => ({ content: changeFn(prevState.content, enabled) })) } - onSave() { - console.log('onSave!', this.props.content, this.state.content) + onSave(close=false) { // Save the internal content to the editor state const error = this.props.saveContent(this.props.content, this.state.content) || @@ -155,7 +154,7 @@ class MoreInfoBox extends React.Component { if (!error) { this.setState({ error }) this.props.markUnsaved() - this.close() + if (close) this.close() return } @@ -163,7 +162,6 @@ class MoreInfoBox extends React.Component { } toggleOpen(event) { - console.log('to', this.state.isOpen, this.state.needsUpdate) stopPropagation(event) if (this.state.isOpen) { @@ -218,6 +216,7 @@ class MoreInfoBox extends React.Component { // Prevent info box from closing when modal is opened document.removeEventListener('mousedown', this.handleClick, false) ModalUtil.show() + this.setState({ modalOpen: true }) } // TriggerListModal.onClose is called w/ no arguments when canceled @@ -228,13 +227,14 @@ class MoreInfoBox extends React.Component { if (!modalState) return // do not save changes - console.log('closed', { ...this.state.content, ...modalState }) - this.setState( - prevState => ({ - content: { ...prevState.content, ...modalState }, - needsUpdate: true - }), + prevState => { + return { + content: { ...prevState.content, ...modalState }, + needsUpdate: true, + modalOpen: false + } + }, () => { this.onSave() } diff --git a/packages/app/obojobo-document-engine/src/scripts/oboeditor/components/variables/variable-list-modal.js b/packages/app/obojobo-document-engine/src/scripts/oboeditor/components/variables/variable-list-modal.js index 3d48b6b651..37715f630c 100644 --- a/packages/app/obojobo-document-engine/src/scripts/oboeditor/components/variables/variable-list-modal.js +++ b/packages/app/obojobo-document-engine/src/scripts/oboeditor/components/variables/variable-list-modal.js @@ -7,7 +7,6 @@ import VariableProperty from './variable-property/variable-property' import NewVariable from './new-variable/new-variable' import VariableBlock from './variable-block' import { RANDOM_NUMBER, RANDOM_LIST } from './constants' -import withoutUndefined from '../../../common/util/without-undefined' import { getParsedRange } from '../../../common/util/range-parsing' const { Button } = Common.components @@ -19,7 +18,6 @@ const rangesToIndividualValues = vars => { } return vars.map(v => { - console.log('reading ', v) switch (v.type) { case 'random-list': { const size = getParsedRange(v.size) @@ -161,7 +159,6 @@ const individualValuesToRanges = vars => { } const VariableListModal = props => { - console.log('vlm', props) const firstRef = useRef() // First element to fucus on when open the modal const tabRef = useRef() // First element to focus on when open a variable @@ -255,13 +252,16 @@ const VariableListModal = props => { return firstRef.current.focus() } - console.log('variables', variables) + const handleOnConfirm = () => { + const processedVariables = individualValuesToRanges(variables) + props.onClose({ variables: processedVariables }) + } return ( props.onClose({ variables: individualValuesToRanges(variables) })} + onConfirm={handleOnConfirm} focusOnFirstElement={focusOnFirstElement} >
diff --git a/packages/app/obojobo-document-engine/src/scripts/viewer/components/viewer-app.js b/packages/app/obojobo-document-engine/src/scripts/viewer/components/viewer-app.js index e594a04fb8..5f609de74d 100644 --- a/packages/app/obojobo-document-engine/src/scripts/viewer/components/viewer-app.js +++ b/packages/app/obojobo-document-engine/src/scripts/viewer/components/viewer-app.js @@ -419,7 +419,7 @@ export default class ViewerApp extends React.Component { let value = null if (variable.indexOf(':') !== -1) { - const [varName, ownerId] = variable.split(':') + const [ownerId, varName] = variable.split(':') value = VariableUtil.getValue( NavUtil.getContext(this.state.navState), diff --git a/packages/obonode/obojobo-chunks-break/converter.js b/packages/obonode/obojobo-chunks-break/converter.js index 443fb67930..27b4e05461 100644 --- a/packages/obonode/obojobo-chunks-break/converter.js +++ b/packages/obonode/obojobo-chunks-break/converter.js @@ -13,6 +13,7 @@ const slateToObo = node => ({ content: withoutUndefined({ triggers: node.content.triggers, objectives: node.content.objectives, + variables: node.content.variables, width: node.content.width }) }) diff --git a/packages/obonode/obojobo-chunks-text/converter.js b/packages/obonode/obojobo-chunks-text/converter.js index bbf49ca723..4f4432c523 100644 --- a/packages/obonode/obojobo-chunks-text/converter.js +++ b/packages/obonode/obojobo-chunks-text/converter.js @@ -46,6 +46,7 @@ const slateToObo = node => { content: withoutUndefined({ triggers: node.content.triggers, objectives: node.content.objectives, + variables: node.content.variables, textGroup }) }