Skip to content

Commit

Permalink
Refactor to remove reducer layer for roles
Browse files Browse the repository at this point in the history
  • Loading branch information
testower committed Dec 17, 2024
1 parent ec60d23 commit 4ed9ecb
Show file tree
Hide file tree
Showing 26 changed files with 362 additions and 644 deletions.
18 changes: 0 additions & 18 deletions src/actions/RolesActions.js

This file was deleted.

80 changes: 40 additions & 40 deletions src/actions/TiamatActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const findTagByName = (name) => async (dispatch, getState) =>
variables: {
name,
},
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const addTag =
Expand All @@ -154,7 +154,7 @@ export const addTag =
name,
comment,
},
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getStopPlaceById = (id) => async (dispatch, getState) =>
Expand All @@ -164,15 +164,15 @@ export const getStopPlaceById = (id) => async (dispatch, getState) =>
variables: {
id,
},
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getAddStopPlaceInfo =
(stopPlaceIds) => async (dispatch, getState) =>
handleQuery(getTiamatClient(), {
query: getStopPlacesById(stopPlaceIds),
fetchPolicy: "network-only",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const saveStopPlaceBasedOnType =
Expand All @@ -190,7 +190,7 @@ export const saveStopPlaceBasedOnType =
mutation: mutateStopPlace,
variables,
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch)
.then((result) => {
if (result.data.mutateStopPlace[0].id) {
Expand All @@ -214,7 +214,7 @@ export const saveStopPlaceBasedOnType =
mutation: updateChildOfParentStop,
variables,
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch)
.then((result) => {
resolve(stopPlace.id);
Expand All @@ -231,7 +231,7 @@ export const saveParentStopPlace = (variables) => async (dispatch, getState) =>
mutation: mutateParentStopPlace,
variables,
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const removeStopPlaceFromMultiModalStop =
Expand All @@ -243,15 +243,15 @@ export const removeStopPlaceFromMultiModalStop =
parentSiteRef,
},
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const deleteQuay = (variables) => async (dispatch, getState) => {
handleMutation(getTiamatClient(), {
mutation: mutateDeleteQuay,
variables,
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);
};

Expand All @@ -262,7 +262,7 @@ export const deleteStopPlace = (stopPlaceId) => async (dispatch, getState) =>
stopPlaceId,
},
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const terminateStop =
Expand All @@ -277,7 +277,7 @@ export const terminateStop =
modificationEnumeration: shouldTerminatePermanently ? "delete" : null,
},
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const addToMultiModalStopPlace =
Expand All @@ -289,7 +289,7 @@ export const addToMultiModalStopPlace =
parentSiteRef,
},
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const createParentStopPlace =
Expand All @@ -313,7 +313,7 @@ export const createParentStopPlace =
stopPlaceIds,
},
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const mutateGroupOfStopPlace =
Expand All @@ -323,7 +323,7 @@ export const mutateGroupOfStopPlace =
mutation: mutateGroupOfStopPlaces,
variables,
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch)
.then(({ data }) => {
const id = data["mutateGroupOfStopPlaces"]
Expand All @@ -344,7 +344,7 @@ export const getStopPlaceVersions =
id: stopPlaceId,
},
fetchPolicy: "network-only",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const mergeQuays =
Expand All @@ -359,7 +359,7 @@ export const mergeQuays =
versionComment,
},
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getStopPlaceWithAll = (id) => async (dispatch, getState) =>
Expand All @@ -369,7 +369,7 @@ export const getStopPlaceWithAll = (id) => async (dispatch, getState) =>
id,
},
fetchPolicy: "network-only",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const mergeAllQuaysFromStop =
Expand All @@ -384,7 +384,7 @@ export const mergeAllQuaysFromStop =
toVersionComment,
},
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const moveQuaysToStop =
Expand All @@ -399,7 +399,7 @@ export const moveQuaysToStop =
toVersionComment,
},
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const moveQuaysToNewStop =
Expand All @@ -413,7 +413,7 @@ export const moveQuaysToNewStop =
toVersionComment,
},
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getNeighbourStops =
Expand All @@ -429,14 +429,14 @@ export const getNeighbourStops =
lonMin: bounds.getSouthWest().lng,
lonMax: bounds.getNorthEast().lng,
},
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getTopographicPlaces = (ids) => async (dispatch, getState) =>
handleQuery(getTiamatClient(), {
fetchPolicy: "network-only",
query: getQueryTopographicPlaces(ids),
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getMergeInfoForStops =
Expand All @@ -447,7 +447,7 @@ export const getMergeInfoForStops =
variables: {
stopPlaceId,
},
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const findEntitiesWithFilters =
Expand Down Expand Up @@ -475,7 +475,7 @@ export const findEntitiesWithFilters =
pointInTime: showFutureAndExpired ? null : new Date().toISOString(),
versionValidity: showFutureAndExpired ? "MAX_VERSION" : null,
},
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);
};

