diff --git a/src/components/NewCommitsToggle.tsx b/src/components/NewCommitsToggle.tsx new file mode 100644 index 00000000..45757a78 --- /dev/null +++ b/src/components/NewCommitsToggle.tsx @@ -0,0 +1,33 @@ +import styled from "@emotion/styled"; +import { observer } from "mobx-react-lite"; +import React from "react"; + +export interface NewCommitsToggleProps { + toggled: boolean; + onToggle(): void; +} + +export const NewCommitsToggle = observer((props: NewCommitsToggleProps) => { + return ( + + + Include new commits + + ); +}); + +const Container = styled.label` + padding: 8px; + margin: 0; + display: flex; + flex-direction: row; + align-items: center; +`; + +const NewCommitsCheckbox = styled.input` + margin-right: 8px; +`; diff --git a/src/components/Popup.tsx b/src/components/Popup.tsx index 155981a1..50279d52 100644 --- a/src/components/Popup.tsx +++ b/src/components/Popup.tsx @@ -12,9 +12,11 @@ import { Link } from "./design/Link"; import { Row } from "./design/Row"; import { IgnoredRepositories } from "./IgnoredRepositories"; import { Loader } from "./Loader"; +import { NewCommitsToggle } from "./NewCommitsToggle"; import { PullRequestList } from "./PullRequestList"; import { Settings } from "./Settings"; import { Status } from "./Status"; +import { WhitelistedTeams } from "./WhitelistedTeams"; export interface PopupProps { core: Core; @@ -159,6 +161,31 @@ export const Popup = observer((props: PopupProps) => { /> + + + + ) + } pullRequests={ props.core.filteredPullRequests ? props.core.filteredPullRequests[state.currentFilter] @@ -176,28 +203,6 @@ export const Popup = observer((props: PopupProps) => { ? "allow-unmuting" : "none" } - newCommitsNotificationToggled={ - state.currentFilter === Filter.INCOMING - ? !!props.core.muteConfiguration.notifyNewCommits - : null - } - onlyDirectRequestsToggled={ - state.currentFilter === Filter.INCOMING - ? !!props.core.muteConfiguration.onlyDirectRequests - : null - } - whitelistedTeams={ - state.currentFilter === Filter.INCOMING - ? props.core.muteConfiguration.whitelistedTeams || [] - : [] - } - userLogin={ - (props.core.loadedState && props.core.loadedState.userLogin) || - undefined - } - onToggleNewCommitsNotification={onToggleNewCommitsNotification} - onToggleOnlyDirectRequests={onToggleOnlyDirectRequests} - onChangeWhitelistedTeams={onChangeWhitelistedTeams} onOpenAll={onOpenAll} onOpen={onOpen} onMute={onMute} diff --git a/src/components/PullRequestList.tsx b/src/components/PullRequestList.tsx index 37a43108..aa9b9307 100644 --- a/src/components/PullRequestList.tsx +++ b/src/components/PullRequestList.tsx @@ -1,10 +1,9 @@ import styled from "@emotion/styled"; import { observer } from "mobx-react-lite"; -import React, { useRef, useState } from "react"; +import React from "react"; import { EnrichedPullRequest } from "../filtering/enriched-pull-request"; import { PullRequest } from "../storage/loaded-state"; import { MuteType } from "../storage/mute-configuration"; -import { LargeButton } from "./design/Button"; import { Link } from "./design/Link"; import { Paragraph } from "./design/Paragraph"; import { Loader } from "./Loader"; @@ -17,40 +16,6 @@ const List = styled.div` margin-bottom: 16px; `; -const NewCommitsToggle = styled.label` - padding: 8px; - margin: 0; - display: flex; - flex-direction: row; - align-items: center; -`; - -const NewCommitsCheckbox = styled.input` - margin-right: 8px; -`; - -const OnlyDirectRequestsCheckbox = styled.input` - margin-right: 8px; -`; - -const OnlyDirectRequestsToggle = styled.label` - padding: 8px; - margin: 0; - display: flex; - flex-direction: row; - align-items: center; -`; - -const WhitelistedTeamsInput = styled.input` - flex-grow: 1; - padding: 4px 8px; - margin-right: 8px; - - &:focus { - outline-color: #2ee59d; - } -`; - const OpenAllParagraph = styled(Paragraph)` text-align: center; color: #777; @@ -60,13 +25,7 @@ export interface PullRequestListProps { pullRequests: EnrichedPullRequest[] | null; emptyMessage: string; mutingConfiguration: "allow-muting" | "allow-unmuting" | "none"; - newCommitsNotificationToggled: boolean | null; - onlyDirectRequestsToggled: boolean | null; - whitelistedTeams: string[]; - userLogin?: string; - onToggleNewCommitsNotification?(): void; - onToggleOnlyDirectRequests?(): void; - onChangeWhitelistedTeams?: (text: string) => void; + header: React.ReactNode; onOpenAll(): void; onOpen(pullRequestUrl: string): void; onMute(pullRequest: PullRequest, muteType: MuteType): void; @@ -74,71 +33,9 @@ export interface PullRequestListProps { } export const PullRequestList = observer((props: PullRequestListProps) => { - const defaultWhitelistedTeams = props.whitelistedTeams.join(", "); - const [whitelistedTeams, setWhitelistedTeams] = useState( - defaultWhitelistedTeams - ); - const inputRef = useRef(null); - const handleWhitelistedTeamsChange = (e: React.FormEvent) => { - e.preventDefault(); - if (!inputRef.current) { - return; - } - - setWhitelistedTeams(inputRef.current.value); - }; - const handleApplyWhitelistedTeamsChange = (e: React.FormEvent) => { - e.preventDefault(); - props.onChangeWhitelistedTeams && - props.onChangeWhitelistedTeams(whitelistedTeams); - }; return ( - {props.onlyDirectRequestsToggled !== null && ( - - -
- Only directly requested - {props.userLogin && ( - - {" "} - (@{props.userLogin}){" "} - - )} - and whitelisted teams - {props.onlyDirectRequestsToggled && props.onChangeWhitelistedTeams && ( -
- - - Apply - -
- )} -
-
- )} - {props.newCommitsNotificationToggled !== null && ( - - - Include new commits - - )} + {props.header} {props.pullRequests === null ? ( ) : props.pullRequests.length === 0 ? ( diff --git a/src/components/WhitelistedTeams.tsx b/src/components/WhitelistedTeams.tsx new file mode 100644 index 00000000..cc55a092 --- /dev/null +++ b/src/components/WhitelistedTeams.tsx @@ -0,0 +1,89 @@ +import styled from "@emotion/styled"; +import { observer } from "mobx-react-lite"; +import React, { useRef, useState } from "react"; +import { LargeButton } from "./design/Button"; + +export interface WhitelistedTeamsProps { + onlyDirectRequestsToggled: boolean; + whitelistedTeams: string[]; + userLogin?: string; + onToggleOnlyDirectRequests(): void; + onChangeWhitelistedTeams(text: string): void; +} + +export const WhitelistedTeams = observer((props: WhitelistedTeamsProps) => { + const defaultWhitelistedTeams = props.whitelistedTeams.join(", "); + const [whitelistedTeams, setWhitelistedTeams] = useState( + defaultWhitelistedTeams + ); + const inputRef = useRef(null); + const handleWhitelistedTeamsChange = (e: React.FormEvent) => { + e.preventDefault(); + if (!inputRef.current) { + return; + } + + setWhitelistedTeams(inputRef.current.value); + }; + const handleApplyWhitelistedTeamsChange = (e: React.FormEvent) => { + e.preventDefault(); + props.onChangeWhitelistedTeams(whitelistedTeams); + }; + return ( + + +
+ Only directly requested + {props.userLogin && ( + + {" "} + (@{props.userLogin}){" "} + + )}{" "} + and whitelisted teams + {props.onlyDirectRequestsToggled && ( +
+ + + Apply + +
+ )} +
+
+ ); +}); + +const OnlyDirectRequestsCheckbox = styled.input` + margin-right: 8px; +`; + +const OnlyDirectRequestsToggle = styled.label` + padding: 8px; + margin: 0; + display: flex; + flex-direction: row; + align-items: center; +`; + +const WhitelistedTeamsInput = styled.input` + flex-grow: 1; + padding: 4px 8px; + margin-right: 8px; + + &:focus { + outline-color: #2ee59d; + } +`;