Skip to content

Commit

Permalink
Merge branch 'main' into bmo/add-github-settings-page
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Feb 8, 2024
2 parents b64be37 + f6db0d2 commit c743f29
Show file tree
Hide file tree
Showing 45 changed files with 1,014 additions and 1,556 deletions.
9 changes: 9 additions & 0 deletions messages/git-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Git: Error

An error occurred while syncing models to Prismic from a Git repository.

### How to fix the issue

Sync the project again by committing to the repository.

If the issue is not resolved, please check the [Prismic Help Center](https://prismic.io/docs/help-center).
26 changes: 26 additions & 0 deletions messages/git-invalid-slice-machine-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Git: Invalid Slice Machine config

The Git repository's Slice Machine configuration file (`slicemachine.config.json`) was not valid.

Any of the following issues could cause this error:

- Missing required properties, such as `repositoryName` and `adapter`.
- Invalid values given to configuration properties.
- Invalid JSON with incorrect syntax.

## How to fix the issue

Update the project's Slice Machine configuration file, fixing any syntax errors or incorrect properties.

A basic Slice Machine configuration file looks like this:

```json
// slicemachine.config.json

{
"repositoryName": "example-prismic-repo",
"adapter": "@slicemachine/adapter-next",
"libraries": ["./src/slices"],
"localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
}
```
12 changes: 12 additions & 0 deletions messages/git-unauthorized-github.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Git: Unauthorized GitHub access

The GitHub app tried to make a request to GitHub, but failed due to unauthorized access.

This error can occur when your GitHub access token expires. Note that GitHub access tokens are managed for you by installing the Prismic GitHub app and is not something you need to manage manually.

## How to fix the issue

If the error occurs continuously, try the following steps:

1. On GitHub, uninstall the Prismic GitHub app.
2. In Slice Machine, navigate to the Settings page and re-install the Prismic GitHub app.
19 changes: 19 additions & 0 deletions messages/git-unauthorized-prismic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Git: Unauthorized Prismic access

The GitHub app tried to make a request to Prismic, but failed due to unauthorized access.

This error can occur when syncing model changes to Prismic from GitHub with an invalid Prismic Write API token.

## How to fix the issue

Re-connect the Prismic and GitHub repositories, ensuring the Write API token is active and correct:

1. In Slice Machine's Settings page, disconnect the connected GitHub repository.
1. Re-connect the GitHub repository.
1. When asked for a Write API token, provide a valid token.

Tokens can be created following these steps:

1. In the Prismic repository, navigate to the Settings page.
1. Select **API & Security** in the sidebar and the **Write APIs** tab at the top of the page.
1. Create and copy a new Write API token or copy an existing token.
30 changes: 30 additions & 0 deletions messages/git-unsupported-adapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Git: Unsupported adapter

The Slice Machine project uses an adapter that is not supported in the GitHub app.

The following adapters are supported:

- [`@slicemachine/adapter-next`](https://github.com/prismicio/slice-machine/tree/main/packages/adapter-next#readme): Next.js projects.
- [`@slicemachine/adapter-nuxt`](https://github.com/prismicio/slice-machine/tree/main/packages/adapter-nuxt#readme): Nuxt projects.
- [`@slicemachine/adapter-sveltekit`](https://github.com/prismicio/slice-machine/tree/main/packages/adapter-sveltekit#readme): SvelteKit projects.

### How to fix the issue

Use a supported adapter.

You can verify which adapter your project uses by checking the `adapter` property in your project's `slicemachine.config.json`.

A basic Slice Machine configuration file looks like this:

```jsonc
// slicemachine.config.json

{
"repositoryName": "example-prismic-repo",
"adapter": "@slicemachine/adapter-next",
"libraries": ["./src/slices"],
"localSliceSimulatorURL": "http://localhost:3000/slice-simulator"
}
```

If you would like us to support your adapter, please [open a feature request](https://github.com/prismicio/slice-machine/issues/new/choose).
16 changes: 9 additions & 7 deletions packages/init/src/SliceMachineInitProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ export class SliceMachineInitProcess {
);

try {
try {
await setupSentry();
} catch (error) {
// noop - We don't want to stop the user from using Slice Machine
// because of failed tracking set up. We probably couldn't determine the
// Sentry environment.
}
if (this.options.starter) {
await this.copyStarter();
} else if (this.options.directoryName) {
Expand All @@ -133,17 +140,12 @@ export class SliceMachineInitProcess {
)}\n`,
);
}

await this.manager.telemetry.initTelemetry({
appName: pkg.name,
appVersion: pkg.version,
});
try {
await setupSentry();
} catch (error) {
// noop - We don't want to stop the user from using Slice Machine
// because of failed tracking set up. We probably couldn't determine the
// Sentry environment.
}

await this.manager.telemetry.track({
event: "command:init:start",
repository: this.options.repository,
Expand Down
14 changes: 8 additions & 6 deletions packages/manager/src/managers/telemetry/TelemetryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class TelemetryManager extends BaseManager {
};

if (isTelemetryEnabled) {
await this.initExperiment();
this.initExperiment();
}

this._anonymousID = randomUUID();
Expand Down Expand Up @@ -272,15 +272,17 @@ export class TelemetryManager extends BaseManager {
async checkIsTelemetryEnabled(): Promise<boolean> {
let root: string;
try {
root = await this.project.getRoot();
root = await this.project
.getRoot()
.catch(() => this.project.suggestRoot());

return readPrismicrc(root).telemetry !== false;
} catch {
root = await this.project.suggestRoot();
return true;
}

return readPrismicrc(root).telemetry !== false;
}

private async initExperiment(): Promise<void> {
private initExperiment(): void {
try {
this._experiment = Experiment.initializeRemote(API_TOKENS.AmplitudeKey);
} catch (error) {
Expand Down
58 changes: 34 additions & 24 deletions packages/slice-machine/components/DeleteSliceModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,54 @@
import { useState } from "react";
import { MdOutlineDelete } from "react-icons/md";
import { Close, Flex, Heading, Paragraph, Text, useThemeUI } from "theme-ui";

import SliceMachineModal from "@components/SliceMachineModal";
import { useSelector } from "react-redux";
import { SliceMachineStoreType } from "@src/redux/type";
import { isModalOpen } from "@src/modules/modal";
import { ModalKeysEnum } from "@src/modules/modal/types";
import useSliceMachineActions from "@src/modules/useSliceMachineActions";
import { Close, Flex, Heading, Paragraph, Text, useThemeUI } from "theme-ui";
import Card from "@components/Card";
import { MdOutlineDelete } from "react-icons/md";
import { Button } from "@components/Button";
import { LoadingKeysEnum } from "@src/modules/loading/types";
import { isLoading } from "@src/modules/loading";
import { deleteSlice } from "@src/features/slices/actions/deleteSlice";

type DeleteSliceModalProps = {
isOpen: boolean;
libName: string;
sliceId: string;
sliceName: string;
libName: string;
onClose: () => void;
};

export const DeleteSliceModal: React.FunctionComponent<
DeleteSliceModalProps
> = ({ sliceId, sliceName, libName }) => {
const { isSliceModalOpen, isDeletingSlice } = useSelector(
(store: SliceMachineStoreType) => ({
isSliceModalOpen: isModalOpen(store, ModalKeysEnum.DELETE_SLICE),
isDeletingSlice: isLoading(store, LoadingKeysEnum.DELETE_SLICE),
}),
);
> = ({ sliceId, sliceName, libName, isOpen, onClose }) => {
const [isDeleting, setIsDeleting] = useState(false);
const { deleteSliceSuccess } = useSliceMachineActions();
const { theme } = useThemeUI();

const { closeModals, deleteSlice } = useSliceMachineActions();
const onDelete = async () => {
setIsDeleting(true);

const { theme } = useThemeUI();
await deleteSlice({
sliceID: sliceId,
sliceName,
libraryID: libName,
onSuccess: () => {
deleteSliceSuccess(sliceId, libName);
},
});

onClose();
setIsDeleting(false);
};

return (
<SliceMachineModal
isOpen={isSliceModalOpen}
isOpen={isOpen}
shouldCloseOnOverlayClick={true}
style={{
content: {
maxWidth: 612,
},
}}
onRequestClose={closeModals}
onRequestClose={onClose}
>
<Card
bodySx={{
Expand Down Expand Up @@ -79,7 +87,7 @@ export const DeleteSliceModal: React.FunctionComponent<
Delete Slice
</Heading>
</Flex>
<Close type="button" onClick={closeModals} />
<Close type="button" onClick={onClose} />
</Flex>
)}
Footer={() => (
Expand All @@ -96,7 +104,7 @@ export const DeleteSliceModal: React.FunctionComponent<
<Button
label="Cancel"
variant="secondary"
onClick={() => closeModals()}
onClick={onClose}
sx={{
mr: "10px",
fontWeight: "bold",
Expand All @@ -107,9 +115,11 @@ export const DeleteSliceModal: React.FunctionComponent<
<Button
label="Delete"
variant="danger"
isLoading={isDeletingSlice}
isLoading={isDeleting}
sx={{ minHeight: 39, minWidth: 78 }}
onClick={() => deleteSlice(sliceId, sliceName, libName)}
onClick={() => {
void onDelete();
}}
/>
</Flex>
)}
Expand Down
Loading

0 comments on commit c743f29

Please sign in to comment.