Skip to content

Commit

Permalink
Merge branch 'main' into ships/add-stevie
Browse files Browse the repository at this point in the history
  • Loading branch information
ships authored May 20, 2024
2 parents 2f355f4 + 26b2ab8 commit 062b2f8
Show file tree
Hide file tree
Showing 23 changed files with 362 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changesets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: setup node.js
uses: actions/setup-node@v3
with:
node-version: 20
node-version: 20.13.1
- name: install pnpm
run: npm i pnpm@latest -g
- name: setup npmrc
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 20.13.1

- name: Install pnpm
uses: pnpm/action-setup@v3
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.6.0
v20.13.1
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# If you need more help, visit the Dockerfile reference guide at
# https://docs.docker.com/go/dockerfile-reference/

ARG NODE_VERSION=20.6.0
ARG NODE_VERSION=20.13.1

ARG PACKAGE
ARG PORT=3000
Expand Down
27 changes: 27 additions & 0 deletions core/.github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm install -g pnpm && pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
- name: Run Playwright tests
run: pnpm exec playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
7 changes: 7 additions & 0 deletions core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/

playwright/.auth
5 changes: 3 additions & 2 deletions core/app/(user)/communities/AddCommunityDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { AddCommunityForm } from "./AddCommunityForm";

type Props = { user: any };
export const AddCommunity = (props: Props) => {
const [open, setOpen] = React.useState(false);
return (
<Dialog>
<Dialog open={open} onOpenChange={setOpen}>
<TooltipProvider>
<Tooltip>
<TooltipContent> Create a new community</TooltipContent>
Expand All @@ -26,7 +27,7 @@ export const AddCommunity = (props: Props) => {
</Tooltip>
</TooltipProvider>
<DialogContent>
<AddCommunityForm user={props.user} />
<AddCommunityForm user={props.user} setOpen={setOpen} />
</DialogContent>
</Dialog>
);
Expand Down
2 changes: 2 additions & 0 deletions core/app/(user)/communities/AddCommunityForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const communityCreateFormSchema = z.object({

type Props = {
user: any;
setOpen: (open: false) => void;
};

export const AddCommunityForm = (props: Props) => {
Expand All @@ -30,6 +31,7 @@ export const AddCommunityForm = (props: Props) => {
async function onSubmit(data: z.infer<typeof communityCreateFormSchema>) {
const result = await runCreateCommunity({ ...data, user: props.user });
if (didSucceed(result)) {
props.setOpen(false);
toast({
title: "Success",
description: "Community created",
Expand Down
145 changes: 78 additions & 67 deletions core/app/(user)/communities/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import { v4 as uuidv4 } from "uuid";

import { expect } from "utils";

import type { TableCommunity } from "./getCommunityTableColumns";
import type { CommunitiesId } from "~/kysely/types/public/Communities";
import type { PubTypesId } from "~/kysely/types/public/PubTypes";
import type { UsersId } from "~/kysely/types/public/Users";
import type { UserAndMemberships } from "~/lib/types";
import { corePubFields } from "~/actions/corePubFields";
import { db } from "~/kysely/database";
import { CommunitiesId } from "~/kysely/types/public/Communities";
import { PubTypesId } from "~/kysely/types/public/PubTypes";
import { UsersId } from "~/kysely/types/public/Users";
import { defineServerAction } from "~/lib/server/defineServerAction";
import { slugifyString } from "~/lib/string";
import { UserAndMemberships } from "~/lib/types";
import prisma from "~/prisma/db";
import { crocCrocId } from "~/prisma/exampleCommunitySeeds/croccroc";
import { unJournalId } from "~/prisma/exampleCommunitySeeds/unjournal";
import { TableCommunity } from "./getCommunityTableColumns";

export const createCommunity = defineServerAction(async function createCommunity({
user,
Expand Down Expand Up @@ -44,7 +43,7 @@ export const createCommunity = defineServerAction(async function createCommunity
try {
const communityExists = await db
.selectFrom("communities")
.selectAll() // or `selectAll()` etc
.selectAll()
.where("slug", "=", `${slug}`)
.executeTakeFirst();

Expand All @@ -66,7 +65,12 @@ export const createCommunity = defineServerAction(async function createCommunity
.executeTakeFirst()
);
const communityUUID = c.id as CommunitiesId;
const member = await db

const pubTypeId: string = uuidv4();

const corePubSlugs = corePubFields.map((field) => field.slug);

const memberPromise = db
.insertInto("members")
.values({
user_id: user.id as UsersId,
Expand All @@ -76,78 +80,79 @@ export const createCommunity = defineServerAction(async function createCommunity
.returning("id")
.executeTakeFirst();

const pubTypeId: string = uuidv4();

const corePubSlugs = corePubFields.map((field) => field.slug);

const [title] = await db
const pubFieldsPromise = db
.selectFrom("pub_fields")
.selectAll()
.where("pub_fields.slug", "=", corePubSlugs)
.where("pub_fields.slug", "in", corePubSlugs)
.execute();

await db
const [fields, member] = await Promise.all([pubFieldsPromise, memberPromise]);
const pubTypesPromise = db
.with("core_pub_type", (db) =>
db
.insertInto("pub_types")
.values({
id: pubTypeId as PubTypesId,
name: "Title Pub That Only List Titles",
name: "Submission ",
community_id: c.id as CommunitiesId,
})
.returning("id")
)
.insertInto("_PubFieldToPubType")
.values((eb) => ({
A: title.id,
B: eb.selectFrom("core_pub_type").select("id"),
}))
.values((eb) =>
fields.map((field) => ({
A: field.id,
B: eb.selectFrom("core_pub_type").select("id"),
}))
)
.execute();
const stages = (
await db
.insertInto("stages")
.values([
{
community_id: communityUUID,
name: "Submitted",
order: "aa",
},
{
community_id: communityUUID,
name: "Ask Author for Consent",
order: "bb",
},
{
community_id: communityUUID,
name: "To Evaluate",
order: "cc",
},
{
community_id: communityUUID,
name: "Under Evaluation",
order: "dd",
},
{
community_id: communityUUID,
name: "In Production",
order: "ff",
},
{
community_id: communityUUID,
name: "Published",
order: "gg",
},
{
community_id: communityUUID,
name: "Shelved",
order: "hh",
},
])
.returning("id")
.execute()
).map((x) => x.id);

await db
const stagesPromise = db
.insertInto("stages")
.values([
{
community_id: communityUUID,
name: "Submitted",
order: "aa",
},
{
community_id: communityUUID,
name: "Ask Author for Consent",
order: "bb",
},
{
community_id: communityUUID,
name: "To Evaluate",
order: "cc",
},
{
community_id: communityUUID,
name: "Under Evaluation",
order: "dd",
},
{
community_id: communityUUID,
name: "In Production",
order: "ff",
},
{
community_id: communityUUID,
name: "Published",
order: "gg",
},
{
community_id: communityUUID,
name: "Shelved",
order: "hh",
},
])
.returning("id")
.execute();

const [_, stagesReturn] = await Promise.all([pubTypesPromise, stagesPromise]);
const stages = stagesReturn.map((stage) => stage.id);

const permissionPromise = db
.with("new_permission", (db) =>
db
.insertInto("permissions")
Expand Down Expand Up @@ -177,7 +182,7 @@ export const createCommunity = defineServerAction(async function createCommunity
])
.execute();

await db
const moveConstraintPromise = db
.insertInto("move_constraint")
.values([
{
Expand All @@ -204,7 +209,7 @@ export const createCommunity = defineServerAction(async function createCommunity
])
.execute();

await db
const createPubPromise = db
.with("new_pubs", (db) =>
db
.insertInto("pubs")
Expand All @@ -226,11 +231,17 @@ export const createCommunity = defineServerAction(async function createCommunity
.values((eb) => [
{
pub_id: eb.selectFrom("new_pubs").select("new_pubs.id"),
field_id: title.id,
field_id: fields.find((field) => field.slug === "pubpub:title")!.id,
value: '"The Activity of Slugs I. The Induction of Activity by Changing Temperatures"',
},
{
pub_id: eb.selectFrom("new_pubs").select("new_pubs.id"),
field_id: fields.find((field) => field.slug === "pubpub:content")!.id,
value: '"LONG LIVE THE SLUGS"',
},
])
.execute();
await Promise.all([permissionPromise, moveConstraintPromise, createPubPromise]);
}
revalidatePath("/");
} catch (error) {
Expand Down
5 changes: 5 additions & 0 deletions core/app/(user)/communities/getCommunityTableColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import type { ColumnDef } from "@tanstack/react-table";

import Link from "next/link";

import { Avatar, AvatarFallback, AvatarImage } from "ui/avatar";
import { Badge } from "ui/badge";
import { Button } from "ui/button";
Expand Down Expand Up @@ -72,6 +74,9 @@ export const getCommunityTableColumns = ({ user }: { user: UserAndMemberships })
{
header: ({ column }) => <DataTableColumnHeader column={column} title="Slug" />,
accessorKey: "slug",
cell: ({ row }) => (
<Link href={`/c/${row.getValue("slug")}/pubs`}>{row.original.slug}</Link>
),
},
{
header: ({ column }) => <DataTableColumnHeader column={column} title="Created" />,
Expand Down
1 change: 1 addition & 0 deletions core/app/c/[communitySlug]/stages/components/Assign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default function Assign(props: Props) {
size="sm"
variant="outline"
role="combobox"
name="Assign"
aria-expanded={open}
className="w-[150px] justify-between"
>
Expand Down
3 changes: 3 additions & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "0.0.0",
"private": true,
"scripts": {
"playwright:test": "playwright test",
"playwright:ui": "playwright test --ui",
"dev": "next dev -p 3000 --turbo | pino-pretty",
"build": "SKIP_VALIDATION=true next build",
"invite-users": "dotenv -e .env.local -e .env.development tsx scripts/invite.ts",
Expand Down Expand Up @@ -81,6 +83,7 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@playwright/test": "^1.43.1",
"@preconstruct/next": "^4.0.0",
"@pubpub/eslint-config": "workspace:*",
"@pubpub/prettier-config": "workspace:*",
Expand Down
Loading

0 comments on commit 062b2f8

Please sign in to comment.