Skip to content

Commit

Permalink
fix: Triggers width
Browse files Browse the repository at this point in the history
  • Loading branch information
cyaiox committed Oct 10, 2023
1 parent 3197b21 commit 97b3786
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export const MoreOptionsMenu = ({ children, icon }: { children: JSX.Element | JS
)

const handleClosePanel = useCallback(() => {
setShowMoreOptions(false)
}, [setShowMoreOptions])
if (showMoreOptions) {
setShowMoreOptions(false)
}
}, [showMoreOptions, setShowMoreOptions])

const ref = useOutsideClick(handleClosePanel)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,20 @@
.TriggerActionsContainer > .TriggerAction {
display: flex;
flex-direction: row;
}

.TriggerActionsContainer > .TriggerAction > .Fields {
display: flex;
flex: 1;
flex-wrap: wrap;
align-items: center;
gap: 4px;
}

.TriggerActionsContainer > .TriggerAction .MoreOptionsMenu .MoreOptionsContent {
.TriggerActionsContainer > .TriggerAction > .RightMenu {
align-self: start;
}

.TriggerActionsContainer > .TriggerAction > .RightMenu > .MoreOptionsMenu .MoreOptionsContent {
min-width: 185px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,30 @@ export const TriggerActionContainer = ({ trigger, availableActions, onUpdateActi
: []
return (
<div className="TriggerAction" key={`trigger-action-${idx}`}>
<Dropdown
options={availableActions ? [{ value: '', text: 'Select an Entity' }, ...entities] : []}
value={action.id}
onChange={(e) => handleChangeEntity(e, idx)}
/>
<Dropdown
disabled={!action.id || !availableActions.get(action.id)}
options={
action.id && availableActions.get(action.id)?.actions
? [{ value: '', text: 'Select an Action' }, ...actions]
: []
}
value={action.name}
onChange={(e) => handleChangeAction(e, idx)}
/>
<MoreOptionsMenu>
<Button className="RemoveButton" onClick={(e) => handleRemoveAction(e, idx)}>
<RemoveIcon /> Remove Trigger Action
</Button>
</MoreOptionsMenu>
<div className="Fields">
<Dropdown
options={availableActions ? [{ value: '', text: 'Select an Entity' }, ...entities] : []}
value={action.id}
onChange={(e) => handleChangeEntity(e, idx)}
/>
<Dropdown
disabled={!action.id || !availableActions.get(action.id)}
options={
action.id && availableActions.get(action.id)?.actions
? [{ value: '', text: 'Select an Action' }, ...actions]
: []
}
value={action.name}
onChange={(e) => handleChangeAction(e, idx)}
/>
</div>
<div className="RightMenu">
<MoreOptionsMenu>
<Button className="RemoveButton" onClick={(e) => handleRemoveAction(e, idx)}>
<RemoveIcon /> Remove Trigger Action
</Button>
</MoreOptionsMenu>
</div>
</div>
)
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,20 @@
.TriggerConditionsContainer > .TriggerCondition {
display: flex;
flex-direction: row;
}

.TriggerConditionsContainer > .TriggerCondition > .Fields {
display: flex;
flex: 1;
flex-wrap: wrap;
align-items: center;
gap: 4px;
}

.TriggerConditionsContainer > .TriggerCondition .MoreOptionsMenu .MoreOptionsContent {
.TriggerConditionsContainer > .TriggerCondition > .RightMenu {
align-self: start;
}

.TriggerConditionsContainer > .TriggerCondition > .RightMenu > .MoreOptionsMenu .MoreOptionsContent {
min-width: 205px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const TriggerConditionContainer = ({
const handleChangeType = useCallback(
({ target: { value } }: React.ChangeEvent<HTMLSelectElement>, idx: number) => {
const [id, type] = value.split(SEPARATOR)
console.log('value', value, id, type)
modifyCondition(idx, {
...conditions[idx],
id: parseInt(id),
Expand All @@ -79,7 +78,7 @@ export const TriggerConditionContainer = ({
)

const handleRemoveCondition = useCallback(
(e: React.MouseEvent, idx: number) => {
(_e: React.MouseEvent, idx: number) => {
removeCondition(idx)
},
[removeCondition]
Expand Down Expand Up @@ -130,40 +129,44 @@ export const TriggerConditionContainer = ({
const isCounterCondition = counterConditionTypeOptions.some(($) => $.value === condition.type)
return (
<div className="TriggerCondition" key={`trigger-condition-${idx}`}>
<Dropdown
options={entityOptions ? [{ value: '', text: 'Select an Entity' }, ...entityOptions] : []}
value={entity}
onChange={(e) => handleChangeEntity(e, idx)}
/>
<Dropdown
disabled={isDisabled}
options={conditionOptions.map(({ text, value }) => ({
text,
value: [value.id, value.type].join(SEPARATOR)
}))}
value={type}
onChange={(e) => handleChangeType(e, idx)}
/>
{isStatesCondition && (
<div className="Fields">
<Dropdown
disabled={isDisabled}
options={stateOptions.length > 0 ? [{ value: '', text: 'Select state' }, ...stateOptions] : []}
value={condition.value}
onChange={(e) => handleChangeSelectValue(e, idx)}
options={entityOptions ? [{ value: '', text: 'Select an Entity' }, ...entityOptions] : []}
value={entity}
onChange={(e) => handleChangeEntity(e, idx)}
/>
)}
{isCounterCondition && (
<TextField
<Dropdown
disabled={isDisabled}
value={condition.value}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => handleChangeSelectValue(e, idx)}
options={conditionOptions.map(({ text, value }) => ({
text,
value: [value.id, value.type].join(SEPARATOR)
}))}
value={type}
onChange={(e) => handleChangeType(e, idx)}
/>
)}
<MoreOptionsMenu>
<Button className="RemoveButton" onClick={(e) => handleRemoveCondition(e, idx)}>
<RemoveIcon /> Remove Trigger Condition
</Button>
</MoreOptionsMenu>
{isStatesCondition && (
<Dropdown
disabled={isDisabled}
options={stateOptions.length > 0 ? [{ value: '', text: 'Select state' }, ...stateOptions] : []}
value={condition.value}
onChange={(e) => handleChangeSelectValue(e, idx)}
/>
)}
{isCounterCondition && (
<TextField
disabled={isDisabled}
value={condition.value}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => handleChangeSelectValue(e, idx)}
/>
)}
</div>
<div className="RightMenu">
<MoreOptionsMenu>
<Button className="RemoveButton" onClick={(e) => handleRemoveCondition(e, idx)}>
<RemoveIcon /> Remove Trigger Condition
</Button>
</MoreOptionsMenu>
</div>
</div>
)
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ export default withSdk<Props>(
}, [])

const handleAddNewTrigger = useCallback(
(e: React.MouseEvent) => {
e.stopPropagation()
(_e: React.MouseEvent) => {
addTrigger({
type: TriggerType.ON_CLICK,
conditions: [],
Expand All @@ -207,8 +206,7 @@ export default withSdk<Props>(
)

const handleRemoveTrigger = useCallback(
(e: React.MouseEvent, idx: number) => {
e.stopPropagation()
(_e: React.MouseEvent, idx: number) => {
removeTrigger(idx)
},
[removeTrigger]
Expand All @@ -225,8 +223,7 @@ export default withSdk<Props>(
)

const handleAddNewTriggerAction = useCallback(
(e: React.MouseEvent, idx: number) => {
e.stopPropagation()
(_e: React.MouseEvent, idx: number) => {
modifyTrigger(idx, {
...triggers[idx],
actions: [...triggers[idx].actions, { id: undefined, name: '' }]
Expand All @@ -246,7 +243,7 @@ export default withSdk<Props>(
)

const handleAddNewTriggerCondition = useCallback(
(e: React.MouseEvent, idx: number) => {
(_e: React.MouseEvent, idx: number) => {
modifyTrigger(idx, {
...triggers[idx],
conditions: [
Expand Down
2 changes: 1 addition & 1 deletion packages/@dcl/inspector/src/hooks/useArrayState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useState } from 'react'

export function useArrayState<T>(initialArray: T[] = []) {
const [array, setArray] = useState<T[]>(initialArray)
const [array, setArray] = useState<T[]>([...initialArray])

// Function to add an item to the array
const addItem = useCallback(
Expand Down

0 comments on commit 97b3786

Please sign in to comment.