Skip to content
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

🪟 🔧 Remove useRouter hook [to be closed] #14869

Closed
wants to merge 186 commits into from

Conversation

YatsukBogdan1
Copy link
Contributor

What

Closes #14557

How

As mentioned in the issue description, I removed useRouter hook and replaced it in corresponding places with direct hooks for navigation, location, params, etc. I also added two custom hooks (useRouterQuery, useRouterReplace), that were initially in useRouter, since they responsible for some logic, using direct hooks

@YatsukBogdan1 YatsukBogdan1 requested a review from a team as a code owner July 20, 2022 08:25
@github-actions github-actions bot added area/platform issues related to the platform area/frontend Related to the Airbyte webapp labels Jul 20, 2022
sortBy?: string;
}

export const useRouterQuery = (): UseRouterQueryResult => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel we should not need this anymore, since we (should) know whether something comes in via query parameter or a route parameter, so that we should in the places we use this, just use the useParams hook directly and have one custom useQuery() hook (that doesn't mix the params into the query parameters).

I'll leave in the used places a comment, where I believ the information is coming from.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read your last comment and got what you meant here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so now fixed this. will left comment under every fixed router usage


export default useRouter;
export const useRouterReplace = (): UseRouterReplaceInterface => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we really want to keep this as a custom hook around, since we anyway just use it in one place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -76,7 +76,7 @@ function useWorkspaceApiService() {
}

export const useCurrentWorkspaceId = () => {
const { params } = useRouter<unknown, { workspaceId: string }>();
const params = useParams() as { workspaceId: string };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useParams support a generic paramter, and we should specify this as it's generic parameter not casting it (more type safe approach). This comment applied also for all other useParams calls in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed current version to something like this

export const useCurrentWorkspaceId = () => {
  const params = useParams<{ workspaceId: string }>();

  return params.workspaceId as string;
};

but still need to cast workspaceId to string since it is giving TS errors that value might be undefined. Is that okey,?

@@ -39,7 +40,8 @@ type FullTableProps = CreditConsumptionByConnector & {
};

const UsagePerConnectionTable: React.FC<UsagePerConnectionTableProps> = ({ creditConsumption }) => {
const { query, push } = useRouter();
const query = useRouterQuery();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should purely work from query, no params mixed in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you be more specific on this? not sure I am following the logic here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -31,7 +32,8 @@ interface IProps {
}

const ConnectionTable: React.FC<IProps> = ({ data, entity, onClickRow, onChangeStatus, onSync }) => {
const { query, push } = useRouter();
const navigate = useNavigate();
const query = useRouterQuery();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should only be from query, not require params.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you be more specific on this? not sure I am following the logic here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -47,7 +50,7 @@ export const VerifyEmailAction: React.FC = () => {
};

export const FirebaseActionRoute: React.FC = () => {
const { query: { mode } = {} } = useRouter<{ mode: string }>();
const { mode } = useRouterQuery();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine only with query no params.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you be more specific on this? not sure I am following the logic here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -21,7 +22,8 @@ const ResetPasswordPageValidationSchema = yup.object().shape({
const ResetPasswordConfirmPage: React.FC = () => {
const { confirmPasswordReset } = useAuthService();
const { registerNotification } = useNotificationService();
const { push, query } = useRouterHook<{ oobCode: string }>();
const navigate = useNavigate();
const query = useRouterQuery();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine with query only no params required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you be more specific on this? not sure I am following the logic here

@@ -23,7 +23,8 @@ const LoginPageValidationSchema = yup.object().shape({
const LoginPage: React.FC = () => {
const { formatMessage } = useIntl();
const { login } = useAuthService();
const { query, replace } = useRouter();
const query = useRouterQuery();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine with just query no params.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you be more specific on this? not sure I am following the logic here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those comments all refer to #14869 (comment). I think we should remove the useRouterQuery hook completely, and instead use either the native useParams (if we need it from params) or a useQuery hook (that we'd need to build, since weirdly react-router doesn't include one). Those comments all state if the places earlier using useRouterQuery actually will require to pull in the information from the query i.el. useQuery or from the params i.e. useParams.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. got you. already fixed

@@ -26,22 +26,24 @@ import SourceConnectionTable from "./components/SourceConnectionTable";
import SourceSettings from "./components/SourceSettings";

const SourceItemPage: React.FC = () => {
const { query, params, push } = useRouter<{ id: string }, { id: string; "*": string }>();
const query = useRouterQuery();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the only place we actually are interested in the id from the params and not the query.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you be more specific on this? not sure I am following the logic here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

sortBy?: string;
}

export const useRouterQuery = (): UseRouterQueryResult => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not keep this weird merge of params and queries around anymore. I think we should instead just have a very simpley useQuery hook for getting query parameters (without merging the path params in, since weirdly react-router doesn't have a hook for that) and useParams in all places we need the params. I've checked all current usages of this hook in this PR and left a comment which one they actually need (query or params), so I couldn't find any use-case for this mix of both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all fixed

# Conflicts:
#	airbyte-webapp/src/pages/ConnectionPage/pages/ConnectionItemPage/components/ConnectionPageTitle.tsx
#	airbyte-webapp/src/pages/DestinationPage/pages/CreateDestinationPage/components/DestinationForm.tsx
#	airbyte-webapp/src/pages/OnboardingPage/OnboardingPage.tsx
#	airbyte-webapp/src/pages/SourcesPage/pages/CreateSourcePage/components/SourceForm.tsx
Copy link
Contributor

@dizel852 dizel852 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a review, taking into account all comments from @timroes .
Code - LGTM.
Also tested locally - it seems like no regression.

@timroes need your final review/approve.

YatsukBogdan1 and others added 3 commits August 29, 2022 19:12
# Conflicts:
#	airbyte-webapp/src/packages/cloud/views/credits/CreditsPage/CreditsPage.tsx
#	airbyte-webapp/src/pages/ConnectionPage/pages/CreationFormPage/CreationFormPage.tsx
@timroes timroes changed the title Byatsuk/remove use router 🪟 🔧 Remove useRouter hook Aug 30, 2022
@@ -1,39 +1,19 @@
import queryString from "query-string";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we maybe rename this file to useQuery now, since it does not contain any hook named useRouter anymore.

Comment on lines 7 to 13
interface UseQueryResult {
from?: string;
id?: string;
mode?: string;
oobCode?: string;
order?: SortOrderEnum;
sortBy?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting this into this central place does not feel like the best TypeScript solution. I'd suggest we instead make useQuery to take a generic parameter, which actually then will be the return type, so that every caller of useQuery will specify the parameters it knows exist on this page.

If we want to make it more "fail safe" here, and say we want to make sure that each of the parameters could still be undefined, we could still put this into the return type, i.e.

useQuery = <T>(): Partial<T> => {

robgleason and others added 11 commits August 30, 2022 22:31
Show 0 bytes for cancelled sync job
…alue (#16096)

Signed-off-by: Sergey Chvalyuk <grubberr@gmail.com>
* chore: cleanup dormant workflows

* fix: restore performance test

* fix: add back GKE acceptance test

* ci: add cron to GKE Kube Acceptance Test
* added release notes file

* changed file name

* Added release notes

* Edited formatting and links

* Deleted extra lines and backticks

* Deleted extra spaces

Co-authored-by: Amruta Ranade <11484018+Amruta-Ranade@users.noreply.github.com>
Release name should have a dash instead of a period.
* enforce ssl in strict mysql and postgres source

* Add test to verify tunnel aware strict SSL behavior

* bump version numbers and changelogs

* auto-bump connector version [ci skip]

* auto-bump connector version [ci skip]

Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
* Changed August to July in title, file, and sidebar

* deleted extra spaces
@CLAassistant
Copy link

CLAassistant commented Sep 12, 2022

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
41 out of 42 committers have signed the CLA.

✅ timroes
✅ cgardens
✅ yurii-bidiuk
✅ jhajajaas
✅ grubberr
✅ Amruta-Ranade
✅ zzztimbo
✅ mlavoie-sm360
✅ ambirdsall
✅ evantahler
✅ edmundito
✅ alafanechere
✅ krishnaglick
✅ alexandr-shegeda
✅ etsybaev
✅ alovew
✅ girarda
✅ gosusnp
✅ tealjulia
✅ brianjlai
✅ pmossman
✅ lmossman
✅ subodh1810
✅ vladimir-remar
✅ bazarnov
✅ rileybrook
✅ DoNotPanicUA
✅ adamf
✅ arsenlosenko
✅ marcelopio
✅ Pwaldi
✅ xpuska513
✅ kimerinn
✅ sherifnada
✅ sophia-wiley
✅ davydov-d
✅ davinchia
✅ rodireich
✅ YatsukBogdan1
✅ michaeljguarino
✅ jonathanneo
❌ snyk-bot
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions bot added area/api Related to the api area/connectors Connector related issues area/documentation Improvements or additions to documentation area/protocol area/scheduler area/server area/worker Related to worker CDK Connector Development Kit kubernetes normalization labels Sep 12, 2022
@krishnaglick
Copy link
Contributor

I feel like this has a bad merge from master going on.

@YatsukBogdan1
Copy link
Contributor Author

I feel like this has a bad merge from master going on.

yeah. I will create a new PR, since I am not sure how to restore this one

@YatsukBogdan1 YatsukBogdan1 changed the title 🪟 🔧 Remove useRouter hook 🪟 🔧 Remove useRouter hook [to be closed] Sep 12, 2022
@YatsukBogdan1
Copy link
Contributor Author

created new pull request #16598

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api Related to the api area/connectors Connector related issues area/documentation Improvements or additions to documentation area/frontend Related to the Airbyte webapp area/platform issues related to the platform area/protocol area/scheduler area/server area/worker Related to worker CDK Connector Development Kit connectors/destination/bigquery connectors/destination/bigquery-denormalized connectors/destination/clickhouse connectors/destination/clickhouse-strict-encrypt connectors/destination/e2e-test connectors/destination/gcs connectors/destination/mariadb-columnstore connectors/destination/mongodb connectors/destination/mongodb-strict-encrypt connectors/destination/mqtt connectors/destination/mssql connectors/destination/postgres connectors/destination/postgres-strict-encrypt connectors/destination/rabbitmq connectors/destination/redshift connectors/destination/s3 connectors/destination/snowflake connectors/destination/tidb connectors/source/alloydb connectors/source/amazon-ads connectors/source/amplitude connectors/source/bing-ads connectors/source/clickhouse connectors/source/clickhouse-strict-encrypt connectors/source/cockroachdb connectors/source/cockroachdb-strict-encrypt connectors/source/db2-strict-encrypt connectors/source/db2 connectors/source/e2e-test connectors/source/exchange-rates connectors/source/facebook-marketing connectors/source/google-ads connectors/source/google-analytics-data-api connectors/source/google-analytics-v4 connectors/source/google-sheets connectors/source/greenhouse connectors/source/hubspot connectors/source/instagram connectors/source/iterable connectors/source/mssql connectors/source/mssql-strict-encrypt connectors/source/mysql connectors/source/mysql-strict-encrypt connectors/source/openweather connectors/source/oracle connectors/source/oracle-strict-encrypt connectors/source/pinterest connectors/source/plaid connectors/source/postgres connectors/source/postgres-strict-encrypt connectors/source/redshift connectors/source/relational-db connectors/source/sendgrid connectors/source/snowflake connectors/source/tidb connectors/source/tiktok-marketing connectors/source/zendesk-talk kubernetes normalization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove useRouter hook