Skip to content

Commit

Permalink
Refactor to incompatibleDataSourcesExist
Browse files Browse the repository at this point in the history
Signed-off-by: Huy Nguyen <[email protected]>
  • Loading branch information
huyaboo committed May 6, 2024
1 parent b49a73b commit 5f7a594
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface DataSourceAggregatedViewState extends DataSourceBaseState {
allDataSourcesIdToTitleMap: Map<string, any>;
switchChecked: boolean;
defaultDataSource: string | null;
hasIncompatibleDataSources: boolean;
incompatibleDataSourcesExist: boolean;
}

interface DataSourceOptionDisplay extends DataSourceOption {
Expand All @@ -69,7 +69,7 @@ export class DataSourceAggregatedView extends React.Component<
showError: false,
switchChecked: false,
defaultDataSource: null,
hasIncompatibleDataSources: false,
incompatibleDataSourcesExist: false,
};
}

Expand Down Expand Up @@ -119,7 +119,7 @@ export class DataSourceAggregatedView extends React.Component<
changeState: this.onEmptyState.bind(this, !!fetchedDataSources?.length),
notifications: this.props.notifications,
application: this.props.application,
hasIncompatibleDatasources: !!fetchedDataSources?.length,
incompatibleDataSourcesExist: !!fetchedDataSources?.length,
});
return;
}
Expand All @@ -136,8 +136,8 @@ export class DataSourceAggregatedView extends React.Component<
});
}

onEmptyState(hasIncompatibleDataSources: boolean) {
this.setState({ showEmptyState: true, hasIncompatibleDataSources });
onEmptyState(incompatibleDataSourcesExist: boolean) {
this.setState({ showEmptyState: true, incompatibleDataSourcesExist });
}

onError() {
Expand All @@ -149,7 +149,7 @@ export class DataSourceAggregatedView extends React.Component<
return (
<NoDataSource
application={this.props.application}
hasIncompatibleDatasources={this.state.hasIncompatibleDataSources}
incompatibleDataSourcesExist={this.state.incompatibleDataSourcesExist}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface DataSourceMultiSeletableState extends DataSourceBaseState {
dataSourceOptions: SelectedDataSourceOption[];
selectedOptions: SelectedDataSourceOption[];
defaultDataSource: string | null;
hasIncompatibleDatasources: boolean;
incompatibleDataSourcesExist: boolean;
}

export class DataSourceMultiSelectable extends React.Component<
Expand All @@ -52,7 +52,7 @@ export class DataSourceMultiSelectable extends React.Component<
defaultDataSource: null,
showEmptyState: false,
showError: false,
hasIncompatibleDatasources: false,
incompatibleDataSourcesExist: false,
};
}

Expand Down Expand Up @@ -97,7 +97,7 @@ export class DataSourceMultiSelectable extends React.Component<
notifications: this.props.notifications,
application: this.props.application,
callback: this.props.onSelectedDataSources,
hasIncompatibleDatasources: !!fetchedDataSources?.length,
incompatibleDataSourcesExist: !!fetchedDataSources?.length,
});
return;
}
Expand All @@ -118,8 +118,8 @@ export class DataSourceMultiSelectable extends React.Component<
}
}

onEmptyState(hasIncompatibleDatasources: boolean) {
this.setState({ showEmptyState: true, hasIncompatibleDatasources });
onEmptyState(incompatibleDataSourcesExist: boolean) {
this.setState({ showEmptyState: true, incompatibleDataSourcesExist });

Check warning on line 122 in src/plugins/data_source_management/public/components/data_source_multi_selectable/data_source_multi_selectable.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/data_source_multi_selectable/data_source_multi_selectable.tsx#L122

Added line #L122 was not covered by tests
}

onError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('DataSourceSelectable', () => {
},
],
showError: false,
hasIncompatibleDatasources: false,
incompatibleDataSourcesExist: false,
});

containerInstance.onChange([{ id: 'test2', label: 'test2', checked: 'on' }]);
Expand All @@ -177,7 +177,7 @@ describe('DataSourceSelectable', () => {
},
],
showError: false,
hasIncompatibleDatasources: false,
incompatibleDataSourcesExist: false,
});

expect(onSelectedDataSource).toBeCalledWith([{ id: 'test2', label: 'test2' }]);
Expand Down Expand Up @@ -356,7 +356,7 @@ describe('DataSourceSelectable', () => {
},
],
showError: false,
hasIncompatibleDatasources: false,
incompatibleDataSourcesExist: false,
});
});

Expand Down Expand Up @@ -386,7 +386,7 @@ describe('DataSourceSelectable', () => {
selectedOption: [],
showEmptyState: false,
showError: true,
hasIncompatibleDatasources: false,
incompatibleDataSourcesExist: false,
});

containerInstance.onChange([{ id: 'test2', label: 'test2', checked: 'on' }]);
Expand All @@ -409,7 +409,7 @@ describe('DataSourceSelectable', () => {
},
],
showError: true,
hasIncompatibleDatasources: false,
incompatibleDataSourcesExist: false,
});

expect(onSelectedDataSource).toBeCalledWith([{ id: 'test2', label: 'test2' }]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface DataSourceSelectableState extends DataSourceBaseState {
isPopoverOpen: boolean;
selectedOption?: DataSourceOption[];
defaultDataSource: string | null;
hasIncompatibleDatasources: boolean;
incompatibleDataSourcesExist: boolean;
}

export class DataSourceSelectable extends React.Component<
Expand All @@ -75,7 +75,7 @@ export class DataSourceSelectable extends React.Component<
defaultDataSource: null,
showEmptyState: false,
showError: false,
hasIncompatibleDatasources: false,
incompatibleDataSourcesExist: false,
};

this.onChange.bind(this);
Expand Down Expand Up @@ -194,7 +194,7 @@ export class DataSourceSelectable extends React.Component<
notifications: this.props.notifications,
application: this.props.application,
callback: this.props.onSelectedDataSources,
hasIncompatibleDatasources: !!fetchedDataSources?.length,
incompatibleDataSourcesExist: !!fetchedDataSources?.length,
});
return;
}
Expand All @@ -217,8 +217,8 @@ export class DataSourceSelectable extends React.Component<
}
}

onEmptyState(hasIncompatibleDatasources: boolean) {
this.setState({ showEmptyState: true, hasIncompatibleDatasources });
onEmptyState(incompatibleDataSourcesExist: boolean) {
this.setState({ showEmptyState: true, incompatibleDataSourcesExist });
}

onError() {
Expand Down Expand Up @@ -248,7 +248,7 @@ export class DataSourceSelectable extends React.Component<
return (
<NoDataSource
application={this.props.application}
hasIncompatibleDatasources={this.state.hasIncompatibleDatasources}
incompatibleDataSourcesExist={this.state.incompatibleDataSourcesExist}
/>
);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ describe('NoDataSource', () => {
});

it.each([false, true])(
'should render normally when hasIncompatibleDatasources is %b',
(hasIncompatibleDatasources) => {
'should render normally when incompatibleDataSourcesExist is %b',
(incompatibleDataSourcesExist) => {
component = shallow(
<NoDataSource
totalDataSourceCount={0}
hasIncompatibleDatasource={hasIncompatibleDatasources}
hasIncompatibleDatasource={incompatibleDataSourcesExist}
/>
);
expect(component).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import {

interface DataSourceDropDownHeaderProps {
application?: ApplicationStart;
hasIncompatibleDatasources: boolean;
incompatibleDataSourcesExist: boolean;
}

export const NoDataSource: React.FC<DataSourceDropDownHeaderProps> = ({
application,
hasIncompatibleDatasources,
incompatibleDataSourcesExist,
}) => {
const [showPopover, setShowPopover] = useState<boolean>(false);
const button = (
Expand Down Expand Up @@ -74,7 +74,7 @@ export const NoDataSource: React.FC<DataSourceDropDownHeaderProps> = ({
<FormattedMessage
id="dataSourcesManagement.dataSourceEmptyMenu.noData"
defaultMessage={
hasIncompatibleDatasources
incompatibleDataSourcesExist
? NO_COMPATIBLE_DATASOURCES_MESSAGE
: NO_DATASOURCES_CONNECTED_MESSAGE
}
Expand All @@ -87,7 +87,7 @@ export const NoDataSource: React.FC<DataSourceDropDownHeaderProps> = ({
<FormattedMessage
id="dataSourcesManagement.dataSourceEmptyMenu.connect"
defaultMessage={
hasIncompatibleDatasources
incompatibleDataSourcesExist
? ADD_COMPATIBLE_DATASOURCES_MESSAGE
: CONNECT_DATASOURCES_MESSAGE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,21 @@ describe('DataSourceManagement: Utils.ts', () => {

test.each([
{
hasIncompatibleDatasources: false,
incompatibleDataSourcesExist: false,
defaultMessage: noDataSourcesConnectedMessage,
},
{
hasIncompatibleDatasources: true,
incompatibleDataSourcesExist: true,
defaultMessage: noCompatibleDataSourcesMessage,
},
])(
'should send warning when data source is not available',
({ hasIncompatibleDatasources, defaultMessage }) => {
({ incompatibleDataSourcesExist, defaultMessage }) => {
const changeState = jest.fn();
handleNoAvailableDataSourceError({
changeState,
notifications: toasts,
hasIncompatibleDatasources,
incompatibleDataSourcesExist,
});
expect(toasts.add).toBeCalledTimes(1);
expect(toasts.add).toBeCalledWith(
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/data_source_management/public/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ export interface HandleNoAvailableDataSourceErrorProps {
notifications: ToastsStart;
application?: ApplicationStart;
callback?: (ds: DataSourceOption[]) => void;
hasIncompatibleDatasources: boolean;
incompatibleDataSourcesExist: boolean;
}

export function handleNoAvailableDataSourceError(props: HandleNoAvailableDataSourceErrorProps) {
const { changeState, notifications, application, callback, hasIncompatibleDatasources } = props;
const { changeState, notifications, application, callback, incompatibleDataSourcesExist } = props;

const defaultMessage = hasIncompatibleDatasources
const defaultMessage = incompatibleDataSourcesExist
? `${NO_COMPATIBLE_DATASOURCES_MESSAGE} ${ADD_COMPATIBLE_DATASOURCES_MESSAGE}`
: `${NO_DATASOURCES_CONNECTED_MESSAGE} ${CONNECT_DATASOURCES_MESSAGE}`;

Expand Down

0 comments on commit 5f7a594

Please sign in to comment.