Skip to content

Commit 485c41d

Browse files
committed
Add ability to configure columns in metric and chart blocks
1 parent 3b3c063 commit 485c41d

9 files changed

Lines changed: 164 additions & 47 deletions

File tree

client/web/compose/src/components/Admin/Module/Records/ColumnPicker.vue

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<template>
22
<div class="d-flex">
33
<b-button
4-
size="lg"
5-
variant="light"
4+
:size="size"
5+
:variant="variant"
66
class="flex-fill"
7+
:disabled="disabled"
78
@click="showModal = true"
89
>
9-
{{ $t('allRecords.columns.title') }}
10+
<slot>
11+
{{ $t('allRecords.columns.title') }}
12+
</slot>
1013
</b-button>
1114

1215
<b-modal
@@ -60,6 +63,21 @@ export default {
6063
required: true,
6164
default: () => [],
6265
},
66+
67+
disabled: {
68+
type: Boolean,
69+
default: false,
70+
},
71+
72+
size: {
73+
type: String,
74+
default: 'lg',
75+
},
76+
77+
variant: {
78+
type: String,
79+
default: 'light',
80+
},
6381
},
6482
6583
data () {
@@ -70,10 +88,10 @@ export default {
7088
}
7189
},
7290
73-
created () {
74-
this.filteredFields = this.fields.map(f => {
75-
return { ...f.moduleField }
76-
})
91+
watch: {
92+
fields (fields) {
93+
this.filteredFields = this.module.filterFields(fields)
94+
},
7795
},
7896
7997
beforeDestroy () {

client/web/compose/src/components/PageBlocks/ChartBase.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,15 @@ export default {
162162
this.$root.$emit(`drill-down-recordList:${recordListUniqueID}`, prefilter)
163163
} else {
164164
const { title } = this.block
165+
const { fields = [] } = this.options.drillDown.recordListOptions || {}
165166
166167
// Open in modal
167168
const block = new compose.PageBlockRecordList({
168169
title: title ? `${title} - "${drillDownValue}"` : drillDownValue,
169170
blockID: `drillDown-${chartID}`,
170171
options: {
171172
moduleID,
173+
fields,
172174
prefilter,
173175
presort: 'createdAt DESC',
174176
hideRecordReminderButton: true,

client/web/compose/src/components/PageBlocks/ChartConfigurator.vue

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919
<b-input-group-append>
2020
<b-button
21-
v-b-tooltip.noninteractive.hover="{ title: $t('chart.openInBuilder'), container: '#body' }"
22-
:disabled="!selectedChart || (!selectedChart.canUpdateChart && !selectedChart.canDeleteChart)"
21+
v-b-tooltip.hover="{ title: $t(chartSelectorTooltip), container: '#body' }"
22+
:disabled="selectedChart && (!selectedChart.canUpdateChart && !selectedChart.canDeleteChart)"
2323
variant="extra-light"
2424
class="d-flex align-items-center"
25-
:to="{ name: 'admin.charts.edit', params: { chartID: (selectedChart || {}).chartID }, query: null }"
25+
:to="{ name: chartExternalLink, params: { chartID: (selectedChart || {}).chartID }, query: null }"
2626
>
2727
<font-awesome-icon :icon="['fas', 'external-link-alt']" />
2828
</b-button>
@@ -32,6 +32,7 @@
3232

3333
<template v-if="isDrillDownAvailable">
3434
<b-form-group
35+
:label="$t('chart.drillDown.label')"
3536
:description="$t('chart.drillDown.description')"
3637
label-class="d-flex align-items-center text-primary"
3738
class="mb-1"
@@ -43,16 +44,32 @@
4344
class="mb-2"
4445
/>
4546

46-
<c-input-select
47-
v-model="options.drillDown.blockID"
48-
:options="drillDownOptions"
49-
:get-option-key="getOptionKey"
50-
:disabled="!options.drillDown.enabled"
51-
:get-option-label="o => o.title || o.kind"
52-
:reduce="option => option.blockID"
53-
:clearable="true"
54-
:placeholder="$t('chart.drillDown.openInModal')"
55-
/>
47+
<b-input-group>
48+
<c-input-select
49+
v-model="options.drillDown.blockID"
50+
:options="drillDownOptions"
51+
:get-option-key="getOptionKey"
52+
:disabled="!options.drillDown.enabled"
53+
:get-option-label="o => o.title || o.kind"
54+
:reduce="option => option.blockID"
55+
:clearable="true"
56+
:placeholder="$t('chart.drillDown.openInModal')"
57+
/>
58+
59+
<b-input-group-append>
60+
<column-picker
61+
ref="columnPicker"
62+
:module="selectedChartModule"
63+
:fields="selectedDrilldownFields"
64+
:disabled="!!options.drillDown.blockID || !options.drillDown.enabled"
65+
variant="extra-light"
66+
size="md"
67+
@updateFields="onUpdateFields"
68+
>
69+
<font-awesome-icon :icon="['fas', 'wrench']" />
70+
</column-picker>
71+
</b-input-group-append>
72+
</b-input-group>
5673
</b-form-group>
5774
</template>
5875
</b-tab>
@@ -61,6 +78,7 @@
6178
import base from './base'
6279
import { mapGetters } from 'vuex'
6380
import { NoID } from '@cortezaproject/corteza-js'
81+
import ColumnPicker from 'corteza-webapp-compose/src/components/Admin/Module/Records/ColumnPicker'
6482
6583
export default {
6684
i18nOptions: {
@@ -69,6 +87,10 @@ export default {
6987
7088
name: 'Chart',
7189
90+
components: {
91+
ColumnPicker,
92+
},
93+
7294
extends: base,
7395
7496
data () {
@@ -83,6 +105,7 @@ export default {
83105
computed: {
84106
...mapGetters({
85107
charts: 'chart/set',
108+
getModuleByID: 'module/getByID',
86109
}),
87110
88111
selectedChart () {
@@ -93,6 +116,14 @@ export default {
93116
return this.charts.find(({ chartID }) => chartID === this.options.chartID)
94117
},
95118
119+
chartExternalLink () {
120+
return !this.selectedChart ? 'admin.charts' : 'admin.charts.edit'
121+
},
122+
123+
chartSelectorTooltip () {
124+
return !this.selectedChart ? 'chart.openChartList' : 'chart.openInBuilder'
125+
},
126+
96127
selectedChartModuleID () {
97128
if (!this.selectedChart) return
98129
@@ -101,6 +132,18 @@ export default {
101132
return moduleID
102133
},
103134
135+
selectedChartModule () {
136+
if (!this.selectedChartModuleID) return
137+
138+
return this.getModuleByID(this.selectedChartModuleID)
139+
},
140+
141+
selectedDrilldownFields () {
142+
if (!this.selectedChart) return []
143+
144+
return this.options.drillDown.recordListOptions.fields
145+
},
146+
104147
isDrillDownAvailable () {
105148
if (!this.selectedChart) return
106149
@@ -116,15 +159,16 @@ export default {
116159
117160
methods: {
118161
chartSelected () {
119-
this.options.drillDown = {
120-
enabled: false,
121-
blockID: '',
122-
}
162+
this.block.resetDrillDown()
123163
},
124164
125165
getOptionKey ({ chartID }) {
126166
return chartID
127167
},
168+
169+
onUpdateFields (fields) {
170+
this.options.drillDown.recordListOptions.fields = fields.map(({ fieldID }) => fieldID)
171+
},
128172
},
129173
}
130174
</script>

client/web/compose/src/components/PageBlocks/MetricBase.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,14 @@ export default {
208208
} else {
209209
// Open in modal
210210
const metricID = `${this.block.blockID}-${name.replace(/\s+/g, '-').toLowerCase()}-${moduleID}-${metricIndex}`
211+
const { fields = [] } = this.options.metrics[metricIndex].drillDown.recordListOptions || {}
211212
212213
const block = new compose.PageBlockRecordList({
213214
title: name || this.$t('metric.metricDrillDown'),
214215
blockID: `drillDown-${metricID}`,
215216
options: {
216217
moduleID,
218+
fields,
217219
prefilter: filter,
218220
presort: 'createdAt DESC',
219221
hideRecordReminderButton: true,

client/web/compose/src/components/PageBlocks/MetricConfigurator/index.vue

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
</b-form-group>
167167
</fieldset>
168168

169-
<fieldset>
169+
<fieldset v-if="selectedMetricModule">
170170
<h5>
171171
{{ $t('metric.edit.metricLabel') }}
172172
</h5>
@@ -262,23 +262,39 @@
262262
>
263263
<template #label>
264264
{{ $t('metric.drillDown.label') }}
265+
265266
<b-form-checkbox
266267
v-model="edit.drillDown.enabled"
267268
switch
268-
class="ml-1"
269+
class="ml-1 mb-1"
269270
/>
270271
</template>
271272

272-
<c-input-select
273-
v-model="edit.drillDown.blockID"
274-
:options="drillDownOptions"
275-
:disabled="!edit.drillDown.enabled"
276-
:get-option-label="o => o.title || o.kind"
277-
:reduce="option => option.blockID"
278-
:clearable="true"
279-
:placeholder="$t('metric.drillDown.openInModal')"
280-
append-to-body
281-
/>
273+
<b-input-group>
274+
<c-input-select
275+
v-model="edit.drillDown.blockID"
276+
:options="drillDownOptions"
277+
:disabled="!edit.drillDown.enabled"
278+
:get-option-label="o => o.title || o.kind"
279+
:reduce="option => option.blockID"
280+
:clearable="true"
281+
:placeholder="$t('metric.drillDown.openInModal')"
282+
append-to-body
283+
/>
284+
285+
<b-input-group-append>
286+
<column-picker
287+
:module="selectedMetricModule"
288+
:disabled="!!edit.drillDown.blockID || !edit.drillDown.enabled"
289+
:fields="selectedDrilldownFields"
290+
variant="extra-light"
291+
size="md"
292+
@updateFields="onUpdateFields"
293+
>
294+
<font-awesome-icon :icon="['fas', 'wrench']" />
295+
</column-picker>
296+
</b-input-group-append>
297+
</b-input-group>
282298
</b-form-group>
283299
</fieldset>
284300
</b-card>
@@ -332,6 +348,7 @@ import base from '../base'
332348
import MStyle from './MStyle'
333349
import { mapGetters } from 'vuex'
334350
import MetricBase from '../MetricBase'
351+
import ColumnPicker from 'corteza-webapp-compose/src/components/Admin/Module/Records/ColumnPicker'
335352
import { compose, NoID } from '@cortezaproject/corteza-js'
336353
337354
export default {
@@ -343,6 +360,7 @@ export default {
343360
components: {
344361
MStyle,
345362
MetricBase,
363+
ColumnPicker,
346364
},
347365
extends: base,
348366
@@ -374,15 +392,21 @@ export default {
374392
computed: {
375393
...mapGetters({
376394
modules: 'module/set',
377-
moduleByID: 'module/getByID',
395+
getModuleByID: 'module/getByID',
378396
}),
379397
380398
fields () {
381399
if (!this.edit || !this.edit.moduleID) {
382400
return []
383401
}
384402
385-
return this.moduleByID(this.edit.moduleID).fields
403+
return this.getModuleByID(this.edit.moduleID).fields
404+
},
405+
406+
selectedDrilldownFields () {
407+
if (!this.edit || !this.edit.drillDown.recordListOptions.fields) return []
408+
409+
return this.edit.drillDown.recordListOptions.fields
386410
},
387411
388412
metricFields () {
@@ -405,6 +429,12 @@ export default {
405429
drillDownOptions () {
406430
return this.page.blocks.filter(({ blockID, kind, options = {} }) => kind === 'RecordList' && blockID !== NoID && options.moduleID === this.edit.moduleID)
407431
},
432+
433+
selectedMetricModule () {
434+
if (!this.edit.moduleID) return undefined
435+
436+
return this.getModuleByID(this.edit.moduleID)
437+
},
408438
},
409439
410440
watch: {
@@ -466,6 +496,10 @@ export default {
466496
}
467497
},
468498
499+
onUpdateFields (fields) {
500+
this.edit.drillDown.recordListOptions.fields = fields
501+
},
502+
469503
setDefaultValues () {
470504
this.edit = undefined
471505
this.dimensionModifiers = []

0 commit comments

Comments
 (0)