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

Improve Add and Edit Page Flows #380

Merged
merged 7 commits into from
Sep 21, 2023
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
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.
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.
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.
2 changes: 2 additions & 0 deletions e2e-tests/src/components/CustomTailwindButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ interface Props {
className?: TailwindClass;
}

export const initialProps: Props = { className: "" };

export default function CustomTailwindButton(props: Props) {
return <button className={props.className}>PachiPachiPachi</button>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ export const config: TemplateConfig = {
stream: {
$id: "studio-stream-id-EntityPage",
localization: { locales: ["en"] },
filter: {
entityTypes: ["entity1"],
savedFilterIds: ["entity2", "entity3"],
},
filter: {},
fields: [],
},
};
Expand Down
9 changes: 3 additions & 6 deletions e2e-tests/tests/add-entity-page.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect } from "@playwright/test";
import { studioTest } from "./infra/studioTest.js";
import { StreamScopeForm } from "./infra/StudioPlaywrightPage.js";
import fs from "fs";

const expectedPage = fs.readFileSync(
Expand All @@ -12,11 +11,9 @@ studioTest("can add an entity page", async ({ page, studioPage }) => {
const pageInTree = page.getByText("EntityPage");
await expect(pageInTree).toHaveCount(0);

const streamScopeForm: StreamScopeForm = {
entityTypes: "entity1",
savedFilterIds: "entity2,entity3",
};
await studioPage.addEntityPage("EntityPage", streamScopeForm, "entity-page");
// TODO: Specify a stream scope once we can supply an API key for populating
// the store with account content
await studioPage.addEntityPage("EntityPage", {}, "entity-page");
await expect(pageInTree).toHaveCount(1);
await studioPage.takePageScreenshotAfterImgRender();
await studioPage.saveButton.click();
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/tests/custom-tailwind.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ studioTest("TailwindClass prop editor", async ({ studioPage, page }) => {
const editorSidebar = page.getByTestId("EditorSidebar");
await expect(editorSidebar).toHaveScreenshot();
const classPicker = editorSidebar.getByRole("button", {
name: "Toggle tailwind class picker",
name: "Toggle pill picker",
});
await classPicker.click();
await expect(editorSidebar).toHaveScreenshot();
Expand Down
166 changes: 165 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion packages/studio-plugin/src/createStudioPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { STUDIO_PROCESS_ARGS_OBJ } from "./constants";
import LocalDataMappingManager from "./LocalDataMappingManager";
import getStudioViteOptions from "./viteconfig/getStudioViteOptions";
import { createDevServer } from "@yext/pages";
import ManagementApiService from "./http/ManagementApiService";

/**
* Handles server-client communication.
Expand Down Expand Up @@ -65,6 +66,12 @@ export default async function createStudioPlugin(
);

await pagesDevPortPromise;

const managementAPIService =
studioConfig.isPagesJSRepo && process.env.YEXT_STUDIO_API_KEY
? new ManagementApiService(process.env.YEXT_STUDIO_API_KEY)
: undefined;

return {
name: "yext-studio-vite-plugin",
config(config) {
Expand Down Expand Up @@ -94,7 +101,8 @@ export default async function createStudioPlugin(
orchestrator,
localDataMappingManager,
pathToUserProjectRoot,
studioConfig.paths
studioConfig.paths,
managementAPIService
),
};
}
Expand Down
2 changes: 2 additions & 0 deletions packages/studio-plugin/src/http/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { EntitiesResponse } from "./Entities";
export { SavedFilterData } from "./SavedFilters";
1 change: 1 addition & 0 deletions packages/studio-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export {
STREAM_LOCALIZATION,
STUDIO_PROCESS_ARGS_OBJ,
} from "./constants";
export * from "./http/types";
2 changes: 1 addition & 1 deletion packages/studio-ui/.size-limit.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = [
{
path: "lib/src/index.js",
limit: "700 kB",
limit: "850 kB",
gzip: false,
},
];
1 change: 1 addition & 0 deletions packages/studio-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-modal": "3.16.1",
"react-select": "^5.7.4",
"react-toastify": "^9.1.1",
"react-tooltip": "^5.18.0",
"tailwind-merge": "^1.8.1",
Expand Down
6 changes: 6 additions & 0 deletions packages/studio-ui/src/components/ActivePagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PropsWithChildren, useMemo } from "react";
import RemovePageButton from "./RemovePageButton";
import { Tooltip } from "react-tooltip";
import PageSettingsButton from "./PageSettingsButton/PageSettingsButton";
import EditStreamScopeButton from "./EditStreamScopeButton";

/**
* ActivePagePanel displays the available pages and allows the user to switch
Expand Down Expand Up @@ -55,6 +56,10 @@ function PageItem({ pageName }: { pageName: string }) {
void updateActivePage(pageName);
}

const isEntityPage = useStudioStore(
(store) => !!store.pages.pages[pageName].pagesJS?.streamScope
);

return (
<ListItem>
<div className="flex items-center overflow-auto">
Expand All @@ -68,6 +73,7 @@ function PageItem({ pageName }: { pageName: string }) {
</button>
</div>
<div className="flex items-center space-x-3">
{isEntityPage && <EditStreamScopeButton pageName={pageName} />}
{isPagesJSRepo && <PageSettingsButton pageName={pageName} />}
<RemovePageButton pageName={pageName} />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StreamScope } from "@yext/studio-plugin";
import { createContext } from "react";
import { createContext, useContext } from "react";

export interface AddPageData {
isStatic: boolean;
Expand All @@ -17,6 +17,13 @@ export interface AddPageContextValue {
actions: AddPageActions;
}

export function useStreamScope() {
const { state, actions } = useContext(AddPageContext);
const { streamScope } = state;
const { setStreamScope } = actions;
return [streamScope, setStreamScope] as const;
}

const AddPageContext = createContext<AddPageContextValue>(
{} as AddPageContextValue
);
Expand Down
Loading