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

feat: Add team_themes table #2602

Merged
merged 5 commits into from
Jan 2, 2024
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#95b54b3",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#a70159d",
"@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#95b54b3",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#a70159d",
"axios": "^1.6.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#95b54b3",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#a70159d",
"axios": "^1.6.2",
"dotenv": "^16.3.1",
"eslint": "^8.56.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#95b54b3",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#a70159d",
"@tiptap/core": "^2.0.3",
"@tiptap/extension-bold": "^2.0.3",
"@tiptap/extension-bubble-menu": "^2.1.13",
Expand Down
12 changes: 6 additions & 6 deletions editor.planx.uk/pnpm-lock.yaml

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

3 changes: 3 additions & 0 deletions editor.planx.uk/src/components/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const mockTeam1: Team = {
slug: "opensystemslab",
theme: {
logo: "logo.jpg",
primary: "#0010A4",
secondary: null,
favicon: null,
},
};

Expand Down
2 changes: 1 addition & 1 deletion editor.planx.uk/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const TeamLogo: React.FC = () => {
const altText = teamSettings?.homepage
? `${teamName} Homepage (opens in a new tab)`
: `${teamName} Logo`;
const logo = <Logo alt={altText} src={teamTheme?.logo} />;
const logo = <Logo alt={altText} src={teamTheme?.logo ?? undefined} />;
return teamSettings?.homepage ? (
<LogoLink href={teamSettings?.homepage} target="_blank">
{logo}
Expand Down
7 changes: 6 additions & 1 deletion editor.planx.uk/src/routes/views/published.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ const fetchDataForPublishedView = async (
) {
id
team {
theme
theme {
primary: primary_colour
secondary: secondary_colour
logo
favicon
}
name
settings
slug
Expand Down
7 changes: 6 additions & 1 deletion editor.planx.uk/src/routes/views/standalone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ const fetchDataForStandaloneView = async (
) {
id
team {
theme
theme {
primary: primary_colour
secondary: secondary_colour
logo
favicon
}
name
settings
slug
Expand Down
7 changes: 6 additions & 1 deletion editor.planx.uk/src/routes/views/unpublished.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ const fetchDataForUnpublishedView = async (
) {
id
team {
theme
theme {
primary: primary_colour
secondary: secondary_colour
logo
favicon
}
name
settings
slug
Expand Down
6 changes: 4 additions & 2 deletions editor.planx.uk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export interface Team {
}

export interface TeamTheme {
primary?: string;
logo?: string;
primary: string;
secondary: string | null;
logo: string | null;
favicon: string | null;
}

export interface TeamSettings {
Expand Down
82 changes: 76 additions & 6 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,75 @@
- role: platformAdmin
permission:
filter: {}
- table:
name: team_themes
schema: public
select_permissions:
- role: api
permission:
columns:
- id
- team_id
- favicon
- logo
- primary_colour
- secondary_colour
filter: {}
comment: ""
- role: platformAdmin
permission:
columns:
- id
- team_id
- favicon
- logo
- primary_colour
- secondary_colour
filter: {}
comment: ""
- role: public
permission:
columns:
- id
- team_id
- favicon
- logo
- primary_colour
- secondary_colour
filter: {}
comment: ""
- role: teamEditor
permission:
columns:
- id
- team_id
- favicon
- logo
- primary_colour
- secondary_colour
filter: {}
comment: ""
update_permissions:
- role: platformAdmin
permission:
columns:
- favicon
- logo
- primary_colour
- secondary_colour
filter: {}
check: null
comment: ""
- role: teamEditor
permission:
columns:
- favicon
- logo
- primary_colour
- secondary_colour
filter: {}
check: null
comment: ""
- table:
name: teams
schema: public
Expand All @@ -1375,6 +1444,13 @@
table:
name: team_integrations
schema: public
- name: theme
using:
foreign_key_constraint_on:
column: team_id
table:
name: team_themes
schema: public
array_relationships:
- name: flows
using:
Expand Down Expand Up @@ -1411,7 +1487,6 @@
- settings
- slug
- submission_email
- theme
- updated_at
select_permissions:
- role: api
Expand All @@ -1427,7 +1502,6 @@
- settings
- slug
- submission_email
- theme
- updated_at
computed_fields:
- boundary_bbox
Expand All @@ -1443,7 +1517,6 @@
- reference_code
- settings
- slug
- theme
- updated_at
computed_fields:
- boundary_bbox
Expand All @@ -1460,7 +1533,6 @@
- reference_code
- settings
- slug
- theme
- updated_at
computed_fields:
- boundary_bbox
Expand All @@ -1476,7 +1548,6 @@
- reference_code
- settings
- slug
- theme
- updated_at
computed_fields:
- boundary_bbox
Expand All @@ -1491,7 +1562,6 @@
- settings
- slug
- submission_email
- theme
filter: {}
check: null
- table:
Expand Down
13 changes: 13 additions & 0 deletions hasura.planx.uk/migrations/1703240593405_squashed/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
COMMENT ON COLUMN "public"."team_themes"."secondary_colour" IS NULL;

COMMENT ON COLUMN "public"."team_themes"."primary_colour" IS NULL;

ALTER TABLE "public"."team_themes" DROP CONSTRAINT "team_themes_team_id_key";

DROP TABLE "public"."team_themes";

ALTER TABLE "public"."teams" ADD COLUMN "theme" JSONB;

ALTER TABLE "public"."teams" ALTER COLUMN "theme" SET DEFAULT '{}'::JSONB;

ALTER TABLE "public"."teams" ALTER COLUMN "theme" DROP NOT NULL;
30 changes: 30 additions & 0 deletions hasura.planx.uk/migrations/1703240593405_squashed/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CREATE TABLE "public"."team_themes" (
"id" serial NOT NULL,
"team_id" integer NOT NULL,
"primary_colour" text NOT NULL DEFAULT '#0010A4',
"secondary_colour" text,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check with @ianjon3s in the new year how we should handle defaults for this column.

"logo" text,
"favicon" text,
PRIMARY KEY ("id"),
FOREIGN KEY ("team_id") REFERENCES "public"."teams"("id") ON UPDATE cascade ON DELETE cascade
);

ALTER TABLE
"public"."team_themes"
ADD
CONSTRAINT "team_themes_team_id_key" UNIQUE ("team_id");

COMMENT ON COLUMN "public"."team_themes"."primary_colour" IS E'Must be hex triplet (e.g. #112233)';

COMMENT ON COLUMN "public"."team_themes"."secondary_colour" IS E'Must be hex triplet (e.g. #112233)';

INSERT INTO
team_themes (team_id, primary_colour, logo)
SELECT
id AS team_id,
COALESCE(theme ->> 'primary', '#0010A4') AS primary_colour,
COALESCE(theme ->> 'logo', NULL) AS logo
FROM
teams;

ALTER TABLE "public"."teams" DROP COLUMN "theme" CASCADE;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrating and then dropping the column will work on staging and prod, but on the initial migration on Pizza and locally it won't do anything as the data sync happens after Hasura migrations run.

I tested this locally without dropping the column. If preferred, I can split this into two steps / two PRs.

Loading
Loading