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

Adds Typed Facts #2484

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions services/api-db/docker-entrypoint-initdb.d/00-tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ CREATE TABLE IF NOT EXISTS environment_fact (
environment int REFERENCES environment (id),
name varchar(300) NOT NULL,
value varchar(300) NOT NULL,
type ENUM('TEXT', 'URL') DEFAULT 'TEXT',
source varchar(300) DEFAULT '',
description TEXT NULL DEFAULT '',
created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand Down
20 changes: 20 additions & 0 deletions services/api-db/docker-entrypoint-initdb.d/01-migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,25 @@ CREATE OR REPLACE PROCEDURE
END;
$$


CREATE OR REPLACE PROCEDURE
add_fact_type_to_environment_fact()

BEGIN
IF NOT EXISTS(
SELECT NULL
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
table_name = 'environment_fact'
AND table_schema = 'infrastructure'
AND column_name = 'type'
) THEN
ALTER TABLE `environment_fact`
ADD `type` ENUM('TEXT', 'URL') NOT NULL DEFAULT 'TEXT';
END IF;
END;
$$

DELIMITER ;

-- If adding new procedures, add them to the bottom of this list
Expand Down Expand Up @@ -1314,6 +1333,7 @@ CALL add_min_max_to_billing_modifier();
CALL add_content_type_to_project_notification();
CALL convert_project_production_routes_to_text();
CALL convert_project_standby_routes_to_text();
CALL add_fact_type_to_environment_fact();

-- Drop legacy SSH key procedures
DROP PROCEDURE IF EXISTS CreateProjectSshKey;
Expand Down
10 changes: 6 additions & 4 deletions services/api/src/resources/fact/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const addFact = async (
root,
{
input: {
id, environment: environmentId, name, value, source, description
id, environment: environmentId, name, value, source, description, type
},
},
{ sqlClient, hasPermission },
Expand All @@ -64,7 +64,8 @@ export const addFact = async (
name,
value,
source,
description
description,
type
}),
);

Expand Down Expand Up @@ -93,7 +94,7 @@ export const addFacts = async (
});

return await facts.map(async (fact) => {
const { environment, name, value, source, description } = fact;
const { environment, name, value, source, description, type } = fact;

const {
info: { insertId },
Expand All @@ -104,7 +105,8 @@ export const addFacts = async (
name,
value,
source,
description
description,
type
}),
);

Expand Down
7 changes: 4 additions & 3 deletions services/api/src/resources/fact/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const standardFactReturn = {
name: 'name',
value: 'value',
source: 'source',
description: 'description'
description: 'description',
type: 'type',
};

export const Sql /* : SqlObj */ = {
Expand All @@ -25,8 +26,8 @@ export const Sql /* : SqlObj */ = {
}) => {
return knex('environment_fact').select(standardFactReturn).where('environment', environmentId).toString();
},
insertFact: ({ environment, name, value, source, description }) =>
knex('environment_fact').insert({environment, name, value, source, description}).toString(),
insertFact: ({ environment, name, value, source, description, type }) =>
knex('environment_fact').insert({environment, name, value, source, description, type}).toString(),
deleteFact: (environment, name) =>
knex('environment_fact')
.where({
Expand Down
16 changes: 12 additions & 4 deletions services/api/src/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ const typeDefs = gql`
CRITICAL
}

enum FactType {
TEXT
URL
}

scalar SeverityScore

type Problem {
Expand Down Expand Up @@ -202,6 +207,7 @@ const typeDefs = gql`
value: String
source: String
description: String
type: FactType
}

input AddFactInput {
Expand All @@ -211,20 +217,22 @@ const typeDefs = gql`
value: String!
source: String!
description: String!
type: FactType
}

input AddFactsInput {
facts: [AddFactInput]!
}

input UpdateFactInputValue {
environment: Int!
name: String!
value: String!
source: String!
description: String
type: FactType
}

input UpdateFactInput {
environment: Int!
patch: UpdateFactInputValue!
Expand All @@ -234,7 +242,7 @@ const typeDefs = gql`
environment: Int!
name: String!
}

input DeleteFactsFromSourceInput {
environment: Int!
source: String!
Expand Down
12 changes: 11 additions & 1 deletion services/ui/src/components/Facts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ const Facts = ({ facts }) => {
<div className="description">{fact.description}</div>
</div>
<div className="col col-2">{fact.source}</div>
<div className="col col-3">{fact.value}</div>
{ fact.type == "URL"
? <div className="col col-3"><a className="external-link" href={fact.value} target="_blank">{fact.value}</a></div>
: <div className="col col-3">{fact.value}</div>
}

</div>
);
})}
Expand Down Expand Up @@ -204,6 +208,12 @@ const Facts = ({ facts }) => {
font-style: italic;
font-size: 12px;
}

a.external-link {
color: ${color.brightBlue};
text-decoration: underline;
font-style: italic;
}
}

.row-heading {
Expand Down
1 change: 1 addition & 0 deletions services/ui/src/lib/fragment/Fact.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export default gql`
value
source
description
type
}
`;