From 668c184afd6d6f2dcbe4c9f9eabe5fb098aab059 Mon Sep 17 00:00:00 2001 From: rayzhou-bit Date: Wed, 1 Nov 2023 16:03:12 -0400 Subject: [PATCH] feat: wip2 --- .../LibraryContentEditor/BlocksSelector.jsx | 86 ++++-- .../LibraryContentEditor/LibrarySelector.jsx | 2 +- .../LibraryContentEditor/LibrarySettings.jsx | 89 ++++-- .../LibraryContentEditor/constants.js | 22 +- .../LibraryContentEditor/data/mockApi.js | 253 ++++++++++++++++-- .../LibraryContentEditor/data/reducer.js | 8 +- .../containers/LibraryContentEditor/hooks.js | 50 ++-- .../containers/LibraryContentEditor/index.jsx | 6 +- .../LibraryContentEditor/messages.js | 61 +++-- src/editors/data/services/cms/api.js | 3 +- 10 files changed, 449 insertions(+), 131 deletions(-) diff --git a/src/editors/containers/LibraryContentEditor/BlocksSelector.jsx b/src/editors/containers/LibraryContentEditor/BlocksSelector.jsx index 2556c61c2..1cf0932bc 100644 --- a/src/editors/containers/LibraryContentEditor/BlocksSelector.jsx +++ b/src/editors/containers/LibraryContentEditor/BlocksSelector.jsx @@ -1,59 +1,92 @@ import React from 'react'; import { connect } from 'react-redux'; -import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; - +import { FormattedMessage, injectIntl, intlShape } from '@edx/frontend-platform/i18n'; import { Button, DataTable, Form } from '@edx/paragon'; + +import messages from './messages'; import { actions, selectors } from './data'; import { useBlocksHook } from './hooks'; +import { modes } from './constants'; export const BlocksSelector = ({ studioEndpointUrl, // redux blocksInSelectedLibrary, + libraries, loadBlocksInLibrary, + onSelectCandidates, selectedLibrary, + selectionMode, }) => { - if (selectedLibrary === null || !blocksInSelectedLibrary) return <>; - const { blockLinks, blocksTableData, + selectCandidates, } = useBlocksHook({ blocksInSelectedLibrary, loadBlocksInLibrary, + onSelectCandidates, + selectedLibraryId: (selectedLibrary !== null) ? libraries[selectedLibrary].library_key : null, studioEndpointUrl, }); + if (selectedLibrary === null || !blocksInSelectedLibrary) return <>; + + const ViewAction = ({ row }) => ( + + ); + return ( -
- +
+ { + selectionMode === modes.selected.value + ? + : null + } { - // - // } - // } - // ]} + columns={[ + { + Header: 'Name', + accessor: 'display_name', + }, + { + Header: 'Block Type', + accessor: 'block_type', + }, + ]} + additionalColumns={[ + { + id: 'action', + Header: 'View', + Cell: ({ row }) => ViewAction({ row }), + } + ]} + onSelectedRowsChanged={(selected) => selectCandidates({ selected })} + // maxSelectedRows={2} + // onMaxSelectedRows={() => console.log('hey3 this is the last row allowed')} > + - +
); @@ -61,11 +94,14 @@ export const BlocksSelector = ({ export const mapStateToProps = (state) => ({ blocksInSelectedLibrary: selectors.blocksInSelectedLibrary(state), + libraries: selectors.libraries(state), selectedLibrary: selectors.selectedLibrary(state), + selectionMode: selectors.selectionMode(state), }) export const mapDispatchToProps = { loadBlocksInLibrary: actions.loadBlocksInLibrary, + onSelectCandidates: actions.onSelectCandidates, }; export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(BlocksSelector)); diff --git a/src/editors/containers/LibraryContentEditor/LibrarySelector.jsx b/src/editors/containers/LibraryContentEditor/LibrarySelector.jsx index 08f4a9c8c..01fa29b0a 100644 --- a/src/editors/containers/LibraryContentEditor/LibrarySelector.jsx +++ b/src/editors/containers/LibraryContentEditor/LibrarySelector.jsx @@ -18,7 +18,7 @@ export const LibrarySelector = ({ }; return ( -
+
{libraries ? ( diff --git a/src/editors/containers/LibraryContentEditor/LibrarySettings.jsx b/src/editors/containers/LibraryContentEditor/LibrarySettings.jsx index 8eda188bb..4566f4159 100644 --- a/src/editors/containers/LibraryContentEditor/LibrarySettings.jsx +++ b/src/editors/containers/LibraryContentEditor/LibrarySettings.jsx @@ -1,46 +1,81 @@ import React from 'react'; import { connect } from 'react-redux'; -import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; - +import { FormattedMessage, injectIntl, intlShape } from '@edx/frontend-platform/i18n'; import { Button, Form } from '@edx/paragon'; + +import messages from './messages'; import { modes } from './constants'; import { actions, selectors } from './data'; import { thunkActions } from '../../data/redux'; export const LibrarySettings = ({ // redux - onShowResetSettingsChange, onCountSettingsChange, + onSelectionModeChange, + onShowResetSettingsChange, selectedLibrary, + selectionMode, selectionSettings, }) => { if (selectedLibrary === null) return <>; return ( -
-
- onCountSettingsChange({ - count: e.target.value, - })} - value={selectionSettings.count} - type="number" - /> - -
-
- onShowResetSettingsChange({ - showReset: e.target.checked, +
+
+ onSelectionModeChange({ selectionMode: e.target.value })} + value={selectionMode} + > + + + + + + + + + {/* + } + onChange={(e) => onSelectionModeChange({ + selectionMode: (e.target.checked ? modes.selected.value : modes.random.value) })} > - Show Reset Button - -
- Determines whether a 'Reset Problems' button is shown, so users may reset their answers and reshuffle selected items. + + */} +
+ { + selectionMode === modes.random.value + ?
+ onCountSettingsChange({ + count: e.target.value, + })} + value={selectionSettings.count} + type="number" + /> + +
+ : null + } + +
+
+ onShowResetSettingsChange({ + showReset: e.target.checked, + })} + > + + +
+ +
@@ -49,12 +84,14 @@ export const LibrarySettings = ({ export const mapStateToProps = (state) => ({ selectedLibrary: selectors.selectedLibrary(state), + selectionMode: selectors.selectionMode(state), selectionSettings: selectors.selectionSettings(state), }) export const mapDispatchToProps = { - onShowResetSettingsChange: actions.onShowResetSettingsChange, onCountSettingsChange: actions.onCountSettingsChange, + onSelectionModeChange: actions.onSelectionModeChange, + onShowResetSettingsChange: actions.onShowResetSettingsChange, }; export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(LibrarySettings)); diff --git a/src/editors/containers/LibraryContentEditor/constants.js b/src/editors/containers/LibraryContentEditor/constants.js index cbeb04622..defbdefd2 100644 --- a/src/editors/containers/LibraryContentEditor/constants.js +++ b/src/editors/containers/LibraryContentEditor/constants.js @@ -1,16 +1,14 @@ import messages from "./messages" export const modes = { - all: { - description: messages.modeAll, - value: 'all', - }, - random: { - description: messages.modeRandom, - value: 'random', - }, - selected: { - description: messages.modeSelected, - value: 'selected', - } + random: { + title: messages.modeRandom, + description: messages.modeRandomDescription, + value: 'random', + }, + selected: { + title: messages.modeSelected, + description: messages.modeSelectedDescription, + value: 'selected', + }, }; diff --git a/src/editors/containers/LibraryContentEditor/data/mockApi.js b/src/editors/containers/LibraryContentEditor/data/mockApi.js index 2bd1a4539..5c305c831 100644 --- a/src/editors/containers/LibraryContentEditor/data/mockApi.js +++ b/src/editors/containers/LibraryContentEditor/data/mockApi.js @@ -55,7 +55,15 @@ export const fetchContentStore = ({ studioEndpointUrl }) => { "org": "new", "number": "CPSPRqwer", "can_edit": true - } + }, + { + "display_name": "Really Big Library", + "library_key": "library-v1:new+CPSPR+big", + "url": "/library/library-v1:new+CPSPR+big", + "org": "new", + "number": "CPSPR+big", + "can_edit": true + }, ], "libraries_enabled": true, "library_authoring_mfe_url": "//localhost:3001/course/course-v1:edX+P315+2T2023", @@ -75,34 +83,221 @@ export const fetchContentStore = ({ studioEndpointUrl }) => { }; export const fetchLibraryContent = ({ studioEndpointUrl, libraryId }) => { - return { - "count": 3, - "next": null, - "previous": null, - "results": [ - { - "id": "lb:edx:test202:html:3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab", - "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab/definition.xml", - "block_type": "html", - "display_name": "Text", - "has_unpublished_changes": true - }, - { - "id": "lb:edx:test202:html:b7c18081-0bec-4de0-8d16-8b255924722e", - "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/b7c18081-0bec-4de0-8d16-8b255924722e/definition.xml", - "block_type": "html", - "display_name": "Lorem texts", - "has_unpublished_changes": false - }, - { - "id": "lb:edx:test202:problem:86e480e4-e31c-492f-822e-1a8b2501cfde", - "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:problem:problem/86e480e4-e31c-492f-822e-1a8b2501cfde/definition.xml", - "block_type": "problem", - "display_name": "Blank Problem", - "has_unpublished_changes": true - } - ] - }; + if (libraryId === 'library-v1:new+CPSPR') { + return { + "count": 1, + "next": null, + "previous": null, + "results": [ + { + "id": "lb:edx:test202:html:3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab/definition.xml", + "block_type": "html", + "display_name": "Text", + "has_unpublished_changes": true + }, + ], + }; + } else if (libraryId === 'library-v1:new+CPSPRsadf') { + return { + "count": 3, + "next": null, + "previous": null, + "results": [ + { + "id": "lb:edx:test202:html:3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab/definition.xml", + "block_type": "html", + "display_name": "Text", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:b7c18081-0bec-4de0-8d16-8b255924722e", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/b7c18081-0bec-4de0-8d16-8b255924722e/definition.xml", + "block_type": "html", + "display_name": "Lorem texts", + "has_unpublished_changes": false + }, + ], + }; + } else if (libraryId === 'library-v1:new+CPSPRqwer') { + return { + "count": 3, + "next": null, + "previous": null, + "results": [ + { + "id": "lb:edx:test202:html:3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab/definition.xml", + "block_type": "html", + "display_name": "Text", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:b7c18081-0bec-4de0-8d16-8b255924722e", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/b7c18081-0bec-4de0-8d16-8b255924722e/definition.xml", + "block_type": "html", + "display_name": "Lorem texts", + "has_unpublished_changes": false + }, + { + "id": "lb:edx:test202:problem:86e480e4-e31c-492f-822e-1a8b2501cfde", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:problem:problem/86e480e4-e31c-492f-822e-1a8b2501cfde/definition.xml", + "block_type": "problem", + "display_name": "Blank Problem", + "has_unpublished_changes": true + }, + ], + }; + } else if (libraryId === 'library-v1:new+CPSPR+big') { + return { + "count": 20, + "next": null, + "previous": null, + "results": [ + { + "id": "lb:edx:test202:html:3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab/definition.xml", + "block_type": "html", + "display_name": "a", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:b7c18081-0bec-4de0-8d16-8b255924722e", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/b7c18081-0bec-4de0-8d16-8b255924722e/definition.xml", + "block_type": "html", + "display_name": "b", + "has_unpublished_changes": false + }, + { + "id": "lb:edx:test202:problem:86e480e4-e31c-492f-822e-1a8b2501cfde", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:problem:problem/86e480e4-e31c-492f-822e-1a8b2501cfde/definition.xml", + "block_type": "problem", + "display_name": "c", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab/definition.xml", + "block_type": "html", + "display_name": "d", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:b7c18081-0bec-4de0-8d16-8b255924722e", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/b7c18081-0bec-4de0-8d16-8b255924722e/definition.xml", + "block_type": "html", + "display_name": "e", + "has_unpublished_changes": false + }, + { + "id": "lb:edx:test202:problem:86e480e4-e31c-492f-822e-1a8b2501cfde", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:problem:problem/86e480e4-e31c-492f-822e-1a8b2501cfde/definition.xml", + "block_type": "problem", + "display_name": "f", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab/definition.xml", + "block_type": "html", + "display_name": "g", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:b7c18081-0bec-4de0-8d16-8b255924722e", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/b7c18081-0bec-4de0-8d16-8b255924722e/definition.xml", + "block_type": "html", + "display_name": "h", + "has_unpublished_changes": false + }, + { + "id": "lb:edx:test202:problem:86e480e4-e31c-492f-822e-1a8b2501cfde", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:problem:problem/86e480e4-e31c-492f-822e-1a8b2501cfde/definition.xml", + "block_type": "problem", + "display_name": "i", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab/definition.xml", + "block_type": "html", + "display_name": "j", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:b7c18081-0bec-4de0-8d16-8b255924722e", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/b7c18081-0bec-4de0-8d16-8b255924722e/definition.xml", + "block_type": "html", + "display_name": "k", + "has_unpublished_changes": false + }, + { + "id": "lb:edx:test202:problem:86e480e4-e31c-492f-822e-1a8b2501cfde", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:problem:problem/86e480e4-e31c-492f-822e-1a8b2501cfde/definition.xml", + "block_type": "problem", + "display_name": "l", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab/definition.xml", + "block_type": "html", + "display_name": "m", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:b7c18081-0bec-4de0-8d16-8b255924722e", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/b7c18081-0bec-4de0-8d16-8b255924722e/definition.xml", + "block_type": "html", + "display_name": "n", + "has_unpublished_changes": false + }, + { + "id": "lb:edx:test202:problem:86e480e4-e31c-492f-822e-1a8b2501cfde", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:problem:problem/86e480e4-e31c-492f-822e-1a8b2501cfde/definition.xml", + "block_type": "problem", + "display_name": "o", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab/definition.xml", + "block_type": "html", + "display_name": "p", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:b7c18081-0bec-4de0-8d16-8b255924722e", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/b7c18081-0bec-4de0-8d16-8b255924722e/definition.xml", + "block_type": "html", + "display_name": "q", + "has_unpublished_changes": false + }, + { + "id": "lb:edx:test202:problem:86e480e4-e31c-492f-822e-1a8b2501cfde", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:problem:problem/86e480e4-e31c-492f-822e-1a8b2501cfde/definition.xml", + "block_type": "problem", + "display_name": "r", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/3eb918b1-6ebd-4172-b1e7-bd7c4eaa51ab/definition.xml", + "block_type": "html", + "display_name": "s", + "has_unpublished_changes": true + }, + { + "id": "lb:edx:test202:html:b7c18081-0bec-4de0-8d16-8b255924722e", + "def_key": "bundle-olx:539d7fcc-615c-4b6e-8b57-34cffc82bbd0:studio_draft:html:html/b7c18081-0bec-4de0-8d16-8b255924722e/definition.xml", + "block_type": "html", + "display_name": "t", + "has_unpublished_changes": false + }, + ], + }; + } }; export const emptyMock = () => mockPromise({}); diff --git a/src/editors/containers/LibraryContentEditor/data/reducer.js b/src/editors/containers/LibraryContentEditor/data/reducer.js index de8d31483..d50a9eb06 100644 --- a/src/editors/containers/LibraryContentEditor/data/reducer.js +++ b/src/editors/containers/LibraryContentEditor/data/reducer.js @@ -5,13 +5,13 @@ import { StrictDict } from '../../../utils'; const initialState = { libraries: [], selectedLibrary: null, - selectionMode: modes.all, + selectionMode: modes.random.value, // 'random' or 'selected' selectionSettings: { count: false, showReset: false, - //max count? }, blocksInSelectedLibrary: [], + candidateBlocks: [], // tuples of (block_type, block_id) }; const library = createSlice({ @@ -51,6 +51,10 @@ const library = createSlice({ ...state, blocksInSelectedLibrary: payload.blocks, }), + onSelectCandidates: (state, { payload }) => ({ + ...state, + candidateBlocks: payload.candidates, + }), }, }); diff --git a/src/editors/containers/LibraryContentEditor/hooks.js b/src/editors/containers/LibraryContentEditor/hooks.js index 2576e1774..e4040e851 100644 --- a/src/editors/containers/LibraryContentEditor/hooks.js +++ b/src/editors/containers/LibraryContentEditor/hooks.js @@ -1,23 +1,28 @@ import React, { useEffect } from 'react'; +import { modes } from './constants'; import api from './data/api'; import * as urls from './data/urls'; export const useLibraryHook = ({ + blockFailed, + blockFinished, blockValue, initialize, studioEndpointUrl, }) => { useEffect(() => { - const contentStore = api.fetchContentStore({ studioEndpointUrl }); - initialize({ - libraries: contentStore.libraries, - selectedLibrary: 0, - selectionMode: 'mode', - selectionSettings: { - showReset: blockValue?.data?.metadata?.allow_resetting_children, - count: 1, - }, - }); + if (blockFinished && !blockFailed) { + const contentStore = api.fetchContentStore({ studioEndpointUrl }); + initialize({ + libraries: contentStore.libraries, + selectedLibrary: 0, + selectionMode: modes.random.value, + selectionSettings: { + showReset: blockValue?.data?.metadata?.allow_resetting_children, + count: 1, + }, + }); + } }, []); return { @@ -30,17 +35,20 @@ export const useLibraryHook = ({ export const useBlocksHook = ({ blocksInSelectedLibrary, loadBlocksInLibrary, - selectedLibrary, + onSelectCandidates, + selectedLibraryId, studioEndpointUrl, }) => { useEffect(() => { - if (selectedLibrary !== null) { - const libraryContent = api.fetchLibraryContent({ studioEndpointUrl, selectedLibrary }); + if (selectedLibraryId !== null) { + const libraryContent = api.fetchLibraryContent({ studioEndpointUrl, libraryId: selectedLibraryId }); loadBlocksInLibrary({ blocks: libraryContent.results, }); + } else { + // TODO set candidate to empty list [] } - }, [selectedLibrary]); + }, [selectedLibraryId]); const blockTypeDisplay = (type) => { if (type === 'html') return 'Text'; @@ -51,11 +59,23 @@ export const useBlocksHook = ({ return ({ blockLinks: blocksInSelectedLibrary.map(block => ( - urls.blockContent({ studioEndpointUrl, blockId: block.url }) + urls.blockContent({ + studioEndpointUrl, + blockId: block.id, + }) )), blocksTableData: blocksInSelectedLibrary.map(block => ({ display_name: block.display_name, block_type: blockTypeDisplay(block.block_type), })), + selectCandidates: ({ selected }) => { + let candidates = [] + for (const [key, value] of Object.entries(selected)) { + if (value) { + candidates.push([ blocksInSelectedLibrary[key].block_type, blocksInSelectedLibrary[key].id ]); + } + } + onSelectCandidates({ candidates }); + }, }); }; diff --git a/src/editors/containers/LibraryContentEditor/index.jsx b/src/editors/containers/LibraryContentEditor/index.jsx index 3ad9ed463..cc4bafa20 100644 --- a/src/editors/containers/LibraryContentEditor/index.jsx +++ b/src/editors/containers/LibraryContentEditor/index.jsx @@ -20,7 +20,6 @@ export const thumbEditor = ({ blockFailed, blockFinished, initialize, - lmsEndpointUrl, studioEndpointUrl, // inject intl, @@ -28,6 +27,8 @@ export const thumbEditor = ({ const { getContent, } = useLibraryHook({ + blockFailed, + blockFinished, blockValue, initialize, studioEndpointUrl, @@ -75,7 +76,6 @@ export const thumbEditor = ({ thumbEditor.defaultProps = { blockValue: null, - lmsEndpointUrl: null, }; thumbEditor.propTypes = { @@ -84,7 +84,6 @@ thumbEditor.propTypes = { blockValue: PropTypes.shape({ data: PropTypes.shape({ data: PropTypes.string }), }), - lmsEndpointUrl: PropTypes.string, blockFailed: PropTypes.bool.isRequired, blockFinished: PropTypes.bool.isRequired, initializeEditor: PropTypes.func.isRequired, @@ -94,7 +93,6 @@ thumbEditor.propTypes = { export const mapStateToProps = (state) => ({ blockValue: selectors.app.blockValue(state), - lmsEndpointUrl: selectors.app.lmsEndpointUrl(state), blockFailed: selectors.requests.isFailed(state, { requestKey: RequestKeys.fetchBlock }), blockFinished: selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchBlock }), studioEndpointUrl: selectors.app.studioEndpointUrl(state), diff --git a/src/editors/containers/LibraryContentEditor/messages.js b/src/editors/containers/LibraryContentEditor/messages.js index 46a50345e..3e98a88ab 100644 --- a/src/editors/containers/LibraryContentEditor/messages.js +++ b/src/editors/containers/LibraryContentEditor/messages.js @@ -1,22 +1,51 @@ import { defineMessages } from '@edx/frontend-platform/i18n'; const messages = defineMessages({ - modeAll: { - id: 'authoring.library_content.mode.all', - defaultMessage: 'Show all content from the library to every learner', - description: 'mode of selecting content from a library to put in a course', - }, - modeRandom: { - id: 'authoring.library_content.mode.random', - defaultMessage: 'Show X problems at random from the Library', - description: 'mode of selecting content from a library to put in a course', - }, - modeSelected: { - id: 'authoring.library_content.mode.selected', - defaultMessage: 'Show a specfic portion of the library to all users', - description: 'mode of selecting content from a library to put in a course', - }, - + countLabel: { + id: 'authoring.library_content.count.label', + defaultMessage: 'Enter the number of components to display to each student. Set it to -1 to display all components.', + description: 'label for number of blocks to show', + }, + modeRandom: { + id: 'authoring.library_content.mode.random', + defaultMessage: 'Random Blocks', + description: 'name of mode for selecting content from a library to put in a course', + }, + modeSelected: { + id: 'authoring.library_content.mode.selected', + defaultMessage: 'Selected Blocks', + description: 'name of mode for selecting content from a library to put in a course', + }, + modeRandomDescription: { + id: 'authoring.library_content.mode.random.description', + defaultMessage: 'Show a number of components to display at random from the library.', + description: 'description of mode for selecting content from a library to put in a course', + }, + modeSelectedDescription: { + id: 'authoring.library_content.mode.selected.description', + defaultMessage: 'Show the selected blocks of the library to all users.', + description: 'description of mode for selecting content from a library to put in a course', + }, + resetButton: { + id: 'authoring.library_content.reset.button', + defaultMessage: 'Show Reset Button', + description: 'name of button for allowing users to reset answers and reshuffle selected items', + }, + resetButtonDescription: { + id: 'authoring.library_content.reset.button.description', + defaultMessage: "Determines whether a 'Reset Problems' button is shown, so users may reset their answers and reshuffle selected items.", + description: 'description of button for allowing users to reset answers and reshuffle selected items', + }, + tableInstructionLabel: { + id: 'authoring.library_content.table.instruction.label', + defaultMessage: 'Select the components you want to display:', + description: 'label for block selection table to instruct users to select the blocks to show', + }, + tableViewButton: { + id: 'authoring.library_content.table.view.button', + defaultMessage: 'View', + description: 'button on block selection table for viewing block in a separate browser tab', + }, }); export default messages; \ No newline at end of file diff --git a/src/editors/data/services/cms/api.js b/src/editors/data/services/cms/api.js index d8f0dcab1..c73625a29 100644 --- a/src/editors/data/services/cms/api.js +++ b/src/editors/data/services/cms/api.js @@ -185,13 +185,14 @@ export const apiMethods = { category: blockType, courseKey: learningContextId, display_name: title, //"course-v1:edx+123+test" - has_children: "TODO TRUE FALSE", + // has_children: true, highlights: [], highlights_doc_url: "", highlights_enabled: false, highlights_enabled_for_messaging: false, highlights_preview_only: true, id: blockId, //"block-v1:edx+123+test+type@library_content+block@880758e62c2542d5b45c944360dfa799" + // TODO candidates? metadata: {}, }; } else {