Skip to content

Commit

Permalink
v2.5.2 (#69)
Browse files Browse the repository at this point in the history
* fix AOP prov step handling, performance, selection limit

* handle render, initialization of filters

* fix styling of prov data message in AOP workflow

* prepare v2.5.2
  • Loading branch information
sampsonj authored Oct 26, 2023
1 parent a1c89e8 commit 78da765
Show file tree
Hide file tree
Showing 13 changed files with 2,876 additions and 1,995 deletions.
8 changes: 8 additions & 0 deletions lib/components/DownloadDataContext/DownloadDataContext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export function getTestableItems(): {
s3FileFetches: {};
s3FileFetchProgress: number;
s3Files: {
maxNumFilesSelected: number;
value: never[];
valueMap: {};
cachedValues: never[];
validValues: never[];
isValid: boolean;
Expand Down Expand Up @@ -192,7 +194,9 @@ declare function useDownloadDataState(): {
s3FileFetches: {};
s3FileFetchProgress: number;
s3Files: {
maxNumFilesSelected: number;
value: never[];
valueMap: {};
cachedValues: never[];
validValues: never[];
isValid: boolean;
Expand Down Expand Up @@ -272,7 +276,9 @@ declare function useDownloadDataState(): {
s3FileFetches: {};
s3FileFetchProgress: number;
s3Files: {
maxNumFilesSelected: number;
value: never[];
valueMap: {};
cachedValues: never[];
validValues: never[];
isValid: boolean;
Expand Down Expand Up @@ -356,8 +362,10 @@ declare namespace DEFAULT_STATE {
export const s3FileFetches: {};
export const s3FileFetchProgress: number;
export namespace s3Files {
export const maxNumFilesSelected: number;
const value_1: never[];
export { value_1 as value };
export const valueMap: {};
export const cachedValues: never[];
export const validValues: never[];
export const isValid: boolean;
Expand Down
177 changes: 123 additions & 54 deletions lib/components/DownloadDataContext/DownloadDataContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ var DEFAULT_STATE = {
s3FileFetchProgress: 0,
// Number to track progress of batch fetches for s3 files
s3Files: {
maxNumFilesSelected: 60000,
value: [],
valueMap: {},
cachedValues: [],
// Where all fetched file records are cached
validValues: [],
Expand Down Expand Up @@ -284,7 +286,7 @@ var newStateIsValid = function newStateIsValid(key, value) {
if (!VALIDATABLE_STATE_KEYS.includes(key)) {
return false;
}
var idList = [];
var idList = {};
switch (key) {
case 'sites':
return newStateIsAllowable(key, value) && Array.isArray(validValues) && value.length > 0 && value.every(function (site) {
Expand All @@ -298,11 +300,11 @@ var newStateIsValid = function newStateIsValid(key, value) {
})) {
return false;
}
idList = validValues.map(function (fileObj) {
return fileObj.url;
validValues.forEach(function (fileObj) {
idList[fileObj.url] = true;
});
return newStateIsAllowable(key, value) && value.length > 0 && value.every(function (id) {
return idList.includes(id);
return idList[id] || false;
});
default:
return newStateIsAllowable(key, value) && (!Array.isArray(validValues) || validValues.includes(value));
Expand Down Expand Up @@ -523,15 +525,50 @@ var getInitialStateFromProps = function getInitialStateFromProps(props) {
// Done!
return initialState;
};
var getS3FilesFilteredFileCount = function getS3FilesFilteredFileCount(state) {
return state.s3Files.validValues.filter(function (row) {
return Object.keys(state.s3Files.filters).every(function (col) {
var getS3FilesFilterFunction = function getS3FilesFilterFunction(state) {
return function (row) {
var allowValue = true;
var hasProvisionalDataStep = state.requiredSteps.some(function (step) {
return step.key === 'provisionalData';
});
var excludeProvisionalData = hasProvisionalDataStep && state.provisionalData.value === 'exclude';
if (excludeProvisionalData) {
allowValue = (0, _typeUtil.isStringNonEmpty)(row.release) && !_ReleaseService.default.isNonRelease(row.release);
}
var matchesFilters = Object.keys(state.s3Files.filters).every(function (col) {
if (col === 'name') {
return !state.s3Files.filters.name.length || row.name.includes(state.s3Files.filters.name);
}
return !state.s3Files.filters[col].length || state.s3Files.filters[col].includes(row[col]);
});
}).length;
return matchesFilters && allowValue;
};
};
var getS3FilesFilteredFileCount = function getS3FilesFilteredFileCount(state) {
var filtered = state.s3Files.validValues.filter(getS3FilesFilterFunction(state));
return filtered.length;
};
var calcS3FilesSummaryState = function calcS3FilesSummaryState(previousState, action) {
var newState = _extends({}, previousState);
var s3FilesIdx = newState.requiredSteps.findIndex(function (step) {
return step.key === 's3Files';
});
// If we didn't already update the total size then recalculate it
if (action.type !== 'setIndividualS3FileSelected') {
newState.s3Files.totalSize = newState.s3Files.value.map(function (id) {
return newState.s3Files.bytesByUrl[id];
}).reduce(function (a, b) {
return a + b;
}, 0);
}
// Step is only complete when there's a selection that's not too big
newState.s3Files.estimatedPostSize = estimatePostSize(newState.s3Files, newState.sites);
newState.s3Files.isValid = newState.s3Files.value.length > 0 && newState.s3Files.estimatedPostSize < _manifestUtil.MAX_POST_BODY_SIZE;
newState.requiredSteps[s3FilesIdx].isComplete = newState.s3Files.isValid;
newState.allStepsComplete = newState.requiredSteps.every(function (step) {
return step.isComplete || step.isComplete === null;
});
return newState;
};

// Generate a new full state object with a new value and isValid boolean for the
Expand All @@ -558,44 +595,61 @@ var getAndValidateNewS3FilesState = function getAndValidateNewS3FilesState(previ
return newState;
}
newState.s3Files.value = action.value;
newState.s3Files.valueMap = {};
if ((0, _typeUtil.existsNonEmpty)(newState.s3Files.value)) {
newState.s3Files.value.forEach(function (value) {
newState.s3Files.valueMap[value] = true;
});
}
break;
case 'setValidatableValue':
if (!newStateIsAllowable(action.key, action.value)) {
return newState;
}
newState.s3Files.value = action.value;
newState.s3Files.valueMap = {};
if ((0, _typeUtil.existsNonEmpty)(newState.s3Files.value)) {
newState.s3Files.value.forEach(function (value) {
newState.s3Files.valueMap[value] = true;
});
}
newState.s3Files.validValues.forEach(function (file, idx) {
newState.s3Files.validValues[idx].tableData.checked = newState.s3Files.value.includes(file.url);
newState.s3Files.validValues[idx].tableData.checked = newState.s3Files.valueMap[file.url] || false;
});
break;
case 'setS3FilesValueSelectAll':
newState.s3Files.value = newState.s3Files.validValues.map(function (file) {
return file.url;
});
newState.s3Files.valueMap = {};
if ((0, _typeUtil.existsNonEmpty)(newState.s3Files.value)) {
newState.s3Files.value.forEach(function (value) {
newState.s3Files.valueMap[value] = true;
});
}
newState.s3Files.validValues.forEach(function (file, idx) {
newState.s3Files.validValues[idx].tableData.checked = true;
});
break;
case 'setS3FilesValueSelectNone':
newState.s3Files.value = [];
newState.s3Files.valueMap = {};
newState.s3Files.validValues.forEach(function (file, idx) {
newState.s3Files.validValues[idx].tableData.checked = false;
});
break;
case 'setS3FilesValueSelectFiltered':
newState.s3Files.value = newState.s3Files.validValues.filter(function (row) {
return Object.keys(newState.s3Files.filters).every(function (col) {
if (col === 'name') {
return !newState.s3Files.filters.name.length || row.name.includes(newState.s3Files.filters.name); // eslint-disable-line max-len
}

return !newState.s3Files.filters[col].length || newState.s3Files.filters[col].includes(row[col]); // eslint-disable-line max-len
});
}).map(function (file) {
newState.s3Files.value = newState.s3Files.validValues.filter(getS3FilesFilterFunction(newState)).map(function (file) {
return file.url;
});
newState.s3Files.valueMap = {};
if ((0, _typeUtil.existsNonEmpty)(newState.s3Files.value)) {
newState.s3Files.value.forEach(function (value) {
newState.s3Files.valueMap[value] = true;
});
}
newState.s3Files.validValues.forEach(function (file, idx) {
newState.s3Files.validValues[idx].tableData.checked = newState.s3Files.value.includes(file.url); // eslint-disable-line max-len
newState.s3Files.validValues[idx].tableData.checked = newState.s3Files.valueMap[file.url] || false; // eslint-disable-line max-len
});

break;
Expand All @@ -611,36 +665,21 @@ var getAndValidateNewS3FilesState = function getAndValidateNewS3FilesState(previ
// just add/subtract the size of the file specified
if (action.selected) {
newState.s3Files.value.push(action.url);
newState.s3Files.valueMap[action.url] = true;
newState.s3Files.totalSize += newState.s3Files.bytesByUrl[action.url];
} else {
if (newState.s3Files.value.indexOf(action.url) === -1) {
return newState;
}
newState.s3Files.value.splice(newState.s3Files.value.indexOf(action.url), 1);
delete newState.s3Files.valueMap[action.url];
newState.s3Files.totalSize -= newState.s3Files.bytesByUrl[action.url];
}
break;
default:
return newState;
}

// If we didn't already update the total size then recalculate it
if (action.type !== 'setIndividualS3FileSelected') {
newState.s3Files.totalSize = newState.s3Files.value.map(function (id) {
return newState.s3Files.bytesByUrl[id];
}).reduce(function (a, b) {
return a + b;
}, 0);
}

// Step is only complete when there's a selection that's not too big
newState.s3Files.estimatedPostSize = estimatePostSize(newState.s3Files, newState.sites);
newState.s3Files.isValid = newState.s3Files.value.length > 0 && newState.s3Files.estimatedPostSize < _manifestUtil.MAX_POST_BODY_SIZE;
newState.requiredSteps[s3FilesIdx].isComplete = newState.s3Files.isValid;
newState.allStepsComplete = newState.requiredSteps.every(function (step) {
return step.isComplete || step.isComplete === null;
});
return newState;
return calcS3FilesSummaryState(newState, action);
};

// Generate new s3Files.validValues and s3Files filter values in state.
Expand Down Expand Up @@ -689,31 +728,29 @@ var regenerateS3FilesFiltersAndValidValues = function regenerateS3FilesFiltersAn
}).map(function (file) {
return _extends({}, file, {
tableData: {
checked: updated.s3Files.value.includes(file.url)
checked: updated.s3Files.valueMap[file.url] || false
}
});
});
// If cachedValues and validValues differ in size then rebuild valueLookups for
// filters, adjust filter selections to suit, and regenerate filtered file count.
var filterKeys = Object.keys(updated.s3Files.valueLookups || {});
if (updated.s3Files.validValues.length < updated.s3Files.cachedValues.length) {
filterKeys.forEach(function (key) {
updated.s3Files.valueLookups[key] = {};
});
updated.s3Files.validValues.forEach(function (file) {
filterKeys.forEach(function (lookup) {
if (typeof file[lookup] === 'undefined') {
return;
}
updated.s3Files.valueLookups[lookup][file[lookup]] = file[lookup] || '(none)';
});
filterKeys.forEach(function (key) {
updated.s3Files.valueLookups[key] = {};
});
updated.s3Files.validValues.forEach(function (file) {
filterKeys.forEach(function (lookup) {
if (typeof file[lookup] === 'undefined') {
return;
}
updated.s3Files.valueLookups[lookup][file[lookup]] = file[lookup] || '(none)';
});
filterKeys.forEach(function (key) {
updated.s3Files.filters[key] = updated.s3Files.filters[key].filter(function (filterVal) {
return Object.keys(updated.s3Files.valueLookups[key]).includes(filterVal);
});
});
filterKeys.forEach(function (key) {
updated.s3Files.filters[key] = updated.s3Files.filters[key].filter(function (filterVal) {
return Object.keys(updated.s3Files.valueLookups[key]).includes(filterVal);
});
}
});
updated.s3Files.filteredFileCount = getS3FilesFilteredFileCount(updated);
// Create an action to send to the reducer helper to set an updated value and revalidate.
var action = {
Expand Down Expand Up @@ -753,6 +790,38 @@ var getAndValidateNewState = function getAndValidateNewState(previousState, acti
value: action.value,
isValid: valueIsValid
});
var hasProvDataStep = newState.requiredSteps.some(function (step) {
return step.key === 'provisionalData';
});
var hasS3FilesStep = newState.requiredSteps.some(function (step) {
return step.key === 's3Files';
});
if (hasProvDataStep && hasS3FilesStep && action.key === 'provisionalData') {
if (action.value === 'exclude') {
// Go through validValues, uncheck any provisional when set to exclude
if ((0, _typeUtil.existsNonEmpty)(newState.s3Files.validValues)) {
newState.s3Files.value = [];
newState.s3Files.valueMap = {};
newState.s3Files.validValues = newState.s3Files.validValues.map(function (value) {
var isProv = _ReleaseService.default.isProv(value.release);
if (isProv) {
return _extends({}, value, {
tableData: _extends({}, value.tableData, {
checked: false
})
});
}
if (value.tableData.checked) {
newState.s3Files.value.push(value.url);
newState.s3Files.valueMap[value.url] = true;
}
return value;
});
newState = calcS3FilesSummaryState(newState, action);
}
}
newState.s3Files.filteredFileCount = getS3FilesFilteredFileCount(newState);
}
newState.requiredSteps = previousState.requiredSteps.map(function (step) {
var requiredStateKeys = ALL_STEPS[step.key] ? ALL_STEPS[step.key].requiredStateKeys : [];
return step.isComplete === null ? _extends({}, step) : _extends({}, step, {
Expand Down
4 changes: 2 additions & 2 deletions lib/components/DownloadStepForm/DownloadStepForm.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
declare function DownloadStepForm(props: any): any;
export default DownloadStepForm;
declare function DownloadStepForm(props: any): JSX.Element | null;
declare namespace DownloadStepForm {
namespace propTypes {
const stepKey: PropTypes.Validator<string>;
Expand All @@ -15,5 +16,4 @@ declare namespace DownloadStepForm {
export { renderDownloadButton_1 as renderDownloadButton };
}
}
export default DownloadStepForm;
import PropTypes from "prop-types";
Loading

0 comments on commit 78da765

Please sign in to comment.