-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
♻️ Refactor frontend #165
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
♻️ Refactor frontend #165
Conversation
I'm still learning frontend development at the moment, could you or someone else explain why the test is failing? If we switch to eslint, do we still need tslint.json? When I do
Should this be happening? |
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 fixes the errors with testing.
To remove the warning Unknown custom element
which occured after fixing the test, I also edited upload-button.spec.ts to include the following after import "@/plugins/vuetify";
:
import Vue from 'vue'
import Vuetify from 'vuetify'
Vue.use(Vuetify)
Not sure how to/if it's possible to suggest these changes since it wasn't already edited in the PR.
Hi @Nonameentered, thank you very much for pointing out these issues! I too have just started front-end development, so I really appreciate someone peer-reviewing my changes.
You are right,
These shims are auto-generated by Regarding the changes you suggested, they all look valid. I will incorporate them into the pull request :) Thanks again! |
Suggested by fastapi#165 (review)
As pointed out in fastapi#165 (comment)
As pointed out in fastapi#165 (comment)
I think one way could be to do a Pull Request on the branch inside my fork, but not sure. |
Looks like the Manage Users page is broken in that you can't click to edit the user through the actions column. |
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.
Fixes Manage Users screen to get is_active, is_superuser, and actions working
{{cookiecutter.project_slug}}/frontend/src/views/main/admin/AdminUsers.vue
Outdated
Show resolved
Hide resolved
{{cookiecutter.project_slug}}/frontend/src/views/main/admin/AdminUsers.vue
Outdated
Show resolved
Hide resolved
{{cookiecutter.project_slug}}/frontend/src/views/main/admin/AdminUsers.vue
Outdated
Show resolved
Hide resolved
Ah yes, I've been meaning to address this issue, but hadn't found time to do so yet. Naming conventions in JavaScript mostly require For now though, your changes are correct. |
Hi @tiangolo, any plan to merge this pr? Or should we add it to our fork? |
@Nonameentered why did you used |
I think vue-cli deliberately uses |
Ok, maybe I mentioned the wrong user ^^ Anyway I got the right person, why don't we replace the |
I think vue-cli wants you to use The safest approach I think is just to upgrade vue-cli every once in a while and update the template. |
@cbhagl didn't know that, thanks for the clarification. |
{{cookiecutter.project_slug}}/frontend/src/store/modules/admin.ts
Outdated
Show resolved
Hide resolved
{{cookiecutter.project_slug}}/frontend/src/views/main/admin/EditUser.vue
Outdated
Show resolved
Hide resolved
{{cookiecutter.project_slug}}/frontend/src/views/main/admin/EditUser.vue
Show resolved
Hide resolved
</v-btn> | ||
</v-tooltip> | ||
</td> | ||
<template v-slot:item.is_active="{ item }"> |
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.
My editor (VS-Code) gives me the following error: 'v-slot' directive doesn't support any modifier
. I googled this and found the following answer: https://stackoverflow.com/a/63309643
Which solved this "issue" for me.
Except of this project I never programmed in JS, therefore I don't know the exact reason and if this solution is appropriate. However, I changed my code to look like this (I hate red warnings 😛):
<v-data-table :headers="headers" :items="users">
<template v-slot:[`item.is_active`]="{ item }">
<v-icon v-if="item.is_active">mdi-check</v-icon>
</template>
<template v-slot:[`item.is_superuser`]="{ item }">
<v-icon v-if="item.is_superuser">mdi-check</v-icon>
</template>
<template v-slot:[`item.actions`]="{ item }">
<v-icon @click="routeEditUser(item.id)">mdi-pencil</v-icon>
</template>
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.
What version of eslint are you using?
VScode probably complains because either the language server is unhappy or a linter emits a warning. In this case I think it is the latter (eslint) and the warning you are describing must be a new default, because I did not see this before.
From my understanding of Vue this is indeed valid syntax and would fix the warning. However, I think it is kind of ugly in this case and maybe suppressing the warning (either via inline comment or global setting) would be better?
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.
My version is v6.8.0
and indeed, the "correct" syntax isn't that beautiful. I'll provide a request change with the corresponding ignore comment.
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.
Somehow adding <!-- eslint-disable-next-line vue/valid-v-slot -->
does not help here... I don't know what I'm missing here.
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.
Seems like others run into this problem as well: vuejs/eslint-plugin-vue#260 (comment)
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.
Have you tried <!-- eslint-disable-next-line eslint-plugin-vue/valid-v-slot -->
or <!-- eslint-disable-next-line @vue/valid-v-slot -->
?
EDIT: Just realized that this doesn't make sense and shouldn't work...
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.
Ok, I checked if a update of everything to the latest version fixes this and it did not. But I also opened the project in PyCharm Professional and the error was not linted at all. So it seems to me, that this is a problem of VS-Code? Anyway, as this problem is not present in all editors I wouldn't change 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.
Try running eslint
directly on the file (via command-line) and see if the error appears. Correctly configured editors will generally output the same warnings as they are just displaying what either the vue language server or (in our case) eslint say. I think the error you are seeing is some new default rule (ie. vue/valid-v-slot) that eslint-plugin-vue complains about and there is an bug in the plugin that prohibits correctly disabling it.
{{cookiecutter.project_slug}}/frontend/src/store/modules/main.ts
Outdated
Show resolved
Hide resolved
{{cookiecutter.project_slug}}/frontend/src/store/modules/main.ts
Outdated
Show resolved
Hide resolved
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.
Build fails because response
is now unused.
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.
Fix build errors.
{{cookiecutter.project_slug}}/frontend/src/store/modules/main.ts
Outdated
Show resolved
Hide resolved
* ♻️ Migrate to latest Vuetify 2.x API, for details see migration guide (https://vuetifyjs.com/en/getting-started/releases-and-migrations/#migration-guide) * ♻️ Migrate to latest Vee-Validate 3.x API, for details see migration guide (https://logaretm.github.io/vee-validate/migration.html#migration-guide) * ➕ Refactor state management with vuex-module-decorators (https://github.com/championswimmer/vuex-module-decorators), which is similar in style to vue-class-components * ✨ Add configuration for eslint (+prettier, +typescript) * 🎨 Reformat code with `eslint --fix` * 📌 Upgrade/add relevant dependencies Thanks @Nonameentered and @Biskit1943 for reviewing the code and fixing some errors!
6867de1
to
dd875d5
Compare
I refactored my project by hand using your code here as a guide and it worked splendidly. Excellent work! Thank you. |
Thanks for all the work here @cbhagl! 🙇 I wanted to refactor the frontend and move to React with TypeScript and hooks, etc. It's now been done in other PRs, so I'll pass on this one. But thanks for all the effort! 🍰 |
Hi,
thanks for the great work on FastAPI and this template. We are using it in my team at Hella Aglaia Mobile Vision GmbH to build an internal tool for our machine learning services.
While working with the frontend template, I have noticed that some of the dependencies are outdated, so I started refactoring the frontend to bring everything up-to-date. Here's what I did.
eslint --fix
Maybe there is interest in these changes.
Cheers