Skip to content

Commit

Permalink
feat(md): show delivery config in the configuration tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Rani committed Jun 4, 2021
1 parent b702b5b commit e9e0c2c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 13 deletions.
4 changes: 4 additions & 0 deletions app/scripts/modules/core/src/managed/ManagedReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export class ManagedReader {
return REST('/managed/application').path(app).query({ entities: 'resources' }).get().then(this.decorateResources);
}

public static getDeliveryConfig(app: string): PromiseLike<Record<string, any>> {
return REST('/managed/application', { Accept: 'application/x-yaml' }).path(app).path('config').get();
}

public static getEnvironmentsSummary(app: string): PromiseLike<IManagedApplicationSummary> {
return REST('/managed/application')
.path(app)
Expand Down
33 changes: 20 additions & 13 deletions app/scripts/modules/core/src/managed/config/Configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Illustration } from '@spinnaker/presentation';
import { showModal, useApplicationContextSafe } from 'core/presentation';
import { Spinner } from 'core/widgets';

import { DeliveryConfig } from './DeliveryConfig';
import { useFetchApplicationManagementStatusQuery, useToggleManagementMutation } from '../graphql/graphql-sdk';
import spinner from '../overview/loadingIndicator.svg';
import { ActionModal, IArtifactActionModalProps } from '../utils/ActionModal';
Expand All @@ -27,10 +28,18 @@ const managementStatusToContent = {
};

export const Configuration = () => {
const app = useApplicationContextSafe();
const logEvent = useLogEvent('Management');
return (
<div className="full-width">
<ManagementToggle />
<DeliveryConfig />
</div>
);
};

const ManagementToggle = () => {
const app = useApplicationContextSafe();
const appName = app.name;
const logEvent = useLogEvent('Management');
const { data, loading, refetch } = useFetchApplicationManagementStatusQuery({ variables: { appName } });
const [toggleManagement, { loading: mutationInFlight }] = useToggleManagementMutation();

Expand Down Expand Up @@ -65,17 +74,15 @@ export const Configuration = () => {
return (
<div>
<div>
<div>
{state.title} {mutationInFlight && <img src={spinner} height={14} />}
</div>
<div>
<button
className={classnames(BTN_CLASSNAMES, state.btnClassName)}
onClick={() => onShowToggleManagementModal(!isPaused)}
>
{state.btnText}
</button>
</div>
{state.title} {mutationInFlight && <img src={spinner} height={14} />}
</div>
<div>
<button
className={classnames(BTN_CLASSNAMES, state.btnClassName)}
onClick={() => onShowToggleManagementModal(!isPaused)}
>
{state.btnText}
</button>
</div>
</div>
);
Expand Down
33 changes: 33 additions & 0 deletions app/scripts/modules/core/src/managed/config/DeliveryConfig.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { dump as dumpYaml } from 'js-yaml';
import React from 'react';

import { useApplicationContextSafe, useData } from 'core/presentation';

import { ManagedReader } from '..';
import { useLogEvent } from '../utils/logging';

export const DeliveryConfig = () => {
const app = useApplicationContextSafe();
const { result, error, status } = useData(() => ManagedReader.getDeliveryConfig(app.name), undefined, [app]);
const logError = useLogEvent('DeliveryConfig');
React.useEffect(() => {
if (error) {
logError({ action: 'LoadingFailed', data: { error } });
}
}, [error, logError]);

const yaml = React.useMemo(() => (result ? dumpYaml(result) : undefined), [result]);
return (
<div className="DeliveryConfig sp-margin-xl-top">
{status === 'REJECTED' && <div className="error-message">Failed to load delivery config</div>}
{status === 'RESOLVED' && yaml && (
<>
<div>
<h4>Delivery Config</h4>
</div>
<pre>{yaml}</pre>
</>
)}
</div>
);
};

0 comments on commit e9e0c2c

Please sign in to comment.