You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "Antonio-RiveroMartnez (via GitHub)" <gi...@apache.org> on 2024/11/06 03:07:09 UTC

[PR] fix(time_comparison): Allow deleting dates when using custom shift [superset]

Antonio-RiveroMartnez opened a new pull request, #30848:
URL: https://github.com/apache/superset/pull/30848

   ### SUMMARY
   This PR fixes the date picker for custom start date in time comparison section so users can click the `x` to delete the date and select a new one. Currently it shows `Invalid date` and the whole date picker gets NaN values.
   
   When the user clicks the `x` the control panel shows the error like we do for other fields and the chart cannot be created/updated because the button is disabled.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   Before
   https://github.com/user-attachments/assets/0f509043-32be-44be-8df4-9e5b33765f14
   
   After
   Creating
   
   https://github.com/user-attachments/assets/ee05678e-32bf-4144-aefd-a99937499168
   
   
   Updating
   https://github.com/user-attachments/assets/0779ca8f-ef35-4afc-8ae1-8db5ace3d69f
   
   
   
   
   ### TESTING INSTRUCTIONS
   Create a new Table with Time Comparison chart.
   Expand the Time Comparison section.
   Select Custom date on Time Shift.
   Select a date on shift start date.
   Click on the x next to it to remove it.
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(time_comparison): Allow deleting dates when using custom shift [superset]

Posted by "Antonio-RiveroMartnez (via GitHub)" <gi...@apache.org>.
Antonio-RiveroMartnez commented on code in PR #30848:
URL: https://github.com/apache/superset/pull/30848#discussion_r1830828648


