Skip to content

Commit

Permalink
refactor jv-scheduler: introduce dryRun flag
Browse files Browse the repository at this point in the history
introduce dryRun flag in configuration so that when it is true , we will not call create schedule API
  • Loading branch information
anthomba-tibco committed Oct 16, 2024
1 parent 63e0f3e commit 3eafc87
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
11 changes: 8 additions & 3 deletions packages/jv-scheduler/src/actions/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from "../constants/actionConstants";
import { allTabs } from "../constants/schedulerConstants";
import {
createDummySchedule,
createSchedule,
getFakeRootDataFromService,
getOutputFormatsFromService,
Expand Down Expand Up @@ -91,7 +92,7 @@ export const setPropertiesDetails = (
};
};

export const setSechedulerUIConfig = (
export const setSchedulerUIConfig = (
schedulerUIConfig: SchedulerConfig & { resourceURI: string },
) => {
return {
Expand Down Expand Up @@ -273,7 +274,7 @@ export const setInitialPluginState = (
stepperDefaultState,
fieldsSupportedValues,
} = schedulerData;
dispatch(setSechedulerUIConfig({ ...schedulerUIConfig, resourceURI: uri }));
dispatch(setSchedulerUIConfig({ ...schedulerUIConfig, resourceURI: uri }));
dispatch(getUserTimeZones(scheduleInfo.outputTimeZone));
if (fieldsSupportedValues.outputFormat) {
dispatch(setOutputFormats(fieldsSupportedValues.outputFormat));
Expand Down Expand Up @@ -359,7 +360,11 @@ export const createScheduleJob = (enableCreateBtn: () => void) => {
} else {
repositoryDestination.saveToRepository = true;
}
const jobInfo = await createSchedule({

const createScheduleFun = getState().schedulerUIConfig?.dryRun
? createDummySchedule
: createSchedule;
const jobInfo = await createScheduleFun({
label: scheduleJobName,
description: scheduleJobDescription,
outputFormats: {
Expand Down
1 change: 1 addition & 0 deletions packages/jv-scheduler/src/config/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"server": "",
"contextPath": "",
"dryRun": false,
"stepper": {
"show": true
},
Expand Down
39 changes: 19 additions & 20 deletions packages/jv-scheduler/src/services/schedulerServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import store from "../store/store";
import { IState } from "../types/scheduleType";
import { PUBLIC_FOLDER, ROOT_FOLDER } from "../constants/schedulerConstants";

const mobileDemoPath = "https://mobiledemo.jaspersoft.com/";
const getServerContextPath = () => {
return `${(store.getState() as IState)?.schedulerUIConfig?.server}${(store.getState() as IState)?.schedulerUIConfig?.contextPath}`;
};
Expand Down Expand Up @@ -172,24 +171,24 @@ export const getFakeRootDataFromService = async () => {
};

export const createSchedule = async (scheduleInfo: any) => {
if (getServerContextPath()?.startsWith(mobileDemoPath)) {
return Promise.resolve({});
} else {
return axios.put(
`${getServerContextPath()}/rest_v2/jobs`,
{
...scheduleInfo,
},
{
withCredentials: true,
headers: {
Accept: "application/job+json",
"Content-Type": "application/job+json",
"x-requested-with": "XMLHttpRequest, OWASP CSRFGuard Project",
"X-Remote-Domain": getServer(),
"X-Suppress-Basic": "true",
},
return axios.put(
`${getServerContextPath()}/rest_v2/jobs`,
{
...scheduleInfo,
},
{
withCredentials: true,
headers: {
Accept: "application/job+json",
"Content-Type": "application/job+json",
"x-requested-with": "XMLHttpRequest, OWASP CSRFGuard Project",
"X-Remote-Domain": getServer(),
"X-Suppress-Basic": "true",
},
);
}
},
);
};

export const createDummySchedule = async (scheduleInfo: any) => {
return Promise.resolve(scheduleInfo);
};
4 changes: 4 additions & 0 deletions packages/jv-scheduler/src/types/scheduleType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ApiFailedProps extends ApiErrorMsg {

export interface SchedulerConfig {
server: string;
dryRun?: boolean;
contextPath?: string;
tabs?: {
activeTab?: string;
Expand Down Expand Up @@ -147,6 +148,9 @@ export interface SchedulerInitialPluginDataProps {
stepperDefaultState: StepperStateProps;
stepsToShow: stepsToShow[];
tabsToShow: tabsToShow[];
fieldsSupportedValues: {
outputFormat: string[];
};
}

export interface IState extends SchedulerInitialPluginDataProps {
Expand Down

0 comments on commit 3eafc87

Please sign in to comment.