Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ui): all app locks from locks page are now accessing the all app locks endpoint #2181

Merged
merged 12 commits into from
Jan 6, 2025
4 changes: 4 additions & 0 deletions services/frontend-service/src/ui/App/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Spy.mockModule('../utils/AzureAuthProvider', 'AzureAuthProvider');

const mock_GetConfig = Spy('Config');
const mock_StreamOverview = Spy('Overview');
const mock_GetAllAppLocks = Spy('AllAppLocks');
const mock_StreamStatus = Spy('Status');

jest.mock('../utils/GrpcApi', () => ({
Expand All @@ -41,6 +42,7 @@ jest.mock('../utils/GrpcApi', () => ({
}),
overviewService: () => ({
StreamOverview: () => mock_StreamOverview(),
GetAllAppLocks: () => mock_GetAllAppLocks(),
}),
rolloutService: () => ({
StreamStatus: () => mock_StreamStatus(),
Expand Down Expand Up @@ -73,6 +75,7 @@ describe('App uses the API', () => {
observer.next({ applications: 'test-application' });
})
);
mock_GetAllAppLocks.returns(Promise.resolve('test'));
mock_GetConfig.returns(Promise.resolve('test-config'));
AzureAuthSub.set({ authReady: true });
mock_StreamStatus.returns(
Expand Down Expand Up @@ -102,6 +105,7 @@ describe('App uses the API', () => {
observer.next({});
})
);
mock_GetAllAppLocks.returns(Promise.resolve('test'));
mock_GetConfig.returns(Promise.resolve('test-config'));
AzureAuthSub.set({ authReady: true });

Expand Down
10 changes: 10 additions & 0 deletions services/frontend-service/src/ui/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
FlushRolloutStatus,
PanicOverview,
showSnackbarWarn,
UpdateAllApplicationLocks,
updateAppDetails,
UpdateFrontendConfig,
UpdateOverview,
Expand Down Expand Up @@ -116,6 +117,15 @@ export const App: React.FC = () => {
}
});
updateAppDetails.set(details);
// Get App Locks
api.overviewService()
.GetAllAppLocks({}, authHeader)
.then((res) => {
UpdateAllApplicationLocks.set(res.allAppLocks);
})
.catch((e) => {
PanicOverview.set({ error: JSON.stringify({ msg: 'error in GetAllAppLocks', e }) });
});
},
(error) => {
PanicOverview.set({ error: JSON.stringify({ msg: 'error in streamoverview', error }) });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import { render, renderHook } from '@testing-library/react';
import { LocksPage } from './LocksPage';
import {
DisplayLock,
UpdateAllApplicationLocks,
UpdateOverview,
useAllLocks,
useEnvironmentLock,
useFilteredEnvironmentLockIDs,
} from '../../utils/store';
import { MemoryRouter } from 'react-router-dom';
import { Environment, OverviewApplication, Priority } from '../../../api/api';
import { AllAppLocks, Environment, OverviewApplication, Priority } from '../../../api/api';
import { fakeLoadEverything, enableDexAuth } from '../../../setupTests';

describe('LocksPage', () => {
Expand Down Expand Up @@ -332,6 +333,9 @@ describe('Test app locks', () => {
name: string;
envs: Environment[];
OverviewApps: OverviewApplication[];
AppLocks: {
[key: string]: AllAppLocks;
};
sortOrder: 'oldestToNewest' | 'newestToOldest';
expectedLockIDs: string[];
}
Expand All @@ -343,6 +347,7 @@ describe('Test app locks', () => {
OverviewApps: [],
sortOrder: 'oldestToNewest',
expectedLockIDs: [],
AppLocks: {},
},
{
name: 'get one lock',
Expand All @@ -366,6 +371,15 @@ describe('Test app locks', () => {
priority: 0,
},
],
AppLocks: {
integration: {
appLocks: {
foo: {
locks: [{ message: 'locktest', lockId: 'ui-v2-1337' }],
},
},
},
},
sortOrder: 'oldestToNewest',
expectedLockIDs: ['ui-v2-1337'],
},
Expand Down Expand Up @@ -407,6 +421,31 @@ describe('Test app locks', () => {
priority: 0,
},
],
AppLocks: {
integration: {
appLocks: {
foo: {
locks: [
{
message: 'locktest',
lockId: 'ui-v2-1337',
createdAt: new Date(1995, 11, 17),
},
{
message: 'lockfoo',
lockId: 'ui-v2-123',
createdAt: new Date(1995, 11, 16),
},
{
message: 'lockbar',
lockId: 'ui-v2-321',
createdAt: new Date(1995, 11, 15),
},
],
},
},
},
},
sortOrder: 'newestToOldest',
expectedLockIDs: ['ui-v2-1337', 'ui-v2-123', 'ui-v2-321'],
},
Expand Down Expand Up @@ -460,6 +499,35 @@ describe('Test app locks', () => {
priority: 0,
},
],
AppLocks: {
integration: {
appLocks: {
foo: {
locks: [
{
message: 'lockbar',
lockId: 'ui-v2-321',
createdAt: new Date(1995, 11, 15),
},
],
},
bar: {
locks: [
{
message: 'lockfoo',
lockId: 'ui-v2-123',
createdAt: new Date(1995, 11, 16),
},
{
message: 'locktest',
lockId: 'ui-v2-1337',
createdAt: new Date(1995, 11, 17),
},
],
},
},
},
},
sortOrder: 'oldestToNewest',
expectedLockIDs: ['ui-v2-321', 'ui-v2-123', 'ui-v2-1337'],
},
Expand All @@ -480,6 +548,7 @@ describe('Test app locks', () => {
},
],
});
UpdateAllApplicationLocks.set(testcase.AppLocks);

// when
const obtained = renderHook(() => useAllLocks().appLocks).result.current;
Expand Down
56 changes: 28 additions & 28 deletions services/frontend-service/src/ui/Pages/Locks/LocksPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ Copyright freiheit.com*/
import React, { useMemo } from 'react';
import { LocksTable } from '../../components/LocksTable/LocksTable';
import {
DisplayLock,
searchCustomFilter,
sortLocks,
useAllApplicationLocks,
useApplications,
useEnvironments,
useGlobalLoadingState,
useTeamLocks,
} from '../../utils/store';
import { useSearchParams } from 'react-router-dom';
import { TopAppBar } from '../../components/TopAppBar/TopAppBar';
import { Locks } from '../../../api/api';

const applicationFieldHeaders = [
'Date',
Expand All @@ -45,6 +48,7 @@ export const LocksPage: React.FC = () => {
const appNameParam = params.get('application');
const envs = useEnvironments();
const allApps = useApplications();
const allAppLocks = useAllApplicationLocks((map) => map);
let teamLocks = useTeamLocks(allApps);
const envLocks = useMemo(
() =>
Expand All @@ -68,34 +72,30 @@ export const LocksPage: React.FC = () => {

teamLocks = useMemo(() => sortLocks(teamLocks, 'oldestToNewest'), [teamLocks]);

//Goes through all envs and all apps and checks for locks for each app
const appLocks = useMemo(
() =>
sortLocks(
Object.values(envs)
.map((env) =>
allApps
.map((app) =>
env.appLocks[app.name]
? env.appLocks[app.name].locks.map((lock) => ({
date: lock.createdAt,
environment: env.name,
application: app.name,
lockId: lock.lockId,
message: lock.message,
authorName: lock.createdBy?.name,
authorEmail: lock.createdBy?.email,
}))
: []
)
.flat()
)
.flat()
.filter((lock) => searchCustomFilter(appNameParam, lock.application)),
'oldestToNewest'
),
[appNameParam, envs, allApps]
);
const appLocks = useMemo(() => {
const allAppLocksDisplay: DisplayLock[] = [];
const map = new Map(Object.entries(allAppLocks));
map.forEach((appLocksForEnv, env): void => {
const currAppLocks = new Map<string, Locks>(Object.entries(appLocksForEnv.appLocks));
currAppLocks.forEach((currentAppInfo, app) => {
currentAppInfo.locks.map((lock) =>
allAppLocksDisplay.push({
date: lock.createdAt,
environment: env,
application: app,
lockId: lock.lockId,
message: lock.message,
authorName: lock.createdBy?.name,
authorEmail: lock.createdBy?.email,
})
);
});
});
return sortLocks(
allAppLocksDisplay.flat().filter((lock) => searchCustomFilter(appNameParam, lock.application)),
'oldestToNewest'
);
}, [allAppLocks, appNameParam]);

const element = useGlobalLoadingState();
if (element) {
Expand Down
Loading
Loading