Skip to content

Commit

Permalink
fixes (#3164)
Browse files Browse the repository at this point in the history
  • Loading branch information
persas authored Nov 29, 2023
1 parent 6852753 commit 482a846
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
5 changes: 4 additions & 1 deletion server/modules/reporting/api/reportingApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ export const init = (app) => {
chartSpec.chartType === 'barChart' &&
chartSpec.query &&
chartSpec.query.metric &&
chartSpec.query.metric.field !== '' &&
chartSpec.query.groupBy &&
chartSpec.query.aggregation
chartSpec.query.groupBy.field !== '' &&
chartSpec.query.aggregation &&
chartSpec.query.aggregation.type !== ''
) {
const groupByFieldUuid = chartSpec.query.groupBy.field_uuid
const metricFieldUuid = chartSpec.query.metric.field_uuid
Expand Down
1 change: 1 addition & 0 deletions webapp/components/form/Dropdown/dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

.dropdown__control {
min-height: auto;
z-index: 0;
}

.dropdown__single-value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ const BarChart = ({ specs, originalData }) => {
const chartRef = useRef()

useEffect(() => {
if (!specs?.query?.metric || !specs?.query?.groupBy || !specs?.query?.aggregation) return

if (
!specs?.query?.metric?.field ||
specs?.query?.metric?.field === '' ||
!specs?.query?.groupBy?.field ||
specs?.query?.groupBy?.field === '' ||
!specs?.query?.aggregation?.type ||
specs?.query?.aggregation?.type === ''
)
return
const groupByField = specs.query.groupBy.field

if (groupByField) {
Expand Down Expand Up @@ -42,7 +49,6 @@ BarChart.propTypes = {
query: PropTypes.shape({
metric: PropTypes.shape({
field: PropTypes.string.isRequired,
aggregate: PropTypes.string,
}).isRequired,
groupBy: PropTypes.shape({
field: PropTypes.string.isRequired,
Expand Down
18 changes: 8 additions & 10 deletions webapp/views/App/views/Data/Charts/state/chartTypes/common.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
export const aggregationOptions = {
options: [
{ value: 'average', label: 'Average', name: 'avg', type: 'aggregation' },
{ value: 'count', label: 'Count', name: 'count', type: 'aggregation' },
{ value: 'max', label: 'Maximum', name: 'max', type: 'aggregation' },
{ value: 'median', label: 'Median', name: 'median', type: 'aggregation' },
{ value: 'min', label: 'Minimum', name: 'min', type: 'aggregation' },
{ value: 'sum', label: 'Sum', name: 'sum', type: 'aggregation' },
],
}
export const aggregationOptions = [
{ value: 'average', label: 'Average', name: 'avg', type: 'aggregation' },
{ value: 'count', label: 'Count', name: 'count', type: 'aggregation' },
{ value: 'max', label: 'Maximum', name: 'max', type: 'aggregation' },
{ value: 'median', label: 'Median', name: 'median', type: 'aggregation' },
{ value: 'min', label: 'Minimum', name: 'min', type: 'aggregation' },
{ value: 'sum', label: 'Sum', name: 'sum', type: 'aggregation' },
]
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const pie = {
type: 'container',
blocks: {
groupBy: GroupByBlock({
isMulti: false,
valuesToSpec: ({ value = [], spec = {} }) => {
const { key: field_uuid, as: field } = valuesToCalculations(value)
const groupBy = { field_uuid, field, type: 'nominal' }
Expand All @@ -38,6 +39,7 @@ const pie = {
id: 'metric',
title: 'Metric',
subtitle: '',
isMulti: false,
optionsParams: { filter: ['quantitative'] },
valuesToSpec: ({ spec = {}, value = [] }) => {
const { as: field, key: field_uuid } = valuesToCalculations(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ const useChartRender = (spec, query) => {

// Call renderChart only when necessary data is available
useEffect(() => {
if (spec.chartType === 'barChart' ? spec.metric && spec.query && spec.query.groupBy : spec.metric) {
if (
spec.chartType === 'barChart'
? spec.metric && spec.metric.field !== '' && spec.query && spec.query.groupBy && spec.query.groupBy.field !== ''
: spec.metric && spec.metric.field !== ''
) {
renderChart()
}
}, [spec, renderChart])
Expand Down

0 comments on commit 482a846

Please sign in to comment.