Skip to content
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

feat: ✨ update playground with virtualised table list #34

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified playground/bun.lockb
Binary file not shown.
62 changes: 42 additions & 20 deletions playground/src/components/DemoTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,23 @@ import { Button } from '@/components/ui/button'
import { All, Order, Select as SelectOrders, Create } from '@/sibyl'
import { computed, onMounted, ref } from 'vue'
import { faker } from '@faker-js/faker'
import { useVirtualList } from '@vueuse/core'
import type { SibylResponse } from '@crbroughton/sibyl'

const results = ref<SibylResponse<Order>[] | undefined>([])
const results = ref<SibylResponse<Order>[]>([])
const { list, wrapperProps, containerProps, scrollTo } = useVirtualList(results, {
itemHeight: 53,
})

const currencies = ref<string[]>([])
const selectedCurrency = ref('')
onMounted(() => {
results.value = All('orders')
const response = All('orders')

if (response !== undefined) {
results.value = response
}

function getCurrencies(orders: SibylResponse<Order>[]): string[] {
currencies.value.push('All')

Expand All @@ -53,27 +63,34 @@ if (results.value !== undefined) {

function filterOrders() {
if (selectedCurrency.value !== 'All') {
results.value = SelectOrders('orders', {
const response = SelectOrders('orders', {
where: {
currency: selectedCurrency.value
}
})
if (response !== undefined) {
results.value = response
}
} else {
results.value = All('orders')
const response = All('orders')
if (response !== undefined) {
results.value = response
}
}
scrollTo(0)
}

const tableClasses = computed(() => {
if (results.value!.length <= 15)
return ''
// const tableClasses = computed(() => {
// if (results.value!.length <= 15)
// return ''

if (results.value!.length === 1)
return ''
// if (results.value!.length === 1)
// return ''

if (results.value!.length > 0)
return 'block overflow-scroll h-96 min-h-96'
return ''
})
// if (results.value!.length > 0)
// return 'block overflow-scroll h-96 min-h-96'
// return ''
// })

function createNewEntry() {
Create('orders', {
Expand All @@ -83,7 +100,10 @@ function createNewEntry() {
price: faker.commerce.price(),
booleanTest: false,
})
results.value = All('orders')
const response = All('orders')
if (response !== undefined) {
results.value = response
}
}

const amountOfOrders = computed(() => {
Expand Down Expand Up @@ -120,7 +140,8 @@ const amountOfOrders = computed(() => {
</div>
</CardHeader>
<CardContent>
<Table class="mb-6" :class="tableClasses">
<div v-bind="containerProps" class="h-[380px]">
<Table v-bind="wrapperProps" class="mb-6 h-[380px]">
<TableHeader>
<TableRow>
<TableHead class="w-[25%]">
Expand All @@ -138,18 +159,19 @@ const amountOfOrders = computed(() => {
</TableRow>
</TableHeader>
<TableBody>
<TableRow v-for="row in results" :key="row.id">
<TableRow v-for="row in list" :key="row.index">
<TableCell class="font-medium">
{{ row.id }}
{{ row.data.id }}
</TableCell>
<TableCell>
{{ row.currency }}
{{ row.data.currency }}
</TableCell>
<TableCell>{{ row.product }}</TableCell>
<TableCell>{{ row.price }}</TableCell>
<TableCell>{{ row.data.product }}</TableCell>
<TableCell>{{ row.data.price }}</TableCell>
</TableRow>
</TableBody>
</Table>
</div>
<div>
<Button @click="createNewEntry">
Create New Entry
Expand Down
2 changes: 1 addition & 1 deletion playground/src/sibyl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ createTable('orders', {
})

const insertions: Order[] = []
for (let index = 0; index < 1000; index++) {
for (let index = 0; index < 10000; index++) {
insertions.push({
id: faker.number.int(),
product: faker.commerce.product(),
Expand Down
Loading