-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move domain set default form to sidepanel (#5290)
- Loading branch information
1 parent
469960d
commit 1b19de7
Showing
24 changed files
with
251 additions
and
103 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./ModelActionForm"; |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { DomainListSidePanelContent } from "../../views/DomainsList/constants"; | ||
import { DomainListSidePanelViews } from "../../views/DomainsList/constants"; | ||
|
||
import DomainForm from "./DomainForm"; | ||
|
||
import { Labels as AddDomainLabels } from "@/app/domains/views/DomainsList/DomainListHeaderForm/DomainListHeaderForm"; | ||
import { Labels as DomainTableLabels } from "@/app/domains/views/DomainsList/DomainsTable/DomainsTable"; | ||
import { | ||
domain as domainFactory, | ||
domainState as domainStateFactory, | ||
rootState as rootStateFactory, | ||
} from "@/testing/factories"; | ||
import { renderWithBrowserRouter, screen } from "@/testing/utils"; | ||
|
||
const domain = domainFactory({ name: "test" }); | ||
const state = rootStateFactory({ | ||
domain: domainStateFactory({ | ||
items: [domain], | ||
}), | ||
}); | ||
|
||
it("can render the AddDomain form", () => { | ||
const sidePanelContent: DomainListSidePanelContent = { | ||
view: DomainListSidePanelViews.ADD_DOMAIN, | ||
}; | ||
renderWithBrowserRouter( | ||
<DomainForm | ||
setSidePanelContent={vi.fn()} | ||
sidePanelContent={sidePanelContent} | ||
/>, | ||
{ state } | ||
); | ||
expect(screen.getByRole("form", { name: AddDomainLabels.FormLabel })); | ||
}); | ||
|
||
it("can render the SetDefault form", () => { | ||
const sidePanelContent: DomainListSidePanelContent = { | ||
view: DomainListSidePanelViews.SET_DEFAULT, | ||
extras: { | ||
id: domain.id, | ||
}, | ||
}; | ||
renderWithBrowserRouter( | ||
<DomainForm | ||
setSidePanelContent={vi.fn()} | ||
sidePanelContent={sidePanelContent} | ||
/>, | ||
{ state } | ||
); | ||
expect(screen.getByRole("form", { name: DomainTableLabels.FormTitle })); | ||
}); |
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,41 @@ | ||
import { useCallback } from "react"; | ||
|
||
import SetDefaultForm from "../SetDefaultForm"; | ||
|
||
import type { SidePanelContentTypes } from "@/app/base/side-panel-context"; | ||
import DomainListHeaderForm from "@/app/domains/views/DomainsList/DomainListHeaderForm"; | ||
import { DomainListSidePanelViews } from "@/app/domains/views/DomainsList/constants"; | ||
import { isId } from "@/app/utils"; | ||
|
||
type Props = SidePanelContentTypes & {}; | ||
|
||
const DomainForm = ({ | ||
sidePanelContent, | ||
setSidePanelContent, | ||
}: Props): JSX.Element | null => { | ||
const clearSidePanelContent = useCallback( | ||
() => setSidePanelContent(null), | ||
[setSidePanelContent] | ||
); | ||
|
||
if (!sidePanelContent) { | ||
return null; | ||
} | ||
|
||
switch (sidePanelContent.view) { | ||
case DomainListSidePanelViews.ADD_DOMAIN: | ||
return <DomainListHeaderForm closeForm={clearSidePanelContent} />; | ||
case DomainListSidePanelViews.SET_DEFAULT: { | ||
const id = | ||
sidePanelContent.extras && "id" in sidePanelContent.extras | ||
? sidePanelContent.extras.id | ||
: null; | ||
if (!isId(id)) return null; | ||
return <SetDefaultForm id={id} onClose={clearSidePanelContent} />; | ||
} | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
export default DomainForm; |
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 @@ | ||
export { default } from "./DomainForm"; |
41 changes: 41 additions & 0 deletions
41
src/app/domains/components/SetDefaultForm/SetDefaultForm.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,41 @@ | ||
import configureStore from "redux-mock-store"; | ||
|
||
import SetDefaultForm from "./SetDefaultForm"; | ||
|
||
import { Labels as DomainTableLabels } from "@/app/domains/views/DomainsList/DomainsTable/DomainsTable"; | ||
import type { RootState } from "@/app/store/root/types"; | ||
import { | ||
domain as domainFactory, | ||
domainState as domainStateFactory, | ||
rootState as rootStateFactory, | ||
} from "@/testing/factories"; | ||
import { renderWithBrowserRouter, screen, userEvent } from "@/testing/utils"; | ||
|
||
const mockStore = configureStore<RootState>(); | ||
const domain = domainFactory({ name: "test" }); | ||
const state = rootStateFactory({ | ||
domain: domainStateFactory({ | ||
items: [domain], | ||
}), | ||
}); | ||
|
||
it("renders", () => { | ||
renderWithBrowserRouter(<SetDefaultForm id={domain.id} onClose={vi.fn()} />, { | ||
state, | ||
}); | ||
expect(screen.getByRole("form", { name: DomainTableLabels.FormTitle })); | ||
expect(screen.getByText(DomainTableLabels.AreYouSure)).toBeInTheDocument(); | ||
}); | ||
|
||
it("dispatches the set default action", async () => { | ||
const store = mockStore(state); | ||
renderWithBrowserRouter(<SetDefaultForm id={domain.id} onClose={vi.fn()} />, { | ||
store, | ||
}); | ||
await userEvent.click( | ||
screen.getByRole("button", { name: DomainTableLabels.ConfirmSetDefault }) | ||
); | ||
expect( | ||
store.getActions().some((action) => action.type === "domain/setDefault") | ||
).toBe(true); | ||
}); |
44 changes: 44 additions & 0 deletions
44
src/app/domains/components/SetDefaultForm/SetDefaultForm.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,44 @@ | ||
import { useDispatch, useSelector } from "react-redux"; | ||
|
||
import ModelActionForm from "@/app/base/components/ModelActionForm"; | ||
import { Labels } from "@/app/domains/views/DomainsList/DomainsTable/DomainsTable"; | ||
import { actions as domainActions } from "@/app/store/domain"; | ||
import domainSelectors from "@/app/store/domain/selectors"; | ||
import type { Domain, DomainMeta } from "@/app/store/domain/types"; | ||
|
||
type Props = { | ||
id: Domain[DomainMeta.PK]; | ||
onClose: () => void; | ||
}; | ||
const SetDefaultForm = ({ id, onClose }: Props) => { | ||
const dispatch = useDispatch(); | ||
const errors = useSelector(domainSelectors.errors); | ||
const saving = useSelector(domainSelectors.saving); | ||
const saved = useSelector(domainSelectors.saved); | ||
return ( | ||
<ModelActionForm | ||
aria-label={Labels.FormTitle} | ||
errors={errors} | ||
initialValues={{}} | ||
message={Labels.AreYouSure} | ||
modelType="DNS" | ||
onCancel={() => { | ||
dispatch(domainActions.cleanup()); | ||
onClose(); | ||
}} | ||
onSubmit={() => { | ||
dispatch(domainActions.setDefault(id)); | ||
}} | ||
onSuccess={() => { | ||
dispatch(domainActions.cleanup()); | ||
onClose(); | ||
}} | ||
saved={saved} | ||
saving={saving} | ||
submitAppearance="positive" | ||
submitLabel={Labels.ConfirmSetDefault} | ||
/> | ||
); | ||
}; | ||
|
||
export default SetDefaultForm; |
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 @@ | ||
export { default } from "./SetDefaultForm"; |
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
Oops, something went wrong.