Skip to content

Commit

Permalink
Frontend implementation, missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-crespo-fdc committed Oct 10, 2024
1 parent c09f8cc commit 481cc9a
Show file tree
Hide file tree
Showing 7 changed files with 1,662 additions and 1,677 deletions.
66 changes: 5 additions & 61 deletions pkg/db/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ func (h *DBHandler) UpdateOverviewDeployment(ctx context.Context, transaction *s
appInEnv.DeploymentMetaData.DeployAuthor = deployment.Metadata.DeployedByEmail
appInEnv.DeploymentMetaData.DeployTime = fmt.Sprintf("%d", createdTime.Unix())

app := getApplicationByName(latestOverview.Applications, deployment.App)

if deployment.Version != nil { //Check if not trying to deploy an undeploy version
//Get the undeploy information from the release
release, err := h.DBSelectReleaseByVersion(ctx, transaction, appInEnv.Name, appInEnv.Version, true)
Expand All @@ -135,8 +133,6 @@ func (h *DBHandler) UpdateOverviewDeployment(ctx context.Context, transaction *s
}
appInEnv.UndeployVersion = release.Metadata.UndeployVersion
}
app.Warnings = CalculateWarnings(ctx, app.Name, latestOverview.EnvironmentGroups)
app.UndeploySummary = deriveUndeploySummary(app.Name, latestOverview.EnvironmentGroups)
err = h.WriteOverviewCache(ctx, transaction, latestOverview)
if err != nil {
return err
Expand Down Expand Up @@ -248,71 +244,19 @@ func (h *DBHandler) UpdateOverviewRelease(ctx context.Context, transaction *sql.
if h.IsOverviewEmpty(latestOverview) {
return nil
}
app := getApplicationByName(latestOverview.Applications, release.App)
if app == nil {
if release.Deleted {
return nil
}
selectApp, err := h.DBSelectApp(ctx, transaction, release.App)
if err != nil {
return fmt.Errorf("could not find application '%s' in apps table, got an error: %w", release.App, err)
}
if selectApp == nil {
return fmt.Errorf("could not find application '%s' in apps table: got no result", release.App)
}
app = &api.Application{
Name: release.App,
Releases: []*api.Release{},
SourceRepoUrl: "", // TODO
Team: selectApp.Metadata.Team,
UndeploySummary: 0,
Warnings: []*api.Warning{},
}
latestOverview.Applications[release.App] = app
}
apiRelease := &api.Release{
PrNumber: extractPrNumber(release.Metadata.SourceMessage),
Version: release.ReleaseNumber,
UndeployVersion: release.Metadata.UndeployVersion,
SourceAuthor: release.Metadata.SourceAuthor,
SourceCommitId: release.Metadata.SourceCommitId,
SourceMessage: release.Metadata.SourceMessage,
CreatedAt: timestamppb.New(release.Created),
DisplayVersion: release.Metadata.DisplayVersion,
IsMinor: release.Metadata.IsMinor,
IsPrepublish: release.Metadata.IsPrepublish,
}
foundRelease := false
for relIndex, currentRelease := range app.Releases {
if currentRelease.Version == release.ReleaseNumber {
if release.Deleted {
app.Releases = append(app.Releases[:relIndex], app.Releases[relIndex+1:]...)
} else {
app.Releases[relIndex] = apiRelease
}
foundRelease = true
}
}
if !foundRelease && !release.Deleted {
app.Releases = append(app.Releases, apiRelease)
}

if release.Metadata.UndeployVersion {
app.UndeploySummary = deriveUndeploySummary(app.Name, latestOverview.EnvironmentGroups)
}

err = h.WriteOverviewCache(ctx, transaction, latestOverview)
if err != nil {
return err
}
//err = h.WriteOverviewCache(ctx, transaction, latestOverview)
//if err != nil {
// return err
//}
return nil
}

func (h *DBHandler) IsOverviewEmpty(overviewResp *api.GetOverviewResponse) bool {
if overviewResp == nil {
return true
}
if len(overviewResp.Applications) == 0 && len(overviewResp.EnvironmentGroups) == 0 && overviewResp.GitRevision == "" {
if len(overviewResp.EnvironmentGroups) == 0 && overviewResp.GitRevision == "" {
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>
Copyright freiheit.com*/
import { Releases } from '../../components/Releases/Releases';
import { useGlobalLoadingState } from '../../utils/store';
import React from 'react';
import { getAppDetails, useAppDetailsForApp } from '../../utils/store';
import React, { useEffect } from 'react';
import { TopAppBar } from '../../components/TopAppBar/TopAppBar';
import { useAzureAuthSub } from '../../utils/AzureAuthProvider';
import { Spinner } from '../../components/Spinner/Spinner';

export const ReleaseHistoryPage: React.FC = () => {
const url = window.location.pathname.split('/');
const app_name = url[url.length - 1];
const appDetails = useAppDetailsForApp(app_name);
const { authHeader } = useAzureAuthSub((auth) => auth);

const element = useGlobalLoadingState();
if (element) {
return element;
}
useEffect(() => {
getAppDetails(app_name, authHeader);
}, [app_name, authHeader]);

if (!appDetails) {
return <Spinner message={'Loading History...'} />;
}
return (
<div>
<TopAppBar showAppFilter={false} showTeamFilter={false} showWarningFilter={false} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>
Copyright freiheit.com*/
import classNames from 'classnames';
import { Release } from '../../../api/api';
import { useDisplayApplicationLocks, useReleasesForApp } from '../../utils/store';
import { useAppDetailsForApp, useDisplayApplicationLocks } from '../../utils/store';
import { ReleaseCardMini } from '../ReleaseCardMini/ReleaseCardMini';
import './Releases.scss';
import { ApplicationLockChip } from '../ApplicationLockDisplay/ApplicationLockDisplay';
Expand All @@ -30,7 +30,7 @@ const dateFormat = (date: Date): string => {
return `${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
};

const getReleasesForAppGroupByDate = (releases: Array<Release>): [Release, ...Release[]][] => {
const getReleasesForAppGroupByDate = (releases: Array<Release> | undefined): [Release, ...Release[]][] => {
if (releases === undefined) {
return [];
}
Expand All @@ -51,7 +51,7 @@ const getReleasesForAppGroupByDate = (releases: Array<Release>): [Release, ...Re

export const Releases: React.FC<ReleasesProps> = (props) => {
const { app, className } = props;
const releases = useReleasesForApp(app);
const releases = useAppDetailsForApp(app).application?.releases;
const displayAppLocks = useDisplayApplicationLocks(app);
const rel = getReleasesForAppGroupByDate(releases);
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
// <ServiceLane {...overrides} hideMinors={false} />
// </MemoryRouter>
// );
// const getWrapper = (overrides: { application: Application }) => render(getNode(overrides));
// const getWrapper = (overrides: { application: OverviewApplication }) => render(getNode(overrides));
// describe.each(data)('Service Lane diff number', (testcase) => {
// it(testcase.name, () => {
// UpdateOverview.set({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
getAppDetails,
showSnackbarError,
showSnackbarWarn,
useAppDetails,
useAppDetailsForApp,
useCurrentlyExistsAtGroup,
useMinorsForApp,
Expand Down Expand Up @@ -110,14 +109,14 @@ export const ServiceLane: React.FC<{ application: OverviewApplication; hideMinor
const { authHeader } = useAzureAuthSub((auth) => auth);
// const deployedReleases = useDeployedReleases(application.name);
// const allReleases = useVersionsForApp(application.name);
// const { navCallback } = useNavigateWithSearchParams('releasehistory/' + application.name);
//const { navCallback } = useNavigateWithSearchParams('releasehistory/' + application.Name);
// const prepareUndeployOrUndeployText = deriveUndeployMessage(application.undeploySummary);
const appDetails = useAppDetails((map) => map[application.Name]);
const appDetails = useAppDetailsForApp(application.Name);
React.useEffect(() => {
if (!appDetails) {
getAppDetails(application.Name, authHeader);
}
}, [application, authHeader, appDetails]);
// eslint-disable-next-line no-console
console.log('getting app details...');
getAppDetails(application.Name, authHeader);
}, [application, authHeader]);

if (!appDetails) {
return (
Expand Down Expand Up @@ -187,8 +186,10 @@ export const ReadyServiceLane: React.FC<{
break;
}
}, [application.Name, props.appDetails.application?.undeploySummary]);
const minorReleases = useMinorsForApp(application.Name);

let minorReleases = useMinorsForApp(application.Name);
if (!minorReleases) {
minorReleases = [];
}
const prepareUndeployOrUndeployText = deriveUndeployMessage(props.appDetails.application?.undeploySummary);
const releases = [
...new Set(
Expand Down
Loading

0 comments on commit 481cc9a

Please sign in to comment.