diff --git a/frontend/components/Submit/ReusableComponents/SubmissionHandler.js b/frontend/components/Submit/ReusableComponents/SubmissionHandler.js index 82012fea..6d536268 100644 --- a/frontend/components/Submit/ReusableComponents/SubmissionHandler.js +++ b/frontend/components/Submit/ReusableComponents/SubmissionHandler.js @@ -37,7 +37,7 @@ export default function SubmissionHandler(properties) { category: 'submit' } }).then(response => { - if(response.status === 200) selectOptions.push({value: plugin.name, label: plugin.name}); + if(response.status === 200) selectOptions.push({value: plugin.index, label: plugin.name}); pluginsAvailable = true; }).catch(error => {return;}); } diff --git a/frontend/components/Submit/SubmitButton.js b/frontend/components/Submit/SubmitButton.js index 7a2019e8..d45178ee 100644 --- a/frontend/components/Submit/SubmitButton.js +++ b/frontend/components/Submit/SubmitButton.js @@ -29,19 +29,23 @@ export default function SubmitButton(properties) { 'You must select one or more files and a destination collection before you can submit.' ); else if (properties.submitHandler.value === 'configure') { - properties.change() + properties.configure() } - else + else { + let pluginMapping = new Map(); + for (const file of properties.files) { + pluginMapping.set(file.name, properties.submitHandler.value) + } dispatch( submit( selectedCollection.uri, properties.files, properties.overwriteCollection ? 1 : 0, properties.addingToCollection ? true : false, - properties.submitHandler + pluginMapping ) ); - + } }} > { if(submitted) { - const pluginBundles = new Map(); - fileMap.forEach((value, key) => { - if(value.value !== 'null') { - if(pluginBundles.has(value)) { - pluginBundles.get(value).push(key) - } - else { - const fileList = []; - fileList.push(key) - pluginBundles.set(value, fileList) - } - } + const pluginMapping = new Map(); + fileMap.forEach((plugin, file) => { + pluginMapping.set(file.name, plugin.value) }) - - if(pluginBundles.size !== 0) { - const pluginObject = { - value: 'configure', - pluginBundles: pluginBundles - } dispatch( submit( @@ -62,11 +42,10 @@ export default function ConfigureModal(properties) { properties.files, properties.overwriteCollection ? 1 : 0, properties.addingToCollection ? true : false, - pluginObject, + pluginMapping, properties.failed ) ); - } } @@ -78,9 +57,9 @@ export default function ConfigureModal(properties) {

{file.name}

{ - setFileMap(new Map(fileMap.set(file, e))); + setFileMap(new Map(fileMap.set(file.name, e))); }} configureOption={false} failed={properties.failed} diff --git a/frontend/components/Viewing/PageJSON/Rendering/GenericContent.js b/frontend/components/Viewing/PageJSON/Rendering/GenericContent.js index 0ef9fed0..40d2b82f 100644 --- a/frontend/components/Viewing/PageJSON/Rendering/GenericContent.js +++ b/frontend/components/Viewing/PageJSON/Rendering/GenericContent.js @@ -27,7 +27,6 @@ export default function GenericContent({ json, uri, metadata, plugins, type }) { } const pages = useSelector(state => state.pageSections.order); - const hiddenSections = useSelector(state => state.pageSections.hiddenSections); const content = pages.map((page, index) => { if (page.startsWith('$TABLES[') && json && json.tables) { @@ -43,18 +42,12 @@ export default function GenericContent({ json, uri, metadata, plugins, type }) { ); } if (page.startsWith('PLUGIN: ')) { - if (!hiddenSections.includes(page)) { - const title = page.substring(8, page.length) - const plugin = plugins.rendering.filter(plugin => plugin.name === title)[0] - return ( -
- -
- ); - } - else { - return null; - } + const title = page.substring(8, page.length) + const plugin = plugins.rendering.filter(plugin => plugin.name === title)[0] + return ( + + ); + } const ComponentToRender = CustomComponents[page]; @@ -71,6 +64,10 @@ export default function GenericContent({ json, uri, metadata, plugins, type }) { return {content}; } + + + + // This is Alex's code for the previous table renderer. I'm keeping it // for now to keep track of custom components, but this is dead code/not valid // and if you delete it it's totally fine (zombie code sucks) diff --git a/frontend/components/Viewing/Plugin.js b/frontend/components/Viewing/Plugin.js index 91110c6f..ea0ef298 100644 --- a/frontend/components/Viewing/Plugin.js +++ b/frontend/components/Viewing/Plugin.js @@ -6,15 +6,18 @@ import React from 'react'; import getConfig from 'next/config'; const { publicRuntimeConfig } = getConfig(); import { useSelector, useDispatch } from 'react-redux'; + +import Section from './Sections/Section'; import { updateHiddenSections } from '../../redux/actions'; export default function Plugin(properties) { const [status, setStatus] = useState(null); - const [content, setContent] = useState(""); + const [content, setContent] = useState('
Loading Data From Plugin...
'); const pageSectionsOrder = useSelector(state => state.pageSections.order); - const hiddenSections = useSelector(state => state.pageSections.hiddenSections) - + const hiddenSections = useSelector(state => state.pageSections.hiddenSections); const dispatch = useDispatch(); + + const uri = properties.uri; @@ -46,36 +49,26 @@ export default function Plugin(properties) { useEffect(() => { if (status === null) { - setContent('
Loading Data From Plugin...
') evaluatePlugin(properties.plugin, properties.type).then(status => setStatus(status)); } - else if (status) { + + if (status) { + dispatch(updateHiddenSections(hiddenSections.filter(page => page != `PLUGIN: ${properties.plugin.name}`))) const downloadContent = async () => { const toRender = await runPlugin(properties.plugin, pluginData); setContent(toRender); }; downloadContent(); } - }, [status, pageSectionsOrder]); - - useEffect(() => { - if(status === false) { - hiddenSections.push('PLUGIN: ' + properties.plugin.name) - dispatch( - updateHiddenSections(hiddenSections) - ) - } - else if (status === true) { - const updatedHiddenSections = hiddenSections.filter(str => str !== 'PLUGIN: ' + properties.plugin.name) - dispatch( - updateHiddenSections(updatedHiddenSections) - ) + else { + dispatch(updateHiddenSections(hiddenSections.filter(page => page != `PLUGIN: ${properties.plugin.name}`).concat(`PLUGIN: ${properties.plugin.name}`))) } - }, [status]) + }, [status, pageSectionsOrder]); if (status) { + const options = { replace: domNode => { @@ -108,14 +101,17 @@ export default function Plugin(properties) { } return ( -
- {parse(`${content}`, options)} -
+
+
+ {parse(`${content}`, options)} +
+
+ ); } else { - //return
{`${properties.plugin.name} is not working`}
; //return null for it not to be loaded + return null } diff --git a/frontend/components/Viewing/SectionSelector.js b/frontend/components/Viewing/SectionSelector.js index 6764b8fc..0c83d055 100644 --- a/frontend/components/Viewing/SectionSelector.js +++ b/frontend/components/Viewing/SectionSelector.js @@ -236,19 +236,18 @@ function headerCreate(pages, type, json, hiddenSections) { {renderDraggable(dragProvided => (
- {hiddenSections.includes(page) ? null : ( - - )} - + />}
))}
diff --git a/frontend/pages/submit.js b/frontend/pages/submit.js index f1bcb90c..b48b574d 100644 --- a/frontend/pages/submit.js +++ b/frontend/pages/submit.js @@ -77,7 +77,7 @@ function Submit() { checked={overwriteCollection} setChecked={setOverwriteCollection} /> - +
diff --git a/frontend/redux/actions.js b/frontend/redux/actions.js index f70593f7..f178dbf8 100644 --- a/frontend/redux/actions.js +++ b/frontend/redux/actions.js @@ -257,7 +257,7 @@ export const submit = files, overwriteIncrement = 0, addingToCollection = false, - plugin = null, + pluginMapping = null, resubmit = false ) => async (dispatch, getState) => { @@ -298,7 +298,7 @@ export const submit = const token = getState().user.token; - const convertedFiles = await submitPluginHandler(files, plugin, dispatch, getState); + //const convertedFiles = await submitPluginHandler(files, plugin, dispatch, getState); @@ -308,9 +308,10 @@ export const submit = getState, token, uri, - convertedFiles, + files, overwriteIncrement, - addingToCollection + addingToCollection, + pluginMapping ); dispatch({ @@ -319,7 +320,7 @@ export const submit = }); }; - +/* async function submitPluginHandler(files, plugin, dispatch, getState) { if (plugin.value === 'configure') { @@ -572,7 +573,8 @@ async function uploadFiles( uri, files, overwriteIncrement = 0, - addingToCollection = false + addingToCollection = false, + pluginMapping = null ) { const filesUploading = getState().submit.filesUploading; const failedFiles = getState().submit.failedFiles; @@ -582,9 +584,10 @@ async function uploadFiles( filesUploading.push({ file: file, name: file.name, - url: file.url, + url: file.url, //unnecessary and most likely not even working anyway status: 'pending', - errors: [] + errors: [], + plugin: pluginMapping ? pluginMapping.get(file.name): 'default' }); @@ -623,6 +626,8 @@ async function uploadFiles( form.append('collections', uri); } + form.append('plugin', filesUploading[fileIndex].plugin) + let response; try {