Skip to content

Commit 23f526a

Browse files
allow editing isEnum on fields
1 parent fc2a450 commit 23f526a

File tree

5 files changed

+68
-34
lines changed

5 files changed

+68
-34
lines changed

packages/app-builder/public/locales/en/data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"create_field.type_bool": "Boolean",
3838
"create_field.type_timestamp": "Timestamp",
3939
"edit_field.button_accept": "Save changes",
40-
"edit_field.title": "Edit description",
40+
"edit_field.title": "Edit field",
4141
"edit_table.button_accept": "Save changes",
4242
"edit_table.title": "Edit description",
4343
"empty_description": "No description",

packages/app-builder/src/routes/__builder/data.tsx

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,26 +143,22 @@ function TableDetails({
143143
header: t('data:description'),
144144
size: 500,
145145
cell: ({ cell }) => {
146-
return canEditDataModel ? (
147-
<EditableText key={cell.row.original.id} className="group">
148-
<EditField
149-
fieldId={cell.row.original.id}
150-
description={cell.row.original.description}
151-
>
152-
<div className="flex flex-row gap-5">
153-
<FormatDescription
154-
description={cell.row.original.description}
155-
/>
156-
<Edit
157-
className="text-grey-00 group-hover:text-grey-100 relative bg-transparent transition-colors ease-in-out"
158-
width={'24px'}
159-
height={'24px'}
160-
/>
161-
</div>
162-
</EditField>
163-
</EditableText>
164-
) : (
165-
<FormatDescription description={cell.row.original.description} />
146+
return (
147+
<div className="flex flex-row items-center justify-between">
148+
<FormatDescription description={cell.row.original.description} />
149+
{canEditDataModel && (
150+
<EditField
151+
key={cell.row.original.id}
152+
fieldId={cell.row.original.id}
153+
description={cell.row.original.description}
154+
isEnum={cell.row.original.isEnum}
155+
>
156+
<div className="text-grey-00 group-hover:text-grey-100 relative rounded border-2 border-solid bg-transparent p-2 transition-colors ease-in-out">
157+
<Edit width={'24px'} height={'24px'} />
158+
</div>
159+
</EditField>
160+
)}
161+
</div>
166162
);
167163
},
168164
},

packages/app-builder/src/routes/ressources/data/editField.tsx

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ import {
66
FormLabel,
77
} from '@app-builder/components/Form';
88
import { serverServices } from '@app-builder/services/init.server';
9-
import { parseFormSafe } from '@app-builder/utils/input-validation';
109
import { zodResolver } from '@hookform/resolvers/zod';
1110
import { type ActionArgs, json } from '@remix-run/node';
1211
import { useFetcher } from '@remix-run/react';
13-
import { Button, HiddenInputs, Input, Modal } from '@ui-design-system';
12+
import {
13+
Button,
14+
Checkbox,
15+
HiddenInputs,
16+
Input,
17+
Modal,
18+
} from '@ui-design-system';
1419
import { type Namespace } from 'i18next';
1520
import { useEffect, useState } from 'react';
1621
import { Form, FormProvider, useForm } from 'react-hook-form';
@@ -24,6 +29,7 @@ export const handle = {
2429
const editFieldFormSchema = z.object({
2530
description: z.string(),
2631
fieldId: z.string().uuid(),
32+
isEnum: z.boolean(),
2733
});
2834

2935
export async function action({ request }: ActionArgs) {
@@ -32,43 +38,47 @@ export async function action({ request }: ActionArgs) {
3238
failureRedirect: '/login',
3339
});
3440

35-
const parsedForm = await parseFormSafe(request, editFieldFormSchema);
36-
if (!parsedForm.success) {
37-
parsedForm.error.flatten((issue) => issue);
41+
const parsedData = editFieldFormSchema.safeParse(await request.json());
42+
43+
if (!parsedData.success) {
44+
parsedData.error.flatten((issue) => issue);
3845

3946
return json({
4047
success: false as const,
41-
values: parsedForm.formData,
42-
error: parsedForm.error.format(),
48+
values: null,
49+
error: parsedData.error.format(),
4350
});
4451
}
45-
const { description, fieldId } = parsedForm.data;
52+
const { description, fieldId, isEnum } = parsedData.data;
4653

4754
try {
4855
await apiClient.patchDataModelField(fieldId, {
4956
description,
57+
is_enum: isEnum,
5058
});
5159
return json({
5260
success: true as const,
53-
values: parsedForm.data,
61+
values: parsedData.data,
5462
error: null,
5563
});
5664
} catch (error) {
5765
return json({
5866
success: false as const,
59-
values: parsedForm.data,
60-
error: error,
67+
values: parsedData.data,
68+
error,
6169
});
6270
}
6371
}
6472

6573
export function EditField({
6674
fieldId,
6775
description,
76+
isEnum,
6877
children,
6978
}: {
7079
fieldId: string;
7180
description: string;
81+
isEnum: boolean;
7282
children: React.ReactNode;
7383
}) {
7484
const { t } = useTranslation(handle.i18n);
@@ -80,6 +90,7 @@ export function EditField({
8090
defaultValues: {
8191
description,
8292
fieldId,
93+
isEnum,
8394
},
8495
});
8596
const { control, register, setValue } = formMethods;
@@ -97,10 +108,11 @@ export function EditField({
97108
<Modal.Content>
98109
<Form
99110
control={control}
100-
onSubmit={({ formData }) => {
101-
fetcher.submit(formData, {
111+
onSubmit={({ formDataJson }) => {
112+
fetcher.submit(formDataJson, {
102113
method: 'POST',
103114
action: '/ressources/data/editField',
115+
encType: 'application/json',
104116
});
105117
}}
106118
>
@@ -130,6 +142,29 @@ export function EditField({
130142
)}
131143
/>
132144
</div>
145+
<FormField
146+
name="isEnum"
147+
control={control}
148+
render={({ field }) => (
149+
<FormItem className="flex flex-row items-center gap-4">
150+
<FormControl>
151+
<Checkbox
152+
defaultChecked={isEnum}
153+
onCheckedChange={(checked) => {
154+
field.onChange(checked);
155+
}}
156+
/>
157+
</FormControl>
158+
<FormLabel>
159+
<p>{t('data:create_field.is_enum.title')}</p>
160+
<p className="text-xs">
161+
{t('data:create_field.is_enum.subtitle')}
162+
</p>
163+
</FormLabel>
164+
<FormError />
165+
</FormItem>
166+
)}
167+
/>
133168
<div className="flex flex-1 flex-row gap-2">
134169
<Modal.Close asChild>
135170
<Button className="flex-1" variant="secondary">

packages/marble-api/scripts/openapi.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,8 @@ components:
19301930
properties:
19311931
description:
19321932
type: string
1933+
is_enum:
1934+
type: boolean
19331935
CreateTableLinkBody:
19341936
type: object
19351937
required:

packages/marble-api/src/generated/marble-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ export type CreateTableFieldBody = {
283283
};
284284
export type UpdateTableFieldBody = {
285285
description?: string;
286+
is_enum?: boolean;
286287
};
287288
export type CreateTableLinkBody = {
288289
name: string;

0 commit comments

Comments
 (0)