Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ Edge Browser: support textbox input when the edit invitation is not an enum #2095

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions components/browser/EdgeBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,37 +306,42 @@ export default class EdgeBrowser extends React.Component {
// index is index of the column where the custom load of an entity is changed
// also update if there's column with same parent
updateChildColumn(index, customLoad) {
if (index + 1 >= this.state.columns.length) return
const parentIdOfColumn = this.state.columns[index].parentId
const resultColumns = []
resultColumns.push(this.state.columns[0])
for (let i = 1; i < this.state.columns.length; i += 1) {
const parentColumn = this.state.columns[i - 1]
const column = this.state.columns[i]
if (parentColumn.parentId === parentIdOfColumn) {
resultColumns.push({ ...column, parentCustomLoad: customLoad })
} else {
resultColumns.push(column)
this.setState((prevState) => {
if (index + 1 >= prevState.columns.length) return null
const parentIdOfColumn = prevState.columns[index].parentId
const resultColumns = []
resultColumns.push(prevState.columns[0])
for (let i = 1; i < prevState.columns.length; i += 1) {
const parentColumn = prevState.columns[i - 1]
const column = prevState.columns[i]
if (parentColumn.parentId === parentIdOfColumn) {
const updatedColumn = {
...column,
parentCustomLoad: customLoad,
}
resultColumns.push(updatedColumn)
} else {
resultColumns.push(column)
}
}
}
this.setState({ columns: resultColumns })
return { columns: resultColumns }
})
}

// set the shouldUpdate property of column at index
// and all other columns with same parent
// to trigger entites reload of those columns
reloadColumnEntities(index) {
const parentIdOfColumn = this.state.columns[index].parentId
const resultColumns = []
for (let i = 0; i < this.state.columns.length; i += 1) {
const column = this.state.columns[i]
if (column?.parentId === parentIdOfColumn) {
resultColumns.push({ ...column, shouldReloadEntities: !column.shouldReloadEntities })
} else {
resultColumns.push(column)
}
}
this.setState({ columns: resultColumns })
this.setState((prevState) => {
const parentIdOfColumn = prevState.columns[index].parentId
const resultColumns = prevState.columns.map((column) => {
if (column?.parentId === parentIdOfColumn) {
return { ...column, shouldReloadEntities: !column.shouldReloadEntities }
}
return column
})
return { columns: resultColumns }
})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data loading is updated to avoid state update conflict

reloadColumnEntities update was overwritting state update from updateChildColumns

}

async lookupSignatures() {
Expand Down
60 changes: 60 additions & 0 deletions components/browser/EditEdgeTextbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
/* eslint-disable react/destructuring-assignment */
/* globals $: false */

import { getTooltipTitle } from '../../lib/edge-utils'

export default function EditEdgeTextbox(props) {
const showTrashButton = props.existingEdge?.writers?.length !== 0

const handleHover = (target) => {
if (!props.existingEdge) return
const title = getTooltipTitle(props.existingEdge)
$(target).tooltip({
title,
trigger: 'hover',
container: 'body',
})
}

if (!props.existingEdge && !props.canAddEdge) return null
return (
<div
className="edit-controls full-width"
onClick={(e) => {
e.stopPropagation()
}}
>
<label onMouseEnter={(e) => handleHover(e.target)}>{props.label}:</label>
<div className="btn-group edit-edge-textbox">
<input
type="text"
className="form-control edit-edge-input"
value={props.selected}
onClick={(e) => e.stopPropagation()}
onChange={(e) => {
e.stopPropagation()
props.addEdge({
e,
existingEdge: props.existingEdge,
editEdgeTemplate: props.editEdgeTemplate,
updatedEdgeFields: { [props.type]: Number(e.target.value) },
})
}}
/>
</div>
{props.existingEdge && showTrashButton && (
<a
href="#"
className="edit-edge-remove"
onClick={(e) => {
e.stopPropagation()
props.removeEdge()
}}
>
<span className="glyphicon glyphicon-trash" />
</a>
)}
</div>
)
}
22 changes: 21 additions & 1 deletion components/browser/ProfileEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import EditEdgeToggle from './EditEdgeToggle'
import EditEdgeTwoDropdowns from './EditEdgeTwoDropdowns'
import ScoresList from './ScoresList'
import useQuery from '../../hooks/useQuery'
import EditEdgeTextbox from './EditEdgeTextbox'

export default function ProfileEntity(props) {
const {
Expand Down Expand Up @@ -312,10 +313,27 @@ export default function ProfileEntity(props) {
if (!edge && content?.isInvitedProfile && isEmergencyReviewerStage && !isInviteInvitation)
return null

const editEdgeTextbox = (type) => (
<>
<EditEdgeTextbox
existingEdge={edge}
canAddEdge={
editEdges?.filter((p) => p?.invitation === invitation.id).length === 0 ||
invitation.multiReply
}
label={invitation.name}
selected={edge?.[type]}
addEdge={addEdge}
removeEdge={() => removeEdge(edge)}
type={type} // label or weight
editEdgeTemplate={editEdgeTemplates?.find((p) => p?.invitation === invitation.id)}
/>
</>
)

const editEdgeDropdown = (type, controlType) => (
<EditEdgeDropdown
existingEdge={edge}
// eslint-disable-next-line max-len
canAddEdge={
editEdges?.filter((p) => p?.invitation === invitation.id).length === 0 ||
invitation.multiReply
Expand Down Expand Up @@ -381,12 +399,14 @@ export default function ProfileEntity(props) {
const shouldRenderWeightRadio = weightRadio && !invitation.label
const shouldRenderLabelDropdown = labelDropdown && !invitation.weight
const shouldRenderWeightDropdown = weightDropdown && !invitation.label
const shouldRenderWeightTextbox = invitation.weight?.['value-textbox']

if (shouldRenderTwoRadio) return editEdgeTwoDropdowns('value-radio')
if (shouldRenderTwoDropdown) return editEdgeTwoDropdowns('value-dropdown')
if (shouldRenderLabelRadio) return editEdgeDropdown('label', 'value-radio') // for now treat radio the same as dropdown
if (shouldRenderWeightRadio) return editEdgeDropdown('weight', 'value-radio') // for now treat radio the same as dropdown
if (shouldRenderLabelDropdown) return editEdgeDropdown('label', 'value-dropdown')
if (shouldRenderWeightTextbox) return editEdgeTextbox('weight')
if (shouldRenderWeightDropdown) return editEdgeDropdown('weight', 'value-dropdown')
return editEdgeToggle()
}
Expand Down
3 changes: 3 additions & 0 deletions lib/edge-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ export function translateFieldSpec(invitation, fieldName, version) {
if (field.param?.enum) {
spec['value-dropdown'] = field.param.enum
}
if (field.param?.input === 'text') {
spec['value-textbox'] = true
}
return spec
}
const field = invitation.reply.content[fieldName]
Expand Down
10 changes: 10 additions & 0 deletions styles/pages/edge-browser.scss
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ main.edge-browser {
cursor: no-drop;
}
}
.edit-edge-textbox {
width: 15%;
padding-left: 0.5rem;

.edit-edge-input {
font-size: 0.75rem;
padding: 3px 5px;
height: fit-content;
}
}
.span-disabled {
pointer-events: none;
}
Expand Down