Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mariia-aloshyna committed Nov 6, 2023
1 parent bb91a77 commit 7c70b34
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/ViewInstanceWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ const ViewInstanceWrapper = (props) => {
const userId = stripes?.user?.user?.id;
const centralTenantId = stripes.user.user?.consortium?.centralTenantId;
const consortiumId = stripes.user.user?.consortium?.id;
const { instance, isLoading, refetch, isError, error } = useInstance(id);
const {
instance,
isLoading,
refetch,
isError,
error,
} = useInstance(id);

const isShared = Boolean(instance?.shared);
const tenantId = instance?.tenantId ?? stripes.okapi.tenant;
Expand Down
12 changes: 10 additions & 2 deletions src/common/hooks/useInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ import useSearchInstanceByIdQuery from './useSearchInstanceByIdQuery';
import useInstanceQuery from './useInstanceQuery';

const useInstance = (id) => {
const { isLoading: isSearchInstanceByIdLoading, instance: _instance } = useSearchInstanceByIdQuery(id);
const {
isLoading: isSearchInstanceByIdLoading,
instance: _instance,
} = useSearchInstanceByIdQuery(id);

const instanceTenantId = _instance?.tenantId;
const isShared = _instance?.shared;

const { isLoading: isInstanceLoading, instance: data, refetch, ...rest } = useInstanceQuery(
const {
isLoading: isInstanceLoading,
instance: data,
refetch,
...rest
} = useInstanceQuery(
id,
{ tenantId: instanceTenantId },
{ enabled: Boolean(id && !isSearchInstanceByIdLoading) }
Expand Down
7 changes: 6 additions & 1 deletion src/common/hooks/useInstanceQuery/useInstanceQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ const useInstanceQuery = (instanceId, { tenantId = '' } = {}, options = {}) => {
const ky = useTenantKy({ tenantId });
const [namespace] = useNamespace({ key: 'instance' });

const { isLoading, data: instance = {}, refetch, ...rest } = useQuery(
const {
isLoading,
data: instance = {},
refetch,
...rest
} = useQuery(
[namespace, instanceId, tenantId],
() => ky.get(`inventory/instances/${instanceId}`).json(),
{
Expand Down

0 comments on commit 7c70b34

Please sign in to comment.