Skip to content

Commit 97b2e91

Browse files
authored
re-add the context to circuit queries (#1010)
1 parent b4720d7 commit 97b2e91

File tree

5 files changed

+24
-32
lines changed

5 files changed

+24
-32
lines changed

src/entity-configuration/domain/model/circuit.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { includes } from 'es-toolkit/compat';
1+
import { includes, without } from 'es-toolkit/compat';
22

33
import { ExtendedEntitiesTypeDict } from '@/api/entitycore/types/extended-entity-type';
44
import { DetailViewSectionsDict } from '@/entity-configuration/definitions/types';
@@ -25,8 +25,15 @@ export const Circuit: EntityCoreTypeConfig<ICircuit> = {
2525
list: (...params) => {
2626
return getCircuits({
2727
...params,
28+
context: params[0].context,
2829
withFacets: params[0].withFacets,
29-
filters: { ...params[0].filters },
30+
filters: {
31+
...params[0].filters,
32+
scale__in: without(
33+
Object.values(CircuitScaleDictionary),
34+
CircuitScaleDictionary.Single
35+
),
36+
},
3037
});
3138
},
3239
one: getCircuit,

src/entity-configuration/domain/model/me-model-with-synapses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const MEModelWithSynapsesCircuit: EntityCoreTypeConfig<ICircuit> = {
2222
list: (...params) => {
2323
return getCircuits({
2424
...params,
25+
context: params[0].context,
2526
withFacets: params[0].withFacets,
2627
filters: { ...params[0].filters, scale__in: [CircuitScaleDictionary.Single] },
2728
});

src/ui/segments/explore/circuit/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type Props = {
6464
dataType: TExtendedEntitiesTypeDict;
6565
mainTableProps?: Partial<ComponentProps<typeof CircuitTable>>;
6666
miniViewProps?: Partial<ComponentProps<typeof MiniDetailView>>;
67+
extraQueryParams?: Record<string, any>;
6768
};
6869

6970
export function BrowseCircuit({
@@ -76,6 +77,7 @@ export function BrowseCircuit({
7677
scope: defaultScope,
7778
mainTableProps,
7879
miniViewProps,
80+
extraQueryParams,
7981
}: Props) {
8082
const { virtualLabId, projectId } = useWorkspace();
8183
const { mdv, setMdv } = useMiniDetailView();
@@ -140,7 +142,7 @@ export function BrowseCircuit({
140142
const [{ workspace, queryParameters }] = queryKey;
141143
return await Circuit.api.query.list?.({
142144
withFacets: true,
143-
filters: { ...queryParameters },
145+
filters: { ...queryParameters, ...extraQueryParams },
144146
context: workspace,
145147
});
146148
},

src/ui/segments/explore/entity-link-count.tsx

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
import { useQueries, useQuery } from '@tanstack/react-query';
1+
import { kebabCase, isNil, get } from 'es-toolkit/compat';
2+
import { useQueries } from '@tanstack/react-query';
23
import { useSearchParams } from 'next/navigation';
3-
import { useSession } from 'next-auth/react';
44
import { useAtomValue } from 'jotai';
55
import { unwrap } from 'jotai/utils';
66
import { match } from 'ts-pattern';
77
import { useMemo } from 'react';
88

9-
import kebabCase from 'es-toolkit/compat/kebabCase';
10-
import isNil from 'es-toolkit/compat/isNil';
11-
import get from 'es-toolkit/compat/get';
12-
139
import { PillTabs, PillTabsList, PillTabsTrigger } from '@/ui/molecules/tabs';
14-
import { getPersons } from '@/api/entitycore/queries/general/person-agent';
15-
import { keyBuilder as userKeyBuilder } from '@/ui/use-query-keys/user';
1610
import { useDefaultBreakpoint } from '@/ui/hooks/create-break-point';
1711
import { BrowseLink } from '@/ui/segments/explore/browse-link';
18-
import { ROOT_ROUTE } from '@/config';
1912
import { useTabs } from '@/components/detail-view-tabs';
2013
import { useWorkspace } from '@/ui/hooks/use-workspace';
2114
import { keyBuilder } from '@/ui/use-query-keys/data';
@@ -32,6 +25,7 @@ import {
3225
getAllEntitiesCountScoped,
3326
} from '@/ui/segments/explore/helpers';
3427
import { cn } from '@/utils/css-class';
28+
import { ROOT_ROUTE } from '@/config';
3529

3630
import { type TWorkspaceScope } from '@/constants';
3731

@@ -66,7 +60,6 @@ export const tabsConfigItems: Array<{
6660

6761
export function EntityLinkCount() {
6862
const breakpoint = useDefaultBreakpoint();
69-
const session = useSession();
7063
const scope = (useSearchParams().get('scope') ?? WorkspaceScope.Public) as TWorkspaceScope;
7164

7265
const { virtualLabId, projectId } = useWorkspace();
@@ -81,19 +74,11 @@ export function EntityLinkCount() {
8174
shallow: true,
8275
});
8376

84-
const { data: personId } = useQuery({
85-
queryKey: userKeyBuilder.person({ userId: session.data?.user.id }),
86-
queryFn: () => getPersons({ filters: { sub_id: session.data?.user.id } }),
87-
enabled: Boolean(session.data?.user.id),
88-
select: (data) => data?.data.at(0)?.id,
89-
});
90-
9177
const params = {
9278
virtualLabId,
9379
projectId,
9480
brainRegionId: selectedBrainRegion?.id!,
9581
scope,
96-
personId,
9782
};
9883

9984
const [
@@ -113,7 +98,7 @@ export function EntityLinkCount() {
11398
getSimulationsCount({
11499
...params,
115100
}),
116-
enabled: Boolean(selectedBrainRegion?.id) && Boolean(personId),
101+
enabled: Boolean(selectedBrainRegion?.id),
117102
},
118103
{
119104
queryKey: keyBuilder.dataCount({ ...params, brainRegionId: brainRegionHierarchy?.root.id }),
@@ -168,9 +153,9 @@ export function EntityLinkCount() {
168153
type={value.extendedType}
169154
title={value.title}
170155
count={
171-
<span>
156+
<span className="flex items-center justify-center gap-1">
172157
<span className="font-bold">{count}</span> <span className="font-light">of</span>
173-
<span className="font-bold"> {rootCount}</span>
158+
<span className="font-bold">{rootCount}</span>
174159
</span>
175160
}
176161
isLoading={value.isLoading || isNil(count) || isNil(rootCount)}
@@ -193,7 +178,7 @@ export function EntityLinkCount() {
193178
type={value.extendedType}
194179
title={value.title}
195180
count={
196-
<span>
181+
<span className="flex items-center justify-center gap-1">
197182
<span className="font-bold">{count}</span> <span className="font-light">of</span>
198183
<span className="font-bold">{rootCount}</span>
199184
</span>
@@ -217,7 +202,7 @@ export function EntityLinkCount() {
217202
href={link}
218203
type={value.extendedType}
219204
title={value.title}
220-
count={count ? `${count}` : 0}
205+
count={<span className="font-bold">{count}</span>}
221206
isLoading={value.isLoading || isNil(count)}
222207
isUploadable={value.isUploadable}
223208
/>

src/ui/segments/explore/helpers.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export async function getAllEntitiesCountScoped({
113113
...(scope === WorkspaceScope.Project
114114
? {
115115
authorized_project_id: projectId,
116+
authorized_public: false,
116117
}
117118
: scope === WorkspaceScope.Public
118119
? {
@@ -135,11 +136,9 @@ export async function getSimulationsCount({
135136
virtualLabId,
136137
projectId,
137138
brainRegionId,
138-
personId,
139139
scope,
140140
}: WorkspaceContext & {
141141
brainRegionId: string;
142-
personId: string | undefined;
143142
scope: TWorkspaceScope;
144143
}) {
145144
const promises = Object.fromEntries(
@@ -161,7 +160,7 @@ export async function getSimulationsCount({
161160
...(scope === WorkspaceScope.Project
162161
? {
163162
authorized_project_id: projectId,
164-
created_by__id: personId,
163+
authorized_public: false,
165164
}
166165
: scope === WorkspaceScope.Public
167166
? {
@@ -189,11 +188,9 @@ export function getElectricalCellRecordingsCount({
189188
virtualLabId,
190189
projectId,
191190
brainRegionId,
192-
personId,
193191
scope,
194192
}: WorkspaceContext & {
195193
brainRegionId: string;
196-
personId: string | undefined;
197194
scope: TWorkspaceScope;
198195
}) {
199196
return getElectricalCellRecordings({
@@ -209,7 +206,7 @@ export function getElectricalCellRecordingsCount({
209206
...(scope === WorkspaceScope.Project
210207
? {
211208
authorized_project_id: projectId,
212-
created_by__id: personId,
209+
authorized_public: false,
213210
}
214211
: scope === WorkspaceScope.Public
215212
? {

0 commit comments

Comments
 (0)