From 808d01d9ae22d09c61d5e59dbfe650767329d475 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 28 May 2024 14:43:54 +0100 Subject: [PATCH 01/10] add name column and comment to flows table --- .../down.sql | 3 +++ .../up.sql | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/down.sql create mode 100644 hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql diff --git a/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/down.sql b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/down.sql new file mode 100644 index 0000000000..f284225ed7 --- /dev/null +++ b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/down.sql @@ -0,0 +1,3 @@ +comment on column "public"."flows"."name" is NULL; + +ALTER TABLE flows DROP COLUMN name; diff --git a/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql new file mode 100644 index 0000000000..db80b330c6 --- /dev/null +++ b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql @@ -0,0 +1,3 @@ +alter table "public"."flows" add column "name" text + null; + comment on column "public"."feedback"."node_data" is 'The name of the flow, entered by the user and used to generate the "slug"'; From 83ddc22d6389aa979edcc366ba9743d44666df39 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 28 May 2024 14:57:54 +0100 Subject: [PATCH 02/10] add sql to populate name column with slug data --- .../down.sql | 2 +- .../up.sql | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/down.sql b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/down.sql index f284225ed7..3ec5c863e5 100644 --- a/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/down.sql +++ b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/down.sql @@ -1,3 +1,3 @@ comment on column "public"."flows"."name" is NULL; -ALTER TABLE flows DROP COLUMN name; +ALTER TABLE flows DROP COLUMN name; \ No newline at end of file diff --git a/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql index db80b330c6..33263e9231 100644 --- a/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql +++ b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql @@ -1,3 +1,6 @@ alter table "public"."flows" add column "name" text null; comment on column "public"."feedback"."node_data" is 'The name of the flow, entered by the user and used to generate the "slug"'; + +UPDATE flows +SET name = slug; \ No newline at end of file From 6abef7cd8be5275b67f574f80b4f701c5df616e7 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 28 May 2024 15:05:09 +0100 Subject: [PATCH 03/10] add name column to flow.sql code --- hasura.planx.uk/metadata/tables.yaml | 10 ++++++++++ scripts/seed-database/write/flows.sql | 10 +++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/hasura.planx.uk/metadata/tables.yaml b/hasura.planx.uk/metadata/tables.yaml index eaf09ef72b..e8c8717c4b 100644 --- a/hasura.planx.uk/metadata/tables.yaml +++ b/hasura.planx.uk/metadata/tables.yaml @@ -418,6 +418,7 @@ - creator_id - data - id + - name - settings - slug - team_id @@ -441,6 +442,7 @@ - creator_id - data - id + - name - settings - slug - team_id @@ -471,6 +473,7 @@ - creator_id - data - id + - name - settings - slug - team_id @@ -494,6 +497,7 @@ - creator_id - data - id + - name - settings - slug - status @@ -512,6 +516,7 @@ - creator_id - data - id + - name - settings - slug - status @@ -529,6 +534,7 @@ - creator_id - data - id + - name - settings - slug - status @@ -547,6 +553,7 @@ - creator_id - data - id + - name - settings - slug - status @@ -566,6 +573,7 @@ - creator_id - data - id + - name - settings - slug - status @@ -587,6 +595,7 @@ permission: columns: - data + - name - settings - slug - status @@ -606,6 +615,7 @@ permission: columns: - data + - name - settings - slug - status diff --git a/scripts/seed-database/write/flows.sql b/scripts/seed-database/write/flows.sql index 93a01f5910..1179d6f5f1 100644 --- a/scripts/seed-database/write/flows.sql +++ b/scripts/seed-database/write/flows.sql @@ -11,7 +11,8 @@ CREATE TEMPORARY TABLE sync_flows ( settings jsonb, copied_from uuid, analytics_link text, - status text + status text, + name text ); \copy sync_flows FROM '/tmp/flows.csv' WITH (FORMAT csv, DELIMITER ';'); @@ -26,7 +27,8 @@ INSERT INTO flows ( settings, copied_from, analytics_link, - status + status, + name ) SELECT id, @@ -38,7 +40,8 @@ SELECT settings, copied_from, NULL, - status + status, + name FROM sync_flows ON CONFLICT (id) DO UPDATE SET @@ -51,6 +54,7 @@ SET copied_from = EXCLUDED.copied_from, analytics_link = NULL, status = EXCLUDED.status; + name = EXCLUDED.name; -- ensure that original flows.version is overwritten to match new operation inserted below, else sharedb will fail UPDATE flows SET version = 1; From db8b354e4fab04cb24f48edfa1da3de4914e6201 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 28 May 2024 15:10:28 +0100 Subject: [PATCH 04/10] add condition to populate sql to avoid overwriting name --- .../up.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql index 33263e9231..a5dbed1177 100644 --- a/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql +++ b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql @@ -3,4 +3,5 @@ alter table "public"."flows" add column "name" text comment on column "public"."feedback"."node_data" is 'The name of the flow, entered by the user and used to generate the "slug"'; UPDATE flows -SET name = slug; \ No newline at end of file +SET name = slug +WHERE name IS NULL; \ No newline at end of file From 29ea716dba28660b3f08e208e8eea95736e351b6 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 28 May 2024 15:54:20 +0100 Subject: [PATCH 05/10] add name to store functions --- .../src/pages/FlowEditor/lib/store/editor.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts index e24638d7b8..0817dc2d5c 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts @@ -73,7 +73,7 @@ export interface EditorStore extends Store.Store { connectTo: (id: Store.nodeId) => void; copyFlow: (flowId: string) => Promise; copyNode: (id: Store.nodeId) => void; - createFlow: (teamId: any, newSlug: any) => Promise; + createFlow: (teamId: any, newSlug: any, newName: string) => Promise; deleteFlow: (teamId: number, flowSlug: string) => Promise; validateAndDiffFlow: (flowId: string) => Promise; getFlows: (teamId: number) => Promise; @@ -186,12 +186,17 @@ export const editorStore: StateCreator< localStorage.setItem("clipboard", id); }, - createFlow: async (teamId, newSlug) => { + createFlow: async (teamId, newSlug, newName) => { let response = (await client.mutate({ mutation: gql` - mutation CreateFlow($data: jsonb, $slug: String, $teamId: Int) { + mutation CreateFlow( + $data: jsonb + $slug: String + $name: String + $teamId: Int + ) { insert_flows_one( - object: { slug: $slug, team_id: $teamId, version: 1 } + object: { slug: $slug, name: $name, team_id: $teamId, version: 1 } ) { id data @@ -201,6 +206,7 @@ export const editorStore: StateCreator< variables: { slug: newSlug, teamId, + name: newName, }, })) as any; @@ -277,6 +283,7 @@ export const editorStore: StateCreator< where: { team: { id: { _eq: $teamId } } } ) { id + name slug updated_at operations(limit: 1, order_by: { id: desc }) { From c7176454652350aa5f281e0fc3db7850bc19f341 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 28 May 2024 16:50:10 +0100 Subject: [PATCH 06/10] add string methods to alter slug to fit name formatting --- .../up.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql index a5dbed1177..5352946d88 100644 --- a/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql +++ b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql @@ -1,7 +1,9 @@ alter table "public"."flows" add column "name" text null; - comment on column "public"."feedback"."node_data" is 'The name of the flow, entered by the user and used to generate the "slug"'; + comment on column "public"."flows"."name" is 'The name of the flow, entered by the user and used to generate the "slug"'; UPDATE flows -SET name = slug -WHERE name IS NULL; \ No newline at end of file +SET name = replace(initcap(replace(slug,'-','xax')),'xax',' ') +WHERE name IS NULL + + From e82bcd64d19b00e5db7e1d8ae477694a4e4a3500 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 28 May 2024 16:52:08 +0100 Subject: [PATCH 07/10] revert changes to store --- .../src/pages/FlowEditor/lib/store/editor.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts index 0817dc2d5c..4bb7165609 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts @@ -73,7 +73,7 @@ export interface EditorStore extends Store.Store { connectTo: (id: Store.nodeId) => void; copyFlow: (flowId: string) => Promise; copyNode: (id: Store.nodeId) => void; - createFlow: (teamId: any, newSlug: any, newName: string) => Promise; + createFlow: (teamId: any, newSlug: any) => Promise; deleteFlow: (teamId: number, flowSlug: string) => Promise; validateAndDiffFlow: (flowId: string) => Promise; getFlows: (teamId: number) => Promise; @@ -186,17 +186,12 @@ export const editorStore: StateCreator< localStorage.setItem("clipboard", id); }, - createFlow: async (teamId, newSlug, newName) => { + createFlow: async (teamId, newSlug) => { let response = (await client.mutate({ mutation: gql` - mutation CreateFlow( - $data: jsonb - $slug: String - $name: String - $teamId: Int - ) { + mutation CreateFlow($data: jsonb, $slug: String, $teamId: Int) { insert_flows_one( - object: { slug: $slug, name: $name, team_id: $teamId, version: 1 } + object: { slug: $slug, team_id: $teamId, version: 1 } ) { id data @@ -206,7 +201,6 @@ export const editorStore: StateCreator< variables: { slug: newSlug, teamId, - name: newName, }, })) as any; @@ -283,7 +277,7 @@ export const editorStore: StateCreator< where: { team: { id: { _eq: $teamId } } } ) { id - name + slug updated_at operations(limit: 1, order_by: { id: desc }) { From 499e31bd11c3d41c9fc786a44ca7a260da6b27ed Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Wed, 29 May 2024 14:32:45 +0100 Subject: [PATCH 08/10] alter population script to format slug --- .../up.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql index 5352946d88..349ee9274e 100644 --- a/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql +++ b/hasura.planx.uk/migrations/1716902907392_alter_table_public_flows_add_column_name/up.sql @@ -3,7 +3,7 @@ alter table "public"."flows" add column "name" text comment on column "public"."flows"."name" is 'The name of the flow, entered by the user and used to generate the "slug"'; UPDATE flows -SET name = replace(initcap(replace(slug,'-','xax')),'xax',' ') +SET name = replace(concat(upper(substring(slug,1,1)),right(slug,-1)),'-',' ') WHERE name IS NULL From 35a8dde81231c58de657bf73ab8439d3c023f6ab Mon Sep 17 00:00:00 2001 From: Rory Doak <138574807+RODO94@users.noreply.github.com> Date: Wed, 29 May 2024 16:09:23 +0100 Subject: [PATCH 09/10] Update scripts/seed-database/write/flows.sql MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dafydd Llŷr Pearson --- scripts/seed-database/write/flows.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/seed-database/write/flows.sql b/scripts/seed-database/write/flows.sql index 1179d6f5f1..6244bdfe91 100644 --- a/scripts/seed-database/write/flows.sql +++ b/scripts/seed-database/write/flows.sql @@ -53,7 +53,7 @@ SET settings = EXCLUDED.settings, copied_from = EXCLUDED.copied_from, analytics_link = NULL, - status = EXCLUDED.status; + status = EXCLUDED.status, name = EXCLUDED.name; -- ensure that original flows.version is overwritten to match new operation inserted below, else sharedb will fail From fa04af5067cce8c0b5d203adecc359a5c4ca847b Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Wed, 29 May 2024 16:58:36 +0100 Subject: [PATCH 10/10] remove extra space --- editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts index 4bb7165609..e24638d7b8 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/editor.ts @@ -277,7 +277,6 @@ export const editorStore: StateCreator< where: { team: { id: { _eq: $teamId } } } ) { id - slug updated_at operations(limit: 1, order_by: { id: desc }) {