Skip to content

Commit

Permalink
feat: convert poistable to datatable #142
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Feb 12, 2024
1 parent 76b925e commit d2d8898
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
71 changes: 34 additions & 37 deletions components/PoisList/PoisTable.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script lang="ts">
import type { PropType } from 'vue'
import { defineNuxtComponent } from '#app'
import { VDataTable } from 'vuetify/labs/VDataTable'

Check failure on line 4 in components/PoisList/PoisTable.vue

View workflow job for this annotation

GitHub Actions / Lint code base (ubuntu-latest, 18)

'VDataTable' is defined but never used
import Field from '~/components/Fields/Field.vue'
import type { ApiPois, FieldsListItem } from '~/lib/apiPois'
import { PropertyTranslationsContextEnum } from '~/plugins/property-translations'
export default defineNuxtComponent({
export default {
components: {
Field,
},
Expand All @@ -23,59 +23,56 @@ export default defineNuxtComponent({
},
computed: {
headers(): { value: string, text: string }[] {
const h = this.fields.map(field => ({
value: field.field,
text: this.$propertyTranslations.p(
field.field,
context(): PropertyTranslationsContextEnum {
return PropertyTranslationsContextEnum.List
},
headers(): Array<{ title: string, value?: string, key?: string }> {
const headers = this.fields.map(f => ({
title: this.$propertyTranslations.p(
f.field,
PropertyTranslationsContextEnum.List,
),
value: f.field,
key: `properties.${f.field}`,
}))
h.push({ value: '', text: '' })
return h
},
context(): PropertyTranslationsContextEnum {
return PropertyTranslationsContextEnum.List
headers.push({ title: '', value: '', key: '' })
return headers
},
},
})
}
</script>

<template>
<table>
<thead>
<tr class="tw-bg-gray-100">
<th v-for="header in headers" :key="header.value" scope="col">
{{ header.text }}
</th>
</tr>
</thead>
<tbody v-if="pois.features">
<tr v-for="(feature, i) in pois.features" :key="i" :class="{ 'tw-bg-gray-100': i % 2 !== 0 }">
<v-data-table class="mt-4" :headers="headers" :items="pois.features" item-key="name" items-per-page="5" :no-data-text="$t('poisTable.empty')">
<template #item="{ item }">
<tr>
<td v-for="field in fields" :key="field.field" class="tw-align-top">
<Field
:context="context"
:recursion-stack="[field.field]"
:field="field"
:details="$t('poisTable.details')"
:properties="feature.properties"
:geom="feature.geometry"
:properties="item.selectable.properties"
:geom="item.selectable.geometry"
/>
</td>
<td class="tw-align-top">
<NuxtLink :to="`/poi/${feature.properties.metadata.id}/details`">
<td>
<NuxtLink :to="`/poi/${item.selectable.properties.metadata.id}/details`">
{{ $t('poisTable.details') }}
</NuxtLink>
</td>
</tr>
</tbody>
<tbody v-else>
<tr class="tw-text-center">
<td :colspan="headers.length">
{{ $t('poisTable.empty') }}
</td>
</tr>
</tbody>
</table>
</template>
</v-data-table>
</template>

<style scoped lang="scss">
/* stylelint-disable selector-class-pattern */
.v-data-table .v-table__wrapper > table thead {
background: blue
}
.v-data-table .v-table__wrapper > table tbody > tr:nth-child(even) > td {
background: #F3F4F6;
}
</style>
6 changes: 5 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ export default defineNuxtConfig({
async (_options, nuxt) => {
nuxt.hooks.hook('vite:extendConfig', config =>
// @ts-expect-error: Do we really need to extend the config ?
config.plugins.push(vuetify()))
config.plugins.push(vuetify({
autoImport: {
labs: true,
},
})))
},
],
runtimeConfig: {
Expand Down

0 comments on commit d2d8898

Please sign in to comment.