From 28e55574e6df1897c7da296eafe318fc6cde2412 Mon Sep 17 00:00:00 2001
From: Julien Nahum
Date: Sun, 28 Jan 2024 19:53:49 +0100
Subject: [PATCH] Fix OpenTable performances
---
client/.env.docker | 8 +-
client/components/open/tables/OpenTable.vue | 291 ++++++------------
.../open/tables/components/OpenSelect.vue | 8 +-
.../open/tables/components/OpenText.vue | 85 +----
.../open/tables/components/ResizableTh.vue | 43 ++-
5 files changed, 121 insertions(+), 314 deletions(-)
diff --git a/client/.env.docker b/client/.env.docker
index 56ca9f2..e38db1f 100644
--- a/client/.env.docker
+++ b/client/.env.docker
@@ -1,13 +1,13 @@
NUXT_LOG_LEVEL=
NUXT_PUBLIC_APP_URL=http://localhost/
NUXT_PUBLIC_API_BASE=http://localhost/api
-NUXT_PUBLIC_AI_ENABLED=
+NUXT_PUBLIC_AI_ENABLED=false
NUXT_PUBLIC_AMPLITUDE_CODE=
NUXT_PUBLIC_CRISP_WEBSITE_ID=
-NUXT_PUBLIC_CUSTOM_DOMAINS_ENABLED=
+NUXT_PUBLIC_CUSTOM_DOMAINS_ENABLED=false
NUXT_PUBLIC_ENV=local
NUXT_PUBLIC_GOOGLE_ANALYTICS_CODE=
NUXT_PUBLIC_H_CAPTCHA_SITE_KEY=
-NUXT_PUBLIC_PAID_PLANS_ENABLED=
-NUXT_PUBLIC_S3_ENABLED=
+NUXT_PUBLIC_PAID_PLANS_ENABLED=false
+NUXT_PUBLIC_S3_ENABLED=false
NUXT_API_SECRET=
diff --git a/client/components/open/tables/OpenTable.vue b/client/components/open/tables/OpenTable.vue
index 51c68f5..6e22b0a 100644
--- a/client/components/open/tables/OpenTable.vue
+++ b/client/components/open/tables/OpenTable.vue
@@ -7,72 +7,70 @@
:class="{'absolute': data.length !== 0}"
style="will-change: transform; transform: translate3d(0px, 0px, 0px)"
>
-
-
+
+
-
- {{ col.name }}
-
-
-
-
- Actions
-
- |
-
+ {{ col.name }}
+
+
+
+
+ Actions
+
+ |
+
-
-
-
- |
-
-
-
+ |
+
+ |
+
+
+
-
- |
-
-
- |
-
-
-
-
- |
-
+ >
+
+
+
+
+ |
+
+
+
+
+ |
+
-
-
-
-
- No data found.
-
- |
-
+
+
+
+
+ No data found.
+
+ |
+
@@ -90,7 +88,7 @@ import clonedeep from 'clone-deep'
import {hash} from "~/lib/utils.js";
export default {
- components: { ResizableTh, RecordOperations },
+ components: {ResizableTh, RecordOperations},
props: {
columns: {
type: Array,
@@ -111,77 +109,64 @@ export default {
}
},
- setup () {
+ setup() {
const workingFormStore = useWorkingFormStore()
return {
- workingFormStore
+ workingFormStore,
+ form: storeToRefs(workingFormStore).content,
}
},
- data () {
+ data() {
return {
tableHash: null,
- skip: false
- }
- },
-
- computed: {
- form: {
- get () {
- return this.workingFormStore.content
- },
- /* We add a setter */
- set (value) {
- this.workingFormStore.set(value)
- }
- },
- hasActions () {
- // In future if want to hide based on condition
- return true
- },
- fieldComponents () {
- return {
- text: OpenText,
- number: OpenText,
- select: OpenSelect,
- multi_select: OpenSelect,
- date: OpenDate,
- files: OpenFile,
- checkbox: OpenCheckbox,
- url: OpenUrl,
- email: OpenText,
- phone_number: OpenText,
- signature: OpenFile
+ skip: false,
+ hasActions: true,
+ internalColumns: [],
+ fieldComponents: {
+ text: shallowRef(OpenText),
+ number: shallowRef(OpenText),
+ select: shallowRef(OpenSelect),
+ multi_select: shallowRef(OpenSelect),
+ date: shallowRef(OpenDate),
+ files: shallowRef(OpenFile),
+ checkbox: shallowRef(OpenCheckbox),
+ url: shallowRef(OpenUrl),
+ email: shallowRef(OpenText),
+ phone_number: shallowRef(OpenText),
+ signature: shallowRef(OpenFile)
}
}
},
watch: {
'columns': {
- handler () {
+ handler() {
+ this.internalColumns = clonedeep(this.columns)
this.onStructureChange()
},
deep: true
},
- data () {
+ data() {
this.$nextTick(() => {
this.handleScroll()
})
}
},
- mounted () {
+ mounted() {
+ this.internalColumns = clonedeep(this.columns)
const parent = document.getElementById('table-page')
this.tableHash = hash(JSON.stringify(this.form.properties))
if (parent) {
- parent.addEventListener('scroll', this.handleScroll, { passive: true })
+ parent.addEventListener('scroll', this.handleScroll, {passive: true})
}
window.addEventListener('resize', this.handleScroll)
this.onStructureChange()
this.handleScroll()
},
- beforeUnmount () {
+ beforeUnmount() {
const parent = document.getElementById('table-page')
if (parent) {
parent.removeEventListener('scroll', this.handleScroll)
@@ -190,7 +175,7 @@ export default {
},
methods: {
- colClasses (col) {
+ colClasses(col) {
let colAlign, colColor, colFontWeight, colWrap
// Column align
@@ -215,12 +200,12 @@ export default {
return [colAlign, colColor, colWrap, colFontWeight]
},
- onStructureChange () {
- if (this.columns) {
+ onStructureChange() {
+ if (this.internalColumns) {
this.$nextTick(() => {
- this.columns.forEach(col => {
+ this.internalColumns.forEach(col => {
if (!col.hasOwnProperty('cell_width')) {
- if (this.allowResize && this.columns.length && document.getElementById('table-head-cell-' + col.id)) {
+ if (this.allowResize && this.internalColumns.length && document.getElementById('table-head-cell-' + col.id)) {
// Within editor
this.resizeCol(col, document.getElementById('table-head-cell-' + col.id).offsetWidth)
}
@@ -229,17 +214,16 @@ export default {
})
}
},
- resizeCol (col, width) {
+ resizeCol(col, width) {
if (!this.form) return
- const columns = clonedeep(this.columns)
- const index = this.columns.findIndex(c => c.id === col.id)
- columns[index].cell_width = width
- this.setColumns(columns)
+ const index = this.internalColumns.findIndex(c => c.id === col.id)
+ this.internalColumns[index].cell_width = width
+ this.setColumns(this.internalColumns)
this.$nextTick(() => {
this.$emit('resize')
})
},
- handleScroll () {
+ handleScroll() {
const parent = document.getElementById('table-page')
const posTop = parent.getBoundingClientRect().top
const tablePosition = Math.max(0, posTop - this.$refs.table.getBoundingClientRect().top)
@@ -269,7 +253,7 @@ export default {
}
},
setColumns(val) {
- this.$emit('update-columns',val)
+ this.$emit('update-columns', val)
}
}
}
@@ -299,87 +283,4 @@ export default {
min-width: 80px;
}
}
-
-.notion-table {
-
- td {
- &.text-gray {
- color: #787774;
- }
-
- &.text-brown {
- color: #9f6b53;
- }
-
- &.text-orange {
- color: #d9730d;
- }
-
- &.text-yellow {
- color: #cb912f;
- }
-
- &.text-green {
- color: #448361;
- }
-
- &.text-blue {
- color: #337ea9;
- }
-
- &.text-purple {
- color: #9065b0;
- }
-
- &.text-pink {
- color: #c14c8a;
- }
-
- &.text-red {
- color: #d44c47;
- }
- }
-}
-
-.dark {
- .notion-table {
- td {
- &.text-gray {
- color: #9b9b9b;
- }
-
- &.text-brown {
- color: #ba856f;
- }
-
- &.text-orange {
- color: #c77d48;
- }
-
- &.text-yellow {
- color: #ca9849;
- }
-
- &.text-green {
- color: #529e72;
- }
-
- &.text-blue {
- color: #5e87c9;
- }
-
- &.text-purple {
- color: #9d68d3;
- }
-
- &.text-pink {
- color: #d15796;
- }
-
- &.text-red {
- color: #df5452;
- }
- }
- }
-}
diff --git a/client/components/open/tables/components/OpenSelect.vue b/client/components/open/tables/components/OpenSelect.vue
index 2033628..92dc058 100644
--- a/client/components/open/tables/components/OpenSelect.vue
+++ b/client/components/open/tables/components/OpenSelect.vue
@@ -13,10 +13,7 @@ import OpenTag from './OpenTag.vue'
export default {
components: { OpenTag },
props: {
- value: {
- type: Object
- }
-
+ value: {}
},
data () {
@@ -31,8 +28,5 @@ export default {
return false
}
},
- mounted () {
- },
- methods: {}
}
diff --git a/client/components/open/tables/components/OpenText.vue b/client/components/open/tables/components/OpenText.vue
index 547c572..27cde12 100644
--- a/client/components/open/tables/components/OpenText.vue
+++ b/client/components/open/tables/components/OpenText.vue
@@ -1,41 +1,7 @@
-
+
{{ value }}
-
-
- {{ item.plain_text }}
- {{ item.plain_text }}
-
-
diff --git a/client/components/open/tables/components/ResizableTh.vue b/client/components/open/tables/components/ResizableTh.vue
index 232e088..8564e84 100644
--- a/client/components/open/tables/components/ResizableTh.vue
+++ b/client/components/open/tables/components/ResizableTh.vue
@@ -1,6 +1,6 @@
-
+
this.throttlePeriod) {
+ const dx = e.clientX - this.x
+ this.$emit('resize-width', this.w + dx)
+ this.lastEmit = now
}
},
- mouseMoveHandler (e) {
- // How far the mouse has been moved
- const dx = e.clientX - this.x
-
- // Adjust the dimension of element
- this.$emit('resize-width', this.w + dx)
- },
- mouseUpHandler () {
+ mouseUpHandler() {
// Remove the handlers of `mousemove` and `mouseup`
- if (process.client) {
- document.removeEventListener('mousemove', this.mouseMoveHandler)
- document.removeEventListener('mouseup', this.mouseUpHandler)
- }
+ document.removeEventListener('mousemove', this.mouseMoveHandler)
+ document.removeEventListener('mouseup', this.mouseUpHandler)
}
}
}
|