Skip to content

Commit

Permalink
DataManager more configuration, preload, not update when entering (#750)
Browse files Browse the repository at this point in the history
* DataManager more configuration, preload, not update when entering

* update version

* update version

* update params

* update emit message
  • Loading branch information
yumiguan authored Apr 6, 2023
1 parent 5ee9d76 commit 3582821
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 22 deletions.
2 changes: 1 addition & 1 deletion frontend/src/plugins/vuetify.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const opts = {

error: '#FF4B4B',
warning: '#FB8C00',
info: '#ffc107',
info: '#2196F3',
success: '#4CAF50',

accent: '#000520',
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/store/datamanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default {
deleteNode: [],
dataListSelectedLabel: [],
isLabelDisplay: true,
isCloseReloadWhenEnter: false,
isReloadTreeWhenUpdate: false,
undisplayedKey: ['children', 'type', 'parent_id', 'abs_parent_path', 'parent'],
undeletableKey: ['id', 'rule', 'name', 'label', 'category', 'super_by'],
Expand Down Expand Up @@ -144,6 +145,9 @@ export default {
setIsLabelDisplay (state, isLabelDisplay) {
state.isLabelDisplay = isLabelDisplay
},
setIsCloseReloadWhenEnter (state, isCloseReloadWhenEnter) {
state.isCloseReloadWhenEnter = isCloseReloadWhenEnter
},
setUndisplayedKey (state, undisplayedKey) {
state.undisplayedKey = undisplayedKey
},
Expand Down
31 changes: 28 additions & 3 deletions frontend/src/store/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { bus } from '@/eventbus'

var configCommitMap = [
{'name': 'mock.data.showLabel', 'commit': 'setIsLabelDisplay'},
{'name': 'mock.data.tree.closeReload', 'commit': 'setIsCloseReloadWhenEnter'},
{'name': 'mock.data.tree.undeletableId', 'commit': 'concatTreeUndeletableId'},
{'name': 'mock.data.detail.stickyTopKey', 'commit': 'concatStickyTopKey'},
{'name': 'mock.data.detail.undeletableKey', 'commit': 'concatUndeletableKey'},
Expand All @@ -14,17 +15,32 @@ var configCommitMap = [
{'name': 'env.ip', 'commit': 'setIpList'}
]

var configPreLoad = [
{'name': 'mock.data.tree.preload', 'commit': 'loadDataMap'},
]

export default {
state: {
config: {}
config: {},
initialized: false,
preLoadFuncSet: new Set()
},
mutations: {
setConfig (state, config) {
state.config = config
},
setInitialized (state, initialized) {
state.initialized = initialized
},
addPreLoadFuncSet(state, preLoadFunc) {
state.preLoadFuncSet.add(preLoadFunc)
},
deletePreLoadFuncSet (state, preLoadFunc) {
state.preLoadFuncSet.delete(preLoadFunc)
}
},
actions: {
loadConfig({ commit }) {
loadConfig({ state, commit, dispatch }) {
api.getConfig()
.then(response => {
commit('setConfig', response.data)
Expand All @@ -33,6 +49,16 @@ export default {
commit(config.commit, response.data[config.name], { root: true })
}
}
// preload
if (!state.initialized) {
for (const config of configPreLoad) {
if (response.data.hasOwnProperty(config.name) && response.data[config.name]) {
commit('addPreLoadFuncSet', config.commit, { root: true })
commit('setInitialized', true)
dispatch(config.commit, { root: true })
}
}
}
})
.catch(error => {
bus.$emit('msg.error', 'Load config failed ' + error.data.message)
Expand All @@ -42,7 +68,6 @@ export default {
api.updateConfigByKey(data)
.then(_ => {
dispatch('loadConfig')
dispatch('loadStatus')
bus.$emit('msg.success', `Update config success!`)
})
.catch(error => {
Expand Down
106 changes: 91 additions & 15 deletions frontend/src/views/datamanager/DataList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
<v-icon size="12px" color="primary">mdi-refresh</v-icon>
</v-btn>

<v-btn v-if="isLabelDisplay" icon @click.stop="changeLabelDisplayState" title="Hide labels">
<v-icon size="12px" color="primary">mdi-eye-off-outline</v-icon>
</v-btn>

<v-btn v-else icon @click.stop="changeLabelDisplayState" title="Show labels">
<v-icon size="12px" color="primary">mdi-eye-outline</v-icon>
</v-btn>

<span class="mx-1">
<LabelDropdown :initLabels="selectedLabel" :placement="'bottom-end'" @onLabelChange="editLabel">
<template #dropdownButton>
Expand Down Expand Up @@ -64,8 +56,65 @@
<v-icon size="12px" color="primary">mdi-pencil</v-icon>
</v-btn>

</v-row>
<v-menu
left
bottom
offset-y
offset-overflow
:close-on-content-click="false"
style="position: absolute;"
>

<template v-slot:activator="{ on, attrs }">
<v-btn
icon
v-bind="attrs"
v-on="on"
class="ml-1"
title="Settings"
>
<v-icon size="12px" color="primary">mdi-cog-outline</v-icon>
</v-btn>
</template>

<v-list dense>
<v-list-item>
<v-list-item-action>
<v-switch v-model="isPreloadDataMap"/>
</v-list-item-action>

<v-list-item-content>
<v-list-item-title>Preload</v-list-item-title>
<v-list-item-subtitle>Proload DataTree before entering DataManager</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>

<v-list-item>
<v-list-item-action>
<v-switch v-model="isReloadWhenEnter"/>
</v-list-item-action>

<v-list-item-content>
<v-list-item-title>Reload</v-list-item-title>
<v-list-item-subtitle>Reload when entering DataManager</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>

<v-list-item>
<v-list-item-action>
<v-switch v-model="isLabelDisplay"/>
</v-list-item-action>

<v-list-item-content>
<v-list-item-title>Labels</v-list-item-title>
<v-list-item-subtitle>Display labels in each tree nodes</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</v-list>

</v-menu>

</v-row>
</v-container>

<Row>
Expand Down Expand Up @@ -125,8 +174,39 @@ export default {
selectedLabel () {
return this.$store.state.dataManager.dataListSelectedLabel
},
isLabelDisplay () {
return this.$store.state.dataManager.isLabelDisplay
isLabelDisplay: {
get () {
return this.$store.state.dataManager.isLabelDisplay
},
set (val) {
this.$store.commit('setIsLabelDisplay', val)
this.$store.dispatch('updateConfigByKey', {
'mock.data.showLabel': val
})
}
},
isReloadWhenEnter: {
get () {
return !this.$store.state.dataManager.isCloseReloadWhenEnter
},
set (val) {
const isCloseReloadWhenEnter = !val
this.$store.commit('setIsCloseReloadWhenEnter', isCloseReloadWhenEnter)
this.$store.dispatch('updateConfigByKey', {
'mock.data.tree.closeReload': isCloseReloadWhenEnter
})
}
},
isPreloadDataMap: {
get () {
return this.$store.state.settings.preLoadFuncSet.has('loadDataMap')
},
set (val) {
val ? this.$store.commit('addPreLoadFuncSet', 'loadDataMap') : this.$store.commit('deletePreLoadFuncSet', 'loadDataMap')
this.$store.dispatch('updateConfigByKey', {
'mock.data.tree.preload': val
})
}
},
isSelectableStatus () {
return this.$store.state.dataManager.isSelectableStatus
Expand Down Expand Up @@ -197,10 +277,6 @@ export default {
this.$store.commit('setDataListSelectedLabel', labels)
this.$store.dispatch('loadDataMap')
},
changeLabelDisplayState () {
const status = !this.isLabelDisplay
this.$store.commit('setIsLabelDisplay', status)
},
changeSelectableStatus () {
this.$store.commit('setIsSelectableStatus', !this.isSelectableStatus)
this.$store.commit('setSelectedLeaf', [])
Expand Down
47 changes: 45 additions & 2 deletions frontend/src/views/datamanager/DataManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@
<data-detail></data-detail>
</div>
</Split>

<v-snackbar
v-model="isShownReloadMessage"
transition="slide-y-reverse-transition"
color="primaryBrightest"
:timeout="-1"
rounded="pill"
class="mb-3"
>
<span class="accent--text">Mock Data updated {{durationMessage}}</span>
<v-btn text small class="px-1 ml-1" height="20" color="primary" @click.stop="loadDataMap"><b>CLICK TO UPDATE</b></v-btn>

<template v-slot:action="{ attrs }">
<v-btn
plain
v-bind="attrs"
class="primaryLight--text"
@click="isShownReloadMessage = false"
>
Close
</v-btn>
</template>
</v-snackbar>

</div>
</template>

Expand All @@ -24,19 +48,38 @@ export default {
SnapshotImportSelector,
},
activated () {
this.loadDataMap()
if (this.groupList.length == 0 || this.isReloadWhenEnter) {
this.loadDataMap()
}
this.$io.on('datamanagerUpdate', this.loadDataMap)
this.$io.on('datamanagerUpdateMessage', this.onDatamanagerUpdateMessage)
},
deactivated() {
this.$io.removeListener('datamanagerUpdate', this.loadDataMap)
this.$io.removeListener('datamanagerUpdateMessage', this.onDatamanagerUpdateMessage)
},
data () {
return {
split: 0.35
split: 0.35,
isShownReloadMessage: false,
durationMessage: 'for a long time',
}
},
computed: {
groupList () {
return this.$store.state.dataManager.groupList
},
isReloadWhenEnter () {
return !this.$store.state.dataManager.isCloseReloadWhenEnter
}
},
methods: {
onDatamanagerUpdateMessage (payload) {
this.isShownReloadMessage = true
this.durationMessage = payload.durationMessage ? payload.durationMessage : 'for a long time'
},
loadDataMap () {
this.isShownReloadMessage = false
this.$store.dispatch('loadDataMap')
}
}
Expand Down
1 change: 1 addition & 0 deletions lyrebird/mock/handlers/mock_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def handle(self, handler_context):
handler_context.add_flow_action({
'id': 'mock',
'name': Path(__file__).name,
'group_id': activated_group['id'],
'mock_id': hit_data['id']
})
MockDataHelper.read_mock_data(handler_context)
2 changes: 1 addition & 1 deletion lyrebird/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
IVERSION = (2, 12, 2)
IVERSION = (2, 13, 0)
VERSION = ".".join(str(i) for i in IVERSION)
LYREBIRD = "Lyrebird " + VERSION

0 comments on commit 3582821

Please sign in to comment.