-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement finch tracker #732
Conversation
48a0ccd
to
1466ccd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great and I only have minimal feedback. I haven't run it with data yet because I don't know the params to give to npm run tracker
. Could you provide them please and I'll look more at the UI?
In the meantime, if you want to use less CSS, less bootstrap and more Brave UI style, you might benefit from using the design system which exports react UI Components as well as css variables for colors / fonts / effects. The repo is at https://github.com/brave/leo and preview of all the components is at https://leo.bravesoftware.com/. You could simply use the Button, Toggle and Input components, if helpful.
src/core/core_utils.ts
Outdated
@@ -0,0 +1,88 @@ | |||
// Copyright (c) 2023 The Brave Authors. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: instead of using a utils file, consider either splitting to more specific-named files or perhaps even recognising that these are all similarly related and perhaps calling this config_params.ts
or maybe just params.ts
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, split the file.
|
||
export function getStudyPath(storageDir: string): string { | ||
return path.join(storageDir, 'study'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does getSeedPath
and getStudyPath
belong in your (currently named) core_utils
file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are only for tracker, not relevant for web/core code.
src/web/src/app.tsx
Outdated
.get(currentSeed) | ||
?.studies(filter) | ||
.map((study, i) => ( | ||
<StudyItem key={study.name() + i} study={study} filter={filter} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If study.name
is guaranteed to be unique, then it's not best practice to use i
in the key as the re-use of elements won't be as optimized. But if items never get added or removed then it's irrelevant anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, study.name
is not unique. There is not good key for the list.
Also, we load the lists once, so we could use index
& seedType
as key.
src/web/src/app.tsx
Outdated
const studyList = props.studies | ||
.get(currentSeed) | ||
?.studies(filter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also be memoized if we're going to memoize in our children, in order to make sure each study object is ===
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Could you take a look?
I have a doubt that useMemo()
work well for filter object that recreated each time we render.
Check in devtools that it's not a hot path.
I also created this PR based on this branch which starts webpack's dev web server and enables hot reloading of the UI. Also moves typescript compilation for the web project to webpack. #744 |
Thanks for the feedback, @petemill.
Thanks, I will take a look. The idea to reuse leo repo sounds good to me. Although, the main purpose of this PR is to start collecting Finch data to the private repo and send notifications. So maybe we need another iteration for that. |
src/web/app/app.tsx
Outdated
className={props.className} | ||
target="blank" | ||
rel="noreferrer" | ||
href={props.feature.link} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[semgrep] Detected a variable used in an anchor tag with the 'href' attribute. A malicious actor may be able to input the 'javascript:' URI, which could cause cross-site scripting (XSS). It is recommended to disallow 'javascript:' URIs within your application.
Source: https://semgrep.dev/r/typescript.react.security.audit.react-href-var.react-href-var
Cc @thypon @bcaller
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, this could be only https:// URL. How to fix the warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function sanitizeUrl(url) {
try {
const ALLOWED_PROTOCOLS = ['http:', 'https:'];
const trimmedUrl = url.trim();
return ALLOWED_PROTOCOLS.includes(new URL(trimmedUrl, document.baseURI).protocol) ? trimmedUrl : '#';
} catch(err) {
return '#';
}
}
Wrapping the link in a sanitizeUrl
should do the trick, here
7f6a1e2
to
03d43da
Compare
09070d3
to
09bec21
Compare
@thypon Anything from your side? The files were moved a bit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Just a couple minor suggestions that are up to you!
src/web/app/app.tsx
Outdated
className={props.className} | ||
target="blank" | ||
rel="noreferrer" | ||
href={props.feature.link} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function sanitizeUrl(url) {
try {
const ALLOWED_PROTOCOLS = ['http:', 'https:'];
const trimmedUrl = url.trim();
return ALLOWED_PROTOCOLS.includes(new URL(trimmedUrl, document.baseURI).protocol) ? trimmedUrl : '#';
} catch(err) {
return '#';
}
}
Wrapping the link in a sanitizeUrl
should do the trick, here
22ac8d5
to
efc6892
Compare
For #741
Specs: https://docs.google.com/document/d/1hRWkAnJtPjyvFglUQE0GegtyNtcVkjFpHPssdJJAqN0/
Ready to review.
TODO: