-
Notifications
You must be signed in to change notification settings - Fork 4.6k
🪟 🔧 Refactor FrequentlyUsedDestinations component #19019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
letiescanciano
merged 4 commits into
master
from
leti/refactor-suggested-destinations-component
Nov 8, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
46 changes: 45 additions & 1 deletion
46
airbyte-webapp/src/test-utils/mock-data/mockFrequentlyUsedDestinations.ts
Large diffs are not rendered by default.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
.../Connector/ConnectorForm/components/FrequentlyUsedConnectors/FrequentlyUsedConnectors.tsx
This file contains hidden or 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,37 @@ | ||
import React from "react"; | ||
|
||
import { ConnectorDefinition } from "core/domain/connector"; | ||
|
||
import { FrequentlyUsedConnectorsCard } from "./FrequentlyUsedConnectorsCard"; | ||
import { useAnalyticsTrackFunctions } from "./useAnalyticsTrackFunctions"; | ||
import { useSuggestedConnectors } from "./useSuggestedConnectors"; | ||
|
||
interface FrequentlyUsedConnectorsProps { | ||
availableServices: ConnectorDefinition[]; | ||
connectorType: "source" | "destination"; | ||
connectorIds: string[]; | ||
onConnectorSelect: (id: string) => void; | ||
} | ||
|
||
export const FrequentlyUsedConnectors: React.FC<FrequentlyUsedConnectorsProps> = ({ | ||
availableServices, | ||
connectorType, | ||
connectorIds, | ||
onConnectorSelect, | ||
}) => { | ||
const { trackSelectedSuggestedDestination } = useAnalyticsTrackFunctions(); | ||
|
||
const suggestedConnectors = useSuggestedConnectors({ availableServices, connectorIds }); | ||
const onConnectorCardClick = (id: string, connectorName: string) => { | ||
onConnectorSelect(id); | ||
trackSelectedSuggestedDestination(id, connectorName); | ||
}; | ||
|
||
return ( | ||
<FrequentlyUsedConnectorsCard | ||
connectors={suggestedConnectors} | ||
onConnectorSelect={onConnectorCardClick} | ||
connectorType={connectorType} | ||
/> | ||
); | ||
}; |
File renamed without changes.
41 changes: 41 additions & 0 deletions
41
...r/ConnectorForm/components/FrequentlyUsedConnectors/FrequentlyUsedConnectorsCard.test.tsx
This file contains hidden or 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 @@ | ||
import { fireEvent, render, waitFor } from "@testing-library/react"; | ||
import { IntlProvider } from "react-intl"; | ||
import { mockDestinationsData } from "test-utils/mock-data/mockFrequentlyUsedDestinations"; | ||
|
||
import en from "locales/en.json"; | ||
|
||
import { FrequentlyUsedConnectorsCard, FrequentlyUsedConnectorsCardProps } from "./FrequentlyUsedConnectorsCard"; | ||
|
||
const renderFrequentlyUsedConnectorsComponent = (props: FrequentlyUsedConnectorsCardProps) => | ||
render( | ||
<IntlProvider locale="en" messages={en}> | ||
<FrequentlyUsedConnectorsCard {...props} /> | ||
</IntlProvider> | ||
); | ||
|
||
describe("<mockFrequentlyUsedConnectors />", () => { | ||
it("should renders with mock data without crash", () => { | ||
const component = renderFrequentlyUsedConnectorsComponent({ | ||
connectors: mockDestinationsData, | ||
connectorType: "destination", | ||
onConnectorSelect: jest.fn(), | ||
}); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
it("should call provided handler with right param", async () => { | ||
const handler = jest.fn(); | ||
const { getByText } = renderFrequentlyUsedConnectorsComponent({ | ||
connectors: mockDestinationsData, | ||
connectorType: "destination", | ||
onConnectorSelect: handler, | ||
}); | ||
fireEvent.click(getByText("BigQuery")); | ||
|
||
await waitFor(() => { | ||
expect(handler).toHaveBeenCalledTimes(1); | ||
expect(handler).toHaveBeenCalledWith("2", "BigQuery"); | ||
}); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
...nector/ConnectorForm/components/FrequentlyUsedConnectors/FrequentlyUsedConnectorsCard.tsx
This file contains hidden or 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,42 @@ | ||
import React from "react"; | ||
import { useIntl } from "react-intl"; | ||
|
||
import { ConnectorCard } from "components"; | ||
import { SlickSlider } from "components/ui/SlickSlider"; | ||
|
||
import { ConnectorCard as ConnectorCardType } from "../../types"; | ||
import styles from "./FrequentlyUsedConnectorsCard.module.scss"; | ||
|
||
export interface FrequentlyUsedConnectorsCardProps { | ||
connectors: ConnectorCardType[]; | ||
connectorType: "source" | "destination"; | ||
onConnectorSelect: (id: string, connectorName: string) => void; | ||
} | ||
|
||
export const FrequentlyUsedConnectorsCard: React.FC<FrequentlyUsedConnectorsCardProps> = ({ | ||
connectors, | ||
onConnectorSelect, | ||
connectorType, | ||
}) => { | ||
const { formatMessage } = useIntl(); | ||
|
||
if (connectors.length === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<SlickSlider | ||
title={formatMessage({ | ||
id: `${connectorType}s.frequentlyUsed`, | ||
})} | ||
> | ||
{connectors.map(({ id, name, icon, releaseStage }, index) => ( | ||
<button key={index} className={styles.card} onClick={() => onConnectorSelect(id, name)}> | ||
<ConnectorCard connectionName={name} icon={icon} releaseStage={releaseStage} fullWidth /> | ||
</button> | ||
))} | ||
</SlickSlider> | ||
</div> | ||
); | ||
}; |
2 changes: 1 addition & 1 deletion
2
...quentlyUsedDestinationsCard.test.tsx.snap → ...requentlyUsedConnectorsCard.test.tsx.snap
This file contains hidden or 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
27 changes: 27 additions & 0 deletions
27
...p/src/views/Connector/ConnectorForm/components/FrequentlyUsedConnectors/index.stories.tsx
This file contains hidden or 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,27 @@ | ||
import { ComponentStory, ComponentMeta } from "@storybook/react"; | ||
import { mockDestinationsData, mockSourcesData } from "test-utils/mock-data/mockFrequentlyUsedDestinations"; | ||
|
||
import { FrequentlyUsedConnectorsCard } from "./FrequentlyUsedConnectorsCard"; | ||
|
||
export default { | ||
title: "Views/FrequentlyUsedConnectors", | ||
component: FrequentlyUsedConnectorsCard, | ||
args: { | ||
connectors: mockDestinationsData, | ||
connectorType: "destination", | ||
}, | ||
} as ComponentMeta<typeof FrequentlyUsedConnectorsCard>; | ||
|
||
const Template: ComponentStory<typeof FrequentlyUsedConnectorsCard> = (args) => ( | ||
<div style={{ maxWidth: 560 }}> | ||
<FrequentlyUsedConnectorsCard {...args} /> | ||
</div> | ||
); | ||
export const Destinations = Template.bind({}); | ||
|
||
export const Sources = Template.bind({}); | ||
Sources.args = { | ||
...Template.args, | ||
connectors: mockSourcesData, | ||
connectorType: "source", | ||
}; |
1 change: 1 addition & 0 deletions
1
...yte-webapp/src/views/Connector/ConnectorForm/components/FrequentlyUsedConnectors/index.ts
This file contains hidden or 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 @@ | ||
export { FrequentlyUsedConnectors } from "./FrequentlyUsedConnectors"; |
File renamed without changes.
47 changes: 47 additions & 0 deletions
47
...ews/Connector/ConnectorForm/components/FrequentlyUsedConnectors/useSuggestedConnectors.ts
This file contains hidden or 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,47 @@ | ||
import { useMemo } from "react"; | ||
|
||
import { ConnectorDefinition } from "core/domain/connector"; | ||
import { isDestinationDefinition } from "core/domain/connector/destination"; | ||
import { isSourceDefinition } from "core/domain/connector/source"; | ||
|
||
import { ConnectorCard } from "../../types"; | ||
|
||
interface Props { | ||
availableServices: ConnectorDefinition[]; | ||
connectorIds: string[]; | ||
} | ||
export const useSuggestedConnectors = ({ availableServices, connectorIds }: Props): ConnectorCard[] => { | ||
return useMemo( | ||
() => | ||
availableServices | ||
.filter((service) => { | ||
if (isDestinationDefinition(service)) { | ||
return connectorIds.includes(service.destinationDefinitionId); | ||
} | ||
|
||
return isSourceDefinition(service) && connectorIds.includes(service.sourceDefinitionId); | ||
}) | ||
.map((service) => { | ||
if (isDestinationDefinition(service)) { | ||
const { destinationDefinitionId, name, icon, releaseStage } = service; | ||
return { | ||
id: destinationDefinitionId, | ||
destinationDefinitionId, | ||
name, | ||
icon, | ||
releaseStage, | ||
}; | ||
} | ||
|
||
const { sourceDefinitionId, name, icon, releaseStage } = service; | ||
return { | ||
id: sourceDefinitionId, | ||
sourceDefinitionId, | ||
letiescanciano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name, | ||
icon, | ||
releaseStage, | ||
}; | ||
}), | ||
[availableServices, connectorIds] | ||
); | ||
}; |
54 changes: 0 additions & 54 deletions
54
...nector/ConnectorForm/components/FrequentlyUsedDestinations/FrequentlyUsedDestinations.tsx
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
...nnectorForm/components/FrequentlyUsedDestinations/FrequentlyUsedDestinationsCard.test.tsx
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
...or/ConnectorForm/components/FrequentlyUsedDestinations/FrequentlyUsedDestinationsCard.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer to use the full name of the interface: https://github.com/airbytehq/airbyte/blob/master/airbyte-webapp/STYLEGUIDE.md#component-props