-
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.
Break down KVM list into header, table and cell components.
- Loading branch information
Caleb Ellis
committed
Jun 15, 2020
1 parent
fecc2f4
commit ec7add6
Showing
36 changed files
with
813 additions
and
233 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ | |
|
||
.p-meter__labels { | ||
margin-bottom: 0; | ||
padding-top: $sp-unit * .25; | ||
padding-top: 0; | ||
} | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
ui/src/app/kvm/views/KVMList/KVMListHeader/KVMListHeader.js
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,40 @@ | ||
import { Spinner } from "@canonical/react-components"; | ||
import React, { useEffect } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
|
||
import { pod as podActions } from "app/base/actions"; | ||
import { pod as podSelectors } from "app/base/selectors"; | ||
|
||
const KVMListHeader = () => { | ||
const dispatch = useDispatch(); | ||
const pods = useSelector(podSelectors.all); | ||
const podsLoaded = useSelector(podSelectors.loaded); | ||
|
||
useEffect(() => { | ||
dispatch(podActions.fetch()); | ||
}, [dispatch]); | ||
|
||
return ( | ||
<div className="u-flex--between u-flex--wrap"> | ||
<ul className="p-inline-list u-no-margin--bottom"> | ||
<li className="p-inline-list__item p-heading--four">KVM</li> | ||
{podsLoaded ? ( | ||
<li | ||
className="p-inline-list__item last-item u-text--light" | ||
data-test="pod-count" | ||
> | ||
{`${pods.length} VM hosts available`} | ||
</li> | ||
) : ( | ||
<Spinner | ||
className="u-no-padding u-no-margin" | ||
inline | ||
text="Loading..." | ||
/> | ||
)} | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
export default KVMListHeader; |
52 changes: 52 additions & 0 deletions
52
ui/src/app/kvm/views/KVMList/KVMListHeader/KVMListHeader.test.js
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 { mount } from "enzyme"; | ||
import { Provider } from "react-redux"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
import configureStore from "redux-mock-store"; | ||
import React from "react"; | ||
|
||
import KVMListHeader from "./KVMListHeader"; | ||
|
||
const mockStore = configureStore(); | ||
|
||
describe("KVMListHeader", () => { | ||
let initialState; | ||
beforeEach(() => { | ||
initialState = { | ||
pod: { | ||
loaded: true, | ||
loading: false, | ||
items: [{ id: 1 }, { id: 2 }], | ||
}, | ||
}; | ||
}); | ||
|
||
it("displays a loader if pods have not loaded", () => { | ||
const state = { ...initialState }; | ||
state.pod.loaded = false; | ||
const store = mockStore(state); | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={[{ pathname: "/kvm", key: "testKey" }]}> | ||
<KVMListHeader /> | ||
</MemoryRouter> | ||
</Provider> | ||
); | ||
expect(wrapper.find("Spinner").exists()).toBe(true); | ||
}); | ||
|
||
it("displays a pod count if pods have loaded", () => { | ||
const state = { ...initialState }; | ||
state.pod.loaded = true; | ||
const store = mockStore(state); | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<MemoryRouter initialEntries={[{ pathname: "/kvm", key: "testKey" }]}> | ||
<KVMListHeader /> | ||
</MemoryRouter> | ||
</Provider> | ||
); | ||
expect(wrapper.find('[data-test="pod-count"]').text()).toBe( | ||
"2 VM hosts available" | ||
); | ||
}); | ||
}); |
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 "./KVMListHeader"; |
Oops, something went wrong.