Skip to content

Commit

Permalink
refactor(web/input): select backwards compat with no label
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWasTakenn committed Jan 8, 2023
1 parent d5a9a3f commit f6e2d54
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions web/src/features/dialog/InputDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Group, Modal, Button, Stack } from '@mantine/core';
import { Group, Modal, Button, Stack, SelectItem } from '@mantine/core';
import React, { FormEvent, useRef } from 'react';
import { useNuiEvent } from '../../hooks/useNuiEvent';
import { useLocales } from '../../providers/LocaleProvider';
import { fetchNui } from '../../utils/fetchNui';
import { IInput, ICheckbox, ISelect, INumber, ISlider, IColorInput } from '../../interfaces/dialog';
import { IInput, ICheckbox, ISelect, INumber, ISlider, IColorInput, OptionValue } from '../../interfaces/dialog';
import InputField from './components/fields/input';
import CheckboxField from './components/fields/checkbox';
import SelectField from './components/fields/select';
Expand Down Expand Up @@ -42,6 +42,12 @@ const InputDialog: React.FC = () => {
setVisible(true);
data.rows.forEach((row, index) => {
fieldForm.insert(index, { value: row.type !== 'checkbox' ? row.default : row.checked } || { value: null });
// Backwards compat with new Select data type
if (row.type === 'select') {
row.options = row.options.map((option) =>
!option.label ? { ...option, label: option.value } : option
) as Array<OptionValue>;
}
});
});

Expand Down
1 change: 0 additions & 1 deletion web/src/features/dialog/components/fields/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ interface Props {
control: Control<FormValues>;
}

// TODO: set label to value of value when there is no label provided
const SelectField: React.FC<Props> = (props) => {
const controller = useController({
name: `test.${props.index}.value`,
Expand Down
3 changes: 2 additions & 1 deletion web/src/interfaces/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ export interface ICheckbox {
required?: boolean;
}

export type OptionValue = { value: string; label?: string };
export interface ISelect {
type: 'select';
label: string;
default?: string;
options: Array<SelectItem>;
options: Array<OptionValue>;
disabled?: boolean;
description?: string;
required?: boolean;
Expand Down

0 comments on commit f6e2d54

Please sign in to comment.