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

Trigger e2e #1770

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@tiptap/pm": "^2.1.12",
"@tiptap/react": "^2.1.12",
"@tiptap/starter-kit": "^2.1.12",
"axios": "^0.21.3",
"axios": "^1.6.5",
"bluebird": "^3.7.1",
"bootstrap": "^4.6.0",
"cheerio": "^1.0.0-rc.10",
Expand Down
18 changes: 13 additions & 5 deletions src/components/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ const Header = ({
bg="white"
h="4rem"
w="100%"
spacing="0.5rem"
>
<HStack spacing="1.25rem" flex={1}>
<HStack spacing="1.25rem" flex="0 1 content">
{!showButton ? (
<Box w="180px">
<img
Expand All @@ -120,19 +121,26 @@ const Header = ({
}
onClick={handleBackNav}
/>
<Text color="text.label" textStyle="body-1">
<Text color="text.label" textStyle="body-1" noOfLines={1}>
{backButtonTextFromParams || backButtonText}
</Text>
</>
)}
</HStack>
{/* <Spacer /> */}
{title ? (
<Flex minWidth="-webkit-min-content" alignItems="center">
<Text textStyle="h5">{title}</Text>
<Flex
minWidth="-webkit-min-content"
alignItems="center"
flex={1}
justifyContent="center"
>
<Text textStyle="h5" noOfLines={1}>
{title}
</Text>
</Flex>
) : null}
<HStack flex={1} justifyContent="flex-end">
<HStack flex="0 0 content" justifyContent="flex-end" w="fit-content">
(
{isShowStagingBuildStatusEnabled && (
<Box mr="-0.25rem">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { UseQueryResult, useQuery } from "react-query"

import { GET_CONTACT_US_KEY } from "constants/queryKeys"

import { getAxiosErrorMessage } from "utils/axios"

import { ContactUsService } from "services"
import { ContactUsDto } from "types/contactUs"
import { useErrorToast, DEFAULT_RETRY_MSG } from "utils"
Expand All @@ -18,7 +20,9 @@ export const useGetContactUsHook = (
onError: (err: AxiosError) => {
errorToast({
id: "get-contact-us-error",
description: `Your Contact Us page details could not be retrieved. ${DEFAULT_RETRY_MSG}. Error: ${err.response?.data.error.message}`,
description: `Your Contact Us page details could not be retrieved. ${DEFAULT_RETRY_MSG}. Error: ${getAxiosErrorMessage(
err
)}`,
})
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { UseMutationResult, useQueryClient, useMutation } from "react-query"

import { GET_CONTACT_US_KEY } from "constants/queryKeys"

import { getAxiosErrorMessage } from "utils/axios"

import { ContactUsService } from "services"
import { ContactUsFrontMatter } from "types/contactUs"
import { MiddlewareError } from "types/error"
import { useSuccessToast, useErrorToast, DEFAULT_RETRY_MSG } from "utils"

interface UpdateContactUsParams {
Expand All @@ -15,11 +16,7 @@ interface UpdateContactUsParams {

export const useUpdateContactUsHook = (
siteName: string
): UseMutationResult<
void,
AxiosError<MiddlewareError>,
UpdateContactUsParams
> => {
): UseMutationResult<void, AxiosError, UpdateContactUsParams> => {
const queryClient = useQueryClient()
const successToast = useSuccessToast()
const errorToast = useErrorToast()
Expand All @@ -42,10 +39,12 @@ export const useUpdateContactUsHook = (
description: "Contact Us page updated successfully",
})
},
onError: (err: AxiosError) => {
onError: (err) => {
errorToast({
id: "update-homepage-error",
description: `Could not update Contact Us page. ${DEFAULT_RETRY_MSG}. Error: ${err.response?.data.error.message}`,
description: `Could not update Contact Us page. ${DEFAULT_RETRY_MSG}. Error: ${getAxiosErrorMessage(
err
)}`,
})
},
}
Expand Down
6 changes: 5 additions & 1 deletion src/hooks/homepageHooks/useGetHomepageHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { UseQueryResult, useQuery } from "react-query"

import { GET_HOMEPAGE_KEY } from "constants/queryKeys"

import { getAxiosErrorMessage } from "utils/axios"

import { HomepageService } from "services"
import { HomepageDto } from "types/homepage"
import { useErrorToast, DEFAULT_RETRY_MSG } from "utils"
Expand All @@ -18,7 +20,9 @@ export const useGetHomepageHook = (
onError: (err: AxiosError) => {
errorToast({
id: "get-homepage-error",
description: `Your homepage could not be retrieved. ${DEFAULT_RETRY_MSG}. Error: ${err.response?.data.error.message}`,
description: `Your homepage could not be retrieved. ${DEFAULT_RETRY_MSG}. Error: ${getAxiosErrorMessage(
err
)}`,
})
},
}
Expand Down
12 changes: 8 additions & 4 deletions src/hooks/homepageHooks/useUpdateHomepageHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import {

import { GET_HOMEPAGE_KEY } from "constants/queryKeys"

import { getAxiosErrorMessage } from "utils/axios"

import { HomepageService } from "services"
import { MiddlewareError } from "types/error"
import { MiddlewareErrorDto } from "types/error"
import { HomepageDto } from "types/homepage"
import { useSuccessToast, useErrorToast, DEFAULT_RETRY_MSG } from "utils"

export const useUpdateHomepageHook = (
siteName: string,
mutationOptions?: Omit<
UseMutationOptions<void, AxiosError<MiddlewareError>, HomepageDto>,
UseMutationOptions<void, AxiosError<MiddlewareErrorDto>, HomepageDto>,
"mutationFn" | "mutationKey"
>
): UseMutationResult<void, AxiosError<MiddlewareError>, HomepageDto> => {
): UseMutationResult<void, AxiosError<MiddlewareErrorDto>, HomepageDto> => {
const queryClient = useQueryClient()
const successToast = useSuccessToast()
const errorToast = useErrorToast()
Expand All @@ -44,7 +46,9 @@ export const useUpdateHomepageHook = (
if (err.response?.status !== 409) {
errorToast({
id: "update-homepage-error",
description: `Could not update homepage. ${DEFAULT_RETRY_MSG}. Error: ${err.response?.data?.message}`,
description: `Could not update homepage. ${DEFAULT_RETRY_MSG}. Error: ${getAxiosErrorMessage(
err
)}`,
})
}
if (mutationOptions?.onError)
Expand Down
55 changes: 27 additions & 28 deletions src/hooks/mediaHooks/useDeleteMultipleMediaHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,22 @@ const deleteMultipleMedia = async (
) => {
const mediaService = new MediaService({ apiClient: apiService })

await selectedMediaDto
.map((deleteMedia) => {
const pathTokens = deleteMedia.filePath.split("/")

const reqParams = {
siteName,
mediaDirectoryName: pathTokens.slice(0, -1).join("%2F"),
fileName: pathTokens.pop(),
sha: deleteMedia.sha,
await mediaService
.deleteMultiple(
{ siteName },
{
items: selectedMediaDto.map(({ filePath, sha }) => {
return {
filePath,
sha,
}
}),
}

return reqParams
})
.reduce(
(acc, curr) =>
acc
.then(() => {
const { sha, ...rest } = curr
mediaService.delete(rest, { sha }).catch((error) => {
// We want to continue even if some of the media files fail to delete
// because there is no turning back now if we fail (the earlier files
// would have been deleted)
return error
}) as Promise<void>
})
// This wait is necessary to avoid the repo lock
.then(() => new Promise((resolve) => setTimeout(resolve, 500))),
Promise.resolve()
)
// Note: Unfortunately, we have to wait for GitHub to finish deleting the files
// before we can refetch the list of files in the directory. Otherwise, the
// refetch will return the files that were just deleted.
.then(() => new Promise((resolve) => setTimeout(resolve, 1000)))
}

export const useDeleteMultipleMediaHook = (
Expand All @@ -71,7 +58,19 @@ export const useDeleteMultipleMediaHook = (
...mutationOptions,
onSettled: (data, error, variables, context) => {
queryClient.invalidateQueries([LIST_MEDIA_DIRECTORY_FILES_KEY])
queryClient.invalidateQueries([GET_ALL_MEDIA_FILES_KEY])
// Note: We choose to remove here because once the files are deleted,
// refetching will definitely cause a 404 Not Found error, which is what
// we want to avoid
variables.forEach(({ filePath }) => {
const directoryName = encodeURIComponent(
filePath.split("/").slice(0, -1).join("/")
)
const fileName = encodeURIComponent(filePath.split("/").pop() || "")
queryClient.removeQueries([
GET_ALL_MEDIA_FILES_KEY,
{ siteName: params.siteName, directoryName, name: fileName },
])
})
if (mutationOptions?.onSettled)
mutationOptions.onSettled(data, error, variables, context)
},
Expand Down
12 changes: 8 additions & 4 deletions src/hooks/navHooks/useUpdateNavHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
RESOURCE_ROOM_NAME_KEY,
} from "constants/queryKeys"

import { getAxiosErrorMessage } from "utils/axios"

import { NavService } from "services"
import { MiddlewareError } from "types/error"
import { MiddlewareErrorDto } from "types/error"
import {
CollectionNav,
NavDto,
Expand All @@ -27,7 +29,7 @@ export interface UpdateNavParams {

export const useUpdateNavHook = (
siteName: string
): UseMutationResult<void, AxiosError<MiddlewareError>, UpdateNavParams> => {
): UseMutationResult<void, AxiosError<MiddlewareErrorDto>, UpdateNavParams> => {
const queryClient = useQueryClient()
const successToast = useSuccessToast()
const errorToast = useErrorToast()
Expand Down Expand Up @@ -56,10 +58,12 @@ export const useUpdateNavHook = (
description: "Navigation bar updated successfully",
})
},
onError: (err: AxiosError) => {
onError: (err: AxiosError<MiddlewareErrorDto>) => {
errorToast({
id: "update-nav-error",
description: `Could not update navigation bar. ${DEFAULT_RETRY_MSG}. Error: ${err.response?.data.error.message}`,
description: `Could not update navigation bar. ${DEFAULT_RETRY_MSG}. Error: ${getAxiosErrorMessage(
err
)}`,
})
},
}
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/settingsHooks/useUpdateSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AxiosError } from "axios"
import _ from "lodash"
import { useMutation, UseMutationResult, useQueryClient } from "react-query"

import { SETTINGS_CONTENT_KEY } from "constants/queryKeys"
import { SETTINGS_CONTENT_KEY, STAGING_URL_KEY } from "constants/queryKeys"

import * as SettingsService from "services/SettingsService"

Expand Down Expand Up @@ -58,6 +58,7 @@ export const useUpdateSettings = (
{
onSettled: () => {
queryClient.invalidateQueries([SETTINGS_CONTENT_KEY, siteName])
queryClient.invalidateQueries([STAGING_URL_KEY, siteName])
},
onSuccess,
onError,
Expand Down
Loading
Loading