Skip to content

Commit 84ea507

Browse files
authored
Activity Log Enhancement - change date so it includes time, refactor composition-api (#3515)
1 parent e9d6eb4 commit 84ea507

File tree

3 files changed

+116
-80
lines changed

3 files changed

+116
-80
lines changed

auth-web/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auth-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "auth-web",
3-
"version": "2.10.21",
3+
"version": "2.10.22",
44
"appName": "Auth Web",
55
"sbcName": "SBC Common Components",
66
"private": true,

auth-web/src/components/auth/account-settings/activity-log/ActivityLog.vue

Lines changed: 113 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</template>
3838
<template #[`item.created`]="{ item }">
3939
<div class="font-weight-bold">
40-
{{ formatDate(item.created,'MMMM DD, YYYY') }}
40+
{{ formatDate(moment.utc(item.created).toDate(), 'MMMM DD, YYYY h:mm A') }}
4141
</div>
4242
</template>
4343
</v-data-table>
@@ -46,96 +46,132 @@
4646
</template>
4747

4848
<script lang="ts">
49-
import { Action, State } from 'pinia-class'
5049
import { ActivityLog, ActivityLogFilterParams } from '@/models/activityLog'
51-
import { Component, Mixins, Prop, Watch } from 'vue-property-decorator'
52-
import { Member, Organization } from '@/models/Organization'
53-
import AccountChangeMixin from '@/components/auth/mixins/AccountChangeMixin.vue'
50+
import { PropType, computed, defineComponent, onBeforeUnmount, onMounted, reactive, toRefs, watch } from '@vue/composition-api'
5451
import CommonUtils from '@/util/common-util'
52+
import moment from 'moment'
5553
import { useActivityStore } from '@/stores/activityLog'
5654
import { useOrgStore } from '@/stores/org'
5755
58-
@Component({})
59-
export default class ActivityLogs extends Mixins(AccountChangeMixin) {
60-
@Prop({ default: '' }) private orgId: number
61-
@State(useOrgStore) public currentOrganization!: Organization
62-
@State(useOrgStore) public currentMembership!: Member
63-
@State(useActivityStore) public currentOrgActivity!: ActivityLog
64-
@Action(useActivityStore) public getActivityLog!:(filterParams:ActivityLogFilterParams) =>Promise<ActivityLog>
65-
66-
private readonly ITEMS_PER_PAGE = 5
67-
private readonly PAGINATION_COUNTER_STEP = 4
68-
public formatDate = CommonUtils.formatDisplayDate
69-
public totalActivityCount: number = 0
70-
public tableDataOptions: any = {}
71-
public isDataLoading: boolean = false
72-
public activityList: ActivityLog[] = []
73-
public isLoading: boolean = false
74-
75-
public readonly activityHeader = [
76-
{
77-
text: 'Date',
78-
align: 'left',
79-
sortable: false,
80-
value: 'created',
81-
class: 'bold-header'
82-
},
83-
84-
{
85-
text: 'Initiated by',
86-
align: 'left',
87-
sortable: false,
88-
value: 'actor',
89-
class: 'bold-header'
90-
},
91-
{
92-
text: 'Subject',
93-
align: 'left',
94-
sortable: false,
95-
value: 'action',
96-
class: 'bold-header'
56+
export default defineComponent({
57+
name: 'ActivityLogs',
58+
props: {
59+
orgId: {
60+
type: Number as PropType<number>,
61+
default: 0
9762
}
98-
]
63+
},
64+
setup () {
65+
const activityStore = useActivityStore()
66+
const orgStore = useOrgStore()
9967
100-
public get getPaginationOptions () {
101-
return [...Array(this.PAGINATION_COUNTER_STEP)].map((value, index) => this.ITEMS_PER_PAGE * (index + 1))
102-
}
68+
const ITEMS_PER_PAGE = 5
69+
const PAGINATION_COUNTER_STEP = 4
10370
104-
public async mounted () {
105-
this.setAccountChangedHandler(this.initialize)
106-
this.initialize()
107-
}
71+
const state = reactive({
72+
totalActivityCount: 0,
73+
tableDataOptions: {},
74+
isDataLoading: false,
75+
activityList: [] as ActivityLog[],
76+
isLoading: false,
77+
activityHeader: [
78+
{
79+
text: 'Date (Pacific Time)',
80+
align: 'left',
81+
sortable: false,
82+
value: 'created',
83+
class: 'bold-header'
84+
},
85+
{
86+
text: 'Initiated by',
87+
align: 'left',
88+
sortable: false,
89+
value: 'actor',
90+
class: 'bold-header'
91+
},
92+
{
93+
text: 'Subject',
94+
align: 'left',
95+
sortable: false,
96+
value: 'action',
97+
class: 'bold-header'
98+
}
99+
]
100+
})
108101
109-
public async initialize () {
110-
await this.loadActivityList()
111-
}
102+
const currentOrganization = computed(() => orgStore.currentOrganization)
103+
const currentMembership = computed(() => orgStore.currentMembership)
104+
const currentOrgActivity = computed(() => activityStore.currentOrgActivity)
112105
113-
@Watch('tableDataOptions', { deep: true })
114-
async getActivityLogs (val) {
115-
const pageNumber = val?.page || 1
116-
const itemsPerPage = val?.itemsPerPage
117-
await this.loadActivityList(pageNumber, itemsPerPage)
118-
}
106+
const getPaginationOptions = computed(() => {
107+
return [...Array(PAGINATION_COUNTER_STEP)].map((value, index) => ITEMS_PER_PAGE * (index + 1))
108+
})
109+
110+
const loadActivityList = async (pageNumber?: number, itemsPerPage?: number) => {
111+
state.isDataLoading = true
112+
const filterParams: ActivityLogFilterParams = {
113+
pageNumber: pageNumber,
114+
pageLimit: itemsPerPage,
115+
orgId: currentOrganization.value.id
116+
}
117+
try {
118+
const resp: any = await activityStore.getActivityLog(filterParams)
119+
state.activityList = resp?.activityLogs || []
120+
state.totalActivityCount = resp?.total || 0
121+
state.isDataLoading = false
122+
} catch {
123+
state.activityList = []
124+
state.totalActivityCount = 0
125+
state.isDataLoading = false
126+
}
127+
}
128+
129+
const initialize = async () => {
130+
await loadActivityList()
131+
}
132+
133+
let unregisterHandler: (() => void) | null = null
119134
120-
public async loadActivityList (pageNumber?: number, itemsPerPage?: number) {
121-
this.isDataLoading = true
122-
const filterParams: ActivityLogFilterParams = {
123-
pageNumber: pageNumber,
124-
pageLimit: itemsPerPage,
125-
orgId: this.currentOrganization.id
135+
const setAccountChangedHandler = (handler: () => any) => {
136+
unregisterHandler = orgStore.$onAction(({ name, after }) => {
137+
after(() => {
138+
if (['syncOrganization', 'setCurrentOrganization'].includes(name)) {
139+
handler()
140+
}
141+
})
142+
})
126143
}
127-
try {
128-
const resp:any = await this.getActivityLog(filterParams)
129-
this.activityList = resp?.activityLogs || []
130-
this.totalActivityCount = resp?.total || 0
131-
this.isDataLoading = false
132-
} catch {
133-
this.activityList = []
134-
this.totalActivityCount = 0
135-
this.isDataLoading = false
144+
145+
watch(() => state.tableDataOptions, async (val: any) => {
146+
const pageNumber = val?.page || 1
147+
const itemsPerPage = val?.itemsPerPage
148+
await loadActivityList(pageNumber, itemsPerPage)
149+
}, { deep: true })
150+
151+
onMounted(async () => {
152+
setAccountChangedHandler(initialize)
153+
await initialize()
154+
})
155+
156+
onBeforeUnmount(() => {
157+
if (unregisterHandler) {
158+
unregisterHandler()
159+
}
160+
})
161+
162+
return {
163+
...toRefs(state),
164+
currentOrganization,
165+
currentMembership,
166+
currentOrgActivity,
167+
getPaginationOptions,
168+
formatDate: CommonUtils.formatDisplayDate,
169+
loadActivityList,
170+
initialize,
171+
moment
136172
}
137173
}
138-
}
174+
})
139175
</script>
140176

141177
<style lang="scss" scoped>

0 commit comments

Comments
 (0)