Skip to content

Commit

Permalink
Feature/dataset explorer chart update chart (#355)
Browse files Browse the repository at this point in the history
* [cccs-2.0] updating docker file (#188)

* [CLDN-1565] Fixing bugs (#189)

* [CLDN-1565] Fixing bugs

* removing uneeded import

* Feature/cldn 1565 (#192)

* [CLDN-1565] Fixing bugs

* removing uneeded import

* [CLDN-1565] Adding new image

* Feature/cldn 1609 (#195)

* Add row number option to CCCS-Grid (#181)

* Add row number option to CCCS-Grid

* Have row numbers show by default

Co-authored-by: cccs-Dustin <[email protected]>

Co-authored-by: cccs-Dustin <[email protected]>

* Use new build agent (#187)

* Use new build agent

* Remove quotes

* Display datahub link for datasets with defined URN (#177)

* Display datahub link for datasets with defined URN

* Add datahub SVG

* Reorder imports

* Add datahub link to dashboards

* Convert to camel case

* Add tests for DatasetList

* Add tests for dashboard header

* Provide explanation for empty catch

* [CLDN-1540] Added ability for multiple user emails to be filtered on at once

* [CLDN-1540] temp update to docker image tag so that we can deploy code changes to PB-stg

* [CLDN-1540] revert of temp update to docker image tag so that we can deploy code changes to PB-stg

* Add path to url (#193)

* [CLDN-1609] Fixing post merge build errors

* Update cccs-build/superset-base/azure-pipelines.yml

Co-authored-by: Reese <[email protected]>

* Update superset-frontend/src/cccs-viz/plugins/plugin-chart-at-a-glance-user-id/src/styles.js

Co-authored-by: Reese <[email protected]>

Co-authored-by: Reese <[email protected]>
Co-authored-by: cccs-Dustin <[email protected]>

* [CLDN-1609] Updating image (#196)

* [CLDN-1620] Making rendering use advanced type (#197)

* updating image (#198)

* [CLDN-1609] Fixing all QA bugs (#201)

* [CLDN-1609] Fixing all QA bugs

* [CLDN-1609] Fixing build errors

* [CLDN-1609] adding additional fixes

* [CLDN-1609] Removing log files

* [CLDN-1609] Fixing build error

Co-authored-by: reesercollins <[email protected]>

* Feature/cldn 1541 (#200)

* [CLDN-1541] Added the ability to filter on multiple user ID's and IP's at the same time in the Application Links custom viz

* Temp update to image for deploying to PB-stg

* Reverting change to image

* [CLDN-1541] Added a tooltip to the Alfred icon

* Temp update to base image

* Reverting temporary change to image tag

* Update superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/ApplicationLinks.tsx

Co-authored-by: cccs-rc <[email protected]>

* Update superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/ApplicationLinks.tsx

Co-authored-by: cccs-rc <[email protected]>

* [CLDN-1541] Changed the logic around creating the proper links/URL

* Temp update to img

* Undo temp img change

Co-authored-by: cccs-rc <[email protected]>

* [CLDN-1609] Updating docker image (#202)

* [cccs-2.0] Fixing case sensitivity (#203)

* [cccs-2.0] Fixing case sensitivity

* [cccs-2.0] Pusing temp image

* [cccs-2.0] fixing two order bys

* [cccs-2.0] fixing verbose names, fixing sizing, fixing ordering

* [cccs-2.0] fixing build error

* [cccs-2.0] updating image

* [cccs-2.0] fixing time columns

* [cccs-2.0] Fixing build errors

* [cccs-2.0] updating docker file

* [cccs-2.0] Fixing time column to populate default time col

* Fixing default time col

* [cccs-2.0] updating image

* Fix issue where datasets without a date/datetime column would not load in the explore view

* Time column dropdown list is now properly populated with either the default temporal column, or the first temporal column (if a default is not set)

* Temp update to base image tag

* Fixed the bug where when there are no dttm columns, the non-dttm columns were being displayed

* Temp update to base image tag

* Reverting changes to the img

Co-authored-by: cccs-Dustin <[email protected]>

* Fix/cccs 2.0 (#204)

* [cccs-2.0] Fixing case sensitivity

* [cccs-2.0] Pusing temp image

* [cccs-2.0] fixing two order bys

* [cccs-2.0] fixing verbose names, fixing sizing, fixing ordering

* [cccs-2.0] fixing build error

* [cccs-2.0] updating image

* [cccs-2.0] fixing time columns

* [cccs-2.0] Fixing build errors

* [cccs-2.0] updating docker file

* [cccs-2.0] Fixing time column to populate default time col

* Fixing default time col

* [cccs-2.0] updating image

* Fix issue where datasets without a date/datetime column would not load in the explore view

* Time column dropdown list is now properly populated with either the default temporal column, or the first temporal column (if a default is not set)

* Temp update to base image tag

* Fixed the bug where when there are no dttm columns, the non-dttm columns were being displayed

* Temp update to base image tag

* Reverting changes to the img

* Updating image tag

Co-authored-by: cccs-RyanS <[email protected]>

* Fixed issue with Typescript (#205)

* Fix cccs 2.0 (#206)

* Fixed issue with Typescript

* Update image tag

* Feature/cldn 1563 (#207)

* Ran pre-commit hook on the front-end

* Removed unused file & removed duplicate method

* Made changes so that the pre-commit hook would pass all tests

* Temp update to build img

* revert temp change to build img

* Updated image (#208)

* [CLDN-1683] Added code to show column descriptions as tooltips in the… (#209)

* [CLDN-1683] Added code to show column descriptions as tooltips in the Hogwarts Table custom visualisation

* [CLDN-1683] Temp update to build image

* [CLDN-1683] Revert update to image tag

* Feature/cldn 1676 (#210)

* [CLDN-1676] Added ability to search for the IPv4 rendered value of an IP address instead of the raw value

* [CLDN-1676] Temp update to img for deploying to UDev

* [CLDN-1676] Undo temp update to img for deploying to UDev

* Updating Superset Base Image Tag (#211)

* added adhoc filter plugin files

* Made sure that adhoc filter uses the adhoc filter object

* added adhocfiltercontrol to native adhoc filter

* fixed hook that made too many requests

* fixed applied filter label

* removed duplicate files

* Removed uneeded functions

* Removed uneeded functions and variables

* Removed unused props variables

* modifying base image tag

* Removed unused config settings

* removed column for filter config form

* Improved the applied filter(s) modal

* Temp update to build image

* fixed string formatting issue:

* updating superset base image tag

* added setFocused hooks to filter when hovering

* Fixed the right click to emit dashboard cross-filters (#213)

* Fixed the right click to emit filters through the context menu as it was not working

* Temp update to build image

* Revert temp update to build image

* Updated superset base image (#214)

* fixed unused declaration error

* updating image

* Prevent invalid filter values from being saved (#215)

By assuming that all input is invalid until the api tells us otherwise,
we can prevent the user from clicking the save button in the time between
the value being entered and the api returning.

* [cccs-2.0] fixing trino req (#216)

* updating superset-base image tag

* added option to emit a filter from a default column for a row in ag grid

* Update trino python client (#219)

* Updated trino python client from 0.316.0 to 0.318.0

* Temp update to base image tag

* Removing temp change to build image

* Updated superset's base image tag (#221)

* Update superset-frontend/src/cccs-viz/plugins/plugin-chart-cccs-grid/src/CccsGrid.tsx

Co-authored-by: cccs-Dustin <[email protected]>

* changed control panel to plural

* disallow columns that are not a part of the chart to be selected as default emit filters

* updated image tag

* updated control panel logic for agg mode

* update image tag

* fixed issues

* updating base image

* fixed refactor error

* updating base image

* fixed so that option disables properly

* updating base image

* Add users API to get and delete users (#223)

* Add users API to get and delete users

* Allow browser login for users api

* updating image

* Update cccs-build/superset/Dockerfile

Co-authored-by: cccs-Dustin <[email protected]>

* Added ability to certify entities with multiple values (#224)

* Added ability to certify entities with multiple values

* Update description text to reflect new feature

* Add tests for multiple certified by values

* Feature/cldn 1749 (#222)

* [CLDN-1749] adding new viz

* chanigng to work with standard filters

* Adding generic filter extraction

* Removing unused imports

* [CLDN-1749] Cleaning up code for reusablility

* [CLDN-1749] removing unused files

* [CLDN-1746] fixing case

* [CLDN-1749] adding parameter validation

* [CLDN-1749] adding error message and prefix parameter

* [CLDN-1749] removing unused files

* [CLDN-1749] adding temp base image for docker deployment

* [CLDN-1749] Better error handling and new icon

* [CLDN-1749] remove unused imports

* temp dockerfile change

* [CLDN-1749] Adding the adhoc filters back in

* [CLDN-1749] Updating image

* [CLDN-1749] Adding new thumbnail

* Updating dockerfile

* [CLDN-1749] Removing uneeded control panel elements

* [CLDN-1749] Fixing build errors

* [CLDN-1749] New image

* Change to use data from dataset

* Removing unsed function

* Fixing typos

* renove unused import

* updating image

* error message and label fixes

* updating image

* Update cccs-build/superset/Dockerfile

Co-authored-by: cccs-Dustin <[email protected]>

* Update superset-frontend/src/cccs-viz/plugins/plugin-chart-iframe/src/plugin/transformProps.ts

Co-authored-by: cccs-RyanK <[email protected]>

* Update superset-frontend/src/cccs-viz/plugins/plugin-chart-iframe/src/plugin/transformProps.ts

Co-authored-by: cccs-RyanK <[email protected]>

Co-authored-by: cccs-Dustin <[email protected]>
Co-authored-by: cccs-RyanK <[email protected]>

* Prevent non-admins from using users api (#236)

* Prevent non-admins from using users api

* Add tests

* added styles to highlight adhoc filter when focused and fix awkward empty header

* removed suggestions from popping up

* added comment

* fixed unused import error

* updating base image

* Update Dockerfile

* [CLDN-1829] fixing principle filter logic with state (#234) (#244)

* [CLDN-1829] fixing principle filter logic with state

* [CLDN-1829] Fixing build error

* [cccs-2.0] Updating image (#245)

* value set to empty list instead of undefined

* updating base image

* Feature/cldn 1748 (#243)

* [CLDN-1748] adding base component

* [CLDN-1748] changing state to use advanced data type

* [CLDN-1748] add multi select for musiness type

* [CLDN-1748] adding config manager

* [CLDN-1748] fixing build errors

* temp update of base image

* [CLDN-1748] Fixing Url parameter encoding and show name of dashboard drilling to

* temp update of image

* Pulling extra data from dashboard endpoint

* Adding more data to filters object

* [CLDN-1748] passing mroe fitler information

* [CLDN-1748] QA feedback

* [CLDN-1748] Fixing build issues

* [CLDN-1748] Updating dockerfile

* [CLDN-1748] Updating dockerfile

* fixing props name

* update image

* updating docker file

* [CLDN-1748] Name changes

* [CLDN-1748] updating image

* [CLDN-1748] Adding icon

* [CLDN-1748] fixing build errors

* [CLDN-1748] update image

* [CLDN-1748] fixing context menue to renderering

* UPdating docker file

* CLDN-1710 including schema in search columns for datasets api (#253)

* Update Dockerfile

* CLDN-1710 tag update (#255)

* update image tag

* updating image tag

* Update vault image to get new CAs

* update image tag

* Update Dockerfile

* Update Dockerfile

* Feature/cldn 1773 (#269)

* [CLDN-1773] Adding default group by

* Updating DockerFile

* Fixing Groupby

* Updating base image

* [CLDN-1773] Saving Group by order

* Updating dockerfile

* Update controlPanel.tsx

* Update superset-frontend/src/cccs-viz/plugins/plugin-chart-cccs-grid/src/plugin/transformProps.ts

Co-authored-by: cccs-tom <[email protected]>

* Update superset-frontend/src/cccs-viz/plugins/plugin-chart-cccs-grid/src/plugin/transformProps.ts

Co-authored-by: cccs-tom <[email protected]>

* Update superset-frontend/src/cccs-viz/plugins/plugin-chart-cccs-grid/src/plugin/transformProps.ts

Co-authored-by: cccs-RyanK <[email protected]>

---------

Co-authored-by: cccs-tom <[email protected]>
Co-authored-by: cccs-RyanK <[email protected]>

* Updating docker file (#270)

* Feature/cldn 1968 (Display JSON data inline) (#268)

* Add buttons to expand and minimize JSON data as well as ability to expand and/or collapse all rows in a certain column

* [CLDN-1968] Added expand button for full row

* [CLDN-1968] Resize JSON columns

* [CLDN-1968] Added new array which tracks JSON cell state

* Revert "[CLDN-1968] Added new array which tracks JSON cell state"

This reverts commit dabc3da.

* [CLDN-1968] Added ability for row level expand all button to track if cells are expanded or not

* [CLDN-1968] Ran pre-commit hook

* [CLDN-1968] Improved UI

* [CLDN-1968] Update image tag for testing

* [CLDN-1968] Revert image tag for testing

* [CLDN-1968] Added multiple UI/UX changes based on QA feedback

* [CLDN-1968] Added more UI/UX changes based on QA feedback

* [CLDN-1968] Temp change to image

* Revert "[CLDN-1968] Temp change to image"

This reverts commit 57490bd.

* Update superset-frontend/src/cccs-viz/plugins/plugin-chart-cccs-grid/src/CccsGrid.tsx

Co-authored-by: cccs-rc <[email protected]>

* [CLDN-1968] Remove 'TODO's as they are no longer needed

* [CLDN-1968] Changed a variable name, and condensed a few lines

* [CLDN-1968] Modified a setState so that only one is needed instead of 2

---------

Co-authored-by: cccs-rc <[email protected]>

* Feature/cldn 1968 (#272)

* Add buttons to expand and minimize JSON data as well as ability to expand and/or collapse all rows in a certain column

* [CLDN-1968] Added expand button for full row

* [CLDN-1968] Resize JSON columns

* [CLDN-1968] Added new array which tracks JSON cell state

* Revert "[CLDN-1968] Added new array which tracks JSON cell state"

This reverts commit dabc3da.

* [CLDN-1968] Added ability for row level expand all button to track if cells are expanded or not

* [CLDN-1968] Ran pre-commit hook

* [CLDN-1968] Improved UI

* [CLDN-1968] Update image tag for testing

* [CLDN-1968] Revert image tag for testing

* [CLDN-1968] Added multiple UI/UX changes based on QA feedback

* [CLDN-1968] Added more UI/UX changes based on QA feedback

* [CLDN-1968] Temp change to image

* Revert "[CLDN-1968] Temp change to image"

This reverts commit 57490bd.

* Update superset-frontend/src/cccs-viz/plugins/plugin-chart-cccs-grid/src/CccsGrid.tsx

Co-authored-by: cccs-rc <[email protected]>

* [CLDN-1968] Remove 'TODO's as they are no longer needed

* [CLDN-1968] Changed a variable name, and condensed a few lines

* [CLDN-1968] Modified a setState so that only one is needed instead of 2

* Update superset base image

---------

Co-authored-by: cccs-rc <[email protected]>

* Adding componenets

* [CLDN-2142] Finish Dateetime Picker and reorg control panael

* added changes to align cccs-viz with upstream cross-filtering

* fixed column sorting being reset on emit filters

* fixed errors

* [CLDN-2142] Adding validation for advanced type input

* update base image

* update base image

* advanced type null fix

* removed legacy time section

* removed unused import

* updating docker image

* fixed bootstrap data

* update docker file

* [CLDN-2064] Fixed column header reset bug

* fix column sorting not updating columns

* updating base image

* updating base image

* [expore++] Fixing bugs with page reload

* fixing build errors

* Dockerfile update

* CLDN-2198 updated formatting and removed change dataset button from cccs-grid

* CLDN-2202 updated formatting and  fixed time range validation errors

* CLDN-2195 prevent running an emtpy query aggregate mode

* CLDN-2203 make wording in date errors consistent with labels

* CLDN-2205 make time range invisible when no time column is selected

* CLDN-2206 Fixed formatting, labelling, classname, and disable selector values when there is no selector

* CLDN-2207 show advanced type labels and not ids in selector dropdown

* CLDN-2208 clear values when selector is changed

* CLDN-2210 change button name to Swap Dataset

* CLDN-2211 fix query builder to use actual values rather than strings

* fixed npm errors

* update image tag

* merge fixes and tool tip update

* CLDN-2209 fix incorrect dimensions after swapping datasets

* Select All not working on swap datasets, default to no selection

* fixed npm build errros

* update base image

* CLDN-2208 Mandatory to have a value if selector is selected and invalid entries disable run query button

* disable time range when no time column is selected

* change selector to advanced data type and values now saved in form data properly

* fix refactor mistake and allow querying ranges of advanced types

* added comments and removed debugging lines

* remove unecessary tool tip and fix npm issues

* validation in progress to prevent running query on bad values

* update base image

* fix for temporarily caching form data

* readded tooltip

* fixed tooltip, added order by

* npm error fix

* update base image

* removed changes from hogwarts table viz

* fix error in tooltip for adt value

* update image  tag

* removed unused adhoc time filter

* fixed import order

* update docker file

* [dataset explorer] pr feedback

* Updating docker file

* testing datetime formatting

* fixing npm error

* updating image tag

* small formatting fix

* update image tag

* fixes to control panel

* fix npm issues

* updated base image tag

* update base image tag

* fixed default values for control components

* updated base image tag

---------

Co-authored-by: Reese <[email protected]>
Co-authored-by: cccs-Dustin <[email protected]>
Co-authored-by: cccs-rc <[email protected]>
Co-authored-by: cccs-RyanK <[email protected]>
Co-authored-by: GITHUB_USERNAME <EMAIL>
Co-authored-by: cccs-nik <[email protected]>
Co-authored-by: cccs-RyanK <[email protected]>
Co-authored-by: cccs-tom <[email protected]>
  • Loading branch information
8 people authored Jul 26, 2023
1 parent 3f0d912 commit ae5eb1b
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cccs-build/superset/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Vault CA container import
ARG VAULT_CA_CONTAINER=uchimera.azurecr.io/cccs/hogwarts/vault-ca:master_11376_a25c34e1
FROM $VAULT_CA_CONTAINER AS vault_ca
FROM uchimera.azurecr.io/cccs/superset-base:cccs-2.1_20230704153241_b7209
FROM uchimera.azurecr.io/cccs/superset-base:feature_dataset-explorer-chart-update-chart_20230725150622_b7385

USER root

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,33 @@ const AdvancedDataTypeValueControlValueControl: React.FC<Props> = ({
value = [],
description,
}) => {
const [rawValues, setRawValues] = useState([]);
const [rawValues, setRawValues] = useState(
value && ensureIsArray(value).length === 1 ? value[0].rawData : [],
);
const [validationErrors, setValidationErrors] = useState<string[]>([]);
const [currentAdvancedDataType, setCurrentAdvancedDataType] =
useState<string>();
useState<string>(advancedDataType);

const default_advanced_data_type_state = {
parsedAdvancedDataType: '',
advancedDataTypeOperatorList: [],
errorMessage: '',
useDefaultOperators: false,
values: value && ensureIsArray(value).length === 1 ? value[0].data : [],
};

const {
advancedDataTypesState,
subjectAdvancedDataType,
fetchAdvancedDataTypeValueCallback,
} = useAdvancedDataTypes(() => {});
} = useAdvancedDataTypes(() => {}, default_advanced_data_type_state);

const onChangeWrapper = (selection: any) => {
setValidationErrors([...validationErrors, 'Validation in progress']);
setValidationErrors(
selection.length > 0
? [...validationErrors, 'Validation in progress']
: [...validationErrors],
);
setRawValues(selection);
};

Expand All @@ -68,8 +82,7 @@ const AdvancedDataTypeValueControlValueControl: React.FC<Props> = ({

useEffect(() => {
const data =
advancedDataTypesState.parsedAdvancedDataType.length > 0 &&
advancedDataTypesState.parsedAdvancedDataType.split(',').length > 0
advancedDataTypesState.values.length > 0
? {
data: advancedDataTypesState.values,
columns: datasource.columns
Expand All @@ -82,11 +95,13 @@ const AdvancedDataTypeValueControlValueControl: React.FC<Props> = ({
}, [advancedDataTypesState, validationErrors]);

useEffect(() => {
fetchAdvancedDataTypeValueCallback(
rawValues,
advancedDataTypesState,
ensureIsArray(advancedDataType)[0],
);
if (rawValues.length > 0) {
fetchAdvancedDataTypeValueCallback(
rawValues,
advancedDataTypesState,
ensureIsArray(advancedDataType)[0],
);
}
}, [advancedDataType, rawValues, subjectAdvancedDataType]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ChangeDatasourceModal } from 'src/components/Datasource';
import { withTheme } from '@superset-ui/core';
import { connect, useDispatch } from 'react-redux';
import Button from 'src/components/Button';
import { updateFormDataByDatasource } from 'src/explore/actions/exploreActions';
import { updateCCCSFormDataByDatasource } from 'src/explore/actions/exploreActions';

export interface Props {
colorScheme: string;
Expand Down Expand Up @@ -32,7 +32,7 @@ const ChangeDatasourceButtonControll: React.FC<Props> = ({
setShowChangeDatasourceModal(!showChangeDatasourceModal);
};
const onDatasourceSave = (new_datasource: any) => {
dispatch(updateFormDataByDatasource(datasource, new_datasource));
dispatch(updateCCCSFormDataByDatasource(datasource, new_datasource));
};
const onChangeWrapper = (a: any) => {
onChange(a);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React, { useEffect, useState } from 'react';
import { SLOW_DEBOUNCE, SupersetClient, t, withTheme } from '@superset-ui/core';
import {
NO_TIME_RANGE,
SLOW_DEBOUNCE,
SupersetClient,
t,
withTheme,
} from '@superset-ui/core';
import {
buildTimeRangeString,
formatTimeRange,
Expand All @@ -21,7 +27,7 @@ export interface Props {
name: string;
actions: object;
label: string;
value?: object[];
value?: string;
onChange: (value: any, errors: any[]) => void;
default: string;
disabled: boolean;
Expand Down Expand Up @@ -52,9 +58,17 @@ const fetchTimeRange = async (timeRange: string) => {
};

const DatetimeControl: React.FC<Props> = props => {
const [timeRange, setTimeRange] = useState(props.default);
// if the value passed in is "no filter", leave the control empty
// if the value does not exist, set it to the default
const [timeRange, setTimeRange] = useState(
props.value
? props.value === NO_TIME_RANGE
? ''
: props.value
: props.default,
);
const [validationErrors, setValidationErrors] = useState<string[]>([]);
const [actualTimeRange, setactualTimeRange] = useState<string>();
const [actualTimeRange, setActualTimeRange] = useState<string>();

const [since, until] = timeRange.split(SEPARATOR);

Expand All @@ -64,7 +78,9 @@ const DatetimeControl: React.FC<Props> = props => {

function onChange(control: 'since' | 'until', value: string) {
if (control === 'since') {
setTimeRange(`${value}${SEPARATOR}${until}`);
setTimeRange(
until ? `${value}${SEPARATOR}${until}` : `${value}${SEPARATOR}`,
);
} else {
setTimeRange(`${since}${SEPARATOR}${value}`);
}
Expand All @@ -74,7 +90,7 @@ const DatetimeControl: React.FC<Props> = props => {
() => {
fetchTimeRange(timeRange)
.then(value => {
setactualTimeRange(
setActualTimeRange(
value?.value ? `Actual Time Range ${value?.value}` : '',
);
setValidationErrors(value?.error ? [value?.error] : []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ensureIsArray,
getMetricLabel,
PostProcessingRule,
QueryFormColumn,
QueryMode,
QueryObject,
removeDuplicates,
Expand Down Expand Up @@ -125,7 +126,7 @@ const buildQuery: BuildQuery<CccsGridQueryFormData> = (
const { advanced_data_type_value } = formData;
const { advanced_data_type_selection } = formData;
let filter = [];
if (advanced_data_type_selection.length > 0) {
if (ensureIsArray(advanced_data_type_selection).length > 0) {
// in the case of ipv4s sometimes they can be ranges and not simple values
// this will be handled in the advanced data type definition in the future
// to avoid this complex logic
Expand All @@ -152,8 +153,21 @@ const buildQuery: BuildQuery<CccsGridQueryFormData> = (
[],
);
}

// load the time range as a filter if it exists
if (baseQueryObject.granularity) {
baseQueryObject.filters?.push({
col: baseQueryObject.granularity as QueryFormColumn,
op: 'TEMPORAL_RANGE',
val: baseQueryObject.time_range || '',
});
}

const baseQueryObjectCopy = baseQueryObject;
baseQueryObjectCopy.granularity = undefined;

const queryObject = {
...baseQueryObject,
...baseQueryObjectCopy,
formData: formDataCopy,
orderby,
metrics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ const config: ControlPanelConfig = {
'expression',
),
clearable: false,
optionRenderer: (c: any) => (
<StyledColumnOption column={c} showType />
),
valueKey: 'column_name',
rerender: ['time_range'],
mapStateToProps: state => {
Expand All @@ -141,12 +138,23 @@ const config: ControlPanelConfig = {
state.datasource &&
'granularity_sqla' in state.datasource
) {
props.choices = state.datasource.granularity_sqla;
props.default = null;
props.options = state.datasource.columns
.filter(c =>
ensureIsArray(
(state.datasource as Dataset)?.granularity_sqla,
)
.map(g => g[0])
.includes(c.column_name),
)
.map(c => ({
label: c.verbose_name ? c.verbose_name : c.column_name,
column_name: c.column_name,
}));
props.default = undefined;
if (state.datasource.main_dttm_col) {
props.default = state.datasource.main_dttm_col;
} else if (props.choices && props.choices.length > 0) {
props.default = props.choices[0].column_name;
} else if (props.options && props.options.length > 0) {
props.default = props.options.column_name;
}
}
return props;
Expand Down
13 changes: 13 additions & 0 deletions superset-frontend/src/explore/actions/exploreActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ export function updateFormDataByDatasource(
};
}

export const UPDATE_CCCS_FORM_DATA_BY_DATASOURCE =
'UPDATE_CCCS_FORM_DATA_BY_DATASOURCE';
export function updateCCCSFormDataByDatasource(
prevDatasource: Dataset,
newDatasource: Dataset,
) {
return {
type: UPDATE_CCCS_FORM_DATA_BY_DATASOURCE,
prevDatasource,
newDatasource,
};
}

export const POST_DATASOURCE_STARTED = 'POST_DATASOURCE_STARTED';
export const FETCH_DATASOURCE_SUCCEEDED = 'FETCH_DATASOURCE_SUCCEEDED';
export function fetchDatasourceSucceeded() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ const INITIAL_ADVANCED_DATA_TYPES_STATE: AdvancedDataTypesState = {
values: [],
};

const useAdvancedDataTypes = (validHandler: (isValid: boolean) => void) => {
const useAdvancedDataTypes = (
validHandler: (isValid: boolean) => void,
default_state: AdvancedDataTypesState = INITIAL_ADVANCED_DATA_TYPES_STATE,
) => {
const [advancedDataTypesState, setAdvancedDataTypesState] =
useState<AdvancedDataTypesState>(INITIAL_ADVANCED_DATA_TYPES_STATE);
useState<AdvancedDataTypesState>(default_state);
const [subjectAdvancedDataType, setSubjectAdvancedDataType] = useState<
string | undefined
>();
Expand Down
95 changes: 95 additions & 0 deletions superset-frontend/src/explore/reducers/exploreReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,101 @@ export default function exploreReducer(state = {}, action) {
controlsTransferred,
};
},
[actions.UPDATE_CCCS_FORM_DATA_BY_DATASOURCE]() {
const newFormData = { ...state.form_data };
const { prevDatasource, newDatasource } = action;
const controls = { ...state.controls };
const controlsTransferred = [];

if (
prevDatasource.id !== newDatasource.id ||
prevDatasource.type !== newDatasource.type
) {
newFormData.datasource = newDatasource.uid;
}
// reset control values for column/metric related controls
Object.entries(controls).forEach(([controlName, controlState]) => {
if (
// for direct column select controls
controlState.valueKey === 'column_name' ||
// for all other controls
'savedMetrics' in controlState ||
'columns' in controlState ||
('options' in controlState && !Array.isArray(controlState.options))
) {
newFormData[controlName] = getControlValuesCompatibleWithDatasource(
newDatasource,
controlState,
controlState.value,
);
if (
ensureIsArray(newFormData[controlName]).length > 0 &&
newFormData[controlName] !== controls[controlName].default
) {
controlsTransferred.push(controlName);
}
}
});

const newState = {
...state,
controls,
datasource: action.newDatasource,
};
const newControls = getControlsState(newState, newFormData);

if (newControls.advanced_data_type_selection) {
// filter out incompatible Advanced Data Types in the new Datasource
const advancedDataTypeSelectionControl =
newControls.advanced_data_type_selection;
newFormData.advanced_data_type_selection = newDatasource.columns.some(
c => c.advanced_data_type === advancedDataTypeSelectionControl.value,
)
? advancedDataTypeSelectionControl.value
: [];
newControls.advanced_data_type_selection.value =
newFormData.advanced_data_type_selection;
// check if the new datasource has any columns with the same Advanced Data Type
if (
ensureIsArray(newFormData.advanced_data_type_selection).length > 0
) {
// transfer the control to use the new columns
newControls.advanced_data_type_value.value[0].columns =
newDatasource.columns
.filter(
c =>
c.advanced_data_type ===
advancedDataTypeSelectionControl.value,
)
.map(c => c.column_name);
controlsTransferred.push('advanced_data_type_selection');
controlsTransferred.push('advanced_data_type_value');
} else {
// if there are no compatible columns, clear the controls and disable the value control
newControls.advanced_data_type_value.value = [
{ columns: [], data: [], rawData: [] },
];
newControls.advanced_data_type_value.disabled = true;
newControls.advanced_data_type_value.advancedDataType = [];
newFormData.advanced_data_type_value =
newControls.advanced_data_type_value.value;
}
}
// check if date column is compatible with new datasource
if (!newDatasource.columns.includes(newFormData.granularity_sqla)) {
// set the time column to the new default time column
newControls.granularity_sqla.value = newDatasource.main_dttm_col;
newFormData.granularity_sqla = newDatasource.main_dttm_col;
// disable the time range if there is no default
newControls.time_range.disabled = !newDatasource.main_dttm_col;
}
return {
...newState,
form_data: newFormData,
controls: newControls,
controlsTransferred,
};
},
[actions.FETCH_DATASOURCES_STARTED]() {
return {
...state,
Expand Down

0 comments on commit ae5eb1b

Please sign in to comment.