Skip to content

Commit

Permalink
666 - bugfix: store more than only one plugin/module/author
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kuhlmay committed Dec 19, 2023
1 parent c043ba2 commit d7e5104
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 57 deletions.
116 changes: 89 additions & 27 deletions Build/Sources/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,51 +75,113 @@ function App() {
}
}

const updateAuthorHandler = (authorId, field, value) => {
const updateAuthorHandler = (authorIndex, field, value) => {
if (authorIndex < 0 || authorIndex >= authors.length) {
console.error("Invalid author index");
return;
}

setAuthors((prevAuthors) => {
return prevAuthors.map((author) => {
if (author.id === authorId) {
return prevAuthors.map((author, index) => {
if (index === authorIndex) {
return {...author, [field]: value};
} else {
return author;
}
return author;
});
});
};

const updatePluginHandler = (pluginId, field, value) => {
const updatePluginHandler = (pluginIndex, fieldPath, value) => {
if (pluginIndex < 0 || pluginIndex >= plugins.length) {
console.error("Invalid plugin index");
return;
}

// Teile den Pfad in seine Bestandteile
const pathParts = fieldPath.split('.');

setPlugins((prevPlugins) => {
return prevPlugins.map((plugin) => {
if (plugin.id === pluginId) {
if (field.includes('.')) {
const [parentKey, childKey] = field.split('.');
return {...plugin, [parentKey]: {...plugin[parentKey], [childKey]: value}};
} else {
return {...plugin, [field]: value};
return prevPlugins.map((plugin, index) => {
if (index === pluginIndex) {
// Erstelle eine Kopie des Plugins
let updatedPlugin = {...plugin};

// Referenz zum aktuellen Teil des Plugins
let currentPart = updatedPlugin;

// Gehe durch alle Teile des Pfads, außer dem letzten
for (let i = 0; i < pathParts.length - 1; i++) {
const part = pathParts[i];

// Aktualisiere die Referenz zum nächsten Teil
if (!currentPart[part]) {
currentPart[part] = {}; // Erstelle ein neues Objekt, falls nicht vorhanden
} else {
// Erstelle eine Kopie, um direkte Mutationen zu vermeiden
currentPart[part] = {...currentPart[part]};
}

// Bewege die Referenz
currentPart = currentPart[part];
}
} else {
return plugin;

// Aktualisiere den letzten Teil des Pfads
currentPart[pathParts[pathParts.length - 1]] = value;

// Gib das aktualisierte Plugin zurück
return updatedPlugin;
}
return plugin;
});
});
}
};


const updateModuleHandler = (moduleIndex, fieldPath, value) => {
if (moduleIndex < 0 || moduleIndex >= modules.length) {
console.error("Invalid module index");
return;
}

// Teile den Pfad in seine Bestandteile
const pathParts = fieldPath.split('.');

const updateModuleHandler = (moduleId, field, value) => {
setModules((prevModules) => {
return prevModules.map((module) => {
if (module.id === moduleId) {
if (field.includes('.')) {
const [parentKey, childKey] = field.split('.');
return {...module, [parentKey]: {...module[parentKey], [childKey]: value}};
} else {
return {...module, [field]: value};
return prevModules.map((module, index) => {
if (index === moduleIndex) {
// Erstelle eine Kopie des Moduls
let updatedModule = {...module};

// Referenz zum aktuellen Teil des Moduls
let currentPart = updatedModule;

// Gehe durch alle Teile des Pfads, außer dem letzten
for (let i = 0; i < pathParts.length - 1; i++) {
const part = pathParts[i];

// Aktualisiere die Referenz zum nächsten Teil
if (!currentPart[part]) {
currentPart[part] = {}; // Erstelle ein neues Objekt, falls nicht vorhanden
} else {
// Erstelle eine Kopie, um direkte Mutationen zu vermeiden
currentPart[part] = {...currentPart[part]};
}

// Bewege die Referenz
currentPart = currentPart[part];
}
} else {
return module;

// Aktualisiere den letzten Teil des Pfades
currentPart[pathParts[pathParts.length - 1]] = value;

// Gib das aktualisierte Modul zurück
return updatedModule;
}
return module;
});
});
}
};


const removeAuthorHandler = (authorId) => {
setAuthors((prevAuthors) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SelectComponent from "../forms/select/SelectComponent";
export const SingleAuthorComponent = (props) => {

const updateAuthorHandler = (field, value) => {
props.updateAuthorHandler(props.author.id, field, value);
props.updateAuthorHandler(props.index, field, value);
};

const roles = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import InputComponent from "../forms/input/InputComponent";
export const SingleModuleComponent = (props) => {

const updateModuleHandler = (field, value) => {
props.updateModuleHandler(props.module.id, field, value);
props.updateModuleHandler(props.index, field, value);
};

const mainModules = [
Expand Down Expand Up @@ -76,9 +76,9 @@ export const SingleModuleComponent = (props) => {
placeholder="Blog => edit, update, delete"
label="Cachable controller actions"
identifier="controllerActionCombinations"
initialValue={props.module.controllerActionCombinations}
initialValue={props.module.actions.controllerActionCombinations}
onChange={(value) => {
updateModuleHandler('controllerActionCombinations', value);
updateModuleHandler('actions.controllerActionCombinations', value);
}}
/>
<div className="d-flex module-actions">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from "react";
export const SinglePluginComponent = (props) => {

const updatePluginHandler = (field, value) => {
props.updatePluginHandler(props.plugin.id, field, value);
props.updatePluginHandler(props.index, field, value);
};

return (
Expand Down Expand Up @@ -46,18 +46,18 @@ export const SinglePluginComponent = (props) => {
placeholder="Blog => list, show"
label="Cachable controller actions"
identifier="controllerActionsCachable"
initialValue={props.plugin.controllerActionsCachable}
initialValue={props.plugin.actions.controllerActionCombinations}
onChange={(value) => {
updatePluginHandler('controllerActionsCachable', value);
updatePluginHandler('actions.controllerActionCombinations', value);
}}
/>
<TextareaComponent
placeholder="Blog => edit, update, delete"
label="Non cachable controller actions"
identifier="controllerActionsNonCachable"
initialValue={props.plugin.controllerActionsNonCachable}
initialValue={props.plugin.actions.noncacheableActions}
onChange={(value) => {
updatePluginHandler('controllerActionsNonCachable', value);
updatePluginHandler('actions.noncacheableActions', value);
}}
/>
<div className="d-flex author-actions">
Expand Down
21 changes: 1 addition & 20 deletions Resources/Private/CodeTemplates/Extbase/extTables.phpt
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
{namespace k=EBT\ExtensionBuilder\ViewHelpers}<?php
defined('TYPO3') || die();

(static function() {<f:if condition="{extension.BackendModules}"><f:for each="{extension.BackendModules}" as="backendModule">
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
'{extension.extensionName}',
'{backendModule.mainModule}',
'{backendModule.key}',
'',
[<f:if condition="{backendModule.controllerActionCombinations}"><f:then>
<f:for each="{backendModule.controllerActionCombinations}" as="actionNames" key="controllerName" iteration="j">\{extension.vendorName}\{extension.extensionName}\Controller\{controllerName}Controller::class => '<f:for each="{actionNames}" as="actionName" iteration="i">{actionName}<f:if condition="{i.isLast} == 0">, </f:if></f:for>',
</f:for></f:then><f:else>
<f:for each="{extension.domainObjectsForWhichAControllerShouldBeBuilt}" as="domainObject" iteration="j">\{extension.vendorName}\{extension.extensionName}\Controller\{domainObject.name}Controller::class => '<f:for each="{domainObject.actions}" as="action" iteration="actionIterator">{action.name}<f:if condition="{actionIterator.isLast} == 0">, </f:if></f:for>',
</f:for></f:else></f:if>
],
[
'access' => 'user,group',
'icon' => 'EXT:{extension.extensionKey}/Resources/Public/Icons/user_mod_{backendModule.key}.svg',
'labels' => 'LLL:EXT:{extension.extensionKey}/Resources/Private/Language/locallang_{backendModule.key}.xlf',
]
);
</f:for>
</f:if><f:for each="{extension.domainObjects}" as="domainObject"><f:if condition="{domainObject.mappedToExistingTable}"><f:else>
(static function() {<f:for each="{extension.domainObjects}" as="domainObject"><f:if condition="{domainObject.mappedToExistingTable}"><f:else>
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('{domainObject.databaseTableName}', 'EXT:{extension.extensionKey}/Resources/Private/Language/locallang_csh_{domainObject.databaseTableName}.xlf');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('{domainObject.databaseTableName}');
</f:else></f:if></f:for>})();
2 changes: 1 addition & 1 deletion Resources/Public/JavaScript/main.js

Large diffs are not rendered by default.

0 comments on commit d7e5104

Please sign in to comment.