From 19b7a8eea732455a201d4c2d149a349de9a138ba Mon Sep 17 00:00:00 2001 From: Kirill Shumilov Date: Tue, 24 Oct 2017 17:58:24 +0300 Subject: [PATCH] fix(xod-client): fix renaming of patch paths in all tabs and breadcrumbs --- packages/xod-client/src/editor/reducer.js | 35 +++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/packages/xod-client/src/editor/reducer.js b/packages/xod-client/src/editor/reducer.js index 2ebaa990..eace485e 100644 --- a/packages/xod-client/src/editor/reducer.js +++ b/packages/xod-client/src/editor/reducer.js @@ -288,12 +288,37 @@ const closeTabByPatchPath = R.curry( } ); -const renamePatchInTabs = (newPatchPath, oldPatchPath, state) => { - const tabIdToRename = getTabIdbyPatchPath(oldPatchPath, state); +// :: PatchPath -> PatchPath -> Tab -> Tab +const renamePatchPathInBreadcrumbs = R.curry( + (newPatchPath, oldPatchPath, tab) => R.when( + R.has('breadcrumbs'), + R.over( + R.lensPath(['breadcrumbs', 'chunks']), + R.map(R.when( + R.propEq('patchPath', oldPatchPath), + R.assoc('patchPath', newPatchPath) + )) + ) + )(tab) +); - return (tabIdToRename === null) - ? state - : R.assocPath(['tabs', tabIdToRename, 'patchPath'], newPatchPath, state); +const renamePatchInTabs = (newPatchPath, oldPatchPath, state) => { + const tabIdsToRename = R.compose( + R.map(R.prop('id')), + listTabsByPatchPath + )(oldPatchPath, state); + + return (tabIdsToRename.length === 0) ? state : R.over( + R.lensProp('tabs'), + R.map(R.compose( + renamePatchPathInBreadcrumbs(newPatchPath, oldPatchPath), + R.when( + R.propEq('patchPath', oldPatchPath), + R.assoc('patchPath', newPatchPath) + ) + )), + state + ); }; const createSelectionEntity = R.curry((entityType, id) => ({ entity: entityType, id }));