Skip to content

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.

fix tab order; fix imports

Sara Vieirad6bb48c97578
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/image-upload.tsx b/apps/designer/app/designer/features/sidebar-left/panels/image-upload.tsx
index e1a016dc45..e94fdeadb2 100644
--- a/apps/designer/app/designer/features/sidebar-left/panels/image-upload.tsx
+++ b/apps/designer/app/designer/features/sidebar-left/panels/image-upload.tsx
@@ -1,14 +1,20 @@
import { ImageIcon } from "~/shared/icons";
import { Button, Flex, Grid, Heading } from "~/shared/design-system";
-import { useRef } from "react";
+import React, { useRef } from "react";
import { Form } from "@remix-run/react";
import { Asset } from "@prisma/client";
import { Image } from "~/shared/design-system/components/image";
export const TabContent = ({ assets }: { assets: Array<Asset> }) => {
- const inputRef = useRef<HTMLInputElement>();
- const formRef = useRef<HTMLFormElement>();
- console.log(assets);
+ const inputRef = useRef<HTMLInputElement | null>(null);
+ const submitButtonRef = useRef<HTMLButtonElement | null>(null);
+
+ const onChange = () => {
+ if (submitButtonRef.current) {
+ submitButtonRef.current.click();
+ }
+ };
+
return (
<Flex gap="3" direction="column" css={{ padding: "$1" }}>
<Flex
@@ -17,13 +23,18 @@ export const TabContent = ({ assets }: { assets: Array<Asset> }) => {
}}
>
<Heading>Assets</Heading>
- <Form ref={formRef} method="post" encType="multipart/form-data">
+ <Form method="post" encType="multipart/form-data">
<input
accept="image/*"
type="file"
name="image"
ref={inputRef}
- onChange={() => formRef.current && formRef.current.submit()}
+ onChange={onChange}
+ style={{ display: "none" }}
+ />
+ <button
+ ref={submitButtonRef}
+ type="submit"
style={{ display: "none" }}
/>
<Button onClick={() => inputRef?.current && inputRef.current.click()}>
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/index.ts b/apps/designer/app/designer/features/sidebar-left/panels/index.ts
index 83a3e7fda8..0136118cfd 100644
--- a/apps/designer/app/designer/features/sidebar-left/panels/index.ts
+++ b/apps/designer/app/designer/features/sidebar-left/panels/index.ts
@@ -1,3 +1,5 @@
-export * as components from "./components";
-export * as tree from "./tree";
-export * as imageUpload from "./image-upload";
+import * as components from "./components";
+import * as tree from "./tree";
+import * as imageUpload from "./image-upload";
+
+export const panels = { components, tree, imageUpload };
diff --git a/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx b/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx
index 49f860fe56..57269236ec 100644
--- a/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx
+++ b/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx
@@ -8,9 +8,10 @@ import {
SidebarTabsTrigger,
} from "~/shared/design-system";
import { useSelectedInstanceData } from "../../shared/nano-states";
-import * as panels from "./panels";
+import { panels } from "./panels";
import type { TabName } from "./types";
import { Asset } from "@prisma/client";
+import { isFeatureEnabled } from "~/shared/feature-flags";
const sidebarTabsContentStyle = {
position: "absolute",
@@ -61,11 +62,17 @@ export const SidebarLeft = ({
[onDragChange]
);
+ const panelsToMap = (
+ isFeatureEnabled("assets")
+ ? Object.keys(panels)
+ : Object.keys(panels).filter((panel) => panel !== "imageUpload")
+ ) as Array<TabName>;
+
return (
<Box css={{ position: "relative", zIndex: 1 }}>
<SidebarTabs activationMode="manual" value={activeTab}>
<SidebarTabsList>
- {(Object.keys(panels) as Array<TabName>).map((tabName: TabName) => (
+ {panelsToMap.map((tabName: TabName) => (
<SidebarTabsTrigger
aria-label={tabName}
key={tabName}
diff --git a/apps/designer/app/env.server.ts b/apps/designer/app/env.server.ts
index 7040eecefb..47aacbc299 100644
--- a/apps/designer/app/env.server.ts
+++ b/apps/designer/app/env.server.ts
@@ -4,7 +4,7 @@ const env = {
SENTRY_DSN: process.env.SENTRY_DSN,
VERCEL_ENV: process.env.VERCEL_ENV,
DEBUG: process.env.DEBUG,
- FEATURE: process.env.FEATURE,
+ FEATURES: process.env.FEATURES,
} as const;
export default env;
diff --git a/apps/designer/app/routes/designer/$id.tsx b/apps/designer/app/routes/designer/$id.tsx
index 0e5bf97c8c..061c1e61ec 100644
--- a/apps/designer/app/routes/designer/$id.tsx
+++ b/apps/designer/app/routes/designer/$id.tsx
@@ -10,6 +10,7 @@ import { Designer, links } from "~/designer";
import * as db from "~/shared/db";
import config from "~/config";
import env from "~/env.server";
+import { Asset } from "@prisma/client";
export { links };
export const loader: LoaderFunction = async ({ params }) => {
@@ -27,23 +28,29 @@ const directory = "./public/uploads";
type Data = {
config: typeof config;
project: Project;
+ assets: Asset[];
};
type Error = {
errors: "string";
};
+type ImageUpload = {
+ type: string;
+ name: string;
+};
+
export const action: ActionFunction = async ({ request, params }) => {
if (params.id === undefined) throw new Error("Project id undefined");
const formData = await unstable_parseMultipartFormData(
request,
unstable_createFileUploadHandler({
- maxPartSize: 5_000_000,
+ maxPartSize: 10_000_000,
directory,
file: ({ filename }) => filename,
})
);
- const imageInfo = formData.get("image");
+ const imageInfo = formData.get("image") as ImageUpload;
if (imageInfo) {
const data = {
type: imageInfo.type,
diff --git a/apps/designer/app/shared/db/assets.server.ts b/apps/designer/app/shared/db/assets.server.ts
index 79373c0026..92ddc1739d 100644
--- a/apps/designer/app/shared/db/assets.server.ts
+++ b/apps/designer/app/shared/db/assets.server.ts
@@ -1,4 +1,4 @@
-import { type Project } from "@webstudio-is/sdk";
+import { type Project } from "@webstudio-is/react-sdk";
import { prisma } from "./prisma.server";
export const loadByProject = async (projectId?: Project["id"]) => {
diff --git a/apps/designer/app/shared/feature-flags/feature.ts b/apps/designer/app/shared/feature-flags/feature.ts
index 185e07aabb..00b1c0aff7 100644
--- a/apps/designer/app/shared/feature-flags/feature.ts
+++ b/apps/designer/app/shared/feature-flags/feature.ts
@@ -9,7 +9,7 @@ const parse = (flags?: string | null): Array<Name> =>
const readLocal = (): Array<Name> => {
try {
- const flags = localStorage.getItem("feature");
+ const flags = localStorage.getItem("features");
return parse(flags);
} catch (_error) {
// Not having feature in localStorage or not having localStorage implemented, both should not throw.
@@ -21,12 +21,12 @@ const readLocal = (): Array<Name> => {
* Returns true/false if the feature is turned on.
* A feature can be turned on:
* - by default directly in ./flags
- * - by providing an environment variable server-side (locally or on the server): FEATURE="something1, something2" yarn dev
- * - by setting it in the browser console: localStorage.feature = 'something1, something2', browser defined flag will override server-side flag
+ * - by providing an environment variable server-side (locally or on the server): FEATURES="something1, something2" yarn dev
+ * - by setting it in the browser console: localStorage.features = 'something1, something2', browser defined flag will override server-side flag
*/
export const isFeatureEnabled = (name: Name): boolean => {
const defaultValue = flags[name];
- const envValue = parse(env.FEATURE).includes(name);
+ const envValue = parse(env.FEATURES).includes(name);
const localValue = readLocal().includes(name);
// Any source can enable feature, first `true` value will result in enabling a feature.
// This also means you can't disable a feature if its already enabled in default value.
diff --git a/apps/designer/app/shared/feature-flags/flags.ts b/apps/designer/app/shared/feature-flags/flags.ts
index 015d18540b..56e8f1d294 100644
--- a/apps/designer/app/shared/feature-flags/flags.ts
+++ b/apps/designer/app/shared/feature-flags/flags.ts
@@ -1,3 +1,2 @@
-export const theme = false;
export const assets = false;
export const example = false;
diff --git a/apps/designer/prisma/migrations/20220715192633_add_alt/migration.sql b/apps/designer/prisma/migrations/20220715192633_add_alt/migration.sql
new file mode 100644
index 0000000000..86541afa67
--- /dev/null
+++ b/apps/designer/prisma/migrations/20220715192633_add_alt/migration.sql
@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE "Asset" ADD COLUMN "alt" TEXT;