Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DUOS-2014[risk=no] Updated Researcher Actions functionality to account for DarCollectionSummary #1744

Merged
merged 55 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
78cad95
Merge branch 'develop' into DUOS-1905
connorlbark Jul 25, 2022
92a91e3
update researcher console dar table + actions
connorlbark Jul 26, 2022
30bd225
naming nit
connorlbark Jul 26, 2022
2b00ec3
fix tests
connorlbark Jul 26, 2022
feb667d
Apply suggestions from code review
connorlbark Jul 26, 2022
6d527a7
Update cypress/component/DarCollectionTable/researcher_actions.spec.js
connorlbark Jul 26, 2022
abae302
merged with develop
lu-c Jul 26, 2022
207b559
fixed merge issue
lu-c Jul 26, 2022
738971b
???? Testing new actions component.
lu-c Jul 27, 2022
049cbb0
updated unit tests?
lu-c Jul 27, 2022
139bd50
Fixed eslint
lu-c Jul 27, 2022
3e57b6a
Merge branch 'DUOS-1903' of github.com:DataBiosphere/duos-ui into DUO…
lu-c Jul 27, 2022
b4ba695
Merge branch 'DUOS-1903' into DUOS-1905
connorlbark Jul 27, 2022
40ddc16
fix name
connorlbark Jul 27, 2022
b0038ac
fix admin console
connorlbark Jul 27, 2022
608715a
fix tests
connorlbark Jul 27, 2022
dd377b2
Fixing unit tests
lu-c Jul 27, 2022
18b85e0
Apply suggestions from code review
connorlbark Jul 27, 2022
9fe3206
added unit test for Update button (used to be combined with the vote …
lu-c Jul 27, 2022
b69adb8
Update cypress/component/DarCollectionTable/admin_actions.spec.js
connorlbark Jul 27, 2022
df99fb2
fix codacy
connorlbark Jul 27, 2022
6138a59
Fixed unit tests
lu-c Jul 27, 2022
b5d84dc
Fixed unit tests?
lu-c Jul 27, 2022
fc96fd7
Merge branch 'DUOS-1902' of github.com:DataBiosphere/duos-ui into DUO…
lu-c Jul 27, 2022
60fea9b
merged with DUOS-1902, deleted unnecessary files
lu-c Jul 27, 2022
7e8e79c
Merge branch 'DUOS-1905' of github.com:DataBiosphere/duos-ui into DUO…
lu-c Jul 28, 2022
3fe5316
Merged with 1905
lu-c Jul 28, 2022
aa1bbf2
Fixing unit tests?
lu-c Jul 28, 2022
e825982
Fixing eslint
lu-c Jul 28, 2022
fb8c1e1
Fixing unit test, but dont think this will sovle the problem
lu-c Jul 29, 2022
7a65a4e
Fixing unit test, but dont think this will sovle the problem
lu-c Jul 29, 2022
c5a571f
Fixing unit test, but dont think this will sovle the problem
lu-c Jul 29, 2022
857fdb8
feeling more confident now that the problem will be solved haha
lu-c Jul 29, 2022
cd89dca
DUOS-1997 updated open and close collection functions for Admin and C…
JVThomas Aug 1, 2022
d022d9d
DUOS-1997 updated integration tests for collection callback functions
JVThomas Aug 1, 2022
dc2f0e7
Updated variable names, due to merge conflict discrepancies!
lu-c Aug 1, 2022
e692549
Updated variable names, due to merge conflict discrepancies!
lu-c Aug 1, 2022
d222213
testing cypress tests on github
lu-c Aug 1, 2022
4cf9270
merged with DUOS-1903
lu-c Aug 1, 2022
e5aa265
Checking original researcher unit test. Getting mildly frustrated!
lu-c Aug 1, 2022
7871bc1
Converted hard coded researcher to console type
lu-c Aug 1, 2022
e55aeb1
fixing?
lu-c Aug 1, 2022
0f7e151
fix test
connorlbark Aug 1, 2022
635734b
removed unnecessary line
lu-c Aug 1, 2022
d997737
re-added actions (sorry connor, i deleted it)
lu-c Aug 2, 2022
fc1c330
Merge branch 'DUOS-1904-2' into DUOS-1997
JVThomas Aug 3, 2022
b96e81d
DUOS-1997 used USER_ROLES instead of explicit string values
JVThomas Aug 8, 2022
8db6702
DUOS-1997 updated spec to use USER_ROLES instead of hard coded strings
JVThomas Aug 8, 2022
9d834bd
DUOS-1997 resolved merge conflicts
JVThomas Aug 10, 2022
5eb5e35
DUOS-2014 fixed missing forEach immport from lodash, updated actions …
JVThomas Aug 10, 2022
6108db9
DUOS-2014 adjusted tooltip on cancel action, removed unused function,…
JVThomas Aug 10, 2022
03bad5a
DUOS-2014 resolved merge conflicts
JVThomas Aug 10, 2022
85008d0
DUOS-2014 updated iterating function on applyHoverEffects to match no…
JVThomas Aug 10, 2022
fe13e7a
DUOS-2014 updated getProjectTitle helper method, updated style update…
JVThomas Aug 10, 2022
de0ce7a
DUOS-2014 removed getProjectTitle, inlined collection name in string
JVThomas Aug 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/components/dar_collection_table/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const resumeDARApplication = (referenceId, history) => {
export default function Actions(props) {
const { showConfirmationModal, collection, goToVote, consoleType, actions = [] } = props;
const collectionId = collection.darCollectionId;

const uniqueId = (collectionId ? collectionId : collection.referenceIds[0]);

const history = useHistory();
Expand Down Expand Up @@ -72,7 +71,7 @@ export default function Actions(props) {
onClick: () => showConfirmationModal(collection, 'cancel'),
style: baseCancelButtonStyle,
hoverStyle: hoverCancelButtonStyle,
dataTip: 'Cancel Elections',
dataTip: `Cancel ${consoleType === 'researcher' ? 'Collection' : 'Elections'}`,
icon: Block,
};

Expand Down
2 changes: 1 addition & 1 deletion src/libs/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const Collections = {
return res.data;
},
getCollectionSummaryByRoleNameAndId: async({roleName, id}) => {
const url = `${await Config.getApiUrl()}/api/collections/role/${roleName}/summary/${id}`;
const url = `${await getApiUrl()}/api/collections/role/${roleName}/summary/${id}`;
const res = await axios.get(url, Config.authOpts());
return res.data;
},
Expand Down
4 changes: 2 additions & 2 deletions src/libs/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Noty from 'noty';
import 'noty/lib/noty.css';
import 'noty/lib/themes/bootstrap-v3.css';
import {map as nonFPMap} from 'lodash';
import {map as nonFPMap, forEach as nonFPForEach} from 'lodash';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you feel okay with leaving these as the original names? It seems less confusing that way

Copy link
Contributor Author

@JVThomas JVThomas Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's two forEach's being used in this file, one from 'lodash/fp' and one from 'lodash'. The reason being is that with the fp version, the function is forEach(collection, (value) => //code here) where as in the regular version its forEach(value, key) => //insert code here)(collection).

As for why we need two versions, remember the error Shae pointed out here: #1718 (review)

It's being caused by this function in utils.js

export const applyHoverEffects = (e, style) => { nonFPForEach((key, value) => { e.target.style[key] = value; })(style); };

What had happened was that the normal forEach that was used here was replaced with the fp variant. The difference in the iterating function causes the function to error out.

So in short, we need both functions, but they can't be named the same variable, hence the nonFPForEach.

That said, I still need to update the iterating function to match the non-fp version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! Didnt realize it was because both lodash and lodash/fp were beign used.... That being said, I still think the name is confusing (just because it wasn't immediately obvious to me what it was "nonFP" was supposed to mean. Don't know what to do about that though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it could be lodashForEach and lodashFpForEach ? that way they mirror each other

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way to solve this is to import a prefix for either the non-fp or the fp version. In the past, I've used import _ from 'lodash'; and import * as fp from 'lodash/fp';, for example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but that would cause Webpack to import the entire lodash library on file bundling, and lodash is a pretty big library. Even if the code is minified, I'd rather not import methods that are never used for a particular file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it could be lodashForEach and lodashFpForEach ? that way they mirror each other

That works for me

import { DAR, DataSet } from './ajax';
import {Theme, Styles } from './theme';
import { each, flatMap, flatten, flow, forEach, get, getOr, indexOf, uniq, values, find, first, map, isEmpty, filter, cloneDeep, isNil, toLower, includes, every, capitalize } from 'lodash/fp';
Expand Down Expand Up @@ -110,7 +110,7 @@ export const getPropertyValuesFromUser = (user) => {
};

export const applyHoverEffects = (e, style) => {
forEach((key, value) => {
nonFPForEach((key, value) => {
e.target.style[key] = value;
})(style);
};
Expand Down
33 changes: 6 additions & 27 deletions src/pages/ResearcherConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,10 @@ import { Styles } from '../libs/theme';
import { Collections, DAR } from '../libs/ajax';
import { DarCollectionTableColumnOptions, DarCollectionTable } from '../components/dar_collection_table/DarCollectionTable';
import accessIcon from '../images/icon_access.png';
import {Notifications, searchOnFilteredList, getSearchFilterFunctions, formatDate} from '../libs/utils';
import {Notifications, searchOnFilteredList, getSearchFilterFunctions } from '../libs/utils';
import SearchBar from '../components/SearchBar';
import { consoleTypes } from '../components/dar_table/DarTableActions';

const formatDraft = (draft) => {
const { data, referenceId, id, createDate } = draft;
const {
projectTitle,
datasets,
institution,
} = data;
const darCode = 'DRAFT_DAR_' + formatDate(createDate);

const output = {
darCode,
referenceId,
darCollectionId: id,
projectTitle,
isDraft: true,
createDate: 'Unsubmitted',
datasets,
institution,
};
return output;
};
import { USER_ROLES } from '../libs/utils';

const filterFn = getSearchFilterFunctions().darCollections;

Expand Down Expand Up @@ -73,14 +52,15 @@ export default function ResearcherConsole() {
const cancelCollection = async (darCollection) => {
try {
const { darCollectionId, darCode } = darCollection;
const canceledCollection = await Collections.cancelCollection(darCollectionId);
await Collections.cancelCollection(darCollectionId);
const updatedCollection = await Collections.getCollectionSummaryByRoleNameAndId({roleName: USER_ROLES.researcher, id: darCollectionId});
const targetIndex = researcherCollections.findIndex((collection) =>
collection.darCollectionId === darCollectionId);
if (targetIndex < 0) {
throw new Error('Error: Could not find target Data Access Request');
}
const clonedCollections = cloneDeep(researcherCollections);
clonedCollections[targetIndex] = canceledCollection;
clonedCollections[targetIndex] = updatedCollection;
setResearcherCollections(clonedCollections);
Notifications.showSuccess({text: `Deleted Data Access Request ${darCode}`});
} catch (error) {
Expand All @@ -102,7 +82,7 @@ export default function ResearcherConsole() {
}
//remove resubmitted collection from DAR Collection table
const clonedCollections = cloneDeep(researcherCollections);
clonedCollections[targetIndex] = formatDraft(draftCollection);
clonedCollections[targetIndex] = draftCollection;
setResearcherCollections(clonedCollections);
Notifications.showSuccess({text: `Revising Data Access Request ${darCode}`});
} catch (error) {
Expand Down Expand Up @@ -132,7 +112,6 @@ export default function ResearcherConsole() {
const deleteDraft = async ({ referenceIds, darCode }) => {
try {
const targetIndex = deleteDraftById({ referenceId: referenceIds[0] });

if (targetIndex === -1) {
Notifications.showError({ text: 'Error processing delete request' });
} else {
Expand Down