Skip to content

Commit 1eece20

Browse files
committed
fix(components): fix element key editor tooltip and revert not updating validity
1 parent 95949cf commit 1eece20

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

packages/compass-components/src/components/document-list/element-editors.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export const KeyEditor: React.FunctionComponent<{
8383
usePortal={false}
8484
trigger={({
8585
className,
86+
children,
8687
// Having a tooltip connected to the input elements is not the most
8788
// accessible thing ever and so a lot of event listeners of the
8889
// tooltip conflict with the textarea default behavior (due to
@@ -94,6 +95,8 @@ export const KeyEditor: React.FunctionComponent<{
9495
onPointerUp,
9596
onPointerDown,
9697
onMouseDown,
98+
/* eslint-enable @typescript-eslint/no-unused-vars */
99+
...triggerProps
97100
}: React.HTMLProps<HTMLInputElement>) => {
98101
return (
99102
<div className={className}>
@@ -119,7 +122,9 @@ export const KeyEditor: React.FunctionComponent<{
119122
)}
120123
style={{ width }}
121124
spellCheck="false"
125+
{...triggerProps}
122126
></input>
127+
{children}
123128
</div>
124129
);
125130
}}
@@ -186,6 +191,7 @@ export const ValueEditor: React.FunctionComponent<{
186191
onBlur,
187192
}) => {
188193
const val = String(value);
194+
const darkMode = useDarkMode();
189195

190196
const inputStyle = useMemo(() => {
191197
if (type === 'String') {
@@ -282,7 +288,11 @@ export const ValueEditor: React.FunctionComponent<{
282288
className={cx(
283289
editorReset,
284290
editorOutline,
285-
!valid && editorInvalid
291+
!valid && editorInvalid,
292+
!valid &&
293+
(darkMode
294+
? editorInvalidDarkMode
295+
: editorInvalidLightMode)
286296
)}
287297
style={inputStyle}
288298
spellCheck="false"

packages/compass-components/src/components/document-list/element.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ function useHadronElement(el: HadronElementType) {
9292
[el, forceUpdate]
9393
);
9494

95+
const onElementReverted = useCallback(
96+
(changedElement: HadronElementType) => {
97+
if (el.uuid === changedElement.uuid) {
98+
// When an element is reverted we check again if the key is a duplicate.
99+
setIsDuplicateKey(el.isDuplicateKey(el.key));
100+
forceUpdate();
101+
}
102+
},
103+
[el, forceUpdate]
104+
);
105+
95106
useEffect(() => {
96107
if (prevEl && prevEl !== el) {
97108
forceUpdate();
@@ -101,7 +112,7 @@ function useHadronElement(el: HadronElementType) {
101112
useEffect(() => {
102113
el.on(ElementEvents.Converted, onElementChanged);
103114
el.on(ElementEvents.Edited, onElementChanged);
104-
el.on(ElementEvents.Reverted, onElementChanged);
115+
el.on(ElementEvents.Reverted, onElementReverted);
105116
el.on(ElementEvents.Invalid, onElementChanged);
106117
el.on(ElementEvents.Valid, onElementChanged);
107118
el.on(ElementEvents.Added, onElementAddedOrRemoved);
@@ -113,15 +124,15 @@ function useHadronElement(el: HadronElementType) {
113124
return () => {
114125
el.off(ElementEvents.Converted, onElementChanged);
115126
el.off(ElementEvents.Edited, onElementChanged);
116-
el.off(ElementEvents.Reverted, onElementChanged);
127+
el.off(ElementEvents.Reverted, onElementReverted);
117128
el.off(ElementEvents.Valid, onElementChanged);
118129
el.off(ElementEvents.Added, onElementAddedOrRemoved);
119130
el.off(ElementEvents.Removed, onElementAddedOrRemoved);
120131
el.off(ElementEvents.Expanded, onElementChanged);
121132
el.off(ElementEvents.Collapsed, onElementChanged);
122133
el.off(ElementEvents.VisibleElementsChanged, onElementChanged);
123134
};
124-
}, [el, onElementChanged, onElementAddedOrRemoved]);
135+
}, [el, onElementChanged, onElementAddedOrRemoved, onElementReverted]);
125136

126137
const isValid = el.isCurrentTypeValid();
127138

0 commit comments

Comments
 (0)