Skip to content

Commit

Permalink
improved property id generation for tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisj committed Sep 23, 2024
1 parent d043b4b commit 8be7d30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/annotation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,20 @@ export class LocalAnnotationSource extends AnnotationSource {
);
}

getUniquePropertyId() {
const { properties } = this;
const ids = new Set<string>();
for (const p of properties.value) {
ids.add(p.identifier);
}
while (true) {
const uuid = crypto.randomUUID();
if (!ids.has(uuid)) {
return uuid;
}
}
}

addProperty(property: AnnotationPropertySpec) {
this.properties.value.push(property);
for (const annotation of this) {
Expand Down
2 changes: 1 addition & 1 deletion src/layer/annotation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ class TagsTab extends Tab {
enumLabels: ["", value],
default: 0,
description: value,
identifier: self.crypto.randomUUID(), // TODO
identifier: localAnnotations.getUniquePropertyId(),
});
}
}
Expand Down

0 comments on commit 8be7d30

Please sign in to comment.