Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 61 additions & 19 deletions pkg/app/web/src/components/application-detail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { DeepPartial } from "@reduxjs/toolkit";
import userEvent from "@testing-library/user-event";
import React from "react";
import { MemoryRouter } from "react-router";
import { createStore, render, screen } from "../../test-utils";
import { createStore, render, screen, waitFor } from "../../test-utils";
import { server } from "../mocks/server";
import { AppState } from "../modules";
import { syncApplication } from "../modules/applications";
import { SyncStrategy } from "../modules/deployments";
import { dummyApplication } from "../__fixtures__/dummy-application";
import { dummyApplicationLiveState } from "../__fixtures__/dummy-application-live-state";
import { dummyEnv } from "../__fixtures__/dummy-environment";
Expand Down Expand Up @@ -71,27 +72,68 @@ describe("ApplicationDetail", () => {
expect(screen.getByText(dummyApplication.name)).toBeInTheDocument();
expect(screen.getByText("Healthy")).toBeInTheDocument();
expect(screen.getByText("Synced")).toBeInTheDocument();
expect(screen.getByRole("button", { name: /sync/i })).toBeInTheDocument();
expect(screen.getByRole("button", { name: /sync$/i })).toBeInTheDocument();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this typo? Not sure. ww

});

it("dispatch sync action if click sync button", async () => {
const store = createStore(baseState);
render(
<MemoryRouter>
<ApplicationDetail applicationId={dummyApplication.id} />
</MemoryRouter>,
{
store,
}
);
describe("sync", () => {
it("dispatch sync action if click sync button", async () => {
const store = createStore(baseState);
render(
<MemoryRouter>
<ApplicationDetail applicationId={dummyApplication.id} />
</MemoryRouter>,
{
store,
}
);

userEvent.click(screen.getByRole("button", { name: /sync/i }));
userEvent.click(screen.getByRole("button", { name: /sync$/i }));

expect(store.getActions()).toMatchObject([
{
type: syncApplication.pending.type,
meta: { arg: { applicationId: dummyApplication.id } },
},
]);
await waitFor(() =>
expect(store.getActions()).toMatchObject([
{
type: syncApplication.pending.type,
meta: {
arg: {
applicationId: dummyApplication.id,
syncStrategy: SyncStrategy.AUTO,
},
},
},
])
);
});

it("dispatch sync action with selected sync strategy if changed strategy and click the sync button", async () => {
const store = createStore(baseState);
render(
<MemoryRouter>
<ApplicationDetail applicationId={dummyApplication.id} />
</MemoryRouter>,
{
store,
}
);

userEvent.click(
screen.getByRole("button", { name: /select sync strategy/i })
);
userEvent.click(screen.getByRole("menuitem", { name: /pipeline sync/i }));
userEvent.click(screen.getByRole("button", { name: /pipeline sync/i }));

await waitFor(() =>
expect(store.getActions()).toMatchObject([
{
type: syncApplication.pending.type,
meta: {
arg: {
applicationId: dummyApplication.id,
syncStrategy: SyncStrategy.PIPELINE,
},
},
},
])
);
});
});
});
39 changes: 24 additions & 15 deletions pkg/app/web/src/components/application-detail.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Box,
Button,
CircularProgress,
Link,
makeStyles,
Paper,
Expand All @@ -10,14 +9,16 @@ import {
import SyncIcon from "@material-ui/icons/Cached";
import OpenInNewIcon from "@material-ui/icons/OpenInNew";
import Skeleton from "@material-ui/lab/Skeleton/Skeleton";
import { SerializedError } from "@reduxjs/toolkit";
import dayjs from "dayjs";
import React, { FC, memo } from "react";
import { useDispatch, useSelector } from "react-redux";
import { Link as RouterLink } from "react-router-dom";
import { PAGE_PATH_DEPLOYMENTS } from "../constants/path";
import { APPLICATION_KIND_TEXT } from "../constants/application-kind";
import { APPLICATION_SYNC_STATUS_TEXT } from "../constants/application-sync-status-text";
import { APPLICATION_HEALTH_STATUS_TEXT } from "../constants/health-status-text";
import { PAGE_PATH_DEPLOYMENTS } from "../constants/path";
import { UI_TEXT_REFRESH } from "../constants/ui-text";
import { AppState } from "../modules";
import {
Application,
Expand All @@ -30,17 +31,17 @@ import {
ApplicationLiveState,
selectById as selectLiveStateById,
} from "../modules/applications-live-state";
import { SyncStrategy } from "../modules/deployments";
import {
Environment,
selectById as selectEnvById,
} from "../modules/environments";
import { Piped, selectById as selectPipeById } from "../modules/pipeds";
import { DetailTableRow } from "./detail-table-row";
import { ApplicationHealthStatusIcon } from "./health-status-icon";
import { SplitButton } from "./split-button";
import { SyncStateReason } from "./sync-state-reason";
import { SyncStatusIcon } from "./sync-status-icon";
import { SerializedError } from "@reduxjs/toolkit";
import { UI_TEXT_REFRESH } from "../constants/ui-text";

const useStyles = makeStyles((theme) => ({
root: {
Expand Down Expand Up @@ -138,6 +139,13 @@ const MostRecentlySuccessfulDeployment: FC<{
);
};

const syncOptions = ["Sync", "Quick Sync", "Pipeline Sync"];
const syncStrategyByIndex: SyncStrategy[] = [
SyncStrategy.AUTO,
SyncStrategy.QUICK_SYNC,
SyncStrategy.PIPELINE,
];

export const ApplicationDetail: FC<Props> = memo(function ApplicationDetail({
applicationId,
}) {
Expand Down Expand Up @@ -167,9 +175,14 @@ export const ApplicationDetail: FC<Props> = memo(function ApplicationDetail({

const isSyncing = useIsSyncingApplication(app?.id);

const handleSync = (): void => {
const handleSync = (index: number): void => {
if (app) {
dispatch(syncApplication({ applicationId: app.id }));
dispatch(
syncApplication({
applicationId: app.id,
syncStrategy: syncStrategyByIndex[index],
})
);
}
};

Expand Down Expand Up @@ -288,18 +301,14 @@ export const ApplicationDetail: FC<Props> = memo(function ApplicationDetail({
</Box>

<Box top={0} right={0} pr={2} pt={2} position="absolute">
<Button
variant="outlined"
<SplitButton
label="select sync strategy"
color="primary"
loading={isSyncing}
onClick={handleSync}
disabled={isSyncing || !app}
options={syncOptions}
startIcon={<SyncIcon />}
>
SYNC
{isSyncing && (
<CircularProgress size={24} className={classes.buttonProgress} />
)}
</Button>
/>
</Box>
</Paper>
);
Expand Down
1 change: 1 addition & 0 deletions pkg/app/web/src/components/deployment-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export const DeploymentDetail: FC<Props> = memo(function DeploymentDetail({
<SplitButton
className={classes.actionButtons}
options={CANCEL_OPTIONS}
label="select merge strategy"
onClick={(index) => {
dispatch(
cancelDeployment({
Expand Down
2 changes: 2 additions & 0 deletions pkg/app/web/src/components/split-button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {

export const overview: React.FC = () => (
<SplitButton
label="select option"
startIcon={<CancelIcon />}
options={["Cancel", "Cancel Without Rollback"]}
onClick={action("onClick")}
Expand All @@ -19,6 +20,7 @@ export const overview: React.FC = () => (

export const loading: React.FC = () => (
<SplitButton
label="select option"
startIcon={<CancelIcon />}
options={["Cancel", "Cancel Without Rollback"]}
onClick={action("onClick")}
Expand Down
5 changes: 2 additions & 3 deletions pkg/app/web/src/components/split-button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ it("calls onClick handler with option's index if clicked", () => {
const onClick = jest.fn();
render(
<SplitButton
label="select option"
loading={false}
onClick={onClick}
options={["option1", "option2"]}
Expand All @@ -19,9 +20,7 @@ it("calls onClick handler with option's index if clicked", () => {
expect(onClick).toHaveBeenCalledWith(0);

act(() => {
userEvent.click(
screen.getByRole("button", { name: "select merge strategy" })
);
userEvent.click(screen.getByRole("button", { name: "select option" }));
});
userEvent.click(screen.getByRole("menuitem", { name: "option2" }));
userEvent.click(screen.getByRole("button", { name: "option2" }));
Expand Down
9 changes: 7 additions & 2 deletions pkg/app/web/src/components/split-button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Button,
ButtonGroup,
PropTypes,
CircularProgress,
ClickAwayListener,
Grow,
Expand All @@ -26,9 +27,11 @@ const useStyles = makeStyles((theme) => ({

interface Props {
options: string[];
label: string;
onClick: (index: number) => void;
startIcon?: React.ReactNode;
loading: boolean;
color?: PropTypes.Color;
className?: string;
}

Expand All @@ -38,6 +41,8 @@ export const SplitButton: FC<Props> = ({
loading,
startIcon,
className,
color,
label,
}) => {
const classes = useStyles();
const anchorRef = useRef(null);
Expand All @@ -48,7 +53,7 @@ export const SplitButton: FC<Props> = ({
<div className={className}>
<ButtonGroup
variant="outlined"
color="inherit"
color={color || "inherit"}
ref={anchorRef}
disabled={loading}
>
Expand All @@ -66,7 +71,7 @@ export const SplitButton: FC<Props> = ({
size="small"
aria-controls={openCancelMenu ? "split-button-menu" : undefined}
aria-expanded={openCancelMenu ? "true" : undefined}
aria-label="select merge strategy"
aria-label={label}
aria-haspopup="menu"
onClick={() => setOpenCancelMenu(!openCancelMenu)}
>
Expand Down
11 changes: 4 additions & 7 deletions pkg/app/web/src/modules/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ApplicationGitRepository,
ApplicationKind,
} from "pipe/pkg/app/web/model/common_pb";
import { SyncStrategy } from "pipe/pkg/app/web/model/deployment_pb";
import { SyncStrategy } from "./deployments";
import { fetchCommand, CommandStatus, CommandModel } from "./commands";
import { AppState } from ".";

Expand Down Expand Up @@ -51,12 +51,9 @@ export const fetchApplication = createAsyncThunk<

export const syncApplication = createAsyncThunk<
void,
{ applicationId: string }
>("applications/sync", async ({ applicationId }, thunkAPI) => {
const { commandId } = await applicationsAPI.syncApplication({
applicationId: applicationId,
syncStrategy: SyncStrategy.AUTO,
});
{ applicationId: string; syncStrategy: SyncStrategy }
>("applications/sync", async (values, thunkAPI) => {
const { commandId } = await applicationsAPI.syncApplication(values);

await thunkAPI.dispatch(fetchCommand(commandId));
});
Expand Down
1 change: 1 addition & 0 deletions pkg/app/web/src/modules/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,5 @@ export const deploymentsSlice = createSlice({
export {
DeploymentStatus,
StageStatus,
SyncStrategy,
} from "pipe/pkg/app/web/model/deployment_pb";