-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web: show button to trigger update [ch2697] (#1738)
- Loading branch information
Showing
9 changed files
with
252 additions
and
2 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,23 @@ | ||
@import "constants"; | ||
|
||
.SidebarTriggerButton { | ||
position: absolute; | ||
background-color: transparent; | ||
border: 0 none; | ||
height: $sidebar-item; | ||
width: $sidebar-item; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
fill: $color-white; | ||
opacity: $translucent-ish; | ||
cursor: pointer; | ||
} | ||
|
||
.SidebarTriggerButton.isSelected { | ||
fill: $color-gray-dark; | ||
} | ||
|
||
.SidebarTriggerButton:hover { | ||
opacity: 1; | ||
} |
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,33 @@ | ||
import React from "react" | ||
import { mount } from "enzyme" | ||
import SidebarTriggerButton from "./SidebarTriggerButton" | ||
import { TriggerMode } from "./types" | ||
|
||
describe("SidebarTriggerButtoon", () => { | ||
beforeEach(() => { | ||
fetchMock.resetMocks() | ||
}) | ||
|
||
it("POSTs to endpoint when clicked", () => { | ||
fetchMock.mockResponse(JSON.stringify({})) | ||
|
||
const root = mount( | ||
<SidebarTriggerButton | ||
isSelected={true} | ||
resourceName="doggos" | ||
triggerMode={TriggerMode.TriggerModeManual} | ||
/> | ||
) | ||
|
||
let element = root.find(".SidebarTriggerButton") | ||
expect(element).toHaveLength(1) | ||
element.simulate("click") | ||
|
||
expect(fetchMock.mock.calls.length).toEqual(1) | ||
expect(fetchMock.mock.calls[0][0]).toEqual("//localhost/api/trigger") | ||
expect(fetchMock.mock.calls[0][1].method).toEqual("post") | ||
expect(fetchMock.mock.calls[0][1].body).toEqual( | ||
JSON.stringify({ manifest_names: ["doggos"] }) | ||
) | ||
}) | ||
}) |
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,45 @@ | ||
import React, { PureComponent } from "react" | ||
import { TriggerMode } from "./types" | ||
import { ReactComponent as TriggerSvg } from "./assets/svg/trigger.svg" | ||
import "./SidebarTriggerButton.scss" | ||
|
||
type SidebarTriggerButtonProps = { | ||
resourceName: string | ||
triggerMode: TriggerMode | ||
isSelected: boolean | ||
} | ||
|
||
const triggerUpdate = (name: string): void => { | ||
let url = `//${window.location.host}/api/trigger` | ||
|
||
fetch(url, { | ||
method: "post", | ||
body: JSON.stringify({ manifest_names: [name] }), | ||
}).then(response => { | ||
if (!response.ok) { | ||
console.log(response) | ||
} | ||
}) | ||
} | ||
|
||
export default class SidebarTriggerButton extends PureComponent< | ||
SidebarTriggerButtonProps | ||
> { | ||
render() { | ||
let props = this.props | ||
if (props.triggerMode === TriggerMode.TriggerModeAuto) { | ||
return null | ||
} | ||
|
||
return ( | ||
<button | ||
onClick={() => triggerUpdate(props.resourceName)} | ||
className={`SidebarTriggerButton ${ | ||
props.isSelected ? "isSelected" : "" | ||
}`} | ||
> | ||
<TriggerSvg /> | ||
</button> | ||
) | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,4 +1,9 @@ | ||
import { configure } from "enzyme" | ||
import Adapter from "enzyme-adapter-react-16" | ||
import { GlobalWithFetchMock } from "jest-fetch-mock" | ||
|
||
configure({ adapter: new Adapter() }) | ||
|
||
const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock | ||
customGlobal.fetch = require("jest-fetch-mock") | ||
customGlobal.fetchMock = customGlobal.fetch |
Oops, something went wrong.