Skip to content

Commit a542a26

Browse files
committed
feat: make editors in stream types readonly
1 parent 871d098 commit a542a26

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/components/databrowser/components/display/display-list-edit.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,24 @@ const ListEditForm = ({
6565
<form onSubmit={onSubmit} className="flex flex-col gap-2">
6666
<div className="flex grow flex-col gap-2">
6767
{type !== "list" && (
68-
<FormItem name="key" height={type === "set" ? 250 : 100} label={keyLabel} />
68+
<FormItem
69+
readOnly={type === "stream"}
70+
name="key"
71+
height={type === "set" ? 250 : 100}
72+
label={keyLabel}
73+
/>
6974
)}
7075

7176
{type === "zset" ? (
7277
<NumberFormItem name="value" label={valueLabel} />
7378
) : (
7479
type !== "set" && (
75-
<FormItem name="value" height={type === "list" ? 250 : 100} label={valueLabel} />
80+
<FormItem
81+
readOnly={type === "stream"}
82+
name="value"
83+
height={type === "list" ? 250 : 100}
84+
label={valueLabel}
85+
/>
7686
)
7787
)}
7888
</div>
@@ -131,18 +141,21 @@ const FormItem = ({
131141
name,
132142
label,
133143
height,
144+
readOnly,
134145
}: {
135146
name: string
136147
label: string
137148
isNumber?: boolean
138149
height?: number
150+
readOnly?: boolean
139151
}) => {
140152
const form = useFormContext()
141153
const { editor, selector } = useField({
142154
name,
143155
form,
144156
height: height,
145157
showCopyButton: true,
158+
readOnly,
146159
})
147160

148161
return (

src/components/databrowser/components/display/input/custom-editor.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ export const CustomEditor = ({
1010
onChange,
1111
height,
1212
showCopyButton,
13+
readOnly,
1314
}: {
1415
language: string
1516
value: string
1617
onChange: (value: string) => void
1718
height?: number
1819
showCopyButton?: boolean
20+
readOnly?: boolean
1921
}) => {
2022
const monaco = useMonaco()
2123
const editorRef = useRef()
@@ -48,6 +50,7 @@ export const CustomEditor = ({
4850
}}
4951
defaultLanguage={language}
5052
options={{
53+
readOnly: readOnly,
5154
wordWrap: "on",
5255
overviewRulerBorder: false,
5356
overviewRulerLanes: 0,

src/components/databrowser/components/display/input/use-field.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ export const useField = ({
99
form,
1010
height,
1111
showCopyButton,
12+
readOnly,
1213
}: {
1314
name: string
1415
form: UseFormReturn<any>
1516
height?: number
1617
showCopyButton?: boolean
18+
readOnly?: boolean
1719
}) => {
1820
const { field, fieldState } = useController<Record<string, string>>({
1921
name,
@@ -60,6 +62,7 @@ export const useField = ({
6062
onChange={field.onChange}
6163
height={height}
6264
showCopyButton={showCopyButton}
65+
readOnly={readOnly}
6366
/>
6467
</>
6568
),

0 commit comments

Comments
 (0)