Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Sort dashboard projects by createdAt (#927)
Oleg Isonencffb6dc07169
diff --git a/apps/designer/app/dashboard/dashboard.stories.tsx b/apps/designer/app/dashboard/dashboard.stories.tsxindex f2d0fb4af0..84104649c2 100644--- a/apps/designer/app/dashboard/dashboard.stories.tsx+++ b/apps/designer/app/dashboard/dashboard.stories.tsx@@ -34,6 +34,7 @@ export const WithProjects: ComponentStory<typeof Dashboard> = () => {const projects = [{id: "0",+ createdAt: new Date().toString(),title: "My Project",domain: "domain.com",userId: null,diff --git a/apps/designer/app/dashboard/dashboard.tsx b/apps/designer/app/dashboard/dashboard.tsxindex 29a0b29d00..5602f7f6c4 100644--- a/apps/designer/app/dashboard/dashboard.tsx+++ b/apps/designer/app/dashboard/dashboard.tsx@@ -1,5 +1,4 @@import { Flex, globalCss, theme } from "@webstudio-is/design-system";-import type { DashboardProject } from "@webstudio-is/prisma-client";import { Header } from "./header";// eslint-disable-next-line import/no-internal-modulesimport interFont from "@fontsource/inter/variable.css";@@ -7,6 +6,7 @@ import interFont from "@fontsource/inter/variable.css";import manropeVariableFont from "@fontsource/manrope/variable.css";import { Projects } from "./projects";import type { User } from "~/shared/db/user.server";+import type { DashboardProject } from "@webstudio-is/dashboard";export const links = () => [{ rel: "stylesheet", href: interFont },diff --git a/apps/designer/app/dashboard/projects/projects.tsx b/apps/designer/app/dashboard/projects/projects.tsxindex b8a7c320e0..466e9f423f 100644--- a/apps/designer/app/dashboard/projects/projects.tsx+++ b/apps/designer/app/dashboard/projects/projects.tsx@@ -1,7 +1,7 @@import { Flex, Text } from "@webstudio-is/design-system";import { EmptyState } from "./empty-state";import { Panel } from "./panel";-import type { DashboardProject } from "@webstudio-is/prisma-client";+import type { DashboardProject } from "@webstudio-is/dashboard";import { ProjectCard } from "./project-card";import { CreateProject } from "./project-dialogs";diff --git a/apps/designer/app/designer/designer.tsx b/apps/designer/app/designer/designer.tsxindex 9f9fc32b62..d51966ce40 100644--- a/apps/designer/app/designer/designer.tsx+++ b/apps/designer/app/designer/designer.tsx@@ -2,8 +2,8 @@ import { useCallback, useEffect, useMemo } from "react";import { type Publish, usePublish, useSubscribe } from "~/shared/pubsub";import {type Pages,- type Project,utils as projectUtils,+ type Project,} from "@webstudio-is/project";import { theme, Box, type CSS, Flex, Grid } from "@webstudio-is/design-system";import { registerContainers, useDesignerStore } from "~/shared/sync";diff --git a/packages/dashboard/src/db/index.ts b/packages/dashboard/src/db/index.tsindex c55f927311..18f7d72b27 100644--- a/packages/dashboard/src/db/index.ts+++ b/packages/dashboard/src/db/index.ts@@ -1 +1,2 @@export * as db from "./projects";+export * from "./schema";diff --git a/packages/dashboard/src/db/projects.ts b/packages/dashboard/src/db/projects.tsindex 16870bcc22..6337c5ec6c 100644--- a/packages/dashboard/src/db/projects.ts+++ b/packages/dashboard/src/db/projects.ts@@ -1,11 +1,22 @@import { prisma } from "@webstudio-is/prisma-client";import type { AppContext } from "@webstudio-is/trpc-interface/server";+import { DashboardProjects } from "./schema";export const findMany = async (userId: string, context: AppContext) => {- return await prisma.dashboardProject.findMany({+ const data = await prisma.dashboardProject.findMany({where: {userId,isDeleted: false,},+ orderBy: [+ {+ createdAt: "desc",+ },+ {+ id: "desc",+ },+ ],});++ return DashboardProjects.parse(data);};diff --git a/packages/dashboard/src/db/schema.ts b/packages/dashboard/src/db/schema.tsnew file mode 100644index 0000000000..2cee5a407b--- /dev/null+++ b/packages/dashboard/src/db/schema.ts@@ -0,0 +1,10 @@+import { Project } from "@webstudio-is/project";+import { z } from "zod";++export const DashboardProject = Project.extend({+ isPublished: z.boolean(),+});+export type DashboardProject = z.infer<typeof DashboardProject>;++export const DashboardProjects = z.array(DashboardProject);+export type DashboardProjects = z.infer<typeof DashboardProjects>;diff --git a/packages/dashboard/src/index.ts b/packages/dashboard/src/index.tsindex 9a367e6e46..18b0f48e1e 100644--- a/packages/dashboard/src/index.ts+++ b/packages/dashboard/src/index.ts@@ -1 +1,2 @@export type { DashboardProjectRouter } from "./trpc";+export * from "./db/schema";diff --git a/packages/prisma-client/prisma/migrations/20230202131409_project-created-at/migration.sql b/packages/prisma-client/prisma/migrations/20230202131409_project-created-at/migration.sqlnew file mode 100644index 0000000000..2e737313ca--- /dev/null+++ b/packages/prisma-client/prisma/migrations/20230202131409_project-created-at/migration.sql@@ -0,0 +1,24 @@+-- AlterTable+ALTER TABLE+ "Project"+ADD+ COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;++-- Drop DashboardProject View+DROP VIEW IF EXISTS "DashboardProject";++-- Update DashboardProject View+CREATE VIEW "DashboardProject" AS+SELECT+ *,+ EXISTS (+ SELECT+ 1+ from+ "Build"+ WHERE+ "Build"."projectId" = "Project".id+ AND "Build"."isProd" = true+ ) AS "isPublished"+FROM+ "Project";\ No newline at end of filediff --git a/packages/prisma-client/prisma/schema.prisma b/packages/prisma-client/prisma/schema.prismaindex a09196e056..1e0b8d22a3 100644--- a/packages/prisma-client/prisma/schema.prisma+++ b/packages/prisma-client/prisma/schema.prisma@@ -53,14 +53,15 @@ model User {}model Project {- id String @id @default(uuid())+ id String @id @default(uuid())+ createdAt DateTime @default(now())title String- domain String @unique- user User? @relation(fields: [userId], references: [id])+ domain String @unique+ user User? @relation(fields: [userId], references: [id])userId String?build Build[]trees Tree[]- isDeleted Boolean @default(false)+ isDeleted Boolean @default(false)}model Build {@@ -117,10 +118,11 @@ model AuthorizationToken {// Dashboardview DashboardProject {- id String @id @default(uuid())+ id String @id @default(uuid())+ createdAt DateTime @default(now())title Stringdomain StringuserId String?- isDeleted Boolean @default(false)+ isDeleted Boolean @default(false)isPublished Boolean}diff --git a/packages/project/src/db/project.ts b/packages/project/src/db/project.tsindex 5fa9ffd86a..cdc43bcf96 100644--- a/packages/project/src/db/project.ts+++ b/packages/project/src/db/project.ts@@ -1,12 +1,13 @@import slugify from "slugify";import { customAlphabet } from "nanoid";-import { prisma, Prisma, Project } from "@webstudio-is/prisma-client";+import { prisma, Prisma } from "@webstudio-is/prisma-client";import * as db from "./index";import {authorizeProject,type AppContext,} from "@webstudio-is/trpc-interface/server";import { v4 as uuid } from "uuid";+import { Project, Projects } from "./schema";const nanoid = customAlphabet("1234567890abcdefghijklmnopqrstuvwxyz");@@ -32,9 +33,11 @@ export const loadById = async (throw new Error("You don't have access to this project");}- return await prisma.project.findUnique({+ const data = await prisma.project.findUnique({where: { id: projectId },});++ return Project.parse(data);};export const loadByDomain = async (@@ -53,7 +56,7 @@ export const loadByDomain = async (// Edge case for webstudiois projectif (projectWithId.domain === "webstudiois") {// Hardcode for now that everyone can duplicate webstudiois project- return projectWithId;+ return Project.parse(projectWithId);}// Otherwise, check if the user has access to the project@@ -62,19 +65,21 @@ export const loadByDomain = async (export const loadManyByCurrentUserId = async (context: AppContext-): Promise<Array<Project>> => {+): Promise<Projects> => {const userId = context.authorization.userId;if (userId === undefined) {throw new Error("The user must be authenticated to list projects");}- return await prisma.project.findMany({+ const data = await prisma.project.findMany({where: {user: {id: userId,},},});++ return Projects.parse(data);};const slugifyOptions = { lower: true, strict: true };@@ -218,7 +223,7 @@ const clone = async (return clonedProject;});- return clonedProject;+ return Project.parse(clonedProject);};export const duplicate = async (projectId: string, context: AppContext) => {diff --git a/packages/project/src/db/schema.ts b/packages/project/src/db/schema.tsindex f91daf00a7..44d2f4fd2e 100644--- a/packages/project/src/db/schema.ts+++ b/packages/project/src/db/schema.ts@@ -1,10 +1,20 @@import { z, type ZodType } from "zod";-import { Project } from "@webstudio-is/prisma-client";import type { Breakpoints } from "@webstudio-is/css-data";import type { Styles, StyleSources } from "@webstudio-is/project-build";import type { Data } from "@webstudio-is/react-sdk";-export type { Project };+export const Project = z.object({+ id: z.string(),+ title: z.string(),+ createdAt: z.date().transform((date) => date.toISOString()),+ userId: z.string().nullable(),+ isDeleted: z.boolean(),+ domain: z.string(),+});+export type Project = z.infer<typeof Project>;++export const Projects = z.array(Project);+export type Projects = z.infer<typeof Projects>;const commonPageFields = {id: z.string(),