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/pages/spaces_management/all_spaces/model/product_model.dart';
import 'package:syncrow_web/utils/constants/action_enum.dart'; import 'package:syncrow_web/utils/constants/action_enum.dart';
import 'package:uuid/uuid.dart';
import 'tag.dart'; import 'tag.dart';
@ -8,19 +9,24 @@ class SubspaceModel {
String subspaceName; String subspaceName;
final bool disabled; final bool disabled;
List<Tag>? tags; List<Tag>? tags;
String internalId;
SubspaceModel({ SubspaceModel({
this.uuid, this.uuid,
required this.subspaceName, required this.subspaceName,
required this.disabled, required this.disabled,
this.tags, this.tags,
}); String? internalId,
}) : internalId = internalId ?? const Uuid().v4();
factory SubspaceModel.fromJson(Map<String, dynamic> json) { factory SubspaceModel.fromJson(Map<String, dynamic> json) {
final String internalId = json['internalId'] ?? const Uuid().v4();
return SubspaceModel( return SubspaceModel(
uuid: json['uuid'] ?? '', uuid: json['uuid'] ?? '',
subspaceName: json['subspaceName'] ?? '', subspaceName: json['subspaceName'] ?? '',
disabled: json['disabled'] ?? false, disabled: json['disabled'] ?? false,
internalId: internalId,
tags: (json['tags'] as List<dynamic>?) tags: (json['tags'] as List<dynamic>?)
?.map((item) => Tag.fromJson(item)) ?.map((item) => Tag.fromJson(item))
.toList() ?? .toList() ??
@ -43,7 +49,7 @@ class UpdateSubspaceModel {
final Action action; final Action action;
final String? subspaceName; final String? subspaceName;
final List<UpdateTag>? tags; final List<UpdateTag>? tags;
UpdateSubspaceModel({ UpdateSubspaceModel({
required this.action, required this.action,
required this.uuid, required this.uuid,
this.subspaceName, this.subspaceName,

View File

@ -358,10 +358,21 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
SubspaceNameDisplayWidget( SubspaceNameDisplayWidget(
text: subspace.subspaceName, text: subspace.subspaceName,
validateName: (updatedName) { validateName: (updatedName) {
return subspaces!.any((s) => bool nameExists =
s != subspace && subspaces!.any((s) {
s.subspaceName == bool isSameId = s.internalId ==
updatedName); subspace.internalId;
bool isSameName = s.subspaceName
.trim()
.toLowerCase() ==
updatedName
.trim()
.toLowerCase();
return !isSameId && isSameName;
});
return !nameExists;
}, },
onNameChanged: (updatedName) { onNameChanged: (updatedName) {
setState(() { setState(() {