Skip to content

Commit

Permalink
backport of #3160
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybellwood committed Jun 8, 2022
1 parent 1053965 commit 7eaae54
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 187 deletions.
20 changes: 20 additions & 0 deletions services/api/src/apolloServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,26 @@ const apolloServer = new ApolloServer({
};
},
plugins: [
// Debug plugin for logging resolver execution order
// {
// requestDidStart(initialRequestContext) {
// return {
// executionDidStart(executionRequestContext) {
// return {
// willResolveField({source, args, context, info}) {
// console.log(`Resolving ${info.parentType.name}.${info.fieldName}`);
// const start = process.hrtime.bigint();
// return (error, result) => {
// const end = process.hrtime.bigint();
// // Uncomment to log resolver execution time
// // console.log(`Field ${info.parentType.name}.${info.fieldName} took ${end - start}ns`);
// };
// }
// }
// }
// }
// }
// },
{
requestDidStart: () => ({
willSendResponse: response => {
Expand Down
9 changes: 9 additions & 0 deletions services/api/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ const {
getProjectUser,
updateOpenshift,
deleteAllOpenshifts,
getToken,
getConsoleUrl,
getMonitoringConfig,
} = require('./resources/openshift/resolvers');

const {
Expand Down Expand Up @@ -319,9 +322,15 @@ const resolvers = {
},
Openshift: {
projectUser: getProjectUser,
token: getToken,
consoleUrl: getConsoleUrl,
monitoringConfig: getMonitoringConfig,
},
Kubernetes: {
projectUser: getProjectUser,
token: getToken,
consoleUrl: getConsoleUrl,
monitoringConfig: getMonitoringConfig,
},
Project: {
notifications: getNotificationsByProjectId,
Expand Down
46 changes: 39 additions & 7 deletions services/api/src/resources/openshift/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,47 @@ import * as R from 'ramda';
import { ResolverFn } from '../';
import { query, isPatchEmpty, knex } from '../../util/db';
import { Helpers as projectHelpers } from '../project/helpers';
import sql from '../user/sql';
import { Sql } from './sql';

const attrFilter = async (hasPermission, entity) => {
export const getToken: ResolverFn = async (
kubernetes,
_args,
{ hasPermission }
) => {
try {
await hasPermission('openshift', 'view:token');

return kubernetes.token;
} catch (err) {
return null;
}
};

export const getConsoleUrl: ResolverFn = async (
kubernetes,
_args,
{ hasPermission }
) => {
try {
await hasPermission('openshift', 'view:token');
return entity;

return kubernetes.consoleUrl;
} catch (err) {
return null;
}
};

export const getMonitoringConfig: ResolverFn = async (
kubernetes,
_args,
{ hasPermission }
) => {
try {
await hasPermission('openshift', 'view:token');

return kubernetes.monitoringConfig;
} catch (err) {
return R.omit(['token','consoleUrl','monitoringConfig'], entity);
return null;
}
};

Expand Down Expand Up @@ -82,7 +114,7 @@ export const getOpenshiftByProjectId: ResolverFn = async (
}
);

return rows ? attrFilter(hasPermission, rows[0]) : null;
return rows ? rows[0] : null;
};

export const getOpenshiftByDeployTargetId: ResolverFn = async (
Expand Down Expand Up @@ -119,7 +151,7 @@ export const getOpenshiftByDeployTargetId: ResolverFn = async (
}
);

return rows ? attrFilter(hasPermission, rows[0]) : null;
return rows ? rows[0] : null;
};

export const getOpenshiftByEnvironmentId: ResolverFn = async (
Expand Down Expand Up @@ -149,7 +181,7 @@ export const getOpenshiftByEnvironmentId: ResolverFn = async (
}
);

return rows ? attrFilter(hasPermission, rows[0]) : null;
return rows ? rows[0] : null;
};

export const updateOpenshift: ResolverFn = async (
Expand Down
8 changes: 4 additions & 4 deletions services/ui/src/components/Environments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const { className: boxClassName, styles: boxStyles } = css.resolve`
}
`;

const Environments = ({ environments = [] }) => {
const Environments = ({ environments = [], project }) => {
if (environments.length === 0) {
return null;
}
Expand All @@ -61,20 +61,20 @@ const Environments = ({ environments = [] }) => {
<div className="environment" key={environment.id}>
<EnvironmentLink
environmentSlug={environment.openshiftProjectName}
projectSlug={environment.project.name}
projectSlug={project.name}
>
<Box className={`${boxClassName} ${bgClassName}`}>
{environment.environmentType == 'production' && (
<div className="productionLabel">
<span>Production</span>
</div>
)}
{environment.project.productionEnvironment && environment.project.standbyProductionEnvironment && environment.project.productionEnvironment == environment.name && (
{project.productionEnvironment && project.standbyProductionEnvironment && project.productionEnvironment == environment.name && (
<div className="activeLabel">
<span>Active</span>
</div>
)}
{environment.project.productionEnvironment && environment.project.standbyProductionEnvironment && environment.project.standbyProductionEnvironment == environment.name && (
{project.productionEnvironment && project.standbyProductionEnvironment && project.standbyProductionEnvironment == environment.name && (
<div className="standbyLabel">
<span>Standby</span>
</div>
Expand Down
15 changes: 6 additions & 9 deletions services/ui/src/components/ProjectDetailsSidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import giturlparse from 'git-url-parse';
import Environments from 'components/Environments';
import { bp, color, fontSize } from 'lib/variables';

import { Mutation } from 'react-apollo';

import ProjectByNameQuery from 'lib/query/ProjectByName';

const Project = ({ project }) => {
const [copied, setCopied] = useState(false);
const gitUrlParsed = giturlparse(project.gitUrl);
Expand All @@ -18,6 +14,7 @@ const Project = ({ project }) => {
project.environments
);
const developEnvironmentCount = R.propOr(0, 'development', environmentCount);
const projectUsesDeployTargets = project.deployTargetConfigs.length > 0;

return (
<div className="details">
Expand Down Expand Up @@ -69,15 +66,15 @@ const Project = ({ project }) => {
</CopyToClipboard>
</div>
</div>
{project.deployTargetConfigs.length === 0 && (
{!projectUsesDeployTargets && (
<div className="field-wrapper branches">
<div>
<label>Branches enabled</label>
<div className="field">{project.branches}</div>
</div>
</div>
)}
{project.deployTargetConfigs.length === 0 && (
{!projectUsesDeployTargets === 0 && (
<div className="field-wrapper prs">
<div>
<label>Pull requests enabled</label>
Expand All @@ -94,16 +91,16 @@ const Project = ({ project }) => {
</div>
</div>
</div>
{project.deployTargetConfigs.length > 0 && (
{projectUsesDeployTargets && (
<div className="field-wrapper target">
<div>
<label>Deploy Targets</label>
{project.deployTargetConfigs.map(depTarget => (
<div>
<div key={depTarget.id}>
<div>
<label className="field1">{depTarget.deployTarget.friendlyName != null
? depTarget.deployTarget.friendlyName
: depTarget.deployTarget.name}{}</label>
: depTarget.deployTarget.name}</label>
</div>
<label className="field2">Branches enabled</label>
<div className="field2">{depTarget.branches}</div>
Expand Down
46 changes: 0 additions & 46 deletions services/ui/src/lib/query/AllAdvancedTasksForEnvironment.js

This file was deleted.

21 changes: 0 additions & 21 deletions services/ui/src/lib/query/AllProjectsAfterDate.js

This file was deleted.

14 changes: 0 additions & 14 deletions services/ui/src/lib/query/AllProjectsAndEnvironments.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ export default gql`
environmentType
routes
openshiftProjectName
openshift {
friendlyName
cloudProvider
cloudRegion
}
project {
name
gitUrl
Expand Down
15 changes: 0 additions & 15 deletions services/ui/src/lib/query/GroupByName.js

This file was deleted.

17 changes: 0 additions & 17 deletions services/ui/src/lib/query/ProjectByEnvironmentId.js

This file was deleted.

18 changes: 2 additions & 16 deletions services/ui/src/lib/query/ProjectByName.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,26 @@ export default gql`
productionEnvironment
standbyProductionEnvironment
developmentEnvironmentsLimit
deployTargetConfigs{
deployTargetConfigs {
id
branches
pullrequests
weight
deployTarget{
deployTarget {
id
name
friendlyName
cloudProvider
cloudRegion
}
}
environments {
id
name
created
updated
deployType
environmentType
openshiftProjectName
openshift {
friendlyName
cloudProvider
cloudRegion
}
project {
id
name
productionEnvironment
standbyProductionEnvironment
problemsUi
factsUi
}
}
}
}
Expand Down
Loading

0 comments on commit 7eaae54

Please sign in to comment.