Skip to content

Commit

Permalink
Merge pull request #438 from m2ms/stagingcandidate
Browse files Browse the repository at this point in the history
Implements #1481
  • Loading branch information
Waztom authored Jul 24, 2024
2 parents 3c60628 + 0d8aa38 commit d360a5b
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 5 deletions.
32 changes: 31 additions & 1 deletion js/components/preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ import { PickProjectModal } from './PickProjectModal';
import { withLoadingProjects } from '../target/withLoadingProjects';
import { setProjectModalOpen } from '../projects/redux/actions';
import { setOpenSnapshotSavingDialog } from '../snapshot/redux/actions';
import { setTagEditorOpen, setMoleculeForTagEdit } from '../../reducers/selection/actions';
import { setTagEditorOpen, setMoleculeForTagEdit, setToastMessages } from '../../reducers/selection/actions';
import { LoadingContext } from '../loading';
import { ToastContext } from '../toast';
import { TOAST_LEVELS } from '../toast/constants';

const ReactGridLayout = WidthProvider(ResponsiveGridLayout);

Expand Down Expand Up @@ -120,6 +122,10 @@ const Preview = memo(({ isStateLoaded, hideProjects, isSnapshot = false }) => {

const nglPortal = useMemo(() => createHtmlPortalNode({ attributes: { style: 'height: 100%' } }), []);

const { toastSuccess, toastError, toastInfo, toastWarning } = useContext(ToastContext);

const toastMessages = useSelector(state => state.selectionReducers.toastMessages);

const { setMoleculesAndTagsAreLoading } = useContext(LoadingContext);

useEffect(() => {
Expand All @@ -128,6 +134,30 @@ const Preview = memo(({ isStateLoaded, hideProjects, isSnapshot = false }) => {
}
}, [dispatch, target_on, isSnapshot, setMoleculesAndTagsAreLoading]);

useEffect(() => {
if (toastMessages?.length > 0) {
toastMessages.forEach(message => {
switch (message.level) {
case TOAST_LEVELS.SUCCESS:
toastSuccess(message.text);
break;
case TOAST_LEVELS.ERROR:
toastError(message.text);
break;
case TOAST_LEVELS.INFO:
toastInfo(message.text);
break;
case TOAST_LEVELS.WARNING:
toastWarning(message.text);
break;
default:
break;
}
});
dispatch(setToastMessages([]));
}
}, [dispatch, toastError, toastInfo, toastMessages, toastSuccess, toastWarning]);

// useEffect(() => {
// if (target_on) {
// getTags(target_on).then(data => {
Expand Down
2 changes: 1 addition & 1 deletion js/components/preview/molecule/redux/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ export const getFirstTagAlphabetically = () => (dispatch, getState) => {
const state = getState();
const tagsList = state.apiReducers.tagList;
const newTagList = tagsList.filter(t => {
if (t.additional_info?.downloadName) {
if (t.additional_info?.downloadName || t.hidden) {
return false;
} else {
return true;
Expand Down
6 changes: 6 additions & 0 deletions js/components/toast/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const TOAST_LEVELS = {
SUCCESS: 'SUCCESS',
ERROR: 'ERROR',
WARNING: 'WARNING',
INFO: 'INFO'
};
14 changes: 14 additions & 0 deletions js/reducers/selection/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,17 @@ export const setActualRhsWidth = rhsWidth => {
payload: rhsWidth
};
};

export const setToastMessages = toastMessages => {
return {
type: constants.SET_TOAST_MESSAGES,
toastMessages: toastMessages
};
};

export const addToastMessage = toastMessage => {
return {
type: constants.ADD_TOAST_MESSAGE,
toastMessage: toastMessage
};
};
5 changes: 4 additions & 1 deletion js/reducers/selection/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export const constants = {

SET_RHS_WIDTH: prefix + 'SET_RHS_WIDTH',

SET_LHS_COMPOUNDS_INITIALIZED: prefix + 'SET_LHS_COMPOUNDS_INITIALIZED'
SET_LHS_COMPOUNDS_INITIALIZED: prefix + 'SET_LHS_COMPOUNDS_INITIALIZED',

ADD_TOAST_MESSAGE: prefix + 'ADD_TOAST_MESSAGE',
SET_TOAST_MESSAGES: prefix + 'SET_TOAST_MESSAGES'
};

export const PREDEFINED_FILTERS = {
Expand Down
9 changes: 8 additions & 1 deletion js/reducers/selection/selectionReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export const INITIAL_STATE = {
observationsForLHSCmp: [],
poseIdForObservationsDialog: 0,

areLSHCompoundsInitialized: false
areLSHCompoundsInitialized: false,
toastMessages: []
};

export function selectionReducers(state = INITIAL_STATE, action = {}) {
Expand Down Expand Up @@ -481,6 +482,12 @@ export function selectionReducers(state = INITIAL_STATE, action = {}) {
case constants.SET_RHS_WIDTH:
return Object.assign({}, state, { rhsWidth: action.payload });

case constants.ADD_TOAST_MESSAGE:
return { ...state, toastMessages: [...state.toastMessages, { ...action.toastMessage }] };

case constants.SET_TOAST_MESSAGES:
return { ...state, toastMessages: [...action.toastMessages] };

// Cases like: @@redux/INIT
default:
return state;
Expand Down
10 changes: 9 additions & 1 deletion js/reducers/tracking/dispatchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
appendToMolListToEdit,
removeFromMolListToEdit,
setNextXMolecules,
setTagDetailView
setTagDetailView,
addToastMessage
} from '../selection/actions';
import {
resetReducersForRestoringActions,
Expand Down Expand Up @@ -171,6 +172,7 @@ import { turnSide } from '../../components/preview/viewerControls/redux/actions'
import { getQualityOffActions } from './utils';
import { compoundsColors } from '../../components/preview/compounds/redux/constants';
import { isEqual, uniqWith } from 'lodash';
import { TOAST_LEVELS } from '../../components/toast/constants';

export const addCurrentActionsListToSnapshot = (snapshot, project, nglViewList) => async (dispatch, getState) => {
let projectID = project && project.projectID;
Expand Down Expand Up @@ -1455,6 +1457,9 @@ export const restoreSitesActions = orderedActionList => (dispatch, getState) =>
const tag = getTag(action.object_id, state);
if (tag) {
dispatch(addSelectedTag(tag));
if (tag.hidden) {
dispatch(addToastMessage({ level: TOAST_LEVELS.WARNING, text: `Tag ${tag.tag} is selected in the snapshot but it's hidden.` }));
}
}
});
}
Expand All @@ -1470,6 +1475,9 @@ export const restoreTagActions = orderedActionList => (dispatch, getState) => {
const tag = getTag(action.object_id, state);
if (tag) {
dispatch(addSelectedTag(tag));
if (tag.hidden) {
dispatch(addToastMessage({ level: TOAST_LEVELS.WARNING, text: `Tag ${tag.tag} is selected in the snapshot but it's hidden.` }));
}
}
});
}
Expand Down

0 comments on commit d360a5b

Please sign in to comment.