Skip to content

Commit 6fd9fde

Browse files
fix(ui): validate JSONPath syntax and show inline error instead of alert
1 parent 3c1fd1f commit 6fd9fde

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

frontend/src/components/Topics/Topic/Messages/PreviewModal.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { InputLabel } from 'components/common/Input/InputLabel.styled';
66
import IconButtonWrapper from 'components/common/Icons/IconButtonWrapper';
77
import EditIcon from 'components/common/Icons/EditIcon';
88
import CancelIcon from 'components/common/Icons/CancelIcon';
9+
import { JSONPath } from 'jsonpath-plus';
910

1011
import * as S from './PreviewModal.styled';
1112
import { PreviewFilter } from './Message';
@@ -33,8 +34,14 @@ const PreviewModal: React.FC<InfoModalProps> = ({
3334
newErrors.push('field');
3435
}
3536

36-
if (path === '') {
37+
if (path.trim() === '') {
3738
newErrors.push('path');
39+
} else {
40+
try {
41+
JSONPath({ path, json: {} });
42+
} catch {
43+
newErrors.push('invalidPath');
44+
}
3845
}
3946

4047
if (newErrors?.length) {
@@ -111,6 +118,7 @@ const PreviewModal: React.FC<InfoModalProps> = ({
111118
/>
112119
<FormError>
113120
{errors.includes('path') && 'Json path is required'}
121+
{errors.includes('invalidPath') && 'Invalid JSONPath syntax'}
114122
</FormError>
115123
</div>
116124
<S.ButtonWrapper>

0 commit comments

Comments
 (0)