diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.js index 5ddc5cd4ae223a6cc170827e1ac7fbdfb4b6bddd..e2c0ab1df963dc0f5498fef63d7daccbb0dbe495 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.js @@ -260,19 +260,19 @@ export class SchedulingSetCreate extends Component { } async onTopGridReady(params) { - await this.setState({ + this.setState({ topGridApi: params.api, topGridColumnApi: params.columnApi, }) - this.state.topGridApi.hideOverlay(); + params.api.hideOverlay(); } async onGridReady(params) { - await this.setState({ + this.setState({ gridApi: params.api, gridColumnApi: params.columnApi, }) - this.state.gridApi.hideOverlay(); + params.api.hideOverlay(); } /** @@ -579,6 +579,13 @@ export class SchedulingSetCreate extends Component { } async componentDidMount() { + + let observStrategyFilter = UtilService.localStore({type: 'get', key: 'strategyFilterSUSetEditor'}); + if (Object.keys(observStrategyFilter).length === 0) { + observStrategyFilter = {states: ['active'], purpose: []} + } + const permission = await AuthUtil.getUserPermissionByModule('scheduleunit_draft'); // calling synchronize function getUserPermissionByModule + this.setState({userrole: permission}); const promises = [ ProjectService.getProjectList(false, 'name,url,auto_pin'), TaskService.getTaskTemplates(), @@ -588,9 +595,10 @@ export class SchedulingSetCreate extends Component { ScheduleService.getStrategyPurpose(), ScheduleService.getStrategyState(), ProjectService.getMyRoles(), + this.getMatchingObservationStrategyTemplates(observStrategyFilter) ]; - const permission = await AuthUtil.getUserPermissionByModule('scheduleunit_draft'); - this.setState({userrole: permission}); + + let observStrategies; await Promise.all(promises).then(async (responses) => { this.projects = responses[0]; this.taskTemplates = responses[1]; @@ -600,6 +608,7 @@ export class SchedulingSetCreate extends Component { this.templatePurposes = this.getStrategyFilterOptions(responses[5], 'purpose'); this.templateState = this.getStrategyFilterOptions(responses[6], 'state'); this.myRoles = responses[7]; + observStrategies = responses[8]; const systemRoles = this.myRoles.system_roles.map(role => { return role.toLowerCase() }); @@ -632,13 +641,10 @@ export class SchedulingSetCreate extends Component { this.setState({isLoading: false, priorityQueuelist: queueList}); } }); - let observStrategyFilter = UtilService.localStore({type: 'get', key: 'strategyFilterSUSetEditor'}); - if (Object.keys(observStrategyFilter).length === 0) { - observStrategyFilter = {states: ['active'], purpose: []} - } + this.setState({ - observStrategies: await this.getMatchingObservationStrategyTemplates(observStrategyFilter), + observStrategies: observStrategies, observStrategyFilters: observStrategyFilter }); } @@ -689,10 +695,11 @@ export class SchedulingSetCreate extends Component { isDirty: false, isObsoletStrategy: observStrategy.state_value === 'obsolete' ? true : false }); - await this.getTaskSchema(observStrategy); - if (this.state.schedulingUnit.project && this.state.schedulingUnit.scheduling_set_id) { - this.prepareScheduleUnitListForGrid(); - } + + this.getTaskSchema(observStrategy).then((schemainfo )=> { + if (this.state.schedulingUnit.project && this.state.schedulingUnit.scheduling_set_id) { + this.prepareScheduleUnitListForGrid(observStrategy,schemainfo.schema,schemainfo.defaultStationGroups); + }}); } async getTaskSchema(observStrategy) { @@ -761,7 +768,9 @@ export class SchedulingSetCreate extends Component { paramsOutput: paramsOutput, defaultStationGroups: station_groups }); + return { schema:schema,defaultStationGroups:station_groups} ; } + return {schema:null,defaultStationGroups:null} } /** @@ -813,13 +822,13 @@ export class SchedulingSetCreate extends Component { /** * Function to prepare row data for ag-grid. */ - async prepareScheduleUnitListForGrid() { + async prepareScheduleUnitListForGrid(observStrategy,paramsSchema,defaultStationGroups) { this.custId = 1; let defaultCommonRowData = {}; - let observStrategyContraints = this.state.observStrategy.template.scheduling_constraints_doc; + let observStrategyContraints = observStrategy.template.scheduling_constraints_doc; // Load selected fields of SUDrafts of the selected SU Set and filter the SUDrafts of selected observation strategy; let schedulingUnitList = (await ScheduleService.getSchedulingBySet(this.state.selectedSchedulingSetId, this.SU_DRAFT_FIELDS, this.SU_DRAFT_EXPAND)) - .filter(su => su.observation_strategy_template_id === this.state.observStrategy.id) + .filter(su => su.observation_strategy_template_id === observStrategy.id) .map(su => { su.taskDrafts = su.task_drafts; return su @@ -828,7 +837,7 @@ export class SchedulingSetCreate extends Component { this.agSUWithDefaultValue = {'id': 0, 'suname': '', 'sudesc': '', isDirty: false}; /** Get Column details */ - await this.createGridCellDetails(); + await this.createGridCellDetails(observStrategy,paramsSchema,defaultStationGroups); let observationPropsList = []; this.tmpRowData = []; let totalSU = this.state.noOfSU; @@ -902,10 +911,10 @@ export class SchedulingSetCreate extends Component { } } } else { - let parameters = this.state.observStrategy.template.parameters; + let parameters = observStrategy.template.parameters; for (const parameter of parameters) { let refUrl = parameter['refs']; - let valueItem = (await $RefParser.resolve(this.state.observStrategy.template)).get(refUrl[0]); + let valueItem = (await $RefParser.resolve(observStrategy.template)).get(refUrl[0]); let excelColumns = this.state.columnMap[parameter.name]; if (excelColumns) { let excelColumnsKeys = Object.keys(excelColumns); @@ -1029,14 +1038,14 @@ export class SchedulingSetCreate extends Component { emptyRow[key] = ''; } }); - let tmpRow = _.cloneDeep(this.state.agSUWithDefaultValue); + let tmpRow = _.cloneDeep( this.state.agSUWithDefaultValue || this.agSUWithDefaultValue); /// why is this not this.agSUWithDefaultValue // was this.state.agSUWithDefaultValue tmpRow['custId'] = this.custId++; this.tmpRowData.push(tmpRow); } } else { let availableCount = this.tmpRowData.length; for (let i = availableCount; i < totalSU; i++) { - let tmpRow = _.cloneDeep(this.state.agSUWithDefaultValue); + let tmpRow = _.cloneDeep(this.state.agSUWithDefaultValue || this.agSUWithDefaultValue); // was this.state.agSUWithDefaultValue tmpRow['custId'] = this.custId++; this.tmpRowData.push(tmpRow); } @@ -1367,7 +1376,7 @@ export class SchedulingSetCreate extends Component { return childCellProps; } - async createGridCellDetails() { + async createGridCellDetails(observStrategy,paramsSchema,defaultStationGroups) { let columnMap = []; let colProperty = {}; this.colKeyOrder = []; @@ -1447,11 +1456,11 @@ export class SchedulingSetCreate extends Component { this.colKeyOrder.push("rank"); this.colKeyOrder.push("priority_queue"); // Create Constraint Column for AG Grid - columnDefs = await this.getConstraintColumns(columnDefs); + columnDefs = await this.getConstraintColumns(columnDefs,observStrategy); let cellProps = {}; this.strategyVariables = []; //Observation Schema - const schema = this.state.paramsSchema; + const schema = paramsSchema; if (schema.properties && !_.isEmpty(schema.properties)) { // let definitions = schema.definitions.pointing; let predefineCellProps = this.getAGGridAngelColumnsDefinition(schema); @@ -1574,7 +1583,7 @@ export class SchedulingSetCreate extends Component { for (const stationKey of stationKeys) { let stationValue = ''; let cellProp = {}; - this.state.defaultStationGroups[stationKey].map(stationGroup => { + defaultStationGroups[stationKey].map(stationGroup => { let missingStation = (stationGroup.max_nr_missing) ? stationGroup.max_nr_missing : 0; stationValue += stationGroup.stations + ':' + missingStation + "|"; return stationGroup; @@ -1756,10 +1765,10 @@ export class SchedulingSetCreate extends Component { * @param {*} columnDefs * @returns */ - async getConstraintColumns(columnDefs) { + async getConstraintColumns(columnDefs,observStrategy) { this.constraintVariables = []; // currently only one constraint schema available and not propvided UI to choose constraints, so assign directly - const currentConstraintsTemplate = this.state.observStrategy.template.scheduling_constraints_template; + const currentConstraintsTemplate = observStrategy.template.scheduling_constraints_template; this.constraintSchema = getConstraintTemplate(this.constraintTemplates, currentConstraintsTemplate.name, currentConstraintsTemplate.version) if (!this.constraintSchema) { this.growl.show({ diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.test.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.test.js index ff34dd4a3f60c0b016ba742871804b05217d4886..ba4847568ea98b2faa461e5e4b440502e4d9eadc 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.test.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Scheduling/excelview.schedulingset.test.js @@ -1,7 +1,7 @@ import React from 'react'; import { cleanup, waitFor } from '@testing-library/react'; import '@testing-library/jest-dom'; - +import UtilService from "../../services/util.service"; import SchedulingSetCreate from './excelview.schedulingset'; import ScheduleService from '../../services/schedule.service'; import ProjectService from '../../services/project.service'; @@ -15,7 +15,7 @@ import { clickItem, removeReact18ConsoleErrors, renderPage, setMultiSelectValue import { setSchedulingUnitStrategy } from "./schedulingunit.test.helper"; let projectListSpy, observStrategiesSpy, taskTemplatesSpy, userPermissionSpy, rolesSpy, suConstraintTemplateSpy, - templatePurposesSpy, templateStatesSpy; + templatePurposesSpy, templateStatesSpy,utcSpy; //Jest issue: https://github.com/jestjs/jest/issues/9709: Cannot be called in beforeXX test method const OBSERVATION_STRATEGY_TEMPLATES = SUServiceMock.getObservStrategies() @@ -31,9 +31,7 @@ function createStandardPageMocks() { return Promise.resolve(ProjectServiceMock.projectList) }); - observStrategiesSpy = jest.spyOn(ScheduleService, 'getObservationStrategies').mockImplementation(() => { - return Promise.resolve(SUServiceMock.getObservStrategies()) - }); + observStrategiesSpy = jest.spyOn(ScheduleService, 'getObservationStrategies').mockResolvedValue(OBSERVATION_STRATEGY_TEMPLATES); suConstraintTemplateSpy = jest.spyOn(ScheduleService, 'getSchedulingConstraintTemplates').mockImplementation(() => { return Promise.resolve(SUServiceMock.getSUCTemplates()); @@ -57,6 +55,8 @@ function createStandardPageMocks() { rolesSpy = jest.spyOn(ProjectService, 'getMyRoles').mockImplementation(() => { return Promise.resolve(SUServiceMock.getMyRoles) }); + const utcTime = '2023-08-11 06:20:45'; + utcSpy = jest.spyOn(UtilService, 'getUTC').mockResolvedValue(utcTime); } function getColumnTypes(columnDefs) { @@ -175,7 +175,7 @@ describe('Scheduling Units Excel View create page with an observation strategy t await waitFor(() => expect(pageContent.queryByTestId('save-btn')).toBeInTheDocument()); await clickItem(pageContent.queryByTestId('save-btn')) expect(saveSUFromStrategySpy).not.toHaveBeenCalled(); - expect(pageContent.getByRole('dialog')).toBeDefined(); //pop-up indicating errored SU + expect(pageContent.getByRole('dialog')).toBeInTheDocument(); //pop-up indicating errored SU });