Skip to content

Commit

Permalink
chore!: remove service itemsByArtifact + rm old fallback code
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Sep 20, 2024
1 parent 62aa274 commit 8ff85f9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/modules/explorer/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export const clearSearch = (datasetID) => (dispatch, getState) => {

// Helper function for CSV download functions
const performCSVDownloadHelper = (actionTypes, urlPath) =>
networkAction((ids) => (dispatch, getState) => ({
networkAction((ids) => (_dispatch, getState) => ({
types: actionTypes,
url: `${getState().services.itemsByArtifact.metadata.url}/api/batch/${urlPath}`,
url: `${getState().services.itemsByKind.metadata.url}/api/batch/${urlPath}`,
req: jsonRequest(
{
id: ids,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/services/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const fetchServicesWithMetadataAndDataTypes = () => async (dispatch, getS
export const fetchServicesWithMetadataAndDataTypesIfNeeded = () => (dispatch, getState) => {
const state = getState();
if (
(Object.keys(state.bentoServices.itemsByArtifact).length === 0 ||
(Object.keys(state.bentoServices.itemsByKind).length === 0 ||
state.services.items.length === 0 ||
state.serviceDataTypes.items.length === 0) &&
!state.services.isFetchingAll
Expand Down
23 changes: 2 additions & 21 deletions src/modules/services/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const bentoServices = (
state = {
isFetching: false,
hasAttempted: false,
itemsByArtifact: {},
itemsByKind: {},
},
action,
Expand All @@ -19,24 +18,9 @@ export const bentoServices = (
case FETCH_BENTO_SERVICES.REQUEST:
return { ...state, isFetching: true };
case FETCH_BENTO_SERVICES.RECEIVE:
if (Array.isArray(action.data)) {
// Handle old CHORD services format
// TODO: Remove when no longer relevant
console.warn("The old chord_services.json format will be deprecated soon.");
const byArtifact = Object.fromEntries(action.data.map((s) => [s.type.artifact, s]));
return {
...state,
itemsByArtifact: byArtifact,
itemsByKind: byArtifact, // technically wrong but only rarely; deprecated code to be removed
};
}

// Handle the new Bento services format: an object with the docker-compose service ID as the key
// Handle the Bento services format: an object with the docker-compose service ID as the key
return {
...state,
itemsByArtifact: Object.fromEntries(
Object.entries(action.data).map(([composeID, service]) => [service.artifact, { ...service, composeID }]),
),
itemsByKind: Object.fromEntries(
Object.entries(action.data).map(([composeID, service]) => [
service.service_kind ?? service.artifact,
Expand All @@ -59,7 +43,6 @@ export const services = (
isFetchingAll: false, // TODO: Rename this, since it means more "all data including other stuff"
items: [],
itemsByID: {},
itemsByArtifact: {},
itemsByKind: {},

aggregationService: null,
Expand Down Expand Up @@ -87,18 +70,16 @@ export const services = (
const items = action.data.filter((s) => s?.type);
const itemsByID = Object.fromEntries(items.map((s) => [s.id, s]));
const itemsByKind = Object.fromEntries(items.map((s) => [s.bento?.serviceKind ?? s.type.artifact, s]));
const itemsByArtifact = Object.fromEntries(items.map((s) => [s.type.artifact, s]));

return {
...state,

items,
itemsByID,
itemsByKind,
itemsByArtifact,

// Backwards-compatibility with older Bento versions, where this was called 'federation'
aggregationService: itemsByKind["aggregation"] ?? itemsByKind["federation"] ?? null,
aggregationService: itemsByKind["aggregation"] ?? null,
dropBoxService: itemsByKind["drop-box"] ?? null,
drsService: itemsByKind["drs"] ?? null,
eventRelay: itemsByKind["event-relay"] ?? null,
Expand Down

0 comments on commit 8ff85f9

Please sign in to comment.