Skip to content

Commit

Permalink
Merge branch 'main' into collectionnameerror
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfang97 authored May 22, 2024
2 parents df45f4d + 9fd2ac6 commit f26eb2a
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;});
}
Expand Down
12 changes: 8 additions & 4 deletions frontend/components/Submit/SubmitButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);

}
}}
>
<FontAwesomeIcon
Expand Down
35 changes: 7 additions & 28 deletions frontend/components/Viewing/Modals/ConfigureModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ import SubmissionHandler from "../../Submit/ReusableComponents/SubmissionHandler
import { submit } from '../../../redux/actions';







export default function ConfigureModal(properties) {

const initializeMap = new Map();

for (let file of properties.files) {
initializeMap.set(file, {value: 'default', label: 'Default Handler'})
initializeMap.set(file.name, {value: 'default', label: 'Default Handler'})
}

const [submitted, setSubmitted] = useState(false);
Expand All @@ -36,37 +31,21 @@ export default function ConfigureModal(properties) {

useEffect(() => {
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(
selectedCollection.uri,
properties.files,
properties.overwriteCollection ? 1 : 0,
properties.addingToCollection ? true : false,
pluginObject,
pluginMapping,
properties.failed
)
);
}


}
Expand All @@ -78,9 +57,9 @@ export default function ConfigureModal(properties) {
<div key={file.name} className={styles.configurefile}>
<p className={styles.configurefilename}>{file.name}</p>
<SubmissionHandler
selectedHandler={fileMap.get(file)}
selectedHandler={fileMap.get(file.name)}
setSelectedHandler={(e) => {
setFileMap(new Map(fileMap.set(file, e)));
setFileMap(new Map(fileMap.set(file.name, e)));
}}
configureOption={false}
failed={properties.failed}
Expand Down
23 changes: 10 additions & 13 deletions frontend/components/Viewing/PageJSON/Rendering/GenericContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 (
<Section title={title} key={index} pluginID={page} >
<Plugin plugin={plugin} type={type} uri={uri} />
</Section>
);
}
else {
return null;
}
const title = page.substring(8, page.length)
const plugin = plugins.rendering.filter(plugin => plugin.name === title)[0]
return (
<Plugin plugin={plugin} type={type} uri={uri} title={title} key={index} pluginID={page} />
);

}

const ComponentToRender = CustomComponents[page];
Expand All @@ -71,6 +64,10 @@ export default function GenericContent({ json, uri, metadata, plugins, type }) {
return <Fragment>{content}</Fragment>;
}





// 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)
Expand Down
44 changes: 20 additions & 24 deletions frontend/components/Viewing/Plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div>Loading Data From Plugin...</div>');
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;

Expand Down Expand Up @@ -46,36 +49,26 @@ export default function Plugin(properties) {

useEffect(() => {
if (status === null) {
setContent('<div>Loading Data From Plugin...</div>')
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 => {
Expand Down Expand Up @@ -108,14 +101,17 @@ export default function Plugin(properties) {
}

return (
<div id={properties.plugin.name}>
{parse(`${content}`, options)}
</div>
<Section title={properties.title} key={properties.index} pluginID={properties.page} >
<div id={properties.plugin.name}>
{parse(`${content}`, options)}
</div>
</Section>

);
}

else {
//return <Section title={properties.plugin.name}>{`${properties.plugin.name} is not working`}</Section>; //return null for it not to be loaded

return null
}

Expand Down
11 changes: 5 additions & 6 deletions frontend/components/Viewing/SectionSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,18 @@ function headerCreate(pages, type, json, hiddenSections) {
<Draggable key={page} draggableId={page} index={index}>
{renderDraggable(dragProvided => (
<div
className={`${styles.sectionheaderparent} ${hiddenSections.includes(page) ? styles.hiddensection : ''}`}
className={`${styles.sectionheaderparent}`}
{...dragProvided.dragHandleProps}
{...dragProvided.draggableProps}
ref={dragProvided.innerRef}
>
{hiddenSections.includes(page) ? null : (
<SectionHeader

{ hiddenSections.includes(page) ? null :
<SectionHeader
type={type}
title={page}
icon={iconSelector(page, json)}
/>
)}

/>}
</div>
))}
</Draggable>
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function Submit() {
checked={overwriteCollection}
setChecked={setOverwriteCollection}
/>
<SubmitButton files={files} overwriteCollection={overwriteCollection} submitHandler={selectedHandler} change={handleClick} />
<SubmitButton files={files} overwriteCollection={overwriteCollection} submitHandler={selectedHandler} configure={handleClick} />

</div>
</div>
Expand Down
21 changes: 13 additions & 8 deletions frontend/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export const submit =
files,
overwriteIncrement = 0,
addingToCollection = false,
plugin = null,
pluginMapping = null,
resubmit = false
) =>
async (dispatch, getState) => {
Expand Down Expand Up @@ -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);



Expand All @@ -308,9 +308,10 @@ export const submit =
getState,
token,
uri,
convertedFiles,
files,
overwriteIncrement,
addingToCollection
addingToCollection,
pluginMapping
);

dispatch({
Expand All @@ -319,7 +320,7 @@ export const submit =
});
};


/*
async function submitPluginHandler(files, plugin, dispatch, getState) {
if (plugin.value === 'configure') {
Expand Down Expand Up @@ -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;
Expand All @@ -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'
});


Expand Down Expand Up @@ -623,6 +626,8 @@ async function uploadFiles(
form.append('collections', uri);
}

form.append('plugin', filesUploading[fileIndex].plugin)

let response;

try {
Expand Down

0 comments on commit f26eb2a

Please sign in to comment.