-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix OXD list table highlighting issue (#738)
* TEC-165: Fix OXD list table highlighting issue * TEC-165: Add clickable, localization cells to OXD list table * TEC-165: Fix focus first directive to exclude disabled inputs
- Loading branch information
Chamara Abesinghe
authored
Nov 22, 2023
1 parent
d91a2f5
commit 854bea7
Showing
11 changed files
with
263 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -7,4 +7,5 @@ module.exports = { | |
moduleNameMapper: { | ||
'^!!raw-loader!(.*)$': '$1', | ||
}, | ||
setupFiles: ['<rootDir>/jest.init.js'], | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {config} from '@vue/test-utils'; | ||
|
||
config.global.mocks = { | ||
$t: text => text, | ||
}; |
108 changes: 108 additions & 0 deletions
108
components/src/composables/__tests__/useFlashing.spec.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import {defineComponent} from 'vue'; | ||
import {mount} from '@vue/test-utils'; | ||
import useFlashing, {getDiff} from '../useFlashing'; | ||
|
||
const TestComponent = defineComponent({ | ||
props: ['loading', 'flashing', 'items', 'order'], | ||
setup(props, context) { | ||
return { | ||
flashIndexes: useFlashing(props, context), | ||
}; | ||
}, | ||
template: `<pre>{{flashIndexes}}</pre>`, | ||
}); | ||
|
||
describe('useFlashing composable', () => { | ||
it('useFlashing::getDiff should detect when item added to array', () => { | ||
const original = [ | ||
{id: 1, name: 'Orange'}, | ||
{id: 2, name: 'Apple'}, | ||
{id: 3, name: 'Cherry'}, | ||
]; | ||
|
||
const updated = [...original, {id: 4, name: 'Banana'}]; | ||
expect(getDiff(updated, original)).toStrictEqual([3]); | ||
}); | ||
it('useFlashing::getDiff should detect when item updated in array', () => { | ||
const original = [ | ||
{id: 1, name: 'Orange'}, | ||
{id: 2, name: 'Apple'}, | ||
{id: 3, name: 'Cherry'}, | ||
]; | ||
|
||
const updated = JSON.parse(JSON.stringify(original)); | ||
updated[2].name = 'Guava'; | ||
expect(getDiff(updated, original)).toStrictEqual([2]); | ||
}); | ||
it('useFlashing::getDiff should not detect when items reordered in array', () => { | ||
const original = [ | ||
{id: 1, name: 'Orange'}, | ||
{id: 2, name: 'Apple'}, | ||
{id: 3, name: 'Cherry'}, | ||
]; | ||
|
||
const updated = [...original].reverse(); | ||
expect(getDiff(updated, original)).toStrictEqual([]); | ||
}); | ||
it('useFlashing::getDiff should not detect when items removed in array', () => { | ||
const original = [ | ||
{id: 1, name: 'Orange'}, | ||
{id: 2, name: 'Apple'}, | ||
{id: 3, name: 'Cherry'}, | ||
]; | ||
|
||
const updated = [...original]; | ||
updated.pop(); | ||
expect(getDiff(updated, original)).toStrictEqual([]); | ||
}); | ||
|
||
it('useFlashing should detect changes', async () => { | ||
const wrapper = mount(TestComponent, { | ||
props: { | ||
flashing: true, | ||
}, | ||
}); | ||
await wrapper.setProps({ | ||
items: [ | ||
{id: 1, name: 'Orange'}, | ||
{id: 2, name: 'Apple'}, | ||
{id: 3, name: 'Cherry'}, | ||
], | ||
}); | ||
expect(wrapper.vm.flashIndexes).toStrictEqual([]); | ||
await wrapper.setProps({ | ||
items: [ | ||
{id: 1, name: 'Orange'}, | ||
{id: 2, name: 'Apple'}, | ||
{id: 3, name: 'Cherry'}, | ||
{id: 4, name: 'Guava'}, | ||
], | ||
}); | ||
expect(wrapper.vm.flashIndexes).toStrictEqual([3]); | ||
}); | ||
|
||
it('useFlashing should not detect changes if flashing disabled', async () => { | ||
const wrapper = mount(TestComponent, { | ||
props: { | ||
flashing: false, | ||
}, | ||
}); | ||
await wrapper.setProps({ | ||
items: [ | ||
{id: 1, name: 'Orange'}, | ||
{id: 2, name: 'Apple'}, | ||
{id: 3, name: 'Cherry'}, | ||
], | ||
}); | ||
expect(wrapper.vm.flashIndexes).toStrictEqual([]); | ||
await wrapper.setProps({ | ||
items: [ | ||
{id: 1, name: 'Orange'}, | ||
{id: 2, name: 'Apple'}, | ||
{id: 3, name: 'Cherry'}, | ||
{id: 4, name: 'Guava'}, | ||
], | ||
}); | ||
expect(wrapper.vm.flashIndexes).toStrictEqual([]); | ||
}); | ||
}); |
This file contains 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 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
77 changes: 77 additions & 0 deletions
77
components/src/core/components/ListTable/ClickableCell.vue
This file contains 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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<template> | ||
<div :class="classes" @click.stop="onClick"> | ||
<oxd-skeleton v-if="loading" animate></oxd-skeleton> | ||
<template v-else>{{ item }}</template> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import {defineComponent} from 'vue'; | ||
import Skeleton from '@orangehrm/oxd/core/components/Skeleton/Skeleton.vue'; | ||
export default defineComponent({ | ||
name: 'oxd-table-cell-clickable', | ||
components: { | ||
'oxd-skeleton': Skeleton, | ||
}, | ||
props: { | ||
header: { | ||
type: Object, | ||
default: () => ({}), | ||
}, | ||
rowItem: { | ||
type: Object, | ||
default: () => ({}), | ||
}, | ||
item: { | ||
type: [Number, String, Object], | ||
default: () => null, | ||
}, | ||
loading: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
computed: { | ||
isDisabled(): boolean { | ||
const isRowDisabled = | ||
this.rowItem?.isDisabled === undefined | ||
? false | ||
: Boolean(this.rowItem.isDisabled); | ||
const isTableDisabled = | ||
this.tableProps?.disabled === undefined | ||
? false | ||
: Boolean(this.tableProps.disabled); | ||
return isTableDisabled ? isTableDisabled : isRowDisabled; | ||
}, | ||
classes(): object { | ||
return { | ||
'oxd-table-card-cell': true, | ||
'--clickable': !this.isDisabled && !this.loading, | ||
}; | ||
}, | ||
}, | ||
methods: { | ||
onClick(e: MouseEvent) { | ||
if (this.isDisabled) return; | ||
const cellConfig = this.header?.cellConfig; | ||
if (cellConfig && typeof cellConfig?.onClick === 'function') { | ||
this.header.cellConfig.onClick(this.rowItem, e); | ||
} | ||
}, | ||
}, | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.oxd-table-card-cell { | ||
&.--clickable { | ||
cursor: pointer; | ||
width: fit-content; | ||
} | ||
} | ||
</style> |
This file contains 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
41 changes: 41 additions & 0 deletions
41
components/src/core/components/ListTable/LocalizedCell.vue
This file contains 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<template> | ||
<div class="oxd-table-card-cell"> | ||
<oxd-skeleton v-if="loading" animate></oxd-skeleton> | ||
<template v-else>{{ $vt(item) }}</template> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import {defineComponent} from 'vue'; | ||
import translateMixin from '../../../mixins/translate'; | ||
import Skeleton from '@orangehrm/oxd/core/components/Skeleton/Skeleton.vue'; | ||
export default defineComponent({ | ||
name: 'oxd-table-cell-localized', | ||
components: { | ||
'oxd-skeleton': Skeleton, | ||
}, | ||
mixins: [translateMixin], | ||
props: { | ||
header: { | ||
type: Object, | ||
default: () => ({}), | ||
}, | ||
rowItem: { | ||
type: Object, | ||
default: () => ({}), | ||
}, | ||
item: { | ||
type: [Number, String], | ||
default: () => null, | ||
}, | ||
loading: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}, | ||
}); | ||
</script> |
This file contains 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 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