Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
7d635117
Commit
7d635117
authored
Jul 21, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
Jul 26, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Strip client-specific properties from annotations before exporting
parent
a9fc2258
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
21 deletions
+36
-21
strip-internal-properties.ts
src/sidebar/helpers/strip-internal-properties.ts
+15
-0
annotations-exporter.ts
src/sidebar/services/annotations-exporter.ts
+6
-3
api.ts
src/sidebar/services/api.ts
+1
-16
annotations-exporter-test.js
src/sidebar/services/test/annotations-exporter-test.js
+14
-2
No files found.
src/sidebar/helpers/strip-internal-properties.ts
0 → 100644
View file @
7d635117
/**
* Return a shallow clone of `obj` with all client-only properties removed.
* Client-only properties are marked by a '$' prefix.
*/
export
function
stripInternalProperties
(
obj
:
Record
<
string
,
unknown
>
):
Record
<
string
,
unknown
>
{
const
result
:
Record
<
string
,
unknown
>
=
{};
for
(
const
[
key
,
value
]
of
Object
.
entries
(
obj
))
{
if
(
!
key
.
startsWith
(
'$'
))
{
result
[
key
]
=
value
;
}
}
return
result
;
}
src/sidebar/services/annotations-exporter.ts
View file @
7d635117
import
type
{
Annotation
}
from
'../../types/api'
;
import
type
{
APIAnnotationData
}
from
'../../types/api'
;
import
{
stripInternalProperties
}
from
'../helpers/strip-internal-properties'
;
import
{
VersionData
}
from
'../helpers/version-data'
;
import
type
{
SidebarStore
}
from
'../store'
;
...
...
@@ -6,7 +7,7 @@ export type ExportContent = {
export_date
:
string
;
export_userid
:
string
;
client_version
:
string
;
annotations
:
A
nnotation
[];
annotations
:
A
PIAnnotationData
[];
};
/**
...
...
@@ -26,7 +27,9 @@ export class AnnotationsExporter {
*/
buildExportContent
(
now
=
new
Date
()):
ExportContent
{
const
profile
=
this
.
_store
.
profile
();
const
annotations
=
this
.
_store
.
allAnnotations
();
const
annotations
=
this
.
_store
.
allAnnotations
()
.
map
(
stripInternalProperties
)
as
APIAnnotationData
[];
const
versionData
=
new
VersionData
(
profile
,
[]);
return
{
...
...
src/sidebar/services/api.ts
View file @
7d635117
...
...
@@ -5,28 +5,13 @@ import type {
RouteMetadata
,
Profile
,
}
from
'../../types/api'
;
import
{
stripInternalProperties
}
from
'../helpers/strip-internal-properties'
;
import
type
{
SidebarStore
}
from
'../store'
;
import
{
fetchJSON
}
from
'../util/fetch'
;
import
{
replaceURLParams
}
from
'../util/url'
;
import
type
{
APIRoutesService
}
from
'./api-routes'
;
import
type
{
AuthService
}
from
'./auth'
;
/**
* Return a shallow clone of `obj` with all client-only properties removed.
* Client-only properties are marked by a '$' prefix.
*/
function
stripInternalProperties
(
obj
:
Record
<
string
,
unknown
>
):
Record
<
string
,
unknown
>
{
const
result
:
Record
<
string
,
unknown
>
=
{};
for
(
const
[
key
,
value
]
of
Object
.
entries
(
obj
))
{
if
(
!
key
.
startsWith
(
'$'
))
{
result
[
key
]
=
value
;
}
}
return
result
;
}
/**
* Types of value that can be passed as a parameter to API calls.
*/
...
...
src/sidebar/services/test/annotations-exporter-test.js
View file @
7d635117
import
{
publicAnnotation
}
from
'../../test/annotation-fixtures'
;
import
{
AnnotationsExporter
}
from
'../annotations-exporter'
;
describe
(
'AnnotationsExporter'
,
()
=>
{
...
...
@@ -14,7 +15,18 @@ describe('AnnotationsExporter', () => {
it
(
'generates export content with provided annotations'
,
()
=>
{
const
now
=
new
Date
();
const
annotations
=
[{},
{}];
const
firstBaseAnnotation
=
publicAnnotation
();
const
secondBaseAnnotation
=
publicAnnotation
();
const
annotations
=
[
{
...
firstBaseAnnotation
,
$tag
:
''
,
},
{
...
secondBaseAnnotation
,
$highlight
:
true
,
},
];
fakeStore
.
allAnnotations
.
returns
(
annotations
);
const
result
=
exporter
.
buildExportContent
(
now
);
...
...
@@ -23,7 +35,7 @@ describe('AnnotationsExporter', () => {
export_date
:
now
.
toISOString
(),
export_userid
:
'userId'
,
client_version
:
'__VERSION__'
,
annotations
,
annotations
:
[
firstBaseAnnotation
,
secondBaseAnnotation
]
,
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment