Skip to content

Commit

Permalink
Feature: Add logic for twodimensional dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
pKallert committed Dec 28, 2023
1 parent afd89aa commit 97c025f
Showing 1 changed file with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ export default class DimensionSwitcher extends PureComponent {
loadingPresets: {}
};

componentDidMount() {
const activePresets = mapValues(
this.props.activePresets,
dimensionPreset => dimensionPreset.name
);
this.setState({
transientPresets: activePresets
});
console.log(this.state.transientPresets);
}

getDimensionIcon = (dimensionName, contentDimensionsObject) => {
const dimensionConfiguration = contentDimensionsObject[dimensionName];
return dimensionConfiguration?.icon || null;
Expand Down Expand Up @@ -146,6 +157,7 @@ export default class DimensionSwitcher extends PureComponent {
}
}


handleApplyPresets = () => {
this.props.selectPreset(this.state.transientPresets);
this.setState({isOpen: false, transientPresets: {}});
Expand Down Expand Up @@ -269,16 +281,32 @@ export default class DimensionSwitcher extends PureComponent {
return null;
}
getDocumentDimensions(dimensionName) {
const {getNodeByContextPath, documentNode, allowedPresets, activePresets} = this.props;
const {getNodeByContextPath, documentNode, allowedPresets, contentDimensions} = this.props;
const currentDocumentNode = getNodeByContextPath(documentNode.contextPath)
if(!currentDocumentNode.dimensions) return allowedPresets[dimensionName]
if(!currentDocumentNode.dimensions){
return allowedPresets[dimensionName]
}

let variants = currentDocumentNode?.otherNodeVariants;
let dimensions = [currentDocumentNode.dimensions[dimensionName]];
let variants = [...currentDocumentNode?.otherNodeVariants];
variants.push(currentDocumentNode.dimensions)

for(let dimensionKey of Object.keys(contentDimensions)){
if(dimensionKey == dimensionName) {
break;
}
Object.entries(variants).forEach(entry => {
const [key, value] = entry;
if(value[dimensionKey] != this.state.transientPresets[dimensionKey]){
delete variants[key]
}
});
}
let dimensions = []
Object.values(variants).forEach(entry => {

dimensions.push(entry[dimensionName]);
});

return dimensions;
}

Expand Down

0 comments on commit 97c025f

Please sign in to comment.