Skip to content

Commit

Permalink
feat(md): Types and new data source for environments
Browse files Browse the repository at this point in the history
  • Loading branch information
alanmquach committed Mar 10, 2020
1 parent cfc347a commit b4512c3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 42 deletions.
57 changes: 31 additions & 26 deletions app/scripts/modules/core/src/domain/IManagedEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,33 @@ export interface IManagedResourceSummary {
};
}

export interface IManagedEnvironmentArtifact {
name: string;
type: string;
statuses: string[];
versions: {
current: string;
pending: string[];
approved: string[];
previous: string[];
vetoed: string[];
};
}

export interface IManagedEnviromentSummary {
artifacts: IManagedEnvironmentArtifact[];
name: string;
resources: string[];
}

export interface IManagedArtifactVersionEnvironmentSummary {
name: string;
state: string;
deployedAt?: string;
replacedAt?: string;
replacedBy?: string;
artifacts: Array<{
name: string;
type: string;
statuses: string[];
versions: {
current?: string;
deploying?: string;
pending: string[];
approved: string[];
previous: string[];
vetoed: string[];
};
}>;
}

export interface IManagedArtifactVersion {
version: string;
environments: IManagedArtifactVersionEnvironmentSummary[];
environments: Array<{
name: string;
state: string;
deployedAt?: string;
replacedAt?: string;
replacedBy?: string;
}>;
}

export interface IManagedArtifactSummary {
Expand All @@ -67,12 +64,20 @@ export interface IManagedApplicationEnvironmentsSummary extends IManagedApplicat
artifacts: IManagedArtifactSummary[];
}

export interface IManagedApplicationSummary {
applicationPaused: boolean;
hasManagedResources: boolean;
export interface IManagedApplicationEntities {
resources: IManagedResourceSummary[];
environments: IManagedEnviromentSummary[];
artifacts: IManagedArtifactSummary[];
}

export type IManagedApplicationSummary<T extends keyof IManagedApplicationEntities = 'resources'> = Pick<
IManagedApplicationEntities,
T
> & {
applicationPaused: boolean;
hasManagedResources: boolean;
};

export interface IManagedResource {
managedResourceSummary?: IManagedResourceSummary;
isManaged?: boolean;
Expand Down
40 changes: 24 additions & 16 deletions app/scripts/modules/core/src/managed/ManagedReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,34 @@ const transformManagedResourceDiff = (diff: IManagedResourceEventHistoryResponse
}, {} as IManagedResourceDiff);

export class ManagedReader {
public static getApplicationSummary(app: string, entities = ['resources']): IPromise<IManagedApplicationSummary> {
private static decorateResources(response: IManagedApplicationSummary) {
// Individual resources don't update their status when an application is paused/resumed,
// so for now let's swap to a PAUSED status and keep things simpler in downstream components.
if (response.applicationPaused) {
response.resources.forEach(resource => (resource.status = ManagedResourceStatus.PAUSED));
}

response.resources.forEach(resource => (resource.isPaused = resource.status === ManagedResourceStatus.PAUSED));

return response;
}

public static getApplicationSummary(app: string): IPromise<IManagedApplicationSummary<'resources'>> {
return API.one('managed')
.one('application', app)
.withParams({ includeDetails: true, entities: entities.join(',') })
.withParams({ includeDetails: true, entities: 'resources' })
.get()
.then((response: IManagedApplicationSummary) => {
// Individual resources don't update their status when an application is paused/resumed,
// so for now let's swap to a PAUSED status and keep things simpler in downstream components.
if (response.applicationPaused) {
response.resources.forEach(resource => (resource.status = ManagedResourceStatus.PAUSED));
}

response.resources.forEach(resource => (resource.isPaused = resource.status === ManagedResourceStatus.PAUSED));
.then(this.decorateResources);
}

return response;
});
public static getEnvironmentsSummary(
app: string,
): IPromise<IManagedApplicationSummary<'resources' | 'artifacts' | 'environments'>> {
return API.one('managed')
.one('application', app)
.withParams({ includeDetails: true, entities: ['resources', 'artifacts', 'environments'] })
.get()
.then(this.decorateResources);
}

public static getResourceHistory(resourceId: string): IPromise<IManagedResourceEventHistory> {
Expand All @@ -92,8 +104,4 @@ export class ManagedReader {
return response as IManagedResourceEventHistory;
});
}

public static getEnvironmentsSummary(app: string): IPromise<IManagedApplicationSummary> {
return this.getApplicationSummary(app, ['resources', 'artifacts', 'environments']);
}
}

0 comments on commit b4512c3

Please sign in to comment.