-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/gra 995 workspace settings hide demo banners (#764)
* Add sample_data to updateWorkspace * Add workspace setting * Fix mock * Lint fixes * Test fix
- Loading branch information
Showing
12 changed files
with
194 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
52 changes: 52 additions & 0 deletions
52
grai-frontend/src/components/settings/workspace/HideDemoWorkspace.test.tsx
This file contains 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,52 @@ | ||
import userEvent from "@testing-library/user-event" | ||
import { GraphQLError } from "graphql" | ||
import { act, render, screen, waitFor } from "testing" | ||
import HideDemoWorkspace, { UPDATE_WORKSPACE } from "./HideDemoWorkspace" | ||
|
||
const workspace = { | ||
id: "1", | ||
} | ||
|
||
test("renders", async () => { | ||
render(<HideDemoWorkspace workspace={workspace} />) | ||
}) | ||
|
||
test("submit", async () => { | ||
const user = userEvent.setup() | ||
|
||
render(<HideDemoWorkspace workspace={workspace} />) | ||
|
||
await act(async () => { | ||
await user.click(screen.getByRole("button", { name: /Hide demo banner/i })) | ||
}) | ||
}) | ||
|
||
test("error", async () => { | ||
const user = userEvent.setup() | ||
|
||
const mocks = [ | ||
{ | ||
request: { | ||
query: UPDATE_WORKSPACE, | ||
variables: { | ||
id: "1", | ||
}, | ||
}, | ||
result: { | ||
errors: [new GraphQLError("Error!")], | ||
}, | ||
}, | ||
] | ||
|
||
render(<HideDemoWorkspace workspace={workspace} />, { mocks }) | ||
|
||
await act(async () => { | ||
await user.click(screen.getByRole("button", { name: /Hide demo banner/i })) | ||
}) | ||
|
||
await waitFor(() => { | ||
expect( | ||
screen.getByText("Failed to update workspace ApolloError: Error!"), | ||
).toBeInTheDocument() | ||
}) | ||
}) |
60 changes: 60 additions & 0 deletions
60
grai-frontend/src/components/settings/workspace/HideDemoWorkspace.tsx
This file contains 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,60 @@ | ||
import React from "react" | ||
import { gql, useMutation } from "@apollo/client" | ||
import { useSnackbar } from "notistack" | ||
import { | ||
UpdateWorkspaceSampleData, | ||
UpdateWorkspaceSampleDataVariables, | ||
} from "./__generated__/UpdateWorkspaceSampleData" | ||
import DangerItem from "./DangerItem" | ||
|
||
export const UPDATE_WORKSPACE = gql` | ||
mutation UpdateWorkspaceSampleData($id: ID!) { | ||
updateWorkspace(id: $id, sample_data: false) { | ||
id | ||
sample_data | ||
} | ||
} | ||
` | ||
|
||
interface Workspace { | ||
id: string | ||
} | ||
|
||
type HideDemoWorkspaceProps = { | ||
workspace: Workspace | ||
} | ||
|
||
const HideDemoWorkspace: React.FC<HideDemoWorkspaceProps> = ({ workspace }) => { | ||
const { enqueueSnackbar } = useSnackbar() | ||
|
||
const [updateWorkspace, { loading }] = useMutation< | ||
UpdateWorkspaceSampleData, | ||
UpdateWorkspaceSampleDataVariables | ||
>(UPDATE_WORKSPACE, { | ||
variables: { id: workspace.id }, | ||
}) | ||
|
||
const handleClick = () => { | ||
updateWorkspace() | ||
.then(() => | ||
enqueueSnackbar("Demo banners hidden", { variant: "success" }), | ||
) | ||
.catch(error => | ||
enqueueSnackbar(`Failed to update workspace ${error}`, { | ||
variant: "error", | ||
}), | ||
) | ||
} | ||
|
||
return ( | ||
<DangerItem | ||
onClick={handleClick} | ||
loading={loading} | ||
primary="Hide Demo Banners" | ||
secondary="Hide all demo banners from this workspace" | ||
buttonText="Hide Demo Banners" | ||
/> | ||
) | ||
} | ||
|
||
export default HideDemoWorkspace |
This file contains 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 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
22 changes: 22 additions & 0 deletions
22
grai-frontend/src/components/settings/workspace/__generated__/UpdateWorkspaceSampleData.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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
1 change: 1 addition & 0 deletions
1
grai-frontend/src/pages/settings/__generated__/GetWorkspaceSettingsW.ts
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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