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

Merge branch 'main' into feature/add-page-improvements #377

Merged
merged 21 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 0 additions & 6 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ module.exports = {
"testing-library/prefer-screen-queries": "off",
},
},
{
files: ["**/modules/*.tsx"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
},
},
{
files: ["**/*.js"],
rules: {
Expand Down
4 changes: 1 addition & 3 deletions .github/setup-acceptance/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ runs:
using: composite
steps:
- uses: ./.github/setup-ci
- run: |
npm run build -w=packages/studio-plugin
npm run build -w=packages/studio
- run: npm run build
shell: bash
- uses: actions/cache@v3
with:
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Run Tests
on: workflow_call

jobs:
studio:
studio-ui:
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
Expand All @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: ./.github/setup-ci
- run: npm run build -w=packages/studio-plugin
- run: npm test -w=packages/studio -- --coverage=false
- run: npm test -w=packages/studio-ui -- --coverage=false

studio_plugin:
strategy:
Expand All @@ -32,4 +32,6 @@ jobs:
- uses: actions/checkout@v3
- uses: ./.github/setup-ci
- run: npm run build
- run: npm run build-test-site -w=apps/test-site
- run: npm run typecheck-jest
- run: npm run size-limit -w=packages/studio-ui
3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
**/coverage
**/lib
packages/studio-plugin/tests/__fixtures__/PageFile/noReturnParenthesesPage.tsx
packages/studio-plugin/tests/__fixtures__/PageFile/repeaterPage.tsx
packages/studio-plugin/tests/__fixtures__/ComponentTreeParser/noReturnParentheses.tsx
packages/studio-plugin/tests/__fixtures__/StudioConfigs/malformed/studio.config.js
packages/studio/src/tailwind-full.css
.github
Expand Down
22 changes: 1 addition & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Now that you have a page, you probably want to do some things with it. Specifica

![enter image description here](https://yext-studio-images.s3.amazonaws.com/Screen+Shot+2023-02-02+at+9.18.10+AM.png)

These are the various Components that can be added to your page. For now, you can ignore Layouts and Modules. Those will be described later. Once you select a Component, such as `Banner`, it will appear in the middle preview pane and on the left-hand side under `Layers`:
These are the various Components that can be added to your page. For now, you can ignore Layouts which will be described later. Once you select a Component, such as `Banner`, it will appear in the middle preview pane and on the left-hand side under `Layers`:

![enter image description here](https://yext-studio-images.s3.amazonaws.com/Screen+Shot+2023-02-03+at+9.41.51+AM.png)

Expand Down Expand Up @@ -116,26 +116,6 @@ When the new Component is added to a page, the `Properties` tab on the left-hand

We've already added a few custom Components to the starter for you. One is a Banner, to prominently display an Entity's address. We also added an Entity Result Card and CTA in case you want to add Search functionality. You can use these Components as a guide when writing your own.

## Reuse through Modules

Users may find that they use a certain combination of Components often across pages. For example, they may often pair a Search Bar Component with a Results Component. Repeating this combination over and over, for each page is tedious. That's where Studio Modules come in. A Module represents a named combination of Components. They can be added to a Page just like a single Component.

### Creating a Module

Creating a Module is simple and can be done entirely within Studio. No Developer intervention is needed! To start, you will need to add a Layout. This is done by clicking the same Icon you did for adding a Component:

![enter image description here](https://yext-studio-images.s3.amazonaws.com/Screen+Shot+2023-02-02+at+12.38.01+PM.png)

A Layout groups a set of Studio Components. Once the Layout is in place on the page, add the Components that you want in the Layout. The Components will initially be siblings of the Layout. In the `Layers` pane, you will need to drag the Components under Layout.

![enter image description here](https://yext-studio-images.s3.amazonaws.com/Screen+Shot+2023-02-02+at+1.07.06+PM.png)

Once the Layout has all the necessary Components, click it and you will see a `Create Module` button appear:

![enter image description here](https://yext-studio-images.s3.amazonaws.com/Screen+Shot+2023-02-02+at+1.00.17+PM.png)

The button will open a modal that prompts you to name your Module. The Module is then available for use on any page! The TSX file for the Module will be under `src/modules` in the repo.

## Site Settings

Often, you will want to have attributes that are accessible to all pages within a Site. In Classic Pages, these were known as Site Attributes. In the new Sites system, we usually recommend adding these attributes to a Site Entity. Studio provides an additional mechanism for supplying these values: the `src/siteSettings.ts` file. We cannot rely exclusively on a Site Entity because Studio can be used outside of PagesJS. The `siteSettings.ts` file is initially setup by the Developer:
Expand Down
2 changes: 1 addition & 1 deletion apps/test-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dev": "studio",
"localData": "yext pages generate-test-data -a",
"start": "craco start",
"build": "craco build"
"build-test-site": "craco build"
},
"browserslist": {
"production": [
Expand Down
13 changes: 13 additions & 0 deletions apps/test-site/src/layouts/LocationLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Header from "../components/Header";

function LocationLayout() {
return (
<Header
title="Yext"
logo="https://a.mktgcdn.com/p/R9FjcYjRNA5dAespqgHFLMvu2m18-E5Apnb3KON0oJY/300x300.png"
backgroundColor="#BAD8FD"
/>
);
}

export default LocationLayout;
3 changes: 0 additions & 3 deletions apps/test-site/src/templates/UniversalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ export default function UniversalPage({ document }: TemplateProps) {
<>
<FixedText />
<Cta label="[LABEL]" link="[URL]" linkType="[LINK TYPE]" />
{document.services.map((item, index) => (
<Banner title={`${item}!`} key={index} />
))}
<Container>
<Button />
</Container>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 0 additions & 17 deletions e2e-tests/src/modules/ContainerWithButtons.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions e2e-tests/tests/add-element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const expectedPage = fs.readFileSync(
"utf-8"
);

studioTest("can add a Footer component", async ({ page, studioPage }) => {
studioTest("can add a Footer component", async ({ studioPage }) => {
await studioPage.switchPage("LocationPage");
await studioPage.addElement("Footer", "Components");
const previews = studioPage.preview.getByText("© 2023 Yext");
await expect(previews).toHaveCount(1);
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
await studioPage.saveButton.click();
const pagePath = studioPage.getPagePath("LocationPage");
await expect(pagePath).toHaveContents(expectedPage);
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
});
4 changes: 2 additions & 2 deletions e2e-tests/tests/add-entity-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ studioTest("can add an entity page", async ({ page, studioPage }) => {
// the store with account content
await studioPage.addEntityPage("EntityPage", {}, "entity-page");
await expect(pageInTree).toHaveCount(1);
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
await studioPage.saveButton.click();
const expectedPagePath = studioPage.getPagePath("EntityPage");
await expect(expectedPagePath).toHaveContents(expectedPage);
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
});
4 changes: 2 additions & 2 deletions e2e-tests/tests/add-static-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ studioTest("can add a static page", async ({ page, studioPage }) => {
await expect(pageInTree).toHaveCount(0);
await studioPage.addStaticPage("NewStaticPage", "index.html");
await expect(pageInTree).toHaveCount(1);
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
await studioPage.saveButton.click();
const pagePath = studioPage.getPagePath("NewStaticPage");
await expect(pagePath).toHaveContents(expectedPage);
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
});
4 changes: 2 additions & 2 deletions e2e-tests/tests/custom-tailwind.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ studioTest(
const builtInTailwindClasses =
"text-teal-300 line-through shadow-lg shadow-cyan-500/50";
await classNameInput.type(safelistedClasses + builtInTailwindClasses);
await expect(studioPage.preview.locator("body")).toHaveScreenshot();
await studioPage.takePreviewScreenshotAfterImgRender();
}
);

Expand All @@ -39,7 +39,7 @@ studioTest("TailwindClass prop editor", async ({ studioPage, page }) => {
await expect(editorSidebar).toHaveScreenshot();
await editorSidebar.getByText("bg-primary").click();
await expect(editorSidebar).toHaveScreenshot();
await expect(studioPage.preview.locator("body")).toHaveScreenshot();
await studioPage.takePreviewScreenshotAfterImgRender();
await studioPage.saveButton.click();
const pagePath = studioPage.getPagePath("BasicPage");
const hasExpectedPageContents = fs
Expand Down
8 changes: 4 additions & 4 deletions e2e-tests/tests/deploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ studioTest.use({
createRemote: true,
});

studioTest("can deploy changes", async ({ page, studioPage }) => {
studioTest("can deploy changes", async ({ studioPage }) => {
const gitOps = studioPage.gitOps;
const startingRef = await gitOps.getCurrentRef();
await studioPage.addElement("Container", "Layouts");
await expect(page).toHaveScreenshot();
await studioPage.addElement("Container", "Containers");
await studioPage.takePageScreenshotAfterImgRender();

const numCommitsBeforeDeploy = await gitOps.getNumCommitsFromRef(startingRef);
expect(numCommitsBeforeDeploy).toEqual(0);
await studioPage.deployButton.click();

await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
const numCommitsMade = await gitOps.getNumCommitsFromRef(startingRef);
expect(numCommitsMade).toEqual(1);
const commitMsg = await gitOps.getCommitMessage();
Expand Down
9 changes: 4 additions & 5 deletions e2e-tests/tests/error-component-preview.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { studioTest } from "./infra/studioTest.js";
import { expect } from "@playwright/test";

studioTest("components with parsing errors", async ({ page, studioPage }) => {
studioTest("components with parsing errors", async ({ studioPage }) => {
await studioPage.switchPage("ErrorComponentPreviews");
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();

await studioPage.preview
.getByText(
"We will still try our best to render this component even with a parsing error."
)
.first()
.hover();
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();

await studioPage.setActiveComponent("ErrorComponent");
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
});
5 changes: 2 additions & 3 deletions e2e-tests/tests/field-picker-dropdown.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { expect } from "@playwright/test";
import { studioTest } from "./infra/studioTest.js";

studioTest("renders field picker dropdown", async ({ page, studioPage }) => {
await studioPage.addElement("Button", "Components");
await studioPage.setActiveComponent("Button");
await page.getByLabel("Toggle field picker").click();
await page.getByText("Meta").click();
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
await page.setViewportSize({ width: 1000, height: 720 });
await page.getByText("Meta").hover();
await page.mouse.wheel(200, 0);
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
});
2 changes: 1 addition & 1 deletion e2e-tests/tests/fix-error-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ studioTest("can fix an error page", async ({ page, studioPage }) => {
fs.writeFileSync(pagePath, errorPageScript);
await page.getByRole("button", { name: "ErrorPage", exact: true }).click();
await expect(studioPage.saveButton.button).toBeDisabled();
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
});
4 changes: 2 additions & 2 deletions e2e-tests/tests/hmr/update-component-body.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ studioTest(

await studioPage.addElement("Button", "Components", false);
await expect(updatedButtonPreviews).toHaveCount(0);
await expect(studioPage.preview.locator("body")).toHaveScreenshot();
await studioPage.takePreviewScreenshotAfterImgRender();

const buttonPath = studioPage.getComponentPath("Button");
fs.writeFileSync(buttonPath, updatedComponent);
// Wait for the HMR to complete
await page.waitForResponse(/Button\.tsx/, { timeout: 5000 });
await expect(updatedButtonPreviews).toHaveCount(1);
await expect(studioPage.preview.locator("body")).toHaveScreenshot();
await studioPage.takePreviewScreenshotAfterImgRender();
}
);
10 changes: 5 additions & 5 deletions e2e-tests/tests/hmr/update-component-initial-props.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ studioTest(

await studioPage.addElement("Button", "Components");
await expect(buttonPreviews).toHaveCount(1);
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();

expect(
await studioPage.getStringPropValue("className", "Button", 0)
).toEqual("px-4 py-2 text-lg border-4 border-green-500");
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();

const buttonPath = studioPage.getComponentPath("Button");
fs.writeFileSync(buttonPath, updatedComponent);
Expand All @@ -33,16 +33,16 @@ studioTest(

await studioPage.addElement("Button", "Components");
await expect(buttonPreviews).toHaveCount(2);
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();

expect(
await studioPage.getStringPropValue("className", "Button", 1)
).toEqual("px-4");
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();

await studioPage.saveButton.click();
const pagePath = studioPage.getPagePath("BasicPage");
await expect(pagePath).toHaveContents(expectedPage);
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
}
);
4 changes: 2 additions & 2 deletions e2e-tests/tests/hmr/update-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const updatedPage = fs.readFileSync(

studioTest(
"can update page file and see changes in UI via HMR",
async ({ page, studioPage }) => {
async ({ studioPage }) => {
const containerPreviews = studioPage.preview.getByText("I'm a container:");
await expect(containerPreviews).toHaveCount(1);
const buttonPreviews = studioPage.preview.getByText("Press me!");
Expand All @@ -19,6 +19,6 @@ studioTest(
await expect(containerPreviews).toHaveCount(0);
await expect(buttonPreviews).toHaveCount(2);
await expect(studioPage.saveButton.button).toBeDisabled();
await expect(page).toHaveScreenshot();
await studioPage.takePageScreenshotAfterImgRender();
}
);
Loading
Loading