Skip to content

Commit a5896c8

Browse files
committed
refactor(settings): replace select with Dropdown and align jsonIndentation with context API
Signed-off-by: Pranav-0440 <pranavghorpade61@gmail.com>
1 parent 5fc053a commit a5896c8

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/components/App/Settings.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import InfoIconWrapper from "../base/InfoIconWrapper";
1515
import TextField from "../base/TextField";
1616
import { isValidUrl } from "../../utils/strings";
1717
import EdiTDorContext from "../../context/ediTDorContext";
18+
import Dropdown from "../base/Dropdown";
1819

1920
export interface SettingsData {
2021
northboundUrl: string;
@@ -149,21 +150,14 @@ const Settings: React.FC<SettingsProps> = ({
149150
<div className="my-4 rounded-md bg-black bg-opacity-80 p-2">
150151
{!hideTitle && <h1 className="font-bold">JSON Editor</h1>}
151152
<div className="px-4">
152-
<label
153-
htmlFor="json-indentation-select"
154-
className="mb-1 block text-sm text-gray-300"
155-
>
156-
Space indentation
157-
</label>
158-
<select
153+
<Dropdown
159154
id="json-indentation-select"
160-
value={data.jsonIndentation}
155+
label="Space indentation"
156+
value={String(data.jsonIndentation)}
161157
onChange={handleJsonIndentationChange}
162-
className="w-full rounded-md border-2 border-gray-600 bg-gray-600 p-2 text-white focus:border-blue-500 focus:outline-none sm:text-sm"
163-
>
164-
<option value={2}>2 spaces</option>
165-
<option value={4}>4 spaces</option>
166-
</select>
158+
options={["2", "4"]}
159+
className="w-full"
160+
/>
167161
</div>
168162
</div>
169163

src/components/Editor/JsonEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ interface JsonSchemaEntry {
4747
const JsonEditor: React.FC<JsonEditorProps> = ({ editorRef }) => {
4848
const context = useContext(ediTDorContext);
4949

50-
const jsonIndentation = context.settings?.jsonIndentation ?? 2;
50+
const jsonIndentation = context.jsonIndentation ?? 2;
5151
const [schemas] = useState<JsonSchemaEntry[]>([]);
5252
const [proxy, setProxy] = useState<any>(undefined);
5353
const editorInstance = useRef<editor.IStandaloneCodeEditor | null>(null);

src/components/base/Dropdown.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ interface IDropdownProps {
1717
id: string;
1818
label: string;
1919
options: string[];
20+
value?: string;
21+
onChange?: (event: React.ChangeEvent<HTMLSelectElement>) => void;
2022
className?: string;
2123
}
2224

@@ -33,6 +35,8 @@ const Dropdown: React.FC<IDropdownProps> = (props) => {
3335
<select
3436
className="block w-full appearance-none rounded border-2 border-gray-600 bg-gray-600 px-4 py-3 pr-8 leading-tight text-white focus:border-blue-500 focus:outline-none"
3537
id={props.id}
38+
value={props.value}
39+
onChange={props.onChange}
3640
>
3741
{props.options.map((e) => {
3842
return <option key={e}>{e}</option>;

0 commit comments

Comments
 (0)