-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: derived metrics use different line style (#20242)
- Loading branch information
1 parent
dd4b581
commit 7faf874
Showing
16 changed files
with
161 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
superset-frontend/packages/superset-ui-chart-controls/src/operators/utils/isDerivedSeries.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* eslint-disable camelcase */ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitationsxw | ||
* under the License. | ||
*/ | ||
import { | ||
ensureIsArray, | ||
JsonObject, | ||
QueryFormData, | ||
ComparisionType, | ||
} from '@superset-ui/core'; | ||
import { isString } from 'lodash'; | ||
|
||
export const isDerivedSeries = ( | ||
series: JsonObject, | ||
formData: QueryFormData, | ||
): boolean => { | ||
const comparisonType = formData.comparison_type; | ||
if (comparisonType !== ComparisionType.Values) { | ||
return false; | ||
} | ||
|
||
const timeCompare: string[] = ensureIsArray(formData?.time_compare); | ||
return isString(series.name) | ||
? !!timeCompare.find(timeOffset => series.name.endsWith(timeOffset)) | ||
: false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...frontend/packages/superset-ui-chart-controls/test/operators/utils/isDerivedSeries.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { isDerivedSeries } from '@superset-ui/chart-controls'; | ||
import { SqlaFormData, ComparisionType } from '@superset-ui/core'; | ||
|
||
const formData: SqlaFormData = { | ||
datasource: 'foo', | ||
viz_type: 'table', | ||
}; | ||
const series = { | ||
id: 'metric__1 month ago', | ||
name: 'metric__1 month ago', | ||
data: [100], | ||
}; | ||
|
||
test('should be false if comparison type is not actual values', () => { | ||
expect(isDerivedSeries(series, formData)).toEqual(false); | ||
Object.keys(ComparisionType) | ||
.filter(type => type === ComparisionType.Values) | ||
.forEach(type => { | ||
const formDataWithComparisionType = { | ||
...formData, | ||
comparison_type: type, | ||
time_compare: ['1 month ago'], | ||
}; | ||
expect(isDerivedSeries(series, formDataWithComparisionType)).toEqual( | ||
false, | ||
); | ||
}); | ||
}); | ||
|
||
test('should be true if comparison type is values', () => { | ||
const formDataWithActualTypes = { | ||
...formData, | ||
comparison_type: ComparisionType.Values, | ||
time_compare: ['1 month ago', '1 month later'], | ||
}; | ||
expect(isDerivedSeries(series, formDataWithActualTypes)).toEqual(true); | ||
}); | ||
|
||
test('should be false if series name does not match time_compare', () => { | ||
const arbitrary_series = { | ||
id: 'arbitrary column', | ||
name: 'arbitrary column', | ||
data: [100], | ||
}; | ||
const formDataWithActualTypes = { | ||
...formData, | ||
comparison_type: ComparisionType.Values, | ||
time_compare: ['1 month ago', '1 month later'], | ||
}; | ||
expect(isDerivedSeries(arbitrary_series, formDataWithActualTypes)).toEqual( | ||
false, | ||
); | ||
}); | ||
|
||
test('should be false if time compare is not suffix', () => { | ||
const series = { | ||
id: '1 month ago__metric', | ||
name: '1 month ago__metric', | ||
data: [100], | ||
}; | ||
const formDataWithActualTypes = { | ||
...formData, | ||
comparison_type: ComparisionType.Values, | ||
time_compare: ['1 month ago', '1 month later'], | ||
}; | ||
expect(isDerivedSeries(series, formDataWithActualTypes)).toEqual(false); | ||
}); | ||
|
||
test('should be false if series name invalid', () => { | ||
const series = { | ||
id: 123, | ||
name: 123, | ||
data: [100], | ||
}; | ||
const formDataWithActualTypes = { | ||
...formData, | ||
comparison_type: ComparisionType.Values, | ||
time_compare: ['1 month ago', '1 month later'], | ||
}; | ||
expect(isDerivedSeries(series, formDataWithActualTypes)).toEqual(false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters