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

Refactor new layout: no extra languages; responsive layout #1186

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Knex } from "knex"

export async function up(knex: Knex): Promise<void> {
await knex.raw(`
insert into tag (id, hidden) values ('other_language', false) on conflict do nothing;
`)
await knex.raw(`
insert into tag_type (name) values ('language') on conflict do nothing;
`)
await knex.raw(`
insert into "_TagToTagType" ("A", "B") values ('other_language', 'language')
on conflict do nothing;
`)
await knex.raw(`
insert into "_CourseToTag" ("A", "B")
select c.id, 'other_language' from course c
join "_CourseToTag" ctt on c.id = ctt."A"
join tag on ctt."B" = tag.id
join "_TagToTagType" ttt on tag.id = ttt."A"
where ttt."B" = 'language'
and tag.id not in ('en', 'fi', 'se')
on conflict do nothing;
`)
await knex.raw(`
insert into tag_translation (tag_id, language, name)
values ('other_language', 'en_US', 'other language')
on conflict do nothing;
`)
await knex.raw(`
insert into tag_translation (tag_id, language, name)
values ('other_language', 'fi_FI', 'muu kieli')
on conflict do nothing;
`)
}

export async function down(knex: Knex): Promise<void> {
await knex.raw(`
delete from tag_translation where tag_id = 'other_language';
`)
await knex.raw(`
delete from "_CourseToTag" where "B" = 'other_language';
`)
await knex.raw(`
delete from "_TagToTagType" where "A" = 'other_language';
`)
await knex.raw(`
delete from tag where id = 'other_language';
`)
}
30 changes: 16 additions & 14 deletions backend/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ function prismaTestContext() {
let prisma: null | PrismaClient = null
let knexClient: Knex | null = null

const clean = async () => {
await knexClient?.raw(`DO $$ BEGIN
EXECUTE(
SELECT 'TRUNCATE TABLE '
|| string_agg(format('%I.%I', schemaname, tablename), ', ')
|| ' CASCADE'
FROM pg_tables
WHERE schemaname = '${schemaName}'
AND tableowner = '${DB_USER}'
);
END $$;
`)
}
return {
async before() {
// Generate a unique schema identifier for this test context
Expand All @@ -174,7 +187,8 @@ function prismaTestContext() {
schemaName,
database: databaseUrl,
})

// Clear data that might have been inserted during the migrations
await clean()
// Construct a new Prisma Client connected to the generated Postgres schema
DEBUG && console.log(`creating prisma ${databaseUrl}`)
prisma = new PrismaClient({
Expand All @@ -185,19 +199,7 @@ function prismaTestContext() {
prisma,
}
},
async clean() {
await knexClient?.raw(`DO $$ BEGIN
EXECUTE(
SELECT 'TRUNCATE TABLE '
|| string_agg(format('%I.%I', schemaname, tablename), ', ')
|| ' CASCADE'
FROM pg_tables
WHERE schemaname = '${schemaName}'
AND tableowner = '${DB_USER}'
);
END $$;
`)
},
clean,
async after() {
// Drop the schema after the tests have completed
DEBUG && console.log(`dropping schema ${schemaName}`)
Expand Down
11 changes: 9 additions & 2 deletions frontend/components/BorderedSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ const BorderedSectionBase = styled("div")`
}
`

type PropsOf<T> = T extends React.ComponentType<infer P> ? P : never

function BorderedSection({
title,
children,
}: PropsWithChildren<{ title?: string | React.ReactNode }>) {
...props
}: PropsWithChildren<
Omit<PropsOf<typeof BorderedSectionBase>, "title"> & {
title?: string | React.ReactNode
}
>) {
return (
<BorderedSectionBase>
<BorderedSectionBase {...props}>
<div className="header">
<div className="headerBorderBefore"></div>
{title && <div className="headerTitle">{title}</div>}
Expand Down
1 change: 1 addition & 0 deletions frontend/components/NewLayout/Courses/Catalogue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CoursesTranslations from "/translations/_new/courses"
const Container = styled("section")`
display: grid;
justify-items: center;
margin: 0 auto;
`

const Header = styled(Typography)`
Expand Down
3 changes: 3 additions & 0 deletions frontend/components/NewLayout/Courses/CourseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ const MoocfiLogo = styled(CardHeaderImage)``
const prettifyDate = (date: string) =>
date.split("T").shift()?.split("-").reverse().join(".")

const allowedLanguages = ["en", "fi", "se"]

interface CourseCardProps {
course: CourseFieldsFragment
tags?: string[]
Expand Down Expand Up @@ -303,6 +305,7 @@ function CourseCard({ course }: CourseCardProps) {
<LanguageTags>
{course?.tags
?.filter((t) => t.types?.includes("language"))
.filter((t) => allowedLanguages.includes(t.id))
.map((tag) => (
<LanguageTag
key={tag.id}
Expand Down
Loading