add subspace validation

This commit is contained in:
hannathkadher
2025-01-29 22:03:56 +04:00
parent c173df934d
commit 09c1a785e5
2 changed files with 24 additions and 7 deletions

View File

@ -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<Tag>? 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<String, dynamic> 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<dynamic>?)
?.map((item) => Tag.fromJson(item))
.toList() ??

View File

@ -358,10 +358,21 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
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(() {