Developer Kit Custom Entity

This commit is contained in:
Sedat ÖZTÜRK 2025-10-31 11:30:04 +03:00
parent 93578c49a6
commit e8451627bd
12 changed files with 588 additions and 595 deletions

View file

@ -43,6 +43,7 @@ public class EntityFieldDto : FullAuditedEntityDto<Guid>
public bool IsUnique { get; set; }
public string? DefaultValue { get; set; }
public string? Description { get; set; }
public int DisplayOrder { get; set; } = 0;
}
public class CreateUpdateCustomEntityFieldDto
@ -56,4 +57,5 @@ public class CreateUpdateCustomEntityFieldDto
public bool IsUnique { get; set; }
public string? DefaultValue { get; set; }
public string? Description { get; set; }
public int DisplayOrder { get; set; } = 0;
}

View file

@ -35,12 +35,13 @@ public class CustomEntityAppService : CrudAppService<
_repository = repository;
_migrationRepository = migrationRepository;
_endpointRepository = endpointRepository;
_fieldRepository = fieldRepository;
}
public override async Task<PagedResultDto<CustomEntityDto>> GetListAsync(PagedAndSortedResultRequestDto input)
{
var query = await _repository.GetQueryableAsync();
var fullQuery = query.Include(x => x.Fields);
var fullQuery = query.Include(x => x.Fields.OrderBy(f => f.DisplayOrder));
var totalCount = await fullQuery.CountAsync();
@ -59,7 +60,7 @@ public class CustomEntityAppService : CrudAppService<
{
var query = await _repository.GetQueryableAsync();
var entity = await query
.Include(x => x.Fields)
.Include(x => x.Fields.OrderBy(f => f.DisplayOrder))
.FirstOrDefaultAsync(x => x.Id == id);
if (entity == null)
@ -72,7 +73,7 @@ public class CustomEntityAppService : CrudAppService<
{
var query = await _repository.GetQueryableAsync();
var entities = await query
.Include(x => x.Fields)
.Include(x => x.Fields.OrderBy(f => f.DisplayOrder))
.Where(x => x.IsActive)
.ToListAsync();
@ -83,7 +84,7 @@ public class CustomEntityAppService : CrudAppService<
{
var query = await _repository.GetQueryableAsync();
var entity = await query
.Include(x => x.Fields)
.Include(x => x.Fields.OrderBy(f => f.DisplayOrder))
.FirstOrDefaultAsync(x => x.Id == id);
if (entity == null)
@ -115,13 +116,14 @@ public class CustomEntityAppService : CrudAppService<
var updatedFields = new List<CustomEntityField>();
foreach (var dtoField in input.Fields)
for (int i = 0; i < input.Fields.Count; i++)
{
var dtoField = input.Fields[i];
CustomEntityField? existingField = null;
if (dtoField.Id.HasValue)
{
existingField = entity.Fields.FirstOrDefault(f => f.Id == dtoField.Id.Value);
existingField = entity.Fields?.FirstOrDefault(f => f.Id == dtoField.Id.Value);
}
if (existingField != null)
@ -133,6 +135,7 @@ public class CustomEntityAppService : CrudAppService<
existingField.IsUnique = dtoField.IsUnique;
existingField.DefaultValue = dtoField.DefaultValue;
existingField.Description = dtoField.Description;
existingField.DisplayOrder = dtoField.DisplayOrder;
updatedFields.Add(existingField);
}
@ -147,7 +150,8 @@ public class CustomEntityAppService : CrudAppService<
MaxLength = dtoField.MaxLength,
IsUnique = dtoField.IsUnique,
DefaultValue = dtoField.DefaultValue,
Description = dtoField.Description
Description = dtoField.Description,
DisplayOrder = dtoField.DisplayOrder
};
await _fieldRepository.InsertAsync(newField);
@ -156,9 +160,9 @@ public class CustomEntityAppService : CrudAppService<
}
// Silinecek alanlar
var toRemove = entity.Fields
var toRemove = entity.Fields?
.Where(existing => updatedFields.All(f => f.Id != existing.Id))
.ToList();
.ToList() ?? [];
if (toRemove.Any())
{
@ -185,9 +189,10 @@ public class CustomEntityAppService : CrudAppService<
MigrationStatus = "pending"
};
// Fields ekle
foreach (var fieldDto in input.Fields)
// Fields ekle - sıralama ile
for (int i = 0; i < input.Fields.Count; i++)
{
var fieldDto = input.Fields[i];
var field = new CustomEntityField
{
EntityId = entity.Id,
@ -197,7 +202,8 @@ public class CustomEntityAppService : CrudAppService<
MaxLength = fieldDto.MaxLength,
IsUnique = fieldDto.IsUnique,
DefaultValue = fieldDto.DefaultValue,
Description = fieldDto.Description
Description = fieldDto.Description,
DisplayOrder = fieldDto.DisplayOrder
};
entity.Fields.Add(field);
}

View file

@ -10168,7 +10168,7 @@
{
"resourceName": "Platform",
"key": "App.DeveloperKit.Entity.EndpointStatus",
"en": "Endpoint Status:",
"en": "Crud Endpoint Status:",
"tr": "Uç Nokta Durumu:"
},
{
@ -10681,17 +10681,11 @@
"en": "Active",
"tr": "Aktif"
},
{
"resourceName": "Platform",
"key": "App.DeveloperKit.ComponentEditor.Active",
"en": "Active",
"tr": "Aktif"
},
{
"resourceName": "Platform",
"key": "App.DeveloperKit.ComponentEditor.Save",
"en": "Save Component",
"tr": "Bileşeni Kaydet"
"en": "Save",
"tr": "Kaydet"
},
{
"resourceName": "Platform",

View file

@ -44042,7 +44042,7 @@ public class ListFormSeeder : IDataSeedContributor, ITransientDependency
R = AppCodes.SupplyChain.MaterialGroup,
U = AppCodes.SupplyChain.MaterialGroup + ".Update",
E = true,
I = true,
I = false,
Deny = false
}),
PivotSettingsJson = JsonSerializer.Serialize(new ListFormFieldPivotSettingsDto

View file

@ -38,6 +38,7 @@ public class CustomEntityField : FullAuditedEntity<Guid>
public bool IsUnique { get; set; }
public string? DefaultValue { get; set; }
public string? Description { get; set; }
public int DisplayOrder { get; set; } = 0;
public virtual CustomEntity Entity { get; set; } = null!;

View file

@ -13,7 +13,7 @@ using Volo.Abp.EntityFrameworkCore;
namespace Kurs.Platform.Migrations
{
[DbContext(typeof(PlatformDbContext))]
[Migration("20251030134034_Initial")]
[Migration("20251031075637_Initial")]
partial class Initial
{
/// <inheritdoc />
@ -3001,6 +3001,9 @@ namespace Kurs.Platform.Migrations
.HasMaxLength(500)
.HasColumnType("nvarchar(500)");
b.Property<int>("DisplayOrder")
.HasColumnType("int");
b.Property<Guid>("EntityId")
.HasColumnType("uniqueidentifier");

View file

@ -3459,6 +3459,7 @@ namespace Kurs.Platform.Migrations
IsUnique = table.Column<bool>(type: "bit", nullable: false),
DefaultValue = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
Description = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
DisplayOrder = table.Column<int>(type: "int", nullable: false),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),

View file

@ -2998,6 +2998,9 @@ namespace Kurs.Platform.Migrations
.HasMaxLength(500)
.HasColumnType("nvarchar(500)");
b.Property<int>("DisplayOrder")
.HasColumnType("int");
b.Property<Guid>("EntityId")
.HasColumnType("uniqueidentifier");

View file

@ -17,7 +17,7 @@ import { ROUTES_ENUM } from '@/routes/route.constant'
import { useLocalization } from '@/utils/hooks/useLocalization'
import { Formik, Form, Field, FieldProps } from 'formik'
import * as Yup from 'yup'
import { FormItem } from '@/components/ui'
import { Checkbox, FormContainer, FormItem, Input } from '@/components/ui'
// Error tipini tanımla
interface ValidationError {
@ -180,8 +180,6 @@ const ComponentEditor: React.FC = () => {
}
return (
<div className="min-h-screen bg-gradient-to-br from-slate-50 to-slate-100">
<div className="mx-auto">
<Formik
enableReinitialize
initialValues={initialValues}
@ -215,9 +213,7 @@ const ComponentEditor: React.FC = () => {
: translate('::App.DeveloperKit.ComponentEditor.Title.Create')}
</h1>
<p className="text-sm text-slate-600">
{isEditing
? 'Modify your React component'
: 'Create a new React component'}
{isEditing ? 'Modify your React component' : 'Create a new React component'}
</p>
</div>
</div>
@ -229,7 +225,7 @@ const ComponentEditor: React.FC = () => {
type="button"
onClick={submitForm}
disabled={isSubmitting || !values.name.trim() || !isValid}
className="flex items-center gap-2 bg-gradient-to-r from-blue-600 to-blue-700 hover:from-blue-700 hover:to-blue-800 text-white font-semibold px-4 py-2 rounded-lg shadow-lg hover:shadow-xl transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed"
className="flex items-center gap-1 bg-gradient-to-r from-green-600 to-green-700 hover:from-green-700 hover:to-green-800 text-white font-semibold px-2 py-1.5 rounded shadow transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed text-sm"
>
<FaRegSave className="w-4 h-4" />
{isSubmitting
@ -252,7 +248,7 @@ const ComponentEditor: React.FC = () => {
<h2 className="text-base font-semibold text-slate-900">Component Settings</h2>
</div>
<div className="space-y-3">
<FormContainer size="sm">
<FormItem
label={translate('::App.DeveloperKit.ComponentEditor.ComponentName')}
invalid={!!(errors.name && touched.name)}
@ -261,8 +257,8 @@ const ComponentEditor: React.FC = () => {
<Field
name="name"
type="text"
component={Input}
placeholder="e.g., Button, Card, Modal"
className="w-full px-2 py-1.5 border border-slate-300 rounded focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all duration-200 text-sm bg-slate-50 focus:bg-white"
/>
</FormItem>
@ -274,8 +270,8 @@ const ComponentEditor: React.FC = () => {
<Field
name="description"
type="text"
component={Input}
placeholder="Brief description of the component"
className="w-full px-2 py-1.5 border border-slate-300 rounded focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all duration-200 text-sm bg-slate-50 focus:bg-white"
/>
</FormItem>
@ -286,7 +282,7 @@ const ComponentEditor: React.FC = () => {
>
<Field name="dependencies">
{({ field }: FieldProps) => (
<input
<Input
type="text"
value={(values.dependencies || []).join(', ')}
onChange={(e) =>
@ -298,26 +294,16 @@ const ComponentEditor: React.FC = () => {
.filter(Boolean),
)
}
className="w-full px-2 py-1.5 border border-slate-300 rounded focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all duration-200 text-sm bg-slate-50 focus:bg-white"
placeholder="MyComponent, AnotherComponent, etc."
/>
)}
</Field>
</FormItem>
<FormItem>
<div className="flex items-center p-2 bg-slate-50 rounded border border-slate-200">
<Field
name="isActive"
type="checkbox"
className="rounded border-slate-300 text-blue-600 focus:ring-blue-500 w-3.5 h-3.5"
/>
<label className="ml-2 text-xs font-medium text-slate-700">
{translate('::App.DeveloperKit.ComponentEditor.Active')}
</label>
</div>
<FormItem label={translate('::App.DeveloperKit.ComponentEditor.Active')}>
<Field name="isActive" component={Checkbox} />
</FormItem>
</div>
</FormContainer>
</div>
</div>
@ -340,10 +326,7 @@ const ComponentEditor: React.FC = () => {
</p>
<div className="space-y-1.5 max-h-32 overflow-y-auto">
{validationErrors.slice(0, 5).map((error, index) => (
<div
key={index}
className="bg-white p-2 rounded border border-red-100"
>
<div key={index} className="bg-white p-2 rounded border border-red-100">
<div className="text-xs text-red-800">
<span className="font-medium bg-red-100 px-1.5 py-0.5 rounded text-xs">
Line {error.startLineNumber}
@ -379,8 +362,6 @@ const ComponentEditor: React.FC = () => {
</>
)}
</Formik>
</div>
</div>
)
}

View file

@ -11,12 +11,12 @@ import {
FaTable,
FaColumns,
} from 'react-icons/fa'
import { CreateUpdateCustomEntityFieldDto, CustomEntityField } from '@/proxy/developerKit/models'
import { CustomEntityField } from '@/proxy/developerKit/models'
import { ROUTES_ENUM } from '@/routes/route.constant'
import { useLocalization } from '@/utils/hooks/useLocalization'
import { Formik, Form, Field, FieldProps, FieldArray } from 'formik'
import * as Yup from 'yup'
import { FormItem, Input, Select, Checkbox } from '@/components/ui'
import { FormItem, Input, Select, Checkbox, FormContainer } from '@/components/ui'
import { SelectBoxOption } from '@/shared/types'
// Validation schema
@ -33,8 +33,9 @@ const validationSchema = Yup.object({
isRequired: Yup.boolean(),
maxLength: Yup.number().nullable(),
isUnique: Yup.boolean(),
defaultValue: Yup.string(),
description: Yup.string(),
defaultValue: Yup.string().notRequired(),
description: Yup.string().notRequired(),
displayOrder: Yup.number().required(),
}),
)
.min(1, 'At least one field is required'),
@ -67,6 +68,7 @@ const EntityEditor: React.FC = () => {
isRequired: true,
maxLength: 100,
description: 'Entity name',
displayOrder: 1,
},
] as CustomEntityField[],
isActive: true,
@ -83,12 +85,18 @@ const EntityEditor: React.FC = () => {
if (isEditing && id) {
const entity = getEntity(id)
if (entity) {
// Ensure fields are sorted by displayOrder and normalized to sequential values
const sortedFields = (entity.fields || [])
.slice()
.sort((a, b) => (a.displayOrder ?? 0) - (b.displayOrder ?? 0))
.map((f, idx) => ({ ...f, displayOrder: f.displayOrder ?? idx + 1 }))
setInitialValues({
name: entity.name,
displayName: entity.displayName,
tableName: entity.tableName,
description: entity.description || '',
fields: entity.fields,
fields: sortedFields,
isActive: entity.isActive,
hasAuditFields: entity.hasAuditFields,
hasSoftDelete: entity.hasSoftDelete,
@ -100,7 +108,8 @@ const EntityEditor: React.FC = () => {
const handleSubmit = async (values: typeof initialValues, { setSubmitting }: any) => {
try {
const sanitizedFields = values.fields.map((f) => {
const sanitized: CreateUpdateCustomEntityFieldDto = {
// send both `displayOrder` (frontend proxy) and `order` (backend DTO) to be safe
const sanitized: any = {
...(f.id && isEditing ? { id: f.id } : {}),
name: f.name.trim(),
type: f.type,
@ -109,6 +118,8 @@ const EntityEditor: React.FC = () => {
isUnique: f.isUnique || false,
defaultValue: f.defaultValue,
description: f.description,
displayOrder: f.displayOrder,
order: f.displayOrder,
}
return sanitized
@ -150,8 +161,6 @@ const EntityEditor: React.FC = () => {
]
return (
<div className="min-h-screen bg-gradient-to-br from-slate-50 to-slate-100">
<div className="mx-auto">
<Formik
enableReinitialize
initialValues={initialValues}
@ -162,28 +171,33 @@ const EntityEditor: React.FC = () => {
<>
{/* Enhanced Header */}
<div className="bg-white shadow border-b border-slate-200 sticky top-0 z-10">
<div className="px-3 py-2">
<div className="px-4 py-3">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<div className="flex items-center gap-4">
<button
type="button"
onClick={() => navigate(ROUTES_ENUM.protected.saas.developerKit.entities)}
className="flex items-center gap-1 text-slate-600 hover:text-blue-600 hover:bg-blue-50 px-2 py-1.5 rounded transition-all duration-200"
className="flex items-center gap-2 text-slate-600 hover:text-blue-600 hover:bg-blue-50 px-3 py-2 rounded-lg transition-all duration-200"
>
<FaArrowLeft className="w-3 h-3" />
<span className="text-sm">{translate('::App.DeveloperKit.EntityEditor.Back')}</span>
<FaArrowLeft className="w-4 h-4" />
<span className="text-sm">
{translate('::App.DeveloperKit.EntityEditor.Back')}
</span>
</button>
<div className="h-4 w-px bg-slate-300"></div>
<div className="flex items-center gap-2">
<div className="h-6 w-px bg-slate-300"></div>
<div className="flex items-center gap-3">
<div className="bg-gradient-to-r from-green-500 to-blue-600 p-1 rounded">
<FaDatabase className="w-3 h-3 text-white" />
<FaDatabase className="w-5 h-5 text-white" />
</div>
<div>
<h1 className="text-sm font-bold text-slate-900">
<h1 className="text-xl font-bold text-slate-900">
{isEditing
? `${translate('::App.DeveloperKit.EntityEditor.Title.Edit')} - ${values.name || initialValues.name || 'Entity'}`
: translate('::App.DeveloperKit.EntityEditor.Title.Create')}
</h1>
<p className="text-sm text-slate-600">
{isEditing ? 'Modify your entity' : 'Create a new entity'}
</p>
</div>
</div>
</div>
@ -204,17 +218,18 @@ const EntityEditor: React.FC = () => {
</div>
</div>
<Form className="space-y-2 pt-2">
<Form className="grid grid-cols-1 lg:grid-cols-3 gap-4 pt-2">
{/* Basic Entity Information */}
<div className="bg-white rounded border border-slate-200 p-2">
<div className="flex items-center gap-1.5 mb-2">
<div className="bg-blue-100 p-1 rounded">
<FaCog className="w-3 h-3 text-blue-600" />
<div className="space-y-4 col-span-1">
<div className="bg-white rounded-lg shadow-sm border border-slate-200 p-3">
<div className="flex items-center gap-2 mb-4">
<div className="bg-blue-100 p-1.5 rounded-lg">
<FaCog className="w-4 h-4 text-blue-600" />
</div>
<h2 className="text-sm font-semibold text-slate-900">Entity Settings</h2>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<FormContainer size="sm">
<FormItem
label={translate('::App.DeveloperKit.EntityEditor.EntityName')}
invalid={!!(errors.name && touched.name)}
@ -250,7 +265,6 @@ const EntityEditor: React.FC = () => {
name="displayName"
component={Input}
placeholder="e.g., Product, User, Order"
className="px-2 py-1.5 bg-slate-50 focus:bg-white transition-all duration-200 text-sm h-7"
/>
</FormItem>
@ -264,7 +278,6 @@ const EntityEditor: React.FC = () => {
component={Input}
disabled={isMigrationApplied}
placeholder="e.g., Products, Users, Orders"
className="px-2 py-1.5 bg-slate-50 focus:bg-white transition-all duration-200 disabled:bg-slate-100 disabled:text-slate-500 text-sm h-7"
/>
</FormItem>
@ -277,44 +290,35 @@ const EntityEditor: React.FC = () => {
name="description"
component={Input}
placeholder="Brief description of this entity"
className="px-2 py-1.5 bg-slate-50 focus:bg-white transition-all duration-200 text-sm h-7"
/>
</FormItem>
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-2 mt-2 pt-2 border-t border-slate-200">
<div className="flex items-center p-1 bg-slate-50 rounded border border-slate-200">
<Field name="isActive" component={Checkbox} className="w-3 h-3" />
<label className="ml-1 text-sm font-medium text-slate-700">
{translate('::App.DeveloperKit.EntityEditor.Active')}
</label>
</div>
<FormItem label={translate('::App.DeveloperKit.ComponentEditor.Active')}>
<Field name="isActive" component={Checkbox} />
</FormItem>
<div className="flex items-center p-1 bg-slate-50 rounded border border-slate-200">
<Field name="hasAuditFields" component={Checkbox} className="w-3 h-3" />
<label className="ml-1 text-sm font-medium text-slate-700">
{translate('::App.DeveloperKit.EntityEditor.Audit')}
</label>
</div>
<FormItem label={translate('::App.DeveloperKit.EntityEditor.Audit')}>
<Field name="hasAuditFields" component={Checkbox} />
</FormItem>
<div className="flex items-center p-1 bg-slate-50 rounded border border-slate-200">
<Field name="hasSoftDelete" component={Checkbox} className="w-3 h-3" />
<label className="ml-1 text-sm font-medium text-slate-700">
{translate('::App.DeveloperKit.EntityEditor.SoftDelete')}
</label>
</div>
<FormItem label={translate('::App.DeveloperKit.EntityEditor.SoftDelete')}>
<Field name="hasSoftDelete" component={Checkbox} />
</FormItem>
</FormContainer>
</div>
</div>
{/* Fields Section */}
<div className="bg-white rounded border border-slate-200 p-2">
<div className="space-y-4 col-span-2">
<div className="bg-white rounded-lg shadow-sm border border-slate-200 p-3">
<FormContainer size="sm">
<FieldArray name="fields">
{({ push, remove }) => (
<>
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-1">
<div className="bg-green-100 p-1 rounded">
<FaColumns className="w-3 h-3 text-green-600" />
<div className="bg-green-100 p-1.5 rounded">
<FaColumns className="w-4 h-4 text-green-600" />
</div>
<h2 className="text-sm font-semibold text-slate-900">
{translate('::App.DeveloperKit.EntityEditor.Fields')}
@ -330,6 +334,8 @@ const EntityEditor: React.FC = () => {
type: 'string',
isRequired: false,
description: '',
// Assign next sequential displayOrder
displayOrder: (values.fields?.length ?? 0) + 1,
})
}
className="flex items-center gap-1 bg-gradient-to-r from-blue-600 to-blue-700 text-white px-2 py-1.5 rounded hover:from-blue-700 hover:to-blue-800 transition-all duration-200 text-sm"
@ -339,13 +345,13 @@ const EntityEditor: React.FC = () => {
</button>
</div>
<div className="space-y-2">
{values.fields.map((field, index) => (
<div
key={field.id || `new-${index}`}
className="bg-gradient-to-r from-slate-50 to-slate-100 border border-slate-200 rounded p-2 shadow-sm hover:shadow-md transition-all duration-200"
>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-2 mb-2">
<div key={field.id || `new-${index}`}>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-12 gap-2 mb-2">
<FormItem label="Order *" className="col-span-1">
<Field type="number" name={`fields.${index}.displayOrder`} component={Input} />
</FormItem>
<FormItem
label={`${translate('::App.DeveloperKit.EntityEditor.FieldName')} *`}
invalid={
@ -357,12 +363,12 @@ const EntityEditor: React.FC = () => {
)
}
errorMessage={(errors.fields as any)?.[index]?.name as string}
className="col-span-2"
>
<Field
name={`fields.${index}.name`}
component={Input}
placeholder="e.g., Name, Email, Age"
className="px-2 py-1.5 bg-white border-slate-300 focus:border-blue-500 focus:ring-blue-500 transition-all duration-200 text-sm h-6"
/>
</FormItem>
@ -377,6 +383,7 @@ const EntityEditor: React.FC = () => {
)
}
errorMessage={(errors.fields as any)?.[index]?.type as string}
className="col-span-1"
>
<Field name={`fields.${index}.type`}>
{({ field, form }: FieldProps<SelectBoxOption>) => (
@ -393,12 +400,33 @@ const EntityEditor: React.FC = () => {
onChange={(option) =>
form.setFieldValue(field.name, option?.value)
}
className="bg-white border-slate-300 focus:border-blue-500 focus:ring-blue-500"
/>
)}
</Field>
</FormItem>
<FormItem
label={translate('::App.DeveloperKit.EntityEditor.DefaultValue')}
invalid={
!!(
errors.fields &&
(errors.fields as any)[index]?.defaultValue &&
touched.fields &&
(touched.fields as any)[index]?.defaultValue
)
}
errorMessage={
(errors.fields as any)?.[index]?.defaultValue as string
}
className="col-span-2"
>
<Field
name={`fields.${index}.defaultValue`}
component={Input}
placeholder="Optional default value"
/>
</FormItem>
{field.type === 'string' && (
<FormItem
label={translate('::App.DeveloperKit.EntityEditor.MaxLength')}
@ -419,36 +447,10 @@ const EntityEditor: React.FC = () => {
component={Input}
type="number"
placeholder="e.g., 100"
className="px-2 py-1.5 bg-white border-slate-300 focus:border-blue-500 focus:ring-blue-500 transition-all duration-200 text-sm h-6"
/>
</FormItem>
)}
<FormItem
label={translate('::App.DeveloperKit.EntityEditor.DefaultValue')}
invalid={
!!(
errors.fields &&
(errors.fields as any)[index]?.defaultValue &&
touched.fields &&
(touched.fields as any)[index]?.defaultValue
)
}
errorMessage={
(errors.fields as any)?.[index]?.defaultValue as string
}
>
<Field
name={`fields.${index}.defaultValue`}
component={Input}
placeholder="Optional default value"
className="px-2 py-1.5 bg-white border-slate-300 focus:border-blue-500 focus:ring-blue-500 transition-all duration-200 text-sm h-6"
/>
</FormItem>
</div>
<div className="flex items-center justify-between pt-2 border-t border-slate-200">
<div className="flex-1 mr-2">
<FormItem
label={translate('::App.DeveloperKit.EntityEditor.Description')}
invalid={
@ -462,50 +464,49 @@ const EntityEditor: React.FC = () => {
errorMessage={
(errors.fields as any)?.[index]?.description as string
}
className={field.type === 'string' ? 'col-span-2' : 'col-span-3'}
>
<Field
name={`fields.${index}.description`}
component={Input}
placeholder="Field description"
className="px-2 py-1.5 bg-white border-slate-300 focus:border-blue-500 focus:ring-blue-500 transition-all duration-200 text-sm h-6"
/>
</FormItem>
</div>
<div className="flex items-center gap-2">
<div className="flex items-center p-1 bg-white rounded border border-slate-200">
<Field
name={`fields.${index}.isRequired`}
component={Checkbox}
className="w-3 h-3"
/>
<label className="ml-1 text-sm font-medium text-slate-700">
{translate('::App.DeveloperKit.EntityEditor.Required')}
</label>
</div>
<FormItem
label={translate('::App.DeveloperKit.EntityEditor.Required')}
className="items-center"
>
<Field name={`fields.${index}.isRequired`} component={Checkbox} />
</FormItem>
<div className="flex items-center p-1 bg-white rounded border border-slate-200">
<Field
name={`fields.${index}.isUnique`}
component={Checkbox}
className="w-3 h-3"
/>
<label className="ml-1 text-sm font-medium text-slate-700">
{translate('::App.DeveloperKit.EntityEditor.Unique')}
</label>
</div>
<FormItem
label={translate('::App.DeveloperKit.EntityEditor.Unique')}
className="items-center"
>
<Field name={`fields.${index}.isUnique`} component={Checkbox} />
</FormItem>
<button
type="button"
onClick={() => remove(index)}
className="p-1 text-red-600 hover:text-red-800 hover:bg-red-50 rounded transition-all duration-200 border border-red-200 hover:border-red-300"
onClick={() => {
// Remove the field and reindex displayOrder for remaining fields
remove(index)
const newFields = values.fields ? [...values.fields] : []
newFields.splice(index, 1)
newFields.forEach((f, i) => {
// ensure sequential ordering starting at 1
f.displayOrder = i + 1
})
setFieldValue('fields', newFields)
}}
className="p-3 text-red-600 hover:text-red-800 rounded transition-all duration-200"
title="Remove field"
>
<FaTrashAlt className="w-3 h-3" />
<FaTrashAlt className="w-5 h-5" />
</button>
</div>
</div>
</div>
))}
{values.fields.length === 0 && (
@ -519,17 +520,16 @@ const EntityEditor: React.FC = () => {
</p>
</div>
)}
</div>
</>
)}
</FieldArray>
</FormContainer>
</div>
</div>
</Form>
</>
)}
</Formik>
</div>
</div>
)
}

View file

@ -103,7 +103,7 @@ const EntityManager: React.FC = () => {
</div>
{/* Stats Cards */}
<div className="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8">
<div className="grid grid-cols-1 md:grid-cols-4 gap-4 mb-8">
<div className="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
<div className="flex items-center justify-between">
<div>
@ -162,7 +162,6 @@ const EntityManager: React.FC = () => {
</div>
{/* Filters */}
<div className="bg-white rounded-lg border border-slate-200 p-6 mb-6 shadow-sm">
<div className="flex flex-col lg:flex-row gap-4">
<div className="flex-1 relative">
<FaSearch className="absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-slate-400" />
@ -183,9 +182,7 @@ const EntityManager: React.FC = () => {
className="px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-emerald-500 focus:border-transparent transition-colors"
>
<option value="all">{translate('::App.DeveloperKit.Entity.Filter.All')}</option>
<option value="active">
{translate('::App.DeveloperKit.Entity.Filter.Active')}
</option>
<option value="active">{translate('::App.DeveloperKit.Entity.Filter.Active')}</option>
<option value="inactive">
{translate('::App.DeveloperKit.Entity.Filter.Inactive')}
</option>
@ -193,21 +190,22 @@ const EntityManager: React.FC = () => {
</div>
</div>
</div>
</div>
{/* Entities List */}
{filteredEntities.length > 0 ? (
<div className="grid grid-cols-1 xl:grid-cols-2 gap-6">
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6">
{filteredEntities.map((entity) => {
return (
<div
key={entity.id}
className="bg-white rounded-lg border border-slate-200 shadow-sm hover:shadow-md transition-all duration-200 group"
>
<div className="p-6">
<div className="p-5">
<div className="flex items-start justify-between mb-4">
<div className="flex-1">
<div className="flex items-center gap-3 mb-2">
<div className="flex items-center justify-between mb-2">
{/* Sol taraf */}
<div className="flex items-center gap-3">
<div className="bg-blue-100 text-blue-600 p-2 rounded-lg">
<FaTable className="w-5 h-5" />
</div>
@ -216,14 +214,14 @@ const EntityManager: React.FC = () => {
{entity.displayName}
</h3>
<p className="text-sm text-slate-500">
{translate('::App.DeveloperKit.Entity.TableLabel')}: {entity.tableName}
{translate('::App.DeveloperKit.Entity.TableLabel')}:{' '}
{entity.tableName}
</p>
</div>
</div>
{entity.description && (
<p className="text-slate-600 text-sm mb-3">{entity.description}</p>
)}
<div className="flex items-center gap-4 text-xs text-slate-500 mb-3">
{/* Sağ taraf */}
<div className="flex flex-col items-end text-sm text-slate-600 gap-1">
<div className="flex items-center gap-1">
<FaCalendarAlt className="w-3 h-3" />
<span>
@ -241,15 +239,17 @@ const EntityManager: React.FC = () => {
</div>
</div>
</div>
{entity.description && (
<p className="text-slate-600 text-sm mb-3">{entity.description}</p>
)}
</div>
</div>
{/* Entity Fields Preview */}
<div className="mb-4">
<div className="bg-slate-50 rounded-lg p-3">
<h4 className="text-sm font-medium text-slate-700 mb-2">
{translate('::App.DeveloperKit.Entity.FieldLabel')}
</h4>
<div className="grid grid-cols-2 gap-2 text-xs">
<div className="grid grid-cols-3 gap-2 text-xs">
{entity.fields.slice(0, 4).map((field) => (
<div key={field.id} className="flex items-center gap-2">
<span

View file

@ -27,6 +27,7 @@ export interface CustomEntityField {
description?: string;
creationTime?: string;
lastModificationTime?: string;
displayOrder: number;
}
export interface CreateUpdateCustomEntityFieldDto {
@ -38,6 +39,7 @@ export interface CreateUpdateCustomEntityFieldDto {
isUnique?: boolean;
defaultValue?: string;
description?: string;
displayOrder: number;
}
export interface CreateUpdateCustomEntityDto {