Skip to content

Commit

Permalink
Read only segment override mv value (Flagsmith#1942)
Browse files Browse the repository at this point in the history
* Read only segment override mv value

* disabled styles / disable control value

* disabled styles

* Adjust Segment control value label

* Allow editable segment control value

* Adjust tab unread notification styles
  • Loading branch information
kyle-ssg authored Mar 6, 2023
1 parent 6bd4685 commit cf67ce9
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 12 deletions.
7 changes: 4 additions & 3 deletions frontend/web/components/Highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function escapeHtml(unsafe) {
};
}
const defaultValue = { __html: 'Enter a value...' };
const defaultDisabledValue = { __html: ' ' };
const collapsedHeight = 110;
class Highlight extends React.Component {
state = {
Expand Down Expand Up @@ -111,7 +112,7 @@ class Highlight extends React.Component {
}

render() {
const { children, className, element: Element, innerHTML } = this.props;
const { children, className, element: Element, innerHTML, disabled } = this.props;
const props = { ref: this.setEl, className };

if (innerHTML) {
Expand All @@ -126,8 +127,8 @@ class Highlight extends React.Component {
return <Element {...props}>{children}</Element>;
}

const html = this.props.preventEscape ? this.state.focus ? this.state.value : this.props.children ? { ...this.state.value } : defaultValue
: escapeHtml(this.state.focus ? this.state.value : this.props.children ? { ...this.state.value } : defaultValue);
const html = this.props.preventEscape ? this.state.focus ? this.state.value : this.props.children ? { ...this.state.value } : disabled? defaultDisabledValue : defaultValue
: escapeHtml(this.state.focus ? this.state.value : this.props.children ? { ...this.state.value } : disabled? defaultDisabledValue : defaultValue);
return (
<div className={this.state.expandable ? 'expandable' : ''}>
<pre style={{ ...(this.props.style || {}), opacity: typeof this.state.expandable === 'boolean' || this.props.forceExpanded ? 1 : 0, height: (this.state.expanded || !this.state.expandable) ? 'auto' : collapsedHeight }} ref={this.setEl}>
Expand Down
5 changes: 3 additions & 2 deletions frontend/web/components/SegmentOverrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ const SegmentOverrideInner = class Override extends React.Component {
) : (
<>
<label>
Control Value - {controlPercent}%
Segment Control Value - {controlPercent}%
</label>
<ValueEditor
value={v.value}
data-test={`segment-override-value-${index}`}
placeholder="Value e.g. 'big' "
disabled={readOnly}
onChange={readOnly ? null : (e) => {
this.setState({ changed: true });
setValue(Utils.getTypedValue(Utils.safeParseEventValue(e)));
}}
placeholder="Value e.g. 'big' "
/>
</>
)}
Expand All @@ -191,6 +191,7 @@ const SegmentOverrideInner = class Override extends React.Component {
<FormGroup className="mb-4">
<VariationOptions
preventRemove
readOnlyValue
disabled={readOnly}
controlValue={controlValue}
variationOverrides={mvOptions}
Expand Down
4 changes: 2 additions & 2 deletions frontend/web/components/ValueEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ValueEditor extends Component {
render() {
const { ...rest } = this.props;
return (
<div className={cx('value-editor', { light: this.state.language === 'txt' })}>
<div className={cx('value-editor', { disabled: this.props.disabled, light: this.state.language === 'txt' })}>
<Row className="select-language">
<span
onMouseDown={(e) => {
Expand Down Expand Up @@ -183,7 +183,7 @@ class ValueEditor extends Component {
{...rest}
/>
) : (
<Highlight data-test={rest['data-test']} onChange={rest.disabled ? null : rest.onChange} className={this.state.language}>
<Highlight data-test={rest['data-test']} disabled={rest.disabled} onChange={rest.disabled ? null : rest.onChange} className={this.state.language}>
{(typeof rest.value !== 'undefined' && rest.value != null) ? `${rest.value}` : ''}
</Highlight>
)}
Expand Down
20 changes: 17 additions & 3 deletions frontend/web/components/mv/VariationOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ import VariationValue from './VariationValue';
import ValueEditor from '../ValueEditor';
import InfoMessage from '../InfoMessage';

export default function VariationOptions({ multivariateOptions, disabled, select, controlValue, weightTitle, variationOverrides, removeVariation, updateVariation, setVariations, setValue, preventRemove }) {
export default function VariationOptions({
controlValue,
disabled,
multivariateOptions,
preventRemove,
readOnlyValue,
removeVariation,
select,
setValue,
setVariations,
updateVariation,
variationOverrides,
weightTitle,
}) {
const invalid = multivariateOptions.length && controlValue < 0;
if (!multivariateOptions || !multivariateOptions.length) {
return null;
Expand All @@ -30,7 +43,7 @@ export default function VariationOptions({ multivariateOptions, disabled, select
<div className="panel-content">
<Row>
<Flex>
<ValueEditor disabled={disabled} value={Utils.getTypedValue(controlValue)}/>
<ValueEditor disabled value={Utils.getTypedValue(controlValue)}/>
</Flex>
<div
onMouseDown={(e) => {
Expand All @@ -54,7 +67,7 @@ export default function VariationOptions({ multivariateOptions, disabled, select
<div className="panel-content">
<Row>
<Flex>
<ValueEditor value={Utils.getTypedValue(Utils.featureStateToValue(theValue))}/>
<ValueEditor disabled={true} value={Utils.getTypedValue(Utils.featureStateToValue(theValue))}/>
</Flex>
<div
data-test={`select-variation-${Utils.featureStateToValue(theValue)}`}
Expand All @@ -77,6 +90,7 @@ export default function VariationOptions({ multivariateOptions, disabled, select
<VariationValue
key={i}
index={i}
readOnlyValue={readOnlyValue}
preventRemove={preventRemove || disabled}
value={theValue}
onChange={(e) => {
Expand Down
3 changes: 2 additions & 1 deletion frontend/web/components/mv/VariationValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const VariationValue = ({
onChange,
weightTitle,
onRemove,
readOnlyValue,
index,
disabled,
}) => (
Expand All @@ -20,7 +21,7 @@ const VariationValue = ({
data-test={`featureVariationValue${index}`}
name="featureValue" className="full-width"
value={Utils.getTypedValue(Utils.featureStateToValue(value))}
disabled={disabled}
disabled={disabled||readOnlyValue}
onChange={(e) => {
onChange({
...value,
Expand Down
13 changes: 13 additions & 0 deletions frontend/web/styles/components/_tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,16 @@
font-size: 1.4em;
display: block;
}

.btn-tab {
position: relative;
.unread {
position: absolute;
right:0;
top:13px;
padding-left: 0 !important;
padding-right: 0 !important;
width: 16px;
height: 16px;
}
}
22 changes: 21 additions & 1 deletion frontend/web/styles/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,28 @@ bold, strong {
}

.value-editor {

&.disabled {
code {
background: $input-placeholder-color !important;
}
.select-language {
display: none;
}
}
}
.dark {
.value-editor {
&.disabled {
code {
cursor: not-allowed;
color: $dark-color;
background: $dark-bg-20 !important;
}
}
}
}



.faint-lg {
color: $text-muted;
Expand Down

0 comments on commit cf67ce9

Please sign in to comment.