Expand All @@ -486,7 +486,7 @@ export const findTopographicalPlace = (query) => async (dispatch, getState) =>
variables: {
query,
},
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getTags = (idReference) => async (dispatch, getState) =>
Expand All @@ -496,7 +496,7 @@ export const getTags = (idReference) => async (dispatch, getState) =>
variables: {
idReference,
},
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getTagsByName = (name) => async (dispatch, getState) =>
Expand All @@ -506,7 +506,7 @@ export const getTagsByName = (name) => async (dispatch, getState) =>
variables: {
name,
},
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const removeTag = (name, idReference) => async (dispatch, getState) =>
Expand All @@ -517,7 +517,7 @@ export const removeTag = (name, idReference) => async (dispatch, getState) =>
idReference,
},
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getGroupOfStopPlacesById = (id) => async (dispatch, getState) =>
Expand All @@ -527,7 +527,7 @@ export const getGroupOfStopPlacesById = (id) => async (dispatch, getState) =>
id,
},
fetchPolicy: "network-only",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const deleteGroupOfStopPlaces = (id) => async (dispatch, getState) =>
Expand All @@ -537,7 +537,7 @@ export const deleteGroupOfStopPlaces = (id) => async (dispatch, getState) =>
id,
},
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const deleteParking = (id) => async (dispatch, getState) =>
Expand All @@ -547,7 +547,7 @@ export const deleteParking = (id) => async (dispatch, getState) =>
id,
},
fetchPolicy: "no-cache",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getStopPlaceAndPathLinkByVersion =
Expand All @@ -559,7 +559,7 @@ export const getStopPlaceAndPathLinkByVersion =
id,
version: parseInt(version),
},
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const findStopForReport =
Expand All @@ -568,15 +568,15 @@ export const findStopForReport =
query: findStopForReportQuery,
fetchPolicy: "network-only",
variables: queryVariables,
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getParkingForMultipleStopPlaces =
(stopPlaceIds) => async (dispatch, getState) =>
handleQuery(getTiamatClient(), {
query: getParkingForMultipleStopPlacesQuery(stopPlaceIds),
fetchPolicy: "network-only",
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const topographicalPlaceSearch =
Expand All @@ -587,7 +587,7 @@ export const topographicalPlaceSearch =
variables: {
query: searchText,
},
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getNeighbourStopPlaceQuays = (id) => async (dispatch, getState) =>
Expand All @@ -597,23 +597,23 @@ export const getNeighbourStopPlaceQuays = (id) => async (dispatch, getState) =>
variables: {
id: id,
},
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const savePathLink = (PathLink) => async (dispatch, getState) =>
handleMutation(getTiamatClient(), {
fetchPolicy: "no-cache",
mutation: mutatePathLink,
variables: { PathLink },
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const saveParking = (Parking) => async (dispatch, getState) =>
handleMutation(getTiamatClient(), {
fetchPolicy: "no-cache",
mutation: mutateParking,
variables: { Parking },
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);

export const getLocationPermissionsForCoordinates = (longitude, latitude) => {
Expand All @@ -622,7 +622,7 @@ export const getLocationPermissionsForCoordinates = (longitude, latitude) => {
fetchPolicy: "no-cache",
query: getLocationPermissions,
variables: { longitude, latitude },
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);
};
};
Expand All @@ -632,7 +632,7 @@ export const getUserPermissions = () => {
return handleQuery(getTiamatClient(), {
fetchPolicy: "no-cache",
query: getUserPermissionsQuery,
context: await getContext(getState().roles.auth),
context: await getContext(getState().user.auth),
})(dispatch);
};
};
6 changes: 1 addition & 5 deletions src/actions/Types.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const REMOVE_ADJACENT_SITE = "REMOVE_ADJACENT_SITE";
export const SET_STOP_PLACE_LOADING = "SET_STOP_PLACE_LOADING";

// UserActions
export const UPDATED_AUTH = "UPDATED_AUTH";
export const NAVIGATE_TO = "NAVIGATE_TO";
export const TOGGLED_IS_CREATING_NEW_STOP = "TOGGLED_IS_CREATING_NEW_STOP";
export const APPLIED_STOPTYPE_SEARCH_FILTER = "APPLIED_STOPTYPE_SEARCH_FILTER";
Expand Down Expand Up @@ -198,8 +199,3 @@ export const SETUP_NEW_GROUP = "SETUP_NEW_GROUP";
export const CREATED_NEW_GROUP_OF_STOP_PLACES =
"CREATED_NEW_GROUP_OF_STOP_PLACES";
export const ERROR_NEW_GROUP = "ERROR_NEW_GROUP";

// RolesActions
export const UPDATED_AUTH = "UPDATED_AUTH";
export const UPDATED_ALLOW_NEW_STOPS_EVERYWHERE =
"UPDATED_ALLOW_NEW_STOPS_EVERYWHERE";
Loading

0 comments on commit 4ed9ecb

Please sign in to comment.