Skip to content

Commit

Permalink
fix(portal): add post push history creation
Browse files Browse the repository at this point in the history
  • Loading branch information
KsiBart committed Nov 22, 2024
1 parent e42a936 commit 2071e78
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ test("PushHistoryModal", () => {
<PushHistoryModal
isOpen={true}
onClose={vi.fn()}
onOK={vi.fn()}
envOptions={[{
value: "testEnv",
label: "Test Env"
Expand Down
2 changes: 1 addition & 1 deletion kraken-app/kraken-app-portal/src/hooks/product/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const PRODUCT_CACHE_KEYS = {
get_component_list_v2: "get_component_list_v2",
get_component_spec_details: "get_component_spec_details",
get_current_version: "get_current_version",
get_product_env_list: "get_product_env_list",
get_list_api_deployments: "get_list_api_deployments",
get_mapper_details: "get_mapper_details",
get_product_component_list: "get_product_component_list",
Expand All @@ -118,7 +119,6 @@ export const PRODUCT_CACHE_KEYS = {
get_product_env_activity_detail: "get_product_env_activity_detail",
get_product_env_activity_list: "get_product_env_activity_list",
get_product_env_activity_list_mutation: "get_product_env_activity_list_mutation",
get_product_env_list: "get_product_env_list",
get_product_push_history_log: "get_product_push_history_log",
get_release_list: "get_release_list",
get_running_api_list: "get_running_api_list",
Expand Down
31 changes: 25 additions & 6 deletions kraken-app/kraken-app-portal/src/hooks/pushApiEvent/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import { getPushEventHistory } from '@/services/pushApiActivity';
import { createActivityHistoryLog, getPushEventHistory } from '@/services/pushApiActivity';
import { STALE_TIME } from '@/utils/constants/common';
import { IPagingData } from '@/utils/types/common.type';
import { useQuery } from '@tanstack/react-query';
import { ICreateActivityHistoryLogRequest, IPagingData } from '@/utils/types/common.type';
import { useMutation, useQuery } from '@tanstack/react-query';
import { AxiosResponse } from 'axios';
import { PRODUCT_CACHE_KEYS } from '../product';
import { queryClient } from "@/utils/helpers/reactQuery";

const PUSH_API_EVENT_CACHE_KEYS = {
create_activity_history_log: "create_activity_history_log",
get_product_env_list: "get_product_env_list",
};

export const useGetPushActivityLogHistory = () => {
return useQuery<AxiosResponse, Error, IPagingData<any>>({ // TODO: type push history
queryKey: [PRODUCT_CACHE_KEYS.get_product_env_list],
queryKey: [PUSH_API_EVENT_CACHE_KEYS.get_product_env_list],
queryFn: () => getPushEventHistory(),
select: (data) => data.data,
staleTime: STALE_TIME,
});
}
}

export const usePostPushActivityLog = () => {
return useMutation<any, Error, ICreateActivityHistoryLogRequest>({
mutationKey: [PUSH_API_EVENT_CACHE_KEYS.create_activity_history_log],
mutationFn: (data) => {
return createActivityHistoryLog(data);
},
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: [PUSH_API_EVENT_CACHE_KEYS.create_activity_history_log],
});
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import dayjs from 'dayjs';
import { useGetProductEnvActivitiesMutation } from '@/hooks/product';
import { disabled7DaysDate } from '@/utils/helpers/date';
import { useAppStore } from "@/stores/app.store";
import { usePostPushActivityLog } from '@/hooks/pushApiEvent';
import { ICreateActivityHistoryLogRequest } from '@/utils/types/common.type';
import { TIME_ZONE_FORMAT } from '@/utils/constants/format';

const { RangePicker } = DatePicker;

type Props = {
isOpen: boolean;
onClose: () => void;
onOK: (value: string) => void;
envOptions: Array<{
value: string;
label: string;
Expand All @@ -22,35 +24,48 @@ type Props = {
const PushHistoryModal = ({
isOpen,
onClose,
onOK,
envOptions,
}: Props) => {
const [form] = Form.useForm();
const { currentProduct } = useAppStore();

const { data: responseData, mutateAsync: getProductEnvActivities, isPending, isSuccess } = useGetProductEnvActivitiesMutation();
const { mutateAsync: createPushActivityLog } = usePostPushActivityLog();

const handleOK = () => {
// TODO:
onOK(form.getFieldsValue());
createPushActivityLog(parseParams())
onClose();
};

const { data: responseData, mutateAsync, isPending, isSuccess } = useGetProductEnvActivitiesMutation();

const parseParams = () : ICreateActivityHistoryLogRequest => {
const { envId, requestTime } = form.getFieldsValue();
return {
startTime: requestTime?.[0]
? dayjs(requestTime[0]).startOf("day").format(TIME_ZONE_FORMAT)
: undefined,
endTime: requestTime?.[1]
? dayjs(requestTime[1]).endOf("day").format(TIME_ZONE_FORMAT)
: undefined,
envId
};
}

const handleFormValuesChange = useCallback(
(t: any, values: any) => {
if (t.path) return;
const { requestTime = [] } = values ?? {};

const params = {
requestStartTime: requestTime?.[0]
? dayjs(requestTime[0]).startOf("day").valueOf()
? dayjs(requestTime[0]).startOf("day").format(TIME_ZONE_FORMAT)
: undefined,
requestEndTime: requestTime?.[1]
? dayjs(requestTime[1]).endOf("day").valueOf()
? dayjs(requestTime[1]).endOf("day").format(TIME_ZONE_FORMAT)
: undefined
}

if (values.envId && !!params.requestStartTime) {
mutateAsync({
getProductEnvActivities({
productId: currentProduct,
envId: values.envId,
params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ const EnvironmentActivityLog = () => {
isOpen={isOpen}
envOptions={envOptions}
onClose={close}
onOK={() => alert('OK')}
/>
)}
<Flex align="center" justify="space-between">
Expand Down
10 changes: 10 additions & 0 deletions kraken-app/kraken-app-portal/src/services/pushApiActivity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import request from "@/utils/helpers/request";
import { PUSH_API_ACTIVITY } from "@/utils/constants/api";
import { ICreateActivityHistoryLogRequest } from '@/utils/types/common.type';

export const getPushEventHistory = () =>
request(`${PUSH_API_ACTIVITY}/history`);

export const createActivityHistoryLog = (payload: ICreateActivityHistoryLogRequest) => {
return request(PUSH_API_ACTIVITY, {
method: "POST",
data: {
...payload,
},
});
};
6 changes: 6 additions & 0 deletions kraken-app/kraken-app-portal/src/utils/types/common.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ export interface IEndpointUsageAsset {
};
}

export interface ICreateActivityHistoryLogRequest {
startTime?: string;
endTime?: string;
envId?: string;
};

export enum EnumRightType {
SelectSellerAPI,
AddSonataProp,
Expand Down

0 comments on commit 2071e78

Please sign in to comment.