Skip to content

Commit

Permalink
prevent duplicate token count per image
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-TBT committed Sep 4, 2024
1 parent 1d5d924 commit 7039ea0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/AutoTagForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ export default class AutoTagForm extends React.Component {
const escapedString = this.state.separators.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
const regexPattern = RegExp(`[${escapedString}]+`);

let imageTokens = new Set();

let tokens = image.clientPath.split(regexPattern);
tokens.forEach(value =>
imageTokens.add(this.addOrUpdateToken(tagValuesMap, tokenMap, value))
);
const allTokens = new Set();
// Split and add tokens from image.clientPath
image.clientPath.split(regexPattern).forEach(value => allTokens.add(value));
// Split and add tokens from image.name
image.name.split(regexPattern).forEach(value => allTokens.add(value));

tokens = image.name.split(regexPattern); // Splitting on brackets too
tokens.forEach(value =>
// Process each unique token
let imageTokens = new Set();
allTokens.forEach(value =>
imageTokens.add(this.addOrUpdateToken(tagValuesMap, tokenMap, value))
);

// Return the set of tokens that are present on this image
return imageTokens;

}

loadFromServer(imageIds) {
Expand Down Expand Up @@ -258,7 +258,6 @@ export default class AutoTagForm extends React.Component {
images.forEach(image => {
// Find the tokens on each image, updating the tokenMap in place
image.tokens = this.tokensInName(image, tagValuesMap, tokenMap);
console.log(image.tokens);

// Check any tokens that exist on this image by default
image.checkedTokens = new Set(image.tokens);
Expand Down Expand Up @@ -694,11 +693,11 @@ export default class AutoTagForm extends React.Component {
// Filter out any tokens that do not meet the requirements
// Requirements for inclusion:
// 1) Matches an existing tag value
// 2) Is present on required number of images AND Is not numbers and/or symbols only
// 2) Is present on required number of images
let tokenMap = new Map([...this.state.tokenMap].filter(kv => {
let token = kv[1];

return (

token.possible.size > 0 ||
(
token.count >= this.state.requiredTokenCardinality &&
Expand Down

0 comments on commit 7039ea0

Please sign in to comment.