##########
superset-frontend/packages/superset-ui-chart-controls/src/sections/timeComparison.tsx:
##########
@@ -94,9 +98,29 @@ export const timeComparisonControls: ({
         name: 'start_date_offset',
         config: {
           type: 'TimeOffsetControl',
-          label: t('shift start date'),
+          label: t('Shift start date'),
           visibility: ({ controls }) =>
             controls?.time_compare.value === 'custom',
+          mapStateToProps: (
+            state: ControlPanelState,
+            controlState: ControlState,
+          ) => {
+            const { form_data } = state;
+            const { time_compare } = form_data;
+            const newState = { ...controlState };
+            if (
+              time_compare === 'custom' &&
+              (controlState.value === '' ||
+                controlState.value === 'Invalid date')

Review Comment:
   Let me move that to a const, about translating, that's coming form moment indeed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(time_comparison): Allow deleting dates when using custom shift [superset]

Posted by "kgabryje (via GitHub)" <gi...@apache.org>.
kgabryje commented on code in PR #30848:
URL: https://github.com/apache/superset/pull/30848#discussion_r1830844574


##########
superset-frontend/packages/superset-ui-chart-controls/src/sections/timeComparison.tsx:
##########
@@ -94,9 +98,29 @@ export const timeComparisonControls: ({
         name: 'start_date_offset',
         config: {
           type: 'TimeOffsetControl',
-          label: t('shift start date'),
+          label: t('Shift start date'),
           visibility: ({ controls }) =>
             controls?.time_compare.value === 'custom',
+          mapStateToProps: (
+            state: ControlPanelState,
+            controlState: ControlState,
+          ) => {
+            const { form_data } = state;
+            const { time_compare } = form_data;
+            const newState = { ...controlState };
+            if (
+              time_compare === 'custom' &&
+              (controlState.value === '' ||
+                controlState.value === 'Invalid date')

Review Comment:
   Can we write a small unit test for that „Invalid date” string to future proof it in case it ever changes in momentjs?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(time_comparison): Allow deleting dates when using custom shift [superset]

Posted by "Antonio-RiveroMartnez (via GitHub)" <gi...@apache.org>.
Antonio-RiveroMartnez commented on code in PR #30848:
URL: https://github.com/apache/superset/pull/30848#discussion_r1830823735


##########
superset-frontend/packages/superset-ui-chart-controls/src/sections/timeComparison.tsx:
##########
@@ -94,9 +98,29 @@ export const timeComparisonControls: ({
         name: 'start_date_offset',
         config: {
           type: 'TimeOffsetControl',
-          label: t('shift start date'),
+          label: t('Shift start date'),
           visibility: ({ controls }) =>
             controls?.time_compare.value === 'custom',
+          mapStateToProps: (
+            state: ControlPanelState,
+            controlState: ControlState,
+          ) => {
+            const { form_data } = state;
+            const { time_compare } = form_data;
+            const newState = { ...controlState };
+            if (
+              time_compare === 'custom' &&
+              (controlState.value === '' ||
+                controlState.value === 'Invalid date')
+            ) {
+              newState.externalValidationErrors = [
+                t('A date is required when using Custom date shift'),

Review Comment:
   Oh! Good catch, thanks 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(time_comparison): Allow deleting dates when using custom shift [superset]

Posted by "Antonio-RiveroMartnez (via GitHub)" <gi...@apache.org>.
Antonio-RiveroMartnez commented on code in PR #30848:
URL: https://github.com/apache/superset/pull/30848#discussion_r1830828648


##########
superset-frontend/packages/superset-ui-chart-controls/src/sections/timeComparison.tsx:
##########
@@ -94,9 +98,29 @@ export const timeComparisonControls: ({
         name: 'start_date_offset',
         config: {
           type: 'TimeOffsetControl',
-          label: t('shift start date'),
+          label: t('Shift start date'),
           visibility: ({ controls }) =>
             controls?.time_compare.value === 'custom',
+          mapStateToProps: (
+            state: ControlPanelState,
+            controlState: ControlState,
+          ) => {
+            const { form_data } = state;
+            const { time_compare } = form_data;
+            const newState = { ...controlState };
+            if (
+              time_compare === 'custom' &&
+              (controlState.value === '' ||
+                controlState.value === 'Invalid date')

Review Comment:
   Let me move that to a const, about translating, that's coming from moment indeed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(time_comparison): Allow deleting dates when using custom shift [superset]

Posted by "geido (via GitHub)" <gi...@apache.org>.
geido commented on code in PR #30848:
URL: https://github.com/apache/superset/pull/30848#discussion_r1830819858


##########
superset-frontend/packages/superset-ui-chart-controls/src/sections/timeComparison.tsx:
##########
@@ -94,9 +98,29 @@ export const timeComparisonControls: ({
         name: 'start_date_offset',
         config: {
           type: 'TimeOffsetControl',
-          label: t('shift start date'),
+          label: t('Shift start date'),
           visibility: ({ controls }) =>
             controls?.time_compare.value === 'custom',
+          mapStateToProps: (
+            state: ControlPanelState,
+            controlState: ControlState,
+          ) => {
+            const { form_data } = state;
+            const { time_compare } = form_data;
+            const newState = { ...controlState };
+            if (
+              time_compare === 'custom' &&
+              (controlState.value === '' ||
+                controlState.value === 'Invalid date')
+            ) {
+              newState.externalValidationErrors = [
+                t('A date is required when using Custom date shift'),

Review Comment:
   Is this "Custom" with capital C intended?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(time_comparison): Allow deleting dates when using custom shift [superset]

Posted by "kgabryje (via GitHub)" <gi...@apache.org>.
kgabryje commented on code in PR #30848:
URL: https://github.com/apache/superset/pull/30848#discussion_r1830825810


##########
superset-frontend/packages/superset-ui-chart-controls/src/sections/timeComparison.tsx:
##########
@@ -94,9 +98,29 @@ export const timeComparisonControls: ({
         name: 'start_date_offset',
         config: {
           type: 'TimeOffsetControl',
-          label: t('shift start date'),
+          label: t('Shift start date'),
           visibility: ({ controls }) =>
             controls?.time_compare.value === 'custom',
+          mapStateToProps: (
+            state: ControlPanelState,
+            controlState: ControlState,
+          ) => {
+            const { form_data } = state;
+            const { time_compare } = form_data;
+            const newState = { ...controlState };
+            if (
+              time_compare === 'custom' &&
+              (controlState.value === '' ||
+                controlState.value === 'Invalid date')

Review Comment:
   We use „Invalid date” here and in explore. Should we move it to a const in chart controls package? Also, should it be translated or does that string come from some external library?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(time_comparison): Allow deleting dates when using custom shift [superset]

Posted by "Antonio-RiveroMartnez (via GitHub)" <gi...@apache.org>.
Antonio-RiveroMartnez commented on code in PR #30848:
URL: https://github.com/apache/superset/pull/30848#discussion_r1830846123


##########
superset-frontend/packages/superset-ui-chart-controls/src/sections/timeComparison.tsx:
##########
@@ -94,9 +98,29 @@ export const timeComparisonControls: ({
         name: 'start_date_offset',
         config: {
           type: 'TimeOffsetControl',
-          label: t('shift start date'),
+          label: t('Shift start date'),
           visibility: ({ controls }) =>
             controls?.time_compare.value === 'custom',
+          mapStateToProps: (
+            state: ControlPanelState,
+            controlState: ControlState,
+          ) => {
+            const { form_data } = state;
+            const { time_compare } = form_data;
+            const newState = { ...controlState };
+            if (
+              time_compare === 'custom' &&
+              (controlState.value === '' ||
+                controlState.value === 'Invalid date')

Review Comment:
   Sure thing



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(time_comparison): Allow deleting dates when using custom shift [superset]

Posted by "Antonio-RiveroMartnez (via GitHub)" <gi...@apache.org>.
Antonio-RiveroMartnez merged PR #30848:
URL: https://github.com/apache/superset/pull/30848


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org