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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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