mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-12 13:48:35 +02:00
* move all icons to offline mode * Reorder imports * revert yarn.lock to original * resolve errors * use ConditionalRender, revert material icon css * add all other font weights * fix: add library icon Co-authored-by: Aneesh Relan <aneesh.r@lucideustech.com>
99 lines
3.0 KiB
JavaScript
99 lines
3.0 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { Tooltip, Typography } from '@material-ui/core';
|
|
import { Info } from '@material-ui/icons';
|
|
|
|
import StrategyConstraintInputField from '../StrategyConstraintInputField';
|
|
import { useCommonStyles } from '../../../../../common.styles';
|
|
|
|
const StrategyConstraintInput = ({
|
|
constraints,
|
|
updateConstraints,
|
|
contextNames,
|
|
contextFields,
|
|
enabled,
|
|
}) => {
|
|
const commonStyles = useCommonStyles();
|
|
const addConstraint = evt => {
|
|
evt.preventDefault();
|
|
const updatedConstraints = [...constraints];
|
|
updatedConstraints.push({
|
|
contextName: contextNames[0],
|
|
operator: 'IN',
|
|
values: [],
|
|
});
|
|
|
|
updateConstraints(updatedConstraints);
|
|
};
|
|
|
|
const removeConstraint = index => evt => {
|
|
evt.preventDefault();
|
|
const updatedConstraints = [...constraints];
|
|
updatedConstraints.splice(index, 1);
|
|
|
|
updateConstraints(updatedConstraints);
|
|
};
|
|
|
|
const updateConstraint = index => (value, field) => {
|
|
const updatedConstraints = [...constraints];
|
|
const constraint = updatedConstraints[index];
|
|
constraint[field] = value;
|
|
updateConstraints(updatedConstraints);
|
|
};
|
|
|
|
if (!enabled) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<div className={commonStyles.contentSpacingY}>
|
|
<Tooltip
|
|
placement="right-start"
|
|
title={
|
|
<span>
|
|
Use context fields to constrain the activation strategy.
|
|
</span>
|
|
}
|
|
>
|
|
<Typography variant="subtitle2">
|
|
{'Constraints '}
|
|
|
|
<Info style={{ fontSize: '0.9rem', color: 'gray' }} />
|
|
</Typography>
|
|
</Tooltip>
|
|
<table style={{ margin: 0 }}>
|
|
<tbody>
|
|
{constraints.map((c, index) => (
|
|
<StrategyConstraintInputField
|
|
key={`${c.contextName}-${index}`}
|
|
id={`${c.contextName}-${index}`}
|
|
constraint={c}
|
|
contextFields={contextFields}
|
|
updateConstraint={updateConstraint(index)}
|
|
removeConstraint={removeConstraint(index)}
|
|
/>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
<small>
|
|
<a
|
|
href="#add-constraint"
|
|
title="Add constraint"
|
|
onClick={addConstraint}
|
|
>
|
|
Add constraint
|
|
</a>
|
|
</small>
|
|
</div>
|
|
);
|
|
};
|
|
StrategyConstraintInput.propTypes = {
|
|
constraints: PropTypes.array.isRequired,
|
|
updateConstraints: PropTypes.func.isRequired,
|
|
contextNames: PropTypes.array.isRequired,
|
|
contextFields: PropTypes.array.isRequired,
|
|
enabled: PropTypes.bool.isRequired,
|
|
};
|
|
|
|
export default StrategyConstraintInput;
|