Skip to content

Commit 757017e

Browse files
authored
Merge pull request #215 from MetaCell/feature/vfb-203_2
#VFB-226 - Enhance query validation and improve query handling in fro…
2 parents e41355d + 0fa559d commit 757017e

3 files changed

Lines changed: 20 additions & 51 deletions

File tree

applications/virtual-fly-brain/frontend/src/components/TermInfo.jsx

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,6 @@ const TermInfo = ({ open, setOpen }) => {
256256
const queryComponentOpened = useSelector(
257257
(state) => state.globalInfo.queryComponentOpened
258258
);
259-
const currentTemplate = useSelector(
260-
(state) => state.instances.launchTemplate
261-
);
262259

263260
const [termInfoData, setTermInfoData] = useState(data);
264261
const [toggleReadMore, setToggleReadMore] = useState(false);
@@ -534,40 +531,6 @@ const TermInfo = ({ open, setOpen }) => {
534531
];
535532
};
536533

537-
const handleLinkClick = (href, event) => {
538-
event.preventDefault();
539-
540-
const idsArray = href.split(',');
541-
const templateId = idsArray[idsArray.length - 1];
542-
const currentTemplateId = currentTemplate?.metadata?.Id;
543-
544-
let isAlignedTemplate = false;
545-
if (data?.metadata?.Examples && typeof data?.metadata?.Examples === 'object' && Object.keys(data?.metadata?.Examples).length > 0) {
546-
isAlignedTemplate = !!(data.metadata.Examples[currentTemplateId] && data.metadata.Examples[currentTemplateId].find(e => e.id === templateId));
547-
} else if (data?.metadata?.Images && Array.isArray(data?.metadata?.Images) && data?.metadata?.Images.length > 0) {
548-
isAlignedTemplate = !!(data.metadata.Images[currentTemplateId] && data.metadata.Images[currentTemplateId].find(e => e.id === templateId));
549-
}
550-
551-
if (href.startsWith("http")) {
552-
window.open(href, "_blank", "noopener,noreferrer");
553-
} else {
554-
if (isAlignedTemplate) {
555-
getInstanceByID(
556-
templateId,
557-
true,
558-
true,
559-
true
560-
);
561-
} else {
562-
setConfirmationModal({
563-
open: true,
564-
id: templateId,
565-
message: "The image you requested is aligned to another template. Click Load Template to open it in a new tab or Cancel to just view the image metadata."
566-
});
567-
}
568-
}
569-
};
570-
571534
const queryGroups = useMemo(() => [
572535
{ label: "Types of neurons with...", keys: ["Find neurons", "Find all", "Neurons with"] },
573536
{ label: "Individual neurons with ", keys: ["Images of neurons with"] },
@@ -630,15 +593,16 @@ const TermInfo = ({ open, setOpen }) => {
630593
return (
631594
<ReactMarkdown
632595
components={{
596+
// eslint-disable-next-line no-unused-vars
633597
a: ({ href, children, ...props }) => (
634598
<span
635599
style={{
636600
fontSize: '0.875rem',
637601
":hover": {
638602
color: tabActiveColor,
639-
cursor: 'pointer',
603+
cursor: 'default',
640604
}}}
641-
onClick={e => handleLinkClick(href, e)}
605+
// onClick={e => handleLinkClick(href, e)}
642606
{...props}
643607
>
644608
{children}
@@ -648,7 +612,7 @@ const TermInfo = ({ open, setOpen }) => {
648612
img: ({node, ...props}) => (
649613
<img
650614
{...props}
651-
style={{ maxWidth: 180, maxHeight: 90, width: 'auto', height: 'auto' }}
615+
style={{ maxWidth: 180, maxHeight: 90, width: 'auto', height: 'auto', cursor: 'default' }}
652616
alt={props.alt}
653617
/>
654618
),
@@ -1195,7 +1159,7 @@ const TermInfo = ({ open, setOpen }) => {
11951159
return ( <TableRow key={row.id + '-' + rowIdx}>
11961160
{headers.slice(0, -1).map((h) =>
11971161
(
1198-
<TableCell key={h.key}>
1162+
<TableCell key={h.key} style={{ cursor: 'default' }}>
11991163
{renderCellContent(h.type, row[h.key])}
12001164
</TableCell>
12011165
)
@@ -1425,7 +1389,7 @@ const TermInfo = ({ open, setOpen }) => {
14251389
return ( <TableRow key={row.id + '-' + rowIdx}>
14261390
{headers.slice(0, -1).map((h) =>
14271391
(
1428-
<TableCell key={h.key}>
1392+
<TableCell key={h.key} style={{ cursor: 'default' }}>
14291393
{renderCellContent(h.type, row[h.key])}
14301394
</TableCell>
14311395
)

applications/virtual-fly-brain/frontend/src/reducers/middleware/urlUpdaterMiddleware.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getInstancesTypes } from '../actions/types/getInstancesTypes';
55
import { setFirstIDLoaded, setAlignTemplates, setTemplateID } from '../actions/globals';
66
import { getInstanceByID, get3DMesh, triggerInstanceFailure, setBulkLoadingCount, clearUrlLoadingState, focusInstance, selectInstance } from '../actions/instances';
77
import * as GeppettoActions from '@metacell/geppetto-meta-client/common/actions';
8+
import { DEFAULT_TEMPLATE_ID } from '../../utils/constants';
89

910
function updateUrlParameterWithCurrentUrl(param, value, reset) {
1011
const urlObj = new URL(window.location.href);
@@ -54,7 +55,7 @@ function updateUrlWithInstancesAndSelectedId(selectedId, store) {
5455
}
5556
}
5657

57-
const DEFAULT_ID = "VFB_00101567";
58+
const DEFAULT_ID = DEFAULT_TEMPLATE_ID;
5859
const APP_LOADED_FLAG_KEY = "CURRENT_LOADED_URL";
5960

6061
// Track the initial focus ID from URL to prevent templates from overwriting it
@@ -95,8 +96,8 @@ const isFirstTimeLoad = (allLoadedInstances, store) => {
9596
}
9697

9798
// id= parameter should always take priority for focus
98-
const focusTarget = idSelected ||
99-
(queuedInstances.length > 0
99+
const focusTarget = idSelected ||
100+
(queuedInstances.length > 0
100101
? queuedInstances[queuedInstances.length - 1]
101102
: uniqueLoadOrder[uniqueLoadOrder.length - 1]);
102103

@@ -150,9 +151,14 @@ export const urlUpdaterMiddleware = store => next => (action) => {
150151
const state = store.getState().instances;
151152
const newFinishedCount = state.finishedLoadedInstances + 1;
152153
const isAllBulkInstancesLoaded = state.isBulkLoading && newFinishedCount >= state.bulkLoadingCount;
153-
154+
154155
// If bulk loading completed from URL, apply focus/select and clear the flag
155156
if (isAllBulkInstancesLoaded && isLoadingFromUrl) {
157+
if (!launchTemplate?.metadata?.Id && !action.payload?.IsTemplate) {
158+
getInstanceByID(DEFAULT_TEMPLATE_ID, true, false, false);
159+
updateUrlParameterWithCurrentUrl('i', DEFAULT_TEMPLATE_ID, false);
160+
}
161+
156162
const urlParams = new URLSearchParams(window.location.search);
157163
const pendingFocusId = urlParams.get('id');
158164

@@ -166,7 +172,7 @@ export const urlUpdaterMiddleware = store => next => (action) => {
166172
await focusInstance(pendingFocusId);
167173
await selectInstance(pendingFocusId);
168174
// Clear URL loading state after async operations complete
169-
store.dispatch(clearUrlLoadingState());
175+
store.dispatch(clearUrlLoadingState());
170176
// Clear the initial focus ID after a longer delay to allow all pending template operations to complete
171177
setTimeout(() => {
172178
initialUrlFocusId = null;
@@ -176,13 +182,11 @@ export const urlUpdaterMiddleware = store => next => (action) => {
176182
store.dispatch(clearUrlLoadingState());
177183
}
178184
}
179-
185+
180186
const IsTemplate = action.payload?.IsTemplate || false;
181187
const isClass = action.payload?.IsClass || false;
182188
const isIndividual = action.payload?.IsIndividual || false;
183189

184-
185-
186190
if (!IsTemplate && !isClass && !isIndividual) {
187191
// If the instance is not a template, class, or individual, dispatch the getInstanceFailure with an error message
188192
if (action.payload?.Id === undefined) {
@@ -202,7 +206,7 @@ export const urlUpdaterMiddleware = store => next => (action) => {
202206
}
203207
get3DMesh(action.payload);
204208
store.dispatch(setTemplateID(action.payload.Id));
205-
209+
206210
if (!(initialUrlFocusId && initialUrlFocusId !== action.payload.Id)) {
207211
updateUrlWithInstancesAndSelectedId(action.payload.Id, store);
208212
}

applications/virtual-fly-brain/frontend/src/utils/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const SELECTED_COLOR = { r: 0.8, g: 0.8, b: 0, a: 1 }
22
export const DESELECTED_COLOR = { r: .2, g: .8, b: 1, a: .3 }
33
export const TEMPLATE_COLOR = { r: .8, g: .8, b: .8, a: .4 }
4+
export const DEFAULT_TEMPLATE_ID = "VFB_00101567";
45
export const SKELETON = "skeleton";
56
export const CYLINDERS = "sphere";
67
export const NEURON = "Neuron"

0 commit comments

Comments
 (0)