Skip to content

Commit

Permalink
chore(Dashboard): Disable save button in Native Filters when an error…
Browse files Browse the repository at this point in the history
… is present (#17037)

* Disable save on error

* Remove removed erroredFilter

* Fix cdisabled check
  • Loading branch information
geido authored Oct 21, 2021
1 parent 4c708af commit e5a0342
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
import React, { useCallback, useMemo, useState, useRef } from 'react';
import React, {
useEffect,
useCallback,
useMemo,
useState,
useRef,
} from 'react';
import { uniq, isEqual, sortBy, debounce } from 'lodash';
import { t, styled, SLOW_DEBOUNCE } from '@superset-ui/core';
import { Form } from 'src/common/components';
Expand Down Expand Up @@ -391,6 +397,12 @@ export function FiltersConfigModal({
[handleFilterHierarchyChange, handleErroredFilters],
);

useEffect(() => {
setErroredFilters(prevErroredFilters =>
prevErroredFilters.filter(f => !removedFilters[f]),
);
}, [removedFilters]);

return (
<StyledModalWrapper
visible={isOpen}
Expand All @@ -407,6 +419,7 @@ export function FiltersConfigModal({
onDismiss={() => setSaveAlertVisible(false)}
onCancel={handleCancel}
handleSave={handleSave}
canSave={!erroredFilters.length}
saveAlertVisible={saveAlertVisible}
onConfirmCancel={handleConfirmCancel}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ type FooterProps = {
onConfirmCancel: OnClickHandler;
onDismiss: OnClickHandler;
saveAlertVisible: boolean;
canSave?: boolean;
};

const Footer: FC<FooterProps> = ({
canSave = true,
onCancel,
handleSave,
onDismiss,
Expand Down Expand Up @@ -60,6 +62,7 @@ const Footer: FC<FooterProps> = ({
{t('Cancel')}
</Button>
<Button
disabled={!canSave}
key="submit"
buttonStyle="primary"
onClick={handleSave}
Expand Down

0 comments on commit e5a0342

Please sign in to comment.