Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
fix: Reload records on depends tabs. (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt authored Jun 23, 2022
1 parent 5bbb016 commit 00996eb
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 16 deletions.
14 changes: 14 additions & 0 deletions src/store/modules/ADempiere/dictionary/window/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ export default {
return state.storedWindows[windowUuid].tabsList
},

/**
* Get tabs list form table name
* @param {string} parentUuid window uuid
* @param {string} tableName table name to get tabs on window
* @param {string} containerUuid optional, if exists exclude this tab
* @returns
*/
getStoredTabsFromTableName: (state) => ({ parentUuid, tableName, containerUuid = '' }) => {
return state.storedWindows[parentUuid].tabsList.filter(tab => {
return tab.tableName === tableName &&
tab.uuid !== containerUuid
})
},

getStoredTab: (state) => (windowUuid, tabUuid) => {
return state.storedWindows[windowUuid].tabsList.find(tab => {
return tab.uuid === tabUuid
Expand Down
73 changes: 66 additions & 7 deletions src/store/modules/ADempiere/windowManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ import {
} from '@/api/ADempiere/common/persistence.js'

// constants
import { UUID } from '@/utils/ADempiere/constants/systemColumns'
import { ROW_ATTRIBUTES } from '@/utils/ADempiere/constants/table'

// utils and helper methods
import { containerManager } from '@/utils/ADempiere/dictionary/window'
import { getContextAttributes } from '@/utils/ADempiere/contextUtils.js'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
import { convertObjectToKeyValue } from '@/utils/ADempiere/valueFormat'
import { showMessage } from '@/utils/ADempiere/notification'
import { generatePageToken } from '@/utils/ADempiere/dataUtils'

Expand Down Expand Up @@ -98,9 +101,11 @@ const windowManager = {
* @param {array} filters used as where clause
* @param {number} pageNumber
* @returns {promise} array entities list
* @returns {promise} array current entity
*/
getEntities({
commit,
dispatch,
getters,
rootGetters
}, {
Expand All @@ -111,16 +116,20 @@ const windowManager = {
pageNumber
}) {
return new Promise(resolve => {
const storedPage = getters.getTabPageNumber({
containerUuid
})
if (isEmptyValue(pageNumber)) {
// refresh with same page
pageNumber = getters.getTabPageNumber({
containerUuid
})
pageNumber = storedPage
}
const currentPageNumber = pageNumber
const pageToken = generatePageToken({ pageNumber })

const { contextColumnNames, name, linkColumnName, parentColumnName } = rootGetters.getStoredTab(parentUuid, containerUuid)
const {
contextColumnNames, name, linkColumnName,
parentColumnName, fieldsList
} = rootGetters.getStoredTab(parentUuid, containerUuid)

// add filters with link column name and parent column name
if (!isEmptyValue(linkColumnName) &&
Expand Down Expand Up @@ -177,6 +186,7 @@ const windowManager = {
containerUuid
})

const currentRoute = router.app._route
getEntities({
windowUuid: parentUuid,
tabUuid: containerUuid,
Expand All @@ -195,6 +205,52 @@ const windowManager = {
}
})

// update current record
if (!isEmptyValue(dataToStored)) {
let currentRow = dataToStored.at(0) // set first record
const recordUuid = rootGetters.getUuidOfContainer(containerUuid)
if (!isEmptyValue(recordUuid) && storedPage === pageNumber) {
const recordFromUuid = dataToStored.find(record => record[UUID] === recordUuid)
if (!isEmptyValue(recordFromUuid)) {
currentRow = recordFromUuid
}
}

// remove datatables app attributes
for (const key in ROW_ATTRIBUTES) {
delete currentRow[key]
}

const defaultValues = getters.getParsedDefaultValues({
parentUuid,
containerUuid,
isSOTrxMenu: currentRoute.meta.isSalesTransaction,
fieldsList,
formatToReturn: 'object'
})
const attributes = convertObjectToKeyValue({
object: {
...defaultValues,
...currentRow
}
})
dispatch('updateValuesOfContainer', {
parentUuid,
containerUuid,
attributes
})

// active logics with set records values
fieldsList.forEach(field => {
// change Dependents
dispatch('changeDependentFieldsList', {
field,
fieldsList,
containerManager
})
})
}

commit('setTabData', {
parentUuid,
containerUuid,
Expand All @@ -207,7 +263,8 @@ const windowManager = {

resolve(dataToStored)
})
.catch(() => {
.catch(error => {
console.warn(`Error get entites`, error.message)
commit('setTabData', {
parentUuid,
isLoaded: true,
Expand Down Expand Up @@ -322,7 +379,7 @@ const windowManager = {
* Used by result in tab
* @param {string} containerUuid
*/
getTabData: (state, getters) => ({ containerUuid }) => {
getTabData: (state) => ({ containerUuid }) => {
return state.tabData[containerUuid] || {
parentUuid: undefined,
containerUuid,
Expand All @@ -336,7 +393,9 @@ const windowManager = {
}
},
getIsLoadedTabRecord: (state, getters) => ({ containerUuid }) => {
return state.tabData[containerUuid].isLoaded
return getters.getTabData({
containerUuid
}).isLoaded || false
},
getTabRecordCount: (state, getters) => ({ containerUuid }) => {
return getters.getTabData({ containerUuid }).recordCount
Expand Down
26 changes: 25 additions & 1 deletion src/utils/ADempiere/dictionary/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,35 @@ export const refreshRecords = {
icon: 'el-icon-refresh',
actionName: 'refreshRecords',
refreshRecords: ({ parentUuid, containerUuid }) => {
// used to window
// refresh records on current tab
store.dispatch('getEntities', {
parentUuid,
containerUuid
})

// get tabs with same table to refresh without current tab
const tableName = store.getters.getTableName(parentUuid, containerUuid)
const tabsWithSameTable = store.getters.getStoredTabsFromTableName({
parentUuid,
containerUuid,
tableName
})
// update records on tabs with same table
if (!isEmptyValue(tabsWithSameTable)) {
tabsWithSameTable.forEach(tab => {
const isLoaded = store.getters.getIsLoadedTabRecord({
containerUuid: tab.uuid
})
// if loaded data refresh this data
// TODO: Verify with one entity, not all list
if (isLoaded) {
store.dispatch('getEntities', {
parentUuid,
containerUuid: tab.uuid
})
}
})
}
}
}

Expand Down
33 changes: 25 additions & 8 deletions src/views/ADempiere/Window/MultiTabWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,21 @@ export default defineComponent({
})
return
}
const tab = store.getters.getStoredTab(parentUuid, containerUuid)
if (tab.isParentTab) {
const tabDefinition = store.getters.getStoredTab(parentUuid, containerUuid)
if (tabDefinition.isParentTab) {
const { tableName } = tabDefinition
router.push({
name: root.$route.name,
query: {
...root.$route.query,
action: row.UUID,
tableName: tab.tableName,
recordId: row[`${tab.tableName}_ID`]
tableName,
recordId: row[`${tableName}_ID`]
},
params: {
...root.$route.params,
tableName: tab.tableName,
recordId: row[`${tab.tableName}_ID`]
tableName,
recordId: row[`${tableName}_ID`]
}
}, () => {})
}
Expand All @@ -211,7 +212,7 @@ export default defineComponent({
parentUuid,
containerUuid,
attributes,
isOverWriteParent: tab.isParentTab
isOverWriteParent: tabDefinition.isParentTab
})

// active logics with set records values
Expand All @@ -223,9 +224,25 @@ export default defineComponent({
containerManager: props.windowManager
})
})
}

// update records and logics on child tabs
tabDefinition.childTabs.filter(tabItem => {
// get loaded tabs with records
return store.getters.getIsLoadedTabRecord({
containerUuid: tabItem.uuid
})
}).forEach(tabItem => {
// if loaded data refresh this data
// TODO: Verify with get one entity, not get all list
store.dispatch('getEntities', {
parentUuid,
containerUuid: tabItem.uuid,
pageNumber: 1 // reload with first page
})
})
}
}

const actionsManager = computed(() => {
return {
parentUuid: props.windowMetadata.uuid,
Expand Down

0 comments on commit 00996eb

Please sign in to comment.