Compare commits

..
6 Commits
Author SHA1 Message Date
lana-k 2e3057908f fix lint 2026-10-17 19:49:03 +02:00
lana-k 381f33b9e2 0.32.1 2026-10-17 19:35:51 +02:00
lana-k a68f799fdf #143 clear btn tests 2026-10-17 19:35:24 +02:00
lana-k 835a88cbbb #142 fix tooltips 2026-10-17 19:31:22 +02:00
lana-k a210e77f51 #141 fix search panel layout, #143 add clear button to text input 2026-10-16 22:34:18 +02:00
lana-k df6ba00f2b #142 improve tooltips 2026-10-16 22:33:05 +02:00
8 changed files with 202 additions and 37 deletions
+1 -1
View File
@@ -108,7 +108,7 @@ module.exports = function (config) {
}, },
// start these browsers // start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['ChromiumHeadlessWebGL' /*, 'FirefoxHeadlessTouch'*/], browsers: ['ChromiumHeadlessWebGL', 'FirefoxHeadlessTouch'],
// Continuous Integration mode // Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits // if true, Karma captures browsers, runs the tests and exits
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "sqliteviz", "name": "sqliteviz",
"version": "0.32.0", "version": "0.32.1",
"license": "Apache-2.0", "license": "Apache-2.0",
"private": true, "private": true,
"type": "module", "type": "module",
+1
View File
@@ -10,4 +10,5 @@
border-radius: var(--border-radius-medium); border-radius: var(--border-radius-medium);
white-space: nowrap; white-space: nowrap;
z-index: 999; z-index: 999;
pointer-events: none;
} }
+60 -17
View File
@@ -15,15 +15,27 @@
:iconSize="20" :iconSize="20"
/> />
</div> </div>
<input <div :class="['text-field-container', { disabled }]">
type="text" <input
:placeholder="placeholder" type="text"
:class="{ error: errorMsg }" :placeholder="placeholder"
:style="{ width: width }" :class="{ error: errorMsg }"
:value="modelValue" :style="{ width: width }"
:disabled="disabled" :value="modelValue"
@input="$emit('update:modelValue', $event.target.value)" :disabled="disabled"
/> @input="$emit('update:modelValue', $event.target.value)"
/>
<button
v-if="showClearButton"
type="button"
:disabled="disabled"
class="clear-btn"
@click="$emit('update:modelValue', '')"
>
<i class="myicon myicon-clear" />
</button>
</div>
<div v-show="errorMsg" class="text-field-error">{{ errorMsg }}</div> <div v-show="errorMsg" class="text-field-error">{{ errorMsg }}</div>
</div> </div>
</template> </template>
@@ -42,22 +54,40 @@ export default {
width: String, width: String,
hint: String, hint: String,
maxHintWidth: { type: String, default: '149px' }, maxHintWidth: { type: String, default: '149px' },
disabled: Boolean disabled: Boolean,
showClearButton: Boolean
}, },
emits: ['update:modelValue'] emits: ['update:modelValue']
} }
</script> </script>
<style scoped> <style scoped>
input { .text-field-container {
background: var(--color-white); background: var(--color-white);
border: 1px solid var(--color-border); border: 1px solid var(--color-border);
color: var(--color-text-base);
border-radius: var(--border-radius-medium-2); border-radius: var(--border-radius-medium-2);
height: 36px; height: 36px;
padding: 0 8px; padding: 0 8px;
font-size: 13px; font-size: 13px;
box-sizing: border-box; box-sizing: border-box;
display: flex;
align-items: center;
}
.text-field-container.disabled {
background: var(--color-bg-light);
}
.text-field-container.error {
border-color: var(--color-text-error);
}
input {
background: inherit;
border: none;
color: var(--color-text-base);
height: 100%;
padding: 0;
display: block; display: block;
} }
@@ -70,15 +100,10 @@ input:focus {
} }
input:disabled { input:disabled {
background: var(--color-bg-light);
color: var(--color-text-light-2); color: var(--color-text-light-2);
cursor: default; cursor: default;
} }
input.error {
border-color: var(--color-text-error);
}
.text-field-label { .text-field-label {
font-size: 12px; font-size: 12px;
color: var(--color-text-base); color: var(--color-text-base);
@@ -121,4 +146,22 @@ input.error {
padding: 6px; padding: 6px;
box-sizing: border-box; box-sizing: border-box;
} }
.clear-btn {
background: transparent;
border: none;
padding: 0;
height: 20px;
width: 20px;
color: var(--color-border);
font-size: 20px;
}
.clear-btn i {
display: block;
}
.clear-btn:not(:disabled):hover {
color: var(--color-danger);
}
</style> </style>
+3 -1
View File
@@ -14,6 +14,7 @@
width="250px" width="250px"
placeholder="Search nodes..." placeholder="Search nodes..."
:errorMsg="regExpIsValid ? '' : 'Invalid regular expression'" :errorMsg="regExpIsValid ? '' : 'Invalid regular expression'"
showClearButton
class="query-input" class="query-input"
@keydown.enter.prevent="search" @keydown.enter.prevent="search"
@update:model-value="onSearchInput" @update:model-value="onSearchInput"
@@ -199,6 +200,7 @@ export default {
border-style: solid; border-style: solid;
border-color: var(--color-border-light); border-color: var(--color-border-light);
border-radius: 0 0 0 4px; border-radius: 0 0 0 4px;
display: flex;
} }
.graph-search-panel--search-controls { .graph-search-panel--search-controls {
@@ -213,7 +215,7 @@ export default {
.close-search-panel :deep(i) { .close-search-panel :deep(i) {
transform: scaleX(-1); transform: scaleX(-1);
} }
.query-input :deep(input) { .query-input :deep(.text-field-container) {
height: 26px; height: 26px;
} }
+21 -17
View File
@@ -3,7 +3,8 @@ export default {
return { return {
tooltipStyle: { tooltipStyle: {
visibility: 'hidden' visibility: 'hidden'
} },
showTooltipTimeout: null
} }
}, },
computed: { computed: {
@@ -13,27 +14,30 @@ export default {
}, },
methods: { methods: {
showTooltip(e, tooltipPosition) { showTooltip(e, tooltipPosition) {
const position = tooltipPosition this.showTooltipTimeout = setTimeout(() => {
? tooltipPosition.split('-') const position = tooltipPosition
: ['top', 'right'] ? tooltipPosition.split('-')
const offset = 12 : ['top', 'right']
const offset = 12
if (position[0] === 'top') { if (position[0] === 'top') {
this.tooltipStyle.top = e.clientY - offset + 'px' this.tooltipStyle.top = e.clientY - offset + 'px'
} else { } else {
this.tooltipStyle.top = e.clientY + offset + 'px' this.tooltipStyle.top = e.clientY + offset + 'px'
} }
if (position[1] === 'right') { if (position[1] === 'right') {
this.tooltipStyle.left = e.clientX + offset + 'px' this.tooltipStyle.left = e.clientX + offset + 'px'
} else { } else {
this.tooltipStyle.left = this.tooltipStyle.left =
e.clientX - offset - this.tooltipElement.offsetWidth + 'px' e.clientX - offset - this.tooltipElement.offsetWidth + 'px'
} }
this.tooltipStyle.visibility = 'visible' this.tooltipStyle.visibility = 'visible'
}, 500)
}, },
hideTooltip() { hideTooltip() {
this.showTooltipTimeout && clearTimeout(this.showTooltipTimeout)
this.tooltipStyle.visibility = 'hidden' this.tooltipStyle.visibility = 'hidden'
} }
} }
+99
View File
@@ -0,0 +1,99 @@
import { expect } from 'chai'
import { mount } from '@vue/test-utils'
import TextField from '@/components/Common/TextField'
describe('TextField.vue', () => {
it('renders the model value, placeholder, and configured width', () => {
const wrapper = mount(TextField, {
props: {
modelValue: 'initial value',
placeholder: 'Enter a value',
width: '240px'
}
})
const input = wrapper.find('input')
expect(input.element.value).to.equal('initial value')
expect(input.attributes('placeholder')).to.equal('Enter a value')
expect(input.element.style.width).to.equal('240px')
expect(wrapper.find('.text-field-label').exists()).to.equal(false)
expect(wrapper.find('.clear-btn').exists()).to.equal(false)
})
it('emits update:modelValue when the input changes', async () => {
const wrapper = mount(TextField, {
props: { modelValue: 'before' }
})
await wrapper.find('input').setValue('after')
expect(wrapper.emitted('update:modelValue')).to.eql([['after']])
})
it('renders label and hint with the configured tooltip width', () => {
const wrapper = mount(TextField, {
props: {
label: 'Name',
hint: 'A helpful hint',
maxHintWidth: '200px'
}
})
expect(wrapper.find('.text-field-label').text()).to.include('Name')
expect(wrapper.find('.icon-tooltip').text()).to.equal('A helpful hint')
expect(wrapper.find('.icon-tooltip').element.style.maxWidth).to.equal(
'200px'
)
})
it('shows the error message and applies error classes', () => {
const wrapper = mount(TextField, {
props: {
label: 'Name',
errorMsg: 'A value is required'
}
})
expect(wrapper.find('.text-field-label').classes()).to.include('error')
expect(wrapper.find('input').classes()).to.include('error')
expect(wrapper.find('.text-field-error').isVisible()).to.equal(true)
expect(wrapper.find('.text-field-error').text()).to.equal(
'A value is required'
)
})
it('hides the error message when there is no error', () => {
const wrapper = mount(TextField)
expect(wrapper.find('.text-field-error').element.style.display).to.equal(
'none'
)
})
it('emits an empty value when the clear button is clicked', async () => {
const wrapper = mount(TextField, {
props: { modelValue: 'to clear', showClearButton: true }
})
await wrapper.find('.clear-btn').trigger('click')
expect(wrapper.emitted('update:modelValue')).to.eql([['']])
})
it('disables the input and clear button', () => {
const wrapper = mount(TextField, {
props: {
disabled: true,
label: 'Name',
showClearButton: true
}
})
expect(wrapper.find('input').element.disabled).to.equal(true)
expect(wrapper.find('.clear-btn').element.disabled).to.equal(true)
expect(wrapper.find('.text-field-container').classes()).to.include(
'disabled'
)
expect(wrapper.find('.text-field-label').classes()).to.include('disabled')
})
})
+16
View File
@@ -1,6 +1,7 @@
import { expect } from 'chai' import { expect } from 'chai'
import { mount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import tooltipMixin from '@/tooltipMixin' import tooltipMixin from '@/tooltipMixin'
import sinon from 'sinon'
describe('tooltipMixin.js', () => { describe('tooltipMixin.js', () => {
let container let container
@@ -23,6 +24,7 @@ describe('tooltipMixin.js', () => {
}) })
it('tooltipStyle is correct when showTooltip: top-right', async () => { it('tooltipStyle is correct when showTooltip: top-right', async () => {
const clock = sinon.useFakeTimers()
const component = { const component = {
template: template:
'<div :style="{...tooltipStyle, width: \'100px\'}" ref="tooltip"></div>', '<div :style="{...tooltipStyle, width: \'100px\'}" ref="tooltip"></div>',
@@ -38,15 +40,18 @@ describe('tooltipMixin.js', () => {
clientY: 20 clientY: 20
}) })
) )
await clock.tick(500)
expect(wrapper.vm.tooltipStyle).to.eql({ expect(wrapper.vm.tooltipStyle).to.eql({
visibility: 'visible', visibility: 'visible',
top: '8px', top: '8px',
left: '22px' left: '22px'
}) })
expect(wrapper.find('div').isVisible()).to.equal(true) expect(wrapper.find('div').isVisible()).to.equal(true)
clock.restore()
}) })
it('tooltipStyle is correct when showTooltip: top-left', async () => { it('tooltipStyle is correct when showTooltip: top-left', async () => {
const clock = sinon.useFakeTimers()
const component = { const component = {
template: template:
'<div :style="{...tooltipStyle, width: \'100px\'}" ref="tooltip"></div>', '<div :style="{...tooltipStyle, width: \'100px\'}" ref="tooltip"></div>',
@@ -61,6 +66,7 @@ describe('tooltipMixin.js', () => {
}), }),
'top-left' 'top-left'
) )
await clock.tick(500)
expect(wrapper.vm.tooltipStyle).to.eql({ expect(wrapper.vm.tooltipStyle).to.eql({
visibility: 'visible', visibility: 'visible',
@@ -69,9 +75,11 @@ describe('tooltipMixin.js', () => {
}) })
expect(wrapper.find('div').isVisible()).to.equal(true) expect(wrapper.find('div').isVisible()).to.equal(true)
clock.restore()
}) })
it('tooltipStyle is correct when showTooltip: bottom-right', async () => { it('tooltipStyle is correct when showTooltip: bottom-right', async () => {
const clock = sinon.useFakeTimers()
const component = { const component = {
template: template:
'<div :style="{...tooltipStyle, width: \'100px\'}" ref="tooltip"></div>', '<div :style="{...tooltipStyle, width: \'100px\'}" ref="tooltip"></div>',
@@ -86,15 +94,18 @@ describe('tooltipMixin.js', () => {
}), }),
'bottom-right' 'bottom-right'
) )
await clock.tick(500)
expect(wrapper.vm.tooltipStyle).to.eql({ expect(wrapper.vm.tooltipStyle).to.eql({
visibility: 'visible', visibility: 'visible',
top: '32px', top: '32px',
left: '22px' left: '22px'
}) })
expect(wrapper.find('div').isVisible()).to.equal(true) expect(wrapper.find('div').isVisible()).to.equal(true)
clock.restore()
}) })
it('tooltipStyle is correct when showTooltip: bottom-left', async () => { it('tooltipStyle is correct when showTooltip: bottom-left', async () => {
const clock = sinon.useFakeTimers()
const component = { const component = {
template: template:
'<div :style="{...tooltipStyle, width: \'100px\'}" ref="tooltip"></div>', '<div :style="{...tooltipStyle, width: \'100px\'}" ref="tooltip"></div>',
@@ -109,6 +120,7 @@ describe('tooltipMixin.js', () => {
}), }),
'bottom-left' 'bottom-left'
) )
await clock.tick(500)
expect(wrapper.vm.tooltipStyle).to.eql({ expect(wrapper.vm.tooltipStyle).to.eql({
visibility: 'visible', visibility: 'visible',
@@ -116,9 +128,11 @@ describe('tooltipMixin.js', () => {
left: '100px' left: '100px'
}) })
expect(wrapper.find('div').isVisible()).to.equal(true) expect(wrapper.find('div').isVisible()).to.equal(true)
clock.restore()
}) })
it('tooltip is not visible after hideTooltip', async () => { it('tooltip is not visible after hideTooltip', async () => {
const clock = sinon.useFakeTimers()
const component = { const component = {
template: '<div :style="tooltipStyle"></div>', template: '<div :style="tooltipStyle"></div>',
mixins: [tooltipMixin] mixins: [tooltipMixin]
@@ -131,6 +145,8 @@ describe('tooltipMixin.js', () => {
}) })
) )
await wrapper.vm.hideTooltip() await wrapper.vm.hideTooltip()
await clock.tick(500)
expect(wrapper.find('div').isVisible()).to.equal(false) expect(wrapper.find('div').isVisible()).to.equal(false)
clock.restore()
}) })
}) })