Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
fix getStoredResourcePaths
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpyle committed May 16, 2019
1 parent 30f506b commit ae93806
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
14 changes: 7 additions & 7 deletions app/actions/bundle.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { dblDotLocalService } from '../services/dbl_dot_local.service';
import { bundleManageResourceActions } from './bundleManageResources.actions';
import { workspaceHelpers } from '../helpers/workspaces.helpers';
import { browserWindowService } from '../services/browserWindow.service';
import { getAddedBundle, getResourcesDetails } from '../helpers/bundle.helpers';
import {
getAddedBundle,
getResourcePaths,
getStoredResourcePaths
} from '../helpers/bundle.helpers';

export const bundleActions = {
fetchAll,
Expand Down Expand Up @@ -716,14 +720,10 @@ export function downloadResources(_id, _uris = []) {
}
}

function getResourcePaths(getState, id) {
return Object.keys(getResourcesDetails(getState, id)) || [];
}

export function removeResources(id, selected = []) {
return async (dispatch, getState) => {
try {
const resourcePaths = getResourcePaths(getState, id);
const resourcePaths = getStoredResourcePaths(getState, id);
const resourcePathsToRemove = resourcePaths.filter(
path => !selected.length || selected.includes(path)
);
Expand Down Expand Up @@ -785,7 +785,7 @@ export function requestSaveBundleTo(id, selectedFolder) {
addByteSize,
0
);
const resourcePaths = getResourcePaths(getState, id);
const resourcePaths = getStoredResourcePaths(getState, id);
resourcePaths.unshift('metadata.xml');
const resourcePathsProgress = resourcePaths.reduce((acc, resourcePath) => {
acc[resourcePath] = 0;
Expand Down
22 changes: 16 additions & 6 deletions app/helpers/bundle.helpers.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
export const bundleHelpers = {
getResourcePaths,
getResourcesDetails,
getAddedBundle,
getRawBundleResourcesDetails
};
export default bundleHelpers;

export function getResourcesDetails(getState, id) {
export function getStoredResourcePaths(getState, id) {
const bundle = getAddedBundle(getState, id);
return getRawBundleResourcesDetails(bundle.raw);
return Object.keys(bundle.storedFiles);
}

// TODO: make a separate helper for raw bundles than for getState?
export function getRawBundleResourcesDetails(rawBundle) {
const { metadata } = rawBundle;
return metadata.manifest;
export function getResourcePaths(getState, id) {
return Object.keys(getResourcesDetails(getState, id)) || [];
}

export function getResourcesDetails(getState, id) {
const bundle = getAddedBundle(getState, id);
return getRawBundleResourcesDetails(bundle.raw);
}

export function getAddedBundle(getState, bundleId) {
Expand All @@ -22,3 +26,9 @@ export function getAddedBundle(getState, bundleId) {
const addedBundles = addedByBundleIds[bundleId];
return addedBundles;
}

// TODO: make a separate helper for raw bundles than for getState?
export function getRawBundleResourcesDetails(rawBundle) {
const { metadata } = rawBundle;
return metadata.manifest;
}

0 comments on commit ae93806

Please sign in to comment.