From 09c1a785e5f3dd3b5c7481eeb21a1dc261c34d40 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Wed, 29 Jan 2025 22:03:56 +0400 Subject: [PATCH] add subspace validation --- .../all_spaces/model/subspace_model.dart | 12 +++++++++--- .../widgets/dialogs/create_space_dialog.dart | 19 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/pages/spaces_management/all_spaces/model/subspace_model.dart b/lib/pages/spaces_management/all_spaces/model/subspace_model.dart index 2c86523f..a89ec409 100644 --- a/lib/pages/spaces_management/all_spaces/model/subspace_model.dart +++ b/lib/pages/spaces_management/all_spaces/model/subspace_model.dart @@ -1,5 +1,6 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart'; import 'package:syncrow_web/utils/constants/action_enum.dart'; +import 'package:uuid/uuid.dart'; import 'tag.dart'; @@ -8,19 +9,24 @@ class SubspaceModel { String subspaceName; final bool disabled; List? tags; + String internalId; SubspaceModel({ this.uuid, required this.subspaceName, required this.disabled, this.tags, - }); + String? internalId, + }) : internalId = internalId ?? const Uuid().v4(); factory SubspaceModel.fromJson(Map json) { + final String internalId = json['internalId'] ?? const Uuid().v4(); + return SubspaceModel( uuid: json['uuid'] ?? '', subspaceName: json['subspaceName'] ?? '', disabled: json['disabled'] ?? false, + internalId: internalId, tags: (json['tags'] as List?) ?.map((item) => Tag.fromJson(item)) .toList() ?? @@ -43,7 +49,7 @@ class UpdateSubspaceModel { final Action action; final String? subspaceName; final List? tags; - UpdateSubspaceModel({ + UpdateSubspaceModel({ required this.action, required this.uuid, this.subspaceName, @@ -107,4 +113,4 @@ class UpdateTag { 'product': product?.toMap(), }; } -} \ No newline at end of file +} diff --git a/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart b/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart index 405ccd92..ada60850 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart @@ -358,10 +358,21 @@ class CreateSpaceDialogState extends State { SubspaceNameDisplayWidget( text: subspace.subspaceName, validateName: (updatedName) { - return subspaces!.any((s) => - s != subspace && - s.subspaceName == - updatedName); + bool nameExists = + subspaces!.any((s) { + bool isSameId = s.internalId == + subspace.internalId; + bool isSameName = s.subspaceName + .trim() + .toLowerCase() == + updatedName + .trim() + .toLowerCase(); + + return !isSameId && isSameName; + }); + + return !nameExists; }, onNameChanged: (updatedName) { setState(() {