Skip to content

Commit

Permalink
TASK: support unsetting presets (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaip authored Nov 9, 2020
1 parent f74bc7f commit f8c1639
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
17 changes: 12 additions & 5 deletions Resources/Private/FlatNav/src/makeFlatNavContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,20 @@ const makeFlatNavContainer = OriginalPageTree => {

buildDefaultState = props => {
const state = {};
Object.keys(props.options.presets).forEach(preset => {
Object.keys(props.options.presets).forEach(presetName => {
const preset = props.options.presets[presetName];
if (!presetName) {
return null;
}
let newReferenceNodePath;
// If `newReferenceNodePath` is static, append context to it, otherwise set to empty, as it would be fetched later
const newReferenceNodePathSetting = $get(['options', 'presets', preset, 'newReferenceNodePath'], props);
const newReferenceNodePathSetting = $get(['options', 'presets', presetName, 'newReferenceNodePath'], props);
if (typeof newReferenceNodePathSetting === 'string' && newReferenceNodePathSetting.indexOf('/') === 0) {
newReferenceNodePath = props.options.presets[preset].newReferenceNodePath;
newReferenceNodePath = preset.newReferenceNodePath;
} else {
newReferenceNodePath = '';
}
state[preset] = {
state[presetName] = {
page: 1,
isLoading: false,
isLoadingReferenceNodePath: false,
Expand Down Expand Up @@ -234,6 +238,9 @@ const makeFlatNavContainer = OriginalPageTree => {
}}>
{Object.keys(this.props.options.presets).map(presetName => {
const preset = this.props.options.presets[presetName];
if (!preset) {
return null;
}
const fetchNodes = this.makeFetchNodes(presetName)
const resetNodes = this.makeResetNodes(presetName, fetchNodes)
const debouncedFetchNodes = debounce(fetchNodes, 400);
Expand All @@ -255,7 +262,7 @@ const makeFlatNavContainer = OriginalPageTree => {
{preset.type === 'tree' && (<OriginalPageTree />)}
</Tabs.Panel>
);
})}
}).filter(Boolean)}
</Tabs>
);
}
Expand Down
17 changes: 12 additions & 5 deletions Resources/Public/JavaScript/FlatNav/Plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Resources/Public/JavaScript/FlatNav/Plugin.js.map

Large diffs are not rendered by default.

0 comments on commit f8c1639

Please sign in to comment.