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

feat(SlicesTemplates): Add from template button #1123

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion cypress/e2e/user-flows/scenario_slice_association.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ describe.skip("I am an existing SM user (Next) and I want to associate a Slice t
it.skip("Add the Slice to the Custom Type", () => {
cy.visit(`/custom-types/${customTypeId}`);

cy.get("[data-cy=update-slices]").click();
cy.contains("Add").click();
cy.contains("Add from your library").click();
// forcing this because the input itself is invisible and an svg is displayed
cy.get(`[data-cy=check-${sliceId}]`).click({ force: true });
cy.get("[data-cy=update-slices-modal]").submit();
Expand Down
3 changes: 2 additions & 1 deletion cypress/pages/customTypes/customTypeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class CustomTypeBuilder extends BaseBuilder {
}

get updateSliceZoneButton() {
return cy.get("[data-cy=update-slices]");
cy.contains("Add").click();
return cy.contains("Add from your library");
}

get headerCustomTypeName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Button, Box, Switch } from "@prismicio/editor-ui";
import {
Button,
Box,
Switch,
DropdownMenu,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuItem,
Icon,
} from "@prismicio/editor-ui";
import { useEffect, useMemo, useState } from "react";
import { useSelector } from "react-redux";
import { BaseStyles } from "theme-ui";
Expand Down Expand Up @@ -100,6 +109,7 @@ const SliceZone: React.FC<SliceZoneProps> = ({
sliceZone,
tabId,
}) => {
const isSlicesTemplatesSupported = true;
const [formIsOpen, setFormIsOpen] = useState(false);
const [isCreateSliceModalOpen, setIsCreateSliceModalOpen] = useState(false);
const { remoteSlices, libraries, slices } = useSelector(
Expand Down Expand Up @@ -155,20 +165,40 @@ const SliceZone: React.FC<SliceZoneProps> = ({
<ListHeader
actions={
sliceZone ? (
<>
<Button onClick={onCreateNewSlice} startIcon="add">
New slice
</Button>
{availableSlices.length > 0 ? (
<Button
data-cy="update-slices"
onClick={onAddNewSlice}
startIcon="edit"
>
Update Slices
<DropdownMenu>
<DropdownMenuTrigger>
<Button variant="secondary" startIcon="add">
Add
</Button>
) : undefined}
</>
</DropdownMenuTrigger>

<DropdownMenuContent align="end">
<DropdownMenuItem
startIcon={<Icon name="add" />}
onSelect={onCreateNewSlice}
>
Create a new slice
</DropdownMenuItem>

{availableSlices.length > 0 ? (
<DropdownMenuItem
onSelect={onAddNewSlice}
startIcon={<Icon name="folder" />}
>
Add from your library
</DropdownMenuItem>
) : undefined}

{isSlicesTemplatesSupported ? (
<DropdownMenuItem
onSelect={onAddNewSlice}
startIcon={<Icon name="centerFocusWeak" />}
>
Add from template
</DropdownMenuItem>
) : undefined}
</DropdownMenuContent>
</DropdownMenu>
) : undefined
}
toggle={
Expand Down Expand Up @@ -205,6 +235,7 @@ const SliceZone: React.FC<SliceZoneProps> = ({
onAddNewSlice={onAddNewSlice}
onCreateNewSlice={onCreateNewSlice}
projectHasAvailableSlices={availableSlices.length > 0}
isSlicesTemplatesSupported={isSlicesTemplatesSupported}
/>
)
) : undefined}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box } from "@prismicio/editor-ui";
import type { FC } from "react";
import { FC, Suspense } from "react";
import type { DropResult } from "react-beautiful-dnd";
import { useSelector } from "react-redux";
import type { AnyObjectSchema } from "yup";
Expand Down Expand Up @@ -165,17 +165,19 @@ const TabZone: FC<TabZoneProps> = ({
isRepeatableCustomType={customType.repeatable}
/>

<SliceZone
customType={customType}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
tabId={tabId}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
sliceZone={sliceZone}
onRemoveSharedSlice={onRemoveSharedSlice}
onCreateSliceZone={onCreateSliceZone}
onDeleteSliceZone={onDeleteSliceZone}
onSelectSharedSlices={onSelectSharedSlices}
/>
<Suspense>
<SliceZone
customType={customType}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
tabId={tabId}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
sliceZone={sliceZone}
onRemoveSharedSlice={onRemoveSharedSlice}
onCreateSliceZone={onCreateSliceZone}
onDeleteSliceZone={onDeleteSliceZone}
onSelectSharedSlices={onSelectSharedSlices}
/>
</Suspense>
</Box>
);
};
Expand Down
10 changes: 5 additions & 5 deletions packages/slice-machine/lib/builders/common/Zone/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button } from "@prismicio/editor-ui";
import { Button, ButtonGroup } from "@prismicio/editor-ui";
import { array, arrayOf, bool, func, object, shape, string } from "prop-types";
import { useState } from "react";
import { FaCode, FaPlus } from "react-icons/fa";
Expand Down Expand Up @@ -80,7 +80,7 @@ const Zone = ({
actions={
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
fields.length > 0 ? (
<>
<ButtonGroup size="medium" variant="secondary">
<Button onClick={() => setShowHints(!showHints)}>
{showHints ? "Hide" : "Show"} code snippets
</Button>
Expand All @@ -94,7 +94,7 @@ const Zone = ({
>
Add a new Field
</Button>
</>
</ButtonGroup>
) : undefined
}
>
Expand All @@ -107,7 +107,7 @@ const Zone = ({
Actions={
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
fields.length > 0 ? (
<>
<ButtonGroup size="medium" variant="secondary">
<ThemeUIButton
variant="buttons.lightSmall"
onClick={() => setShowHints(!showHints)}
Expand Down Expand Up @@ -139,7 +139,7 @@ const Zone = ({
/>
Add a new Field
</ThemeUIButton>
</>
</ButtonGroup>
) : null
}
/>
Expand Down
2 changes: 0 additions & 2 deletions packages/slice-machine/src/components/List/List.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ export const header = style([
},
},
]);

export const headerActions = sprinkles({ flexGrow: 1, justifyContent: "end" });
10 changes: 3 additions & 7 deletions packages/slice-machine/src/components/List/List.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ButtonGroup, Text } from "@prismicio/editor-ui";
import { Box, Text } from "@prismicio/editor-ui";
import type { FC, PropsWithChildren, ReactNode } from "react";

import * as styles from "./List.css";
Expand All @@ -23,12 +23,8 @@ export const ListHeader: FC<ListHeaderProps> = ({
{children}
</Text>
{toggle}
<ButtonGroup
className={styles.headerActions}
size="medium"
variant="secondary"
>
<Box flexGrow={1} justifyContent="end">
{actions}
</ButtonGroup>
</Box>
</header>
);
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export type SliceZoneBlankSlateProps = {
onAddNewSlice: () => void;
onCreateNewSlice: () => void;
projectHasAvailableSlices: boolean;
isSlicesTemplatesSupported: boolean;
};

export const SliceZoneBlankSlate: FC<SliceZoneBlankSlateProps> = ({
onCreateNewSlice,
onAddNewSlice,
projectHasAvailableSlices,
isSlicesTemplatesSupported,
}) => {
return (
<Box justifyContent="center">
Expand All @@ -32,11 +34,16 @@ export const SliceZoneBlankSlate: FC<SliceZoneBlankSlateProps> = ({
</BlankSlateDescription>
<BlankSlateActions>
<Button startIcon="add" onClick={onCreateNewSlice}>
New slice
Create a new slice
</Button>
{projectHasAvailableSlices && (
<Button startIcon="edit" onClick={onAddNewSlice}>
Update Slices
<Button startIcon="folder" onClick={onAddNewSlice}>
Add from your library
</Button>
)}
{isSlicesTemplatesSupported && (
<Button startIcon="centerFocusWeak" onClick={onAddNewSlice}>
Add from template
</Button>
)}
</BlankSlateActions>
Expand Down
Loading
Loading