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

Production deploy #2336

Merged
merged 5 commits into from
Oct 23, 2023
Merged
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
2 changes: 1 addition & 1 deletion api.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@airbrake/node": "^2.1.8",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#c2d6f35",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#2b7fa5b",
"@types/isomorphic-fetch": "^0.0.36",
"adm-zip": "^0.5.10",
"aws-sdk": "^2.1467.0",
Expand Down
8 changes: 4 additions & 4 deletions api.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/tests/api-driven/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"dependencies": {
"@cucumber/cucumber": "^9.3.0",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#c2d6f35",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#2b7fa5b",
"axios": "^1.4.0",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
Expand Down
8 changes: 4 additions & 4 deletions e2e/tests/api-driven/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"postinstall": "./install-dependencies.sh"
},
"dependencies": {
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#c2d6f35",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#2b7fa5b",
"axios": "^1.4.0",
"dotenv": "^16.3.1",
"eslint": "^8.44.0",
Expand Down
8 changes: 4 additions & 4 deletions e2e/tests/ui-driven/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion editor.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@mui/styles": "^5.14.5",
"@mui/utils": "^5.14.5",
"@opensystemslab/map": "^0.7.5",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#c2d6f35",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#2b7fa5b",
"@tiptap/core": "^2.0.3",
"@tiptap/extension-bold": "^2.0.3",
"@tiptap/extension-bubble-menu": "^2.1.6",
Expand Down
10 changes: 5 additions & 5 deletions editor.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,78 @@ describe("createFileList function", () => {
expect(result).toEqual(expected);
});

it("correctly handles unique file names", () => {
const fileTypes: FileType[] = [
{
fn: "files.documentA",
name: "Document A",
rule: {
fn: "documentA.required",
val: "true",
operator: Operator.Equals,
condition: Condition.RequiredIf,
},
},
{
fn: "files.documentB",
name: "Document B",
rule: {
fn: "documentB.recommended",
val: "true",
operator: Operator.Equals,
condition: Condition.RecommendedIf,
},
},
{
fn: "files.documentB",
name: "Document B",
rule: {
fn: "documentB.required",
val: "true",
operator: Operator.Equals,
condition: Condition.RequiredIf,
},
},
];
const passport: Store.passport = {
data: {
"documentA.required": ["true"],
"documentB.recommended": ["true"],
},
};

const expected: FileList = {
required: [
{
fn: "files.documentA",
name: "Document A",
rule: {
fn: "documentA.required",
val: "true",
operator: Operator.Equals,
condition: Condition.RequiredIf,
},
},
],
recommended: [
{
fn: "files.documentB",
name: "Document B",
rule: {
fn: "documentB.recommended",
val: "true",
operator: Operator.Equals,
condition: Condition.RecommendedIf,
},
},
],
optional: [],
};
const result = createFileList({ passport, fileTypes });

expect(result).toEqual(expected);
});

it("handles a complex list of FileTypes", () => {
const fileTypes: FileType[] = [
{
Expand Down
30 changes: 22 additions & 8 deletions editor.planx.uk/src/@planx/components/FileUploadAndLabel/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,12 @@ export const createFileList = ({
sortedFileTypes.forEach((fileType) => {
const isUnique = !uniqueNames.includes(fileType.name);
if (isUnique) {
uniqueNames.push(fileType.name);
populateFileList({ fileList, fileType, passport });
const isFileTypeAdded = populateFileList({
fileList,
fileType,
passport,
});
if (isFileTypeAdded) uniqueNames.push(fileType.name);
}
});
return fileList;
Expand All @@ -139,6 +143,10 @@ const sortFileTypes = (fileTypes: FileType[]): FileType[] => {
return sortedFileTypes;
};

/**
* Populate file list based on condition
* @returns true if file added, false if not
*/
const populateFileList = ({
fileList,
fileType,
Expand All @@ -147,27 +155,33 @@ const populateFileList = ({
fileList: FileList;
fileType: FileType;
passport: Store.passport;
}) => {
}): boolean => {
switch (fileType.rule.condition) {
case Condition.AlwaysRequired:
fileList.required.push(fileType);
break;
return true;

case Condition.AlwaysRecommended:
fileList.recommended.push(fileType);
break;
return true;

case Condition.RequiredIf:
if (isRuleMet(passport, fileType.rule)) {
fileList.required.push(fileType);
return true;
}
break;
return false;

case Condition.RecommendedIf:
if (isRuleMet(passport, fileType.rule)) {
fileList.recommended.push(fileType);
return true;
}
break;
return false;

case Condition.NotRequired:
fileList.optional.push(fileType);
break;
return true;
}
};

Expand Down
12 changes: 10 additions & 2 deletions scripts/seed-database/write/flows.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- insert flows skipping conflicts
-- insert flows overwriting conflicts
CREATE TEMPORARY TABLE sync_flows (
id uuid,
team_id int,
Expand Down Expand Up @@ -34,7 +34,15 @@ SELECT
settings,
copied_from
FROM sync_flows
ON CONFLICT (id) DO NOTHING;
ON CONFLICT (id) DO UPDATE
SET
team_id = EXCLUDED.team_id,
slug = EXCLUDED.slug,
creator_id = EXCLUDED.creator_id,
data = EXCLUDED.data,
version = EXCLUDED.version,
settings = EXCLUDED.settings,
copied_from = EXCLUDED.copied_from;

-- ensure that original flows.version is overwritten to match new operation inserted below, else sharedb will fail
UPDATE flows SET version = 1;
Expand Down
9 changes: 8 additions & 1 deletion scripts/seed-database/write/published_flows.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- insert published_flows overwriting conflicts
CREATE TEMPORARY TABLE sync_published_flows (
id int,
data jsonb,
Expand Down Expand Up @@ -25,4 +26,10 @@ SELECT
publisher_id,
created_at
FROM sync_published_flows
ON CONFLICT (id) DO NOTHING;
ON CONFLICT (id) DO UPDATE
SET
data = EXCLUDED.data,
flow_id = EXCLUDED.flow_id,
summary = EXCLUDED.summary,
publisher_id = EXCLUDED.publisher_id,
created_at = EXCLUDED.created_at;
9 changes: 7 additions & 2 deletions scripts/seed-database/write/team_members.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
-- insert team_members overwriting conflicts
CREATE TEMPORARY TABLE sync_team_members (
id uuid,
user_id integer,
team_id integer,
role text
);

\copy team_members FROM '/tmp/team_members.csv' WITH (FORMAT csv, DELIMITER ';');
\copy sync_team_members FROM '/tmp/team_members.csv' WITH (FORMAT csv, DELIMITER ';');

INSERT INTO
team_members (id, user_id, team_id, role)
SELECT
id, user_id, team_id, role
FROM
sync_team_members ON CONFLICT (id) DO NOTHING;
sync_team_members ON CONFLICT (id) DO UPDATE
SET
user_id = EXCLUDED.user_id,
team_id = EXCLUDED.team_id,
role = EXCLUDED.role;
11 changes: 9 additions & 2 deletions scripts/seed-database/write/teams.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- insert teams skipping conflicts
-- insert teams overwriting conflicts
CREATE TEMPORARY TABLE sync_teams (
id integer,
name text,
Expand Down Expand Up @@ -33,6 +33,13 @@ SELECT
notify_personalisation,
boundary
FROM sync_teams
ON CONFLICT (id) DO NOTHING;
ON CONFLICT (id) DO UPDATE
SET
name = EXCLUDED.name,
slug = EXCLUDED.slug,
theme = EXCLUDED.theme,
settings = EXCLUDED.settings,
notify_personalisation = EXCLUDED.notify_personalisation,
boundary = EXCLUDED.boundary;

SELECT setval('teams_id_seq', max(id)) FROM teams;
9 changes: 7 additions & 2 deletions scripts/seed-database/write/users.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- insert users skipping conflicts
-- insert users overwriting conflicts
CREATE TEMPORARY TABLE sync_users (
id integer,
first_name text,
Expand Down Expand Up @@ -30,7 +30,12 @@ SELECT
email,
is_platform_admin
FROM sync_users
ON CONFLICT (id) DO NOTHING;
ON CONFLICT (id) DO UPDATE
SET
first_name = EXCLUDED.first_name,
last_name = EXCLUDED.last_name,
email = EXCLUDED.email,
is_platform_admin = EXCLUDED.is_platform_admin;

ALTER TABLE
users ENABLE TRIGGER grant_new_user_template_team_access;
Expand Down
Loading