Skip to content

Commit

Permalink
Prevent highlights with duplicate uids from being created
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Oct 1, 2024
1 parent c4d0ffd commit 5b7d967
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"redux-devtools-extension": "^2.13.2",
"redux-thunk": "^2.2.0",
"redux-token-auth": "^0.19.0",
"uuid": "^10.0.0",
"xmldom": "^0.6.0"
},
"resolutions": {
Expand Down
7 changes: 4 additions & 3 deletions client/src/CanvasResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import HighlightColorSelect from './HighlightColorSelect';
import AddImageLayer from './AddImageLayer';
import TextField from 'material-ui/TextField';
import deepEqual from 'deep-equal';
import { v4 as uuidv4 } from 'uuid';

// overlay these modules
openSeaDragonFabricOverlay(OpenSeadragon, fabric);
Expand Down Expand Up @@ -375,7 +376,7 @@ class CanvasResource extends Component {
overlay.fabricCanvas().on('path:created', event => {
if (event.path) {
let path = event.path;
const highlightUid = `dm_canvas_highlight_${Date.now()}`;
const highlightUid = `dm_canvas_highlight_${uuidv4()}`;
path._highlightUid = highlightUid;
path.perPixelTargetFind = true;
this.overlay.fabricCanvas().setActiveObject(path);
Expand Down Expand Up @@ -822,7 +823,7 @@ class CanvasResource extends Component {
this.lineInProgress.perPixelTargetFind = true;
this.lineInProgress.selectable = true;
this.lockCanvasObject(this.lineInProgress, true);
const highlightUid = `dm_canvas_highlight_${Date.now()}`;
const highlightUid = `dm_canvas_highlight_${uuidv4()}`;
this.lineInProgress['_highlightUid'] = highlightUid;

this.props.setSaving({ doneSaving: false });
Expand All @@ -849,7 +850,7 @@ class CanvasResource extends Component {
}

addShape(fabricObject) {
const highlightUid = `dm_canvas_highlight_${Date.now()}`;
const highlightUid = `dm_canvas_highlight_${uuidv4()}`;
const { highlightColors } = this.props;
const instanceKey = this.getInstanceKey();
fabricObject['_highlightUid'] = highlightUid;
Expand Down
5 changes: 3 additions & 2 deletions client/src/TextResource.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { v4 as uuidv4 } from 'uuid';

import { yellow500 } from 'material-ui/styles/colors';
import DropDownMenu from 'material-ui/DropDownMenu';
Expand Down Expand Up @@ -814,7 +815,7 @@ class TextResource extends Component {
const markType = this.state.documentSchema.marks.highlight;
const { document_id } = this.props;
const editorState = this.getEditorState();
const cmd = addMark( markType, {highlightUid: `dm_text_highlight_${Date.now()}`, documentId: document_id });
const cmd = addMark( markType, {highlightUid: `dm_text_highlight_${uuidv4()}`, documentId: document_id });
cmd( editorState, this.state.editorView.dispatch );
this.state.editorView.focus();
}
Expand Down Expand Up @@ -1259,7 +1260,7 @@ class TextResource extends Component {
});
pastedMarks.forEach((mark, index) => {
let markEntry = Object.assign({}, mark.attrs);
mark.attrs['highlightUid'] = markEntry['newHighlightUid'] = `dm_text_highlight_${Date.now()}_${index}`;
mark.attrs['highlightUid'] = markEntry['newHighlightUid'] = `dm_text_highlight_${uuidv4()}_${index}`;
mark.attrs['documentId'] = this.props.document_id;
this.highlightsToDuplicate.push(markEntry);
});
Expand Down
5 changes: 5 additions & 0 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9569,6 +9569,11 @@ [email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"

uuid@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-10.0.0.tgz#5a95aa454e6e002725c79055fd42aaba30ca6294"
integrity sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==

uuid@^3.0.1, uuid@^3.3.2:
version "3.3.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.3.tgz#4568f0216e78760ee1dbf3a4d2cf53e224112866"
Expand Down

0 comments on commit 5b7d967

Please sign in to comment.