-
Notifications
You must be signed in to change notification settings - Fork 68
Add admin panel enhancements according to #3283 #618
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
Open
xkello
wants to merge
5
commits into
develop
Choose a base branch
from
implement-3283
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cda6585
Add admin panel enhancements according to #3283
xkello 9a88a5a
Update code with use of reusables, fix some checks
xkello 414817f
Fix some prettier issues
xkello 59902de
Merge remote-tracking branch 'origin/develop' into implement-3283
xkello 005bfc0
Update compiled type declarations for useDataTableSearch and TableDat…
xkello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ | |
| <PInputText | ||
| placeholder="Search accounts" | ||
| data-cy="search-members-field" | ||
| v-model="searchByName" | ||
| v-model="search" | ||
| class="w-full" | ||
| @input="onSearch" | ||
| /> | ||
|
|
@@ -44,48 +44,34 @@ | |
| :first="(options.page - 1) * options.itemsPerPage" | ||
| :sort-field="options.sortBy[0]" | ||
| :sort-order="options.sortDesc[0] ? -1 : 1" | ||
| :rowHover="true" | ||
| removableSort | ||
| reorderable-columns | ||
| @page="onPage" | ||
| @row-click="rowClick" | ||
| @sort="onSort" | ||
| data-cy="accounts-table" | ||
| > | ||
| <template v-for="header in headers" :key="header.field"> | ||
| <PColumn | ||
| v-if="header.field === 'username'" | ||
| :field="header.field" | ||
| :header="header.header" | ||
| :sortable="header.sortable" | ||
| > | ||
| <template #body="slotProps"> | ||
| <template #body="{ data }"> | ||
| <router-link | ||
| class="title-t4" | ||
| :to="{ | ||
| name: 'account', | ||
| params: { username: slotProps.data.username } | ||
| }" | ||
| :to="accountRoute(data)" | ||
| class="dt-row-link" | ||
| :class="header.class" | ||
| > | ||
| {{ slotProps.data.username }} | ||
| <template v-if="header.type === 'boolean'">{{ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I preffer to look based on field attribute. Probably we can get rid of type boolean column. |
||
| fieldValue(data, header.field) ? 'Active' : 'Inactive' | ||
| }}</template> | ||
| <template v-else>{{ | ||
| fieldValue(data, header.field) | ||
| }}</template> | ||
| </router-link> | ||
| </template> | ||
| </PColumn> | ||
| <PColumn | ||
| v-else-if="header.field === 'active'" | ||
| :header="header.header" | ||
| :field="header.field" | ||
| > | ||
| <template #body="slotProps"> | ||
| <i v-if="slotProps.data.active" class="ti ti-check" /> | ||
| <i v-else class="ti ti-x" /> | ||
| </template> | ||
| </PColumn> | ||
| <PColumn | ||
| v-else | ||
| :field="header.field" | ||
| :header="header.header" | ||
| :sortable="header.sortable" | ||
| ></PColumn> | ||
| </template> | ||
| <template #paginatorstart> | ||
| <PButton | ||
|
|
@@ -106,112 +92,90 @@ | |
| <script lang="ts"> | ||
| import { | ||
| PaginatedUsersParams, | ||
| useDialogStore, | ||
| TableDataHeader, | ||
| useDataTableSearch, | ||
| useDialogStore, | ||
| AppContainer, | ||
| AppSection | ||
| } from '@mergin/lib' | ||
| import debounce from 'lodash/debounce' | ||
| import { mapActions, mapState } from 'pinia' | ||
| import { | ||
| DataTablePageEvent, | ||
| DataTableRowClickEvent, | ||
| DataTableSortEvent | ||
| } from 'primevue/datatable' | ||
| import get from 'lodash/get' | ||
| import { mapState } from 'pinia' | ||
| import { defineComponent } from 'vue' | ||
|
|
||
| import { AdminRoutes } from '@/modules' | ||
| import CreateUserForm from '@/modules/admin/components/CreateUserForm.vue' | ||
| import { useAdminStore } from '@/modules/admin/store' | ||
|
|
||
| const headers: TableDataHeader[] = [ | ||
| { | ||
| field: 'username', | ||
| header: 'Username', | ||
| sortable: true, | ||
| linked: true, | ||
| class: 'title-t4' | ||
| }, | ||
| { field: 'email', header: 'Email', sortable: true, linked: true }, | ||
| { field: 'profile.name', header: 'Full name', linked: true }, | ||
| { field: 'active', header: 'Active', linked: true, type: 'boolean' } | ||
| ] | ||
|
|
||
| export default defineComponent({ | ||
| name: 'AccountsTable', | ||
| components: { | ||
| AppContainer, | ||
| AppSection | ||
| }, | ||
| data() { | ||
| setup() { | ||
| const adminStore = useAdminStore() | ||
| const dialogStore = useDialogStore() | ||
|
|
||
| const tableSearch = useDataTableSearch({ | ||
| defaultSortBy: 'username', | ||
| defaultSortDesc: false | ||
| }) | ||
|
|
||
| tableSearch.setFetchFn((signal) => { | ||
| const { options, search } = tableSearch | ||
| const params: PaginatedUsersParams = { | ||
| page: options.page, | ||
| per_page: options.itemsPerPage | ||
| } | ||
| if (options.sortBy[0]) { | ||
| params.descending = options.sortDesc[0] | ||
| params.order_by = options.sortBy[0] | ||
| } | ||
| if (search.value) params.like = search.value.trim() | ||
| adminStore.fetchUsers({ params, signal }) | ||
| }) | ||
|
|
||
| return { | ||
| options: { | ||
| sortBy: ['username'], | ||
| sortDesc: [false], | ||
| itemsPerPage: 20, | ||
| page: 1, | ||
| perPageOptions: [20, 50, 100] | ||
| }, | ||
| searchByName: '', | ||
| headers: [ | ||
| { field: 'username', header: 'Username', sortable: true }, | ||
| { field: 'email', header: 'Email', sortable: true }, | ||
| { field: 'profile.name', header: 'Full name' }, | ||
| { field: 'active', header: 'Active' } | ||
| ] as TableDataHeader[] | ||
| ...tableSearch, | ||
| show: dialogStore.show.bind(dialogStore), | ||
| headers | ||
| } | ||
| }, | ||
| computed: { | ||
| ...mapState(useAdminStore, ['users', 'loading']) | ||
| }, | ||
| created() { | ||
| this.resetPaging = debounce(this.resetPaging, 1000) | ||
| this.fetchUsers({ params: this.getParams() }) | ||
| this.initFromQuery() | ||
| this.doFetch() | ||
| }, | ||
| methods: { | ||
| ...mapActions(useAdminStore, ['fetchUsers']), | ||
| ...mapActions(useDialogStore, ['show']), | ||
|
|
||
| onSearch() { | ||
| this.resetPaging() | ||
| this.fetchUsers({ params: this.getParams() }) | ||
| fieldValue(data: unknown, field: string) { | ||
| return get(data, field) | ||
| }, | ||
|
|
||
| async resetPaging() { | ||
| this.options.page = 1 | ||
| }, | ||
|
|
||
| getParams(): PaginatedUsersParams { | ||
| const params = { | ||
| page: this.options.page, | ||
| per_page: this.options.itemsPerPage | ||
| } as PaginatedUsersParams | ||
| if (this.options.sortBy[0]) { | ||
| params.descending = this.options.sortDesc[0] | ||
| params.order_by = this.options.sortBy[0] | ||
| } | ||
| if (this.searchByName) { | ||
| params.like = this.searchByName.trim() | ||
| } | ||
| return params | ||
| }, | ||
|
|
||
| onRefresh() { | ||
| this.fetchUsers({ params: this.getParams() }) | ||
| }, | ||
|
|
||
| onPage(event: DataTablePageEvent) { | ||
| this.options.page = event.page + 1 | ||
| this.options.itemsPerPage = event.rows | ||
| this.fetchUsers({ params: this.getParams() }) | ||
| }, | ||
|
|
||
| onSort(event: DataTableSortEvent) { | ||
| this.options.sortBy[0] = event.sortField?.toString() | ||
| this.options.sortDesc[0] = event.sortOrder < 1 | ||
| this.fetchUsers({ params: this.getParams() }) | ||
| }, | ||
|
|
||
| rowClick(event: DataTableRowClickEvent) { | ||
| this.$router.push({ | ||
| name: AdminRoutes.ACCOUNT, | ||
| params: { username: event.data.username } | ||
| }) | ||
| accountRoute(data) { | ||
| return { name: AdminRoutes.ACCOUNT, params: { username: data.username } } | ||
| }, | ||
|
|
||
| createUserDialog() { | ||
| const dialog = { maxWidth: 500, header: 'Create user' } | ||
| const listeners = { | ||
| success: () => { | ||
| this.resetPaging() | ||
| this.fetchUsers({ params: this.getParams() }) | ||
| this.options.page = 1 | ||
| this.doFetch() | ||
| } | ||
| } | ||
| this.show({ | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.