Skip to content

Commit

Permalink
fixed frontend part of the ticket. Now properly resolves target based…
Browse files Browse the repository at this point in the history
… on the target name and target access string
  • Loading branch information
boriskovar-m2ms committed Dec 11, 2024
1 parent 97a92e1 commit 9d9bf8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
19 changes: 11 additions & 8 deletions js/components/target/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export const loadProjectsList = () => async (dispatch, getState) => {
return resp.data.results;
};

export const updateTarget = ({ target, setIsLoading, targetIdList, projectId }) => (dispatch, getState) => {
export const updateTarget = ({ targetName, projectName, setIsLoading, targetIdList, projectId }) => (
dispatch,
getState
) => {
const state = getState();
const isActionRestoring = false; //state.trackingReducers.isActionRestoring;
const currentSessionProject = state.projectReducers.currentProject;
Expand All @@ -68,11 +71,13 @@ export const updateTarget = ({ target, setIsLoading, targetIdList, projectId })
// Get from the REST API
let targetUnrecognisedFlag = true;
// if (target !== undefined) {
if (target) {
let target = null;
if (targetName) {
if (targetIdList && targetIdList.length > 0) {
targetIdList.forEach(targetId => {
if (target === targetId.title) {
targetIdList.forEach(t => {
if (targetName === t.title && t.project.target_access_string === projectName) {
targetUnrecognisedFlag = false;
target = t;
}
});
}
Expand All @@ -86,7 +91,7 @@ export const updateTarget = ({ target, setIsLoading, targetIdList, projectId })
setIsLoading(true);
let url = undefined;
if (target) {
url = `${base_url}/api/targets/?title=${target}`;
url = `${base_url}/api/targets/?id=${target.id}`;
return api({ url })
.then(response => {
return dispatch(setTargetOn(response.data['results'][0].id));
Expand Down Expand Up @@ -163,9 +168,7 @@ export const getTargetProjectCombinations = (targets, projects) => {
updatedTarget.project = project;
result.push({ updatedTarget });
} else {
console.log(
`User don't have access to project ${projectId} which is associated with target ${target.title}`
);
console.log(`User don't have access to project ${projectId} which is associated with target ${target.title}`);
}
} else {
result.push({ updatedTarget: { ...target, project: { target_access_string: 'Legacy' } } });
Expand Down
9 changes: 5 additions & 4 deletions js/components/target/withUpdatingTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { connect, useSelector } from 'react-redux';
import HandleUnrecognisedTarget from './handleUnrecognisedTarget';
import { updateTarget, setTargetUUIDs, resetTargetAndSelection } from './redux/dispatchActions';
import { useRouteMatch } from 'react-router-dom';
import { extractTargetFromURLParam } from '../preview/utils';
import { extractProjectFromURLParam, extractTargetFromURLParam } from '../preview/utils';
import { LoadingContext } from '../loading';

export const withUpdatingTarget = WrappedContainer => {
Expand All @@ -12,7 +12,8 @@ export const withUpdatingTarget = WrappedContainer => {
let match = useRouteMatch();

// const target = match && match.params && match.params.target;
let target = match && match.params && extractTargetFromURLParam(match.params[0]);
let targetName = match && match.params && extractTargetFromURLParam(match.params[0]);
const projectName = match && match.params && extractProjectFromURLParam(match.params[0]);
const uuid = match && match.params && match.params.uuid;
const snapshotUuid = match && match.params && match.params.snapshotUuid;
const snapshotId = match && match.params && match.params.snapshotId;
Expand All @@ -30,12 +31,12 @@ export const withUpdatingTarget = WrappedContainer => {
}, [setTargetUUIDs, snapshotUuid, uuid]);

useEffect(() => {
updateTarget({ target, setIsLoading, targetIdList, projectId }).catch(error => {
updateTarget({ targetName, projectName, setIsLoading, targetIdList, projectId }).catch(error => {
setState(() => {
throw error;
});
});
}, [setIsLoading, target, updateTarget, targetIdList, projectId, snapshotId /*, isActionRestoring*/]);
}, [setIsLoading, targetName, updateTarget, targetIdList, projectId, snapshotId, projectName]);

if (isLoading === true) {
return null;
Expand Down

0 comments on commit 9d9bf8c

Please sign in to comment.