Skip to content

Commit

Permalink
Hide configuration settings marked hidden. (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdilauro authored Jan 27, 2025
1 parent c88bda3 commit 831e14a
Show file tree
Hide file tree
Showing 4 changed files with 484 additions and 277 deletions.
17 changes: 13 additions & 4 deletions src/components/EditableInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface EditableInputProps extends React.HTMLProps<EditableInput> {
className?: string;
minLength?: number;
maxLength?: number;
hidden?: boolean;
}

export interface EditableInputState {
Expand Down Expand Up @@ -65,7 +66,11 @@ export default class EditableInput extends React.Component<
error,
label,
extraContent,
hidden,
} = this.props;
if (hidden) {
return this.renderHiddenElement();
}
const checkboxOrRadioOrSelect = !!(
type === "checkbox" ||
type === "radio" ||
Expand All @@ -90,15 +95,15 @@ export default class EditableInput extends React.Component<
<label className="control-label">
{type !== "checkbox" && type !== "radio" && label}
{required && <span className="required-field">Required</span>}
{this.renderElement(descriptionId)}
{this.renderElement(this.props, descriptionId)}
{type === "checkbox" && label}
{type === "radio" && <span>{label}</span>}
</label>
)}
{(extraContent || !label) && (
<div className={extraContent ? "with-add-on" : ""}>
{extraContent}
{!label && this.renderElement(descriptionId)}
{!label && this.renderElement(this.props, descriptionId)}
</div>
)}
{descriptionStr &&
Expand All @@ -107,7 +112,7 @@ export default class EditableInput extends React.Component<
);
}

renderElement(descriptionId?: string) {
renderElement(props, descriptionId?: string) {
const {
type,
elementType,
Expand All @@ -124,7 +129,7 @@ export default class EditableInput extends React.Component<
style,
minLength,
maxLength,
} = this.props;
} = props;

return React.createElement(
elementType || "input",
Expand Down Expand Up @@ -156,6 +161,10 @@ export default class EditableInput extends React.Component<
);
}

renderHiddenElement() {
return this.renderElement({ ...this.props, readOnly: true });
}

renderDescription(id: string, description: string) {
return (
<p
Expand Down
21 changes: 21 additions & 0 deletions src/components/ProtocolFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export default class ProtocolFormField extends React.Component<

render(): JSX.Element {
const setting = this.props.setting as SettingData | CustomListsSetting;
if (setting.hidden) {
// TODO: Hijacking for any hidden fields for now, but need to handle
// some types (e.g., "menu", "list") differently.
return this.renderHiddenElement(setting);
}
if (setting.type === "select") {
return this.renderSelectSetting(setting);
} else if (setting.type === "list" || setting.type === "menu") {
Expand All @@ -65,6 +70,22 @@ export default class ProtocolFormField extends React.Component<
}
}

renderHiddenElement(setting: SettingData) {
const { value, disabled = false, error = null } = this.props;
const props = {
key: setting.key,
hidden: true,
elementType: "input",
type: "hidden",
name: setting.key,
value: defaultValueIfMissing(value, setting.default),
ref: this.elementRef,
disabled,
error,
};
return React.createElement(EditableInput, props, null);
}

renderSetting(setting: SettingData): JSX.Element {
return (
<div className={setting.randomizable ? "randomizable" : ""}>
Expand Down
Loading

0 comments on commit 831e14a

Please sign in to comment.