Skip to content

Commit

Permalink
fix(log): Fix resin isCurrentFileVersion is always true
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingze Xiao committed Jul 22, 2020
1 parent 028af26 commit f932500
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/common/BaseAnnotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type FileOptions = {
annotations?: {
activeId?: string;
};
currentFileVersionId?: string;
fileVersionId?: string;
};
};
Expand Down Expand Up @@ -53,8 +54,9 @@ export default class BaseAnnotator extends EventEmitter {
super();

const fileOptionsValue = fileOptions?.[file.id];
const currentFileVersionId = fileOptionsValue?.currentFileVersionId;
const fileOptionsVersionId = fileOptionsValue?.fileVersionId;
const fileVersionId = file.file_version.id;
const fileVersionId = file.file_version.id; // This is always the currently-previewed version id, not current version id

const initialState = {
annotations: {
Expand All @@ -63,7 +65,7 @@ export default class BaseAnnotator extends EventEmitter {
options: {
fileId: file.id,
fileVersionId: fileOptionsVersionId ?? fileVersionId,
isCurrentFileVersion: !fileOptionsVersionId || fileOptionsVersionId === fileVersionId,
isCurrentFileVersion: !fileOptionsVersionId || fileOptionsVersionId === currentFileVersionId,
permissions: file.permissions,
},
};
Expand Down
13 changes: 7 additions & 6 deletions src/common/__tests__/BaseAnnotator-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,20 @@ describe('BaseAnnotator', () => {
});

test.each`
fileOptionsVersionId | fileVersionId | isCurrentFileVersion
${'0'} | ${'0'} | ${true}
${undefined} | ${'0'} | ${true}
${'1'} | ${'0'} | ${false}
fileOptionsVersionId | currentFileVersionId | isCurrentFileVersion
${'0'} | ${'0'} | ${true}
${undefined} | ${'0'} | ${true}
${'1'} | ${'0'} | ${false}
`(
'should set isCurrentFileVersion to $isCurrentFileVersion',
({ fileOptionsVersionId, fileVersionId, isCurrentFileVersion }) => {
({ currentFileVersionId, fileOptionsVersionId, isCurrentFileVersion }) => {
const file = {
...defaults.file,
file_version: { id: fileVersionId },
file_version: { id: fileOptionsVersionId },
};
const fileOptions = {
'12345': {
currentFileVersionId,
fileVersionId: fileOptionsVersionId,
},
};
Expand Down

0 comments on commit f932500

Please sign in to comment.