Skip to content

Commit

Permalink
Fetch breaking changes data from web api (#5202)
Browse files Browse the repository at this point in the history
Signed-off-by: khanhtc1202 <[email protected]>
  • Loading branch information
khanhtc1202 authored Sep 10, 2024
1 parent 8e62937 commit 2a3836d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions web/src/api/piped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
ListReleasedVersionsRequest,
RestartPipedRequest,
RestartPipedResponse,
ListDeprecatedNotesRequest,
ListDeprecatedNotesResponse,
} from "pipecd/web/api_client/service_pb";

export const getPipeds = ({
Expand All @@ -39,6 +41,16 @@ export const listReleasedVersions = (): Promise<
return apiRequest(req, apiClient.listReleasedVersions);
};

export const listBreakingChanges = ({
projectId,
}: ListDeprecatedNotesRequest.AsObject): Promise<
ListDeprecatedNotesResponse.AsObject
> => {
const req = new ListDeprecatedNotesRequest();
req.setProjectId(projectId);
return apiRequest(req, apiClient.listDeprecatedNotes);
};

export const registerPiped = ({
name,
desc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const baseState: Partial<AppState> = {
registeredPiped: null,
updating: false,
releasedVersions: [],
breakingChangesNote: "",
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const initialState = {
registeredPiped: null,
updating: false,
releasedVersions: [],
breakingChangesNote: "",
},
applications: {
loading: false,
Expand Down
1 change: 1 addition & 0 deletions web/src/components/deployments-detail-page/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("DeploymentDetailPage", () => {
registeredPiped: null,
updating: false,
releasedVersions: [],
breakingChangesNote: "",
},
});

Expand Down
14 changes: 14 additions & 0 deletions web/src/components/settings-page/piped/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
restartPiped,
fetchPipeds,
fetchReleasedVersions,
fetchBreakingChanges,
Piped,
RegisteredPiped,
selectAllPipeds,
Expand Down Expand Up @@ -95,6 +96,7 @@ export const SettingsPipedPage: FC = memo(function SettingsPipedPage() {
enabled: true,
});
const dispatch = useAppDispatch();
const projectId = useAppSelector((state) => state.project.id);
const pipeds = useAppSelector<Piped.AsObject[]>((state) =>
selectFilteredPipeds(state, filterValues)
);
Expand All @@ -103,10 +105,22 @@ export const SettingsPipedPage: FC = memo(function SettingsPipedPage() {
dispatch(fetchReleasedVersions());
}, [dispatch]);

useEffect(() => {
if (projectId) {
dispatch(fetchBreakingChanges({ projectId: projectId }));
}
}, [dispatch, projectId]);

const releasedVersions = useAppSelector<string[]>(
(state) => state.pipeds.releasedVersions
);

const breakingChangesNote = useAppSelector<string | null>(
(state) => state.pipeds.breakingChangesNote
);
// TODO: Remove this console.log
console.log("[DEBUG]", breakingChangesNote);

const [isUpgradeDialogOpen, setIsUpgradeDialogOpen] = useState(false);
const handleUpgradeDialogClose = (): void => setIsUpgradeDialogOpen(false);

Expand Down
1 change: 1 addition & 0 deletions web/src/modules/pipeds/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const baseState = {
registeredPiped: null,
updating: false,
releasedVersions: [],
breakingChangesNote: "",
};

describe("pipedsSlice reducer", () => {
Expand Down
15 changes: 15 additions & 0 deletions web/src/modules/pipeds/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ export const fetchReleasedVersions = createAsyncThunk<string[]>(
}
);

export const fetchBreakingChanges = createAsyncThunk<
string,
{ projectId: string }
>(`${MODULE_NAME}/fetchBreakingChanges`, async (props) => {
const { notes } = await pipedsApi.listBreakingChanges({
projectId: props.projectId,
});
return notes;
});

export const fetchPipeds = createAsyncThunk<Piped.AsObject[], boolean>(
`${MODULE_NAME}/fetchList`,
async (withStatus: boolean) => {
Expand Down Expand Up @@ -120,10 +130,12 @@ export const pipedsSlice = createSlice({
registeredPiped: RegisteredPiped | null;
updating: boolean;
releasedVersions: string[];
breakingChangesNote: string;
}>({
registeredPiped: null,
updating: false,
releasedVersions: [],
breakingChangesNote: "",
}),
reducers: {
clearRegisteredPipedInfo(state) {
Expand Down Expand Up @@ -157,6 +169,9 @@ export const pipedsSlice = createSlice({
})
.addCase(fetchReleasedVersions.fulfilled, (state, action) => {
state.releasedVersions = action.payload;
})
.addCase(fetchBreakingChanges.fulfilled, (state, action) => {
state.breakingChangesNote = action.payload;
});
},
});
Expand Down

0 comments on commit 2a3836d

Please sign in to comment.