Skip to content

Commit

Permalink
Merge branch 'bugfix/ZKUI-359' into tmp/octopus/w/2.0/bugfix/ZKUI-359
Browse files Browse the repository at this point in the history
  • Loading branch information
bert-e committed Jun 5, 2023
2 parents 6d2815d + e13cb7a commit 55452f0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ export class MockedAccountsLocationsAdapter
canonicalId: 'canonical-id-renard-with-out-location',
creationDate: DEFAULT_METRICS_MESURED_ON,
},
{
id: 'account-with-own-metrics',
name: 'Souris',
canonicalId: 'canonical-id-souris-diff-metrics',
creationDate: DEFAULT_METRICS_MESURED_ON,
},
];
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export const DEFAULT_METRICS: LatestUsedCapacity = {
measuredOn: DEFAULT_METRICS_MESURED_ON,
};

export const ACCOUNT_OWN_METRICS: LatestUsedCapacity = {
measuredOn: DEFAULT_METRICS_MESURED_ON,
type: 'hasMetrics',
usedCapacity: {
current: 135000,
nonCurrent: 0,
},
};

export class MockedMetricsAdapter implements IMetricsAdapter {
listBucketsLatestUsedCapacity = jest.fn();

Expand Down Expand Up @@ -49,6 +58,13 @@ export class MockedMetricsAdapter implements IMetricsAdapter {
'orphan-location': DEFAULT_METRICS,
};
}

if (accountCanonicalId === 'canonical-id-souris-diff-metrics') {
return {
'artesca-s3-location': ACCOUNT_OWN_METRICS,
};
}

return {};
}

Expand Down
16 changes: 15 additions & 1 deletion src/react/next-architecture/domain/business/locations.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { renderHook } from '@testing-library/react-hooks';
import { MockedAccountsLocationsAdapter } from '../../adapters/accounts-locations/MockedAccountsLocationsAdapter';
import {
ACCOUNT_OWN_METRICS,
DEFAULT_METRICS,
DEFAULT_METRICS_MESURED_ON,
MockedMetricsAdapter,
Expand All @@ -17,6 +18,7 @@ import { QueryClient, QueryClientProvider } from 'react-query';
import { PropsWithChildren } from 'react';
import * as DSRProvider from '../../../DataServiceRoleProvider';
import { LocationTypeKey } from '../../../../types/config';
import { UsedCapacity } from '../../ui/metrics/LatestUsedCapacity';

const defaultUsedCapacity = {
status: 'success' as const,
Expand Down Expand Up @@ -252,6 +254,15 @@ describe('useListLocationsForCurrentAccount', () => {
});

it('should return only location for current account', async () => {
jest.spyOn(DSRProvider, 'useCurrentAccount').mockReturnValue({
account: {
id: 'account-with-own-metrics',
Name: 'Souris',
Roles: [],
CreationDate: DEFAULT_METRICS_MESURED_ON,
},
});

// S
const { result, waitFor } = setupAndRenderHook();

Expand All @@ -275,7 +286,10 @@ describe('useListLocationsForCurrentAccount', () => {
endpoint: 'https://s3.scality.com',
region: 'us-east-1',
},
defaultUsedCapacity,
{
status: 'success',
value: ACCOUNT_OWN_METRICS,
},
),
},
},
Expand Down
15 changes: 12 additions & 3 deletions src/react/next-architecture/domain/business/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,18 @@ export const useListLocationsForCurrentAccount = ({
const allLocationsValue = Object.values(allLocations.locations.value);
const locations: Record<string, Location> = {};
accountLocationsKey.forEach((locationId) => {
const accountLocation = allLocationsValue.find((l) => l.id === locationId);
if (accountLocation) {
locations[locationId] = accountLocation;
const locationDefinition = allLocationsValue.find(
(l) => l.id === locationId,
);

if (locationDefinition) {
locations[locationId] = {
...locationDefinition,
usedCapacity: {
status: 'success',
value: accountLocationData[locationId],
},
};
}
});

Expand Down
1 change: 0 additions & 1 deletion src/react/workflow/Workflows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export function useWorkflowsWithSelect<T>(
const rolePathName = useRolePathName();
const dispatch = useDispatch();

console.log('acccount', account);
const workflowsQuery = useQuery({
...workflowListQuery(
notFalsyTypeGuard(mgnt),
Expand Down

0 comments on commit 55452f0

Please sign in to comment.