-
Notifications
You must be signed in to change notification settings - Fork 32
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
[Map-Viewer] Added layer from a GeoJSON file #777
Conversation
Affected libs:
|
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.
Well done! Your code looks good :-)
I only have a few comments. Let me know if you have any questions.
this.loading = true | ||
try { | ||
if (!this.isFileFormatValid(file)) { | ||
this.errorMessage = 'Invalid file format' |
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.
Maybe we can save the message in a constant outside this class to reuse it again, e.g. in line 52.
It's better to have a single source of truth. The sentence might change in the future and it could be messy to edit the message in several places.
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.
I have refactored the code to define the message as a constant for reuse.
} | ||
|
||
private isFileFormatValid(file: File): boolean { | ||
const fileExtension = file.name.split('.').pop() |
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 looks quite similar to the logic in line 46.
Maybe you refactor this into a function and reuse it?
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.
I have refactored it into a function.
} | ||
this.mapFacade.addLayer({ ...layerToAdd, title: title }) | ||
this.successMessage = 'File successfully added to map' | ||
setTimeout(() => { |
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.
You are already using a setTimeout
function in the displayError
function. Maybe you could create a displayMessage
function instead and use it for the error and success case but with a different message. WDYT?
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.
Thanks for pointing it out. I have implemented this change. @Angi-Kinas
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.
Great work here! Didn't test, just left a few remarks. I agree with what Angelika said as well 🙂
}) | ||
|
||
describe('handleFileChange', () => { | ||
describe('should set error message if file is not selected', () => { |
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.
Just a remark in terms of UT naming :
Usually, we try to reserve the expectations, such as should do...
to it
blocks.
For describe
blocks, we try to have either a condition (such as if file is not selected
), or the name of the section we're testing (eg : #errorMessage
,like you did line 40 for instance).
So for instance in this case, IMO, the name of the describe block should be if file is not selected
(and the naming of the following it
case is alright since it starts with should
).
This remark is true for the next few tests in this 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.
@cmoinier Thanks for the note on UT naming. I have revised the describe
blocks for clarity and consistency as suggested.
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.
Marginal comments
this.errorMessage = message | ||
} | ||
|
||
setTimeout(() => { |
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.
@jahow do we have a notification système ? Could be another task for @ronitjadhav what do you guys think ?
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.
There's no global notification system and we might not need one, since for now all errors are "situational". Let's keep it like that for now.
} | ||
|
||
const fileExtension = this.getFileExtension(file) | ||
switch (fileExtension) { |
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.
One improvement here would be to use DuckDB spatial WASM, to be able to load any kind of spatial dataset.
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.
Great work!
Thanks for addressing the comments. I found one more little thing, but I will already approve 👍
} | ||
|
||
setTimeout(() => { | ||
if (type === 'success') { |
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 condition might not be necessary, you can just set the values to null (as discussed).
7a58228
to
ffc87e2
Compare
This pull request adds the feature that allows users to add a layer from a GeoJSON file to their map.
add-layer-from-file
component insrc/app/components/add-layer-from-file/add-layer-from-file.component.ts
Task List:
Screenshots:
#756