Skip to content

Commit

Permalink
Setting frontend url logic as envvar and adding toasts. Turning off f…
Browse files Browse the repository at this point in the history
…rontend testing for now
  • Loading branch information
xaviemirmon committed Apr 22, 2024
1 parent 341c4ca commit 3a307dd
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 58 deletions.
File renamed without changes.
6 changes: 0 additions & 6 deletions backend/starters/development/Packs.toml

This file was deleted.

28 changes: 0 additions & 28 deletions backend/starters/development/drupal-with-mysql.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ use Drupal\Core\Link;
* Implements hook_entity_operation_alter().
*/
function powerstack_page_builder_entity_operation_alter(array &$operations, \Drupal\Core\Entity\EntityInterface $entity) {
if ($entity->getEntityTypeId() === 'node') {
if ($entity->getEntityTypeId() === 'node' && getenv('NEXT_HOST'),) {
// Adding an external operation
$operations['edit'] = [
'title' => t('Edit'),
'url' => \Drupal\Core\Url::fromUri('http://frontend.power-stack.docksal.site/node/' . $entity->id() . '/edit'),
'url' => \Drupal\Core\Url::fromUri(getenv('NEXT_HOST') .'/node/' . $entity->id() . '/edit'),
'attributes' => [
'target' => '_blank', // Optionally open in a new tab.
],
'weight' => 1,
];
$operations['view'] = [
'title' => t('View'),
'url' => \Drupal\Core\Url::fromUri('http://frontend.power-stack.docksal.site/node/' . $entity->id()),
'url' => \Drupal\Core\Url::fromUri(getenv('NEXT_HOST') .'/node/' . $entity->id()),
'attributes' => [
'target' => '_blank', // Optionally open in a new tab.
],
Expand All @@ -35,9 +35,9 @@ function powerstack_page_builder_preprocess_views_view_field(&$variables) {
$view = $variables['view'];
$field = $variables['field'];

if ($view->id() == 'content' && $view->current_display == 'page_1' && $field->field == 'title') {
if ($view->id() == 'content' && $view->current_display == 'page_1' && $field->field == 'title' && getenv('NEXT_HOST')) {
$nid = $variables['row']->nid;
$url = Url::fromUri('http://frontend.power-stack.docksal.site/node/' . $nid, [
$url = Url::fromUri(getenv('NEXT_HOST') . '/node/' . $nid, [
'attributes' => [
'target' => '_blank',
'rel' => 'noopener noreferrer', // For security and performance reasons.
Expand Down
50 changes: 33 additions & 17 deletions frontend/starters/development/app/edit/[...puckPath]/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Puck } from "@measured/puck";
import config from "../../../puck.config";
import { drupal } from "@/lib/drupal";
import { drupalFieldPrefix } from "@powerstack/utils";
import toast from "react-hot-toast";
import Link from "next/link";

export function Client({ path, data }: { path: string; data: Data }) {
const backendUrl = process.env.NEXT_PUBLIC_DRUPAL_HOST
Expand Down Expand Up @@ -53,6 +55,7 @@ export function Client({ path, data }: { path: string; data: Data }) {
return blocks; // Returns the fully resolved array of blocks
} catch (error) {
console.error('Error processing blocks:', error);
toast.error("This didn't work.")
}
}
const blocks = await processBlocks(data)
Expand All @@ -64,24 +67,37 @@ export function Client({ path, data }: { path: string; data: Data }) {
target_revision_id: block.drupal_internal__revision_id
}
}));

const page = await drupal.updateResource("node--page", data.root.props?.uuid, {
data: {
attributes: {
title: data.root?.props?.title || 'Default Title',
},
relationships: {
field_page_builder: {
data: blocksRef
try {
const page = await drupal.updateResource("node--page", data.root.props?.uuid, {
data: {
attributes: {
title: data.root?.props?.title || 'Default Title',
},
relationships: {
field_page_builder: {
data: blocksRef
}
}
}
},
}, {
withAuth: {
clientId: process.env.NEXT_PUBLIC_DRUPAL_CLIENT_ID,
clientSecret: process.env.NEXT_PUBLIC_DRUPAL_CLIENT_SECRET,
},
});
},
}, {
withAuth: {
clientId: process.env.NEXT_PUBLIC_DRUPAL_CLIENT_ID,
clientSecret: process.env.NEXT_PUBLIC_DRUPAL_CLIENT_SECRET,
},
});
toast.success((t) => (
<>
Published! &nbsp;
<Link href={path} target="_blank">
View page
</Link>
</>
))
} catch (error) {
console.error('Error processing page:', error);
toast.error("This didn't work.")
}

}}
/>
);
Expand Down
2 changes: 2 additions & 0 deletions frontend/starters/development/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { MantineProvider, ColorSchemeScript } from "@mantine/core";
import { theme } from "../theme";

import "@/styles/globals.css"
import { Toaster } from "react-hot-toast";

export const metadata: Metadata = {
title: {
Expand Down Expand Up @@ -37,6 +38,7 @@ export default function RootLayout({
</head>
<body>
<DraftAlert />
<Toaster position="bottom-right" />
<MantineProvider theme={theme}>{children}</MantineProvider>
</body>
</html>
Expand Down
5 changes: 3 additions & 2 deletions frontend/starters/development/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
"dependencies": {
"@mantine/core": "^7.7.1",
"@mantine/hooks": "^7.7.1",
"@measured/puck": "0.14.2",
"@measured/puck": "0.14.3-canary.73b83ef",
"@powerstack/utils": "workspace:^",
"@tabler/icons-react": "^3.1.0",
"classnames": "^2.3.2",
"next": "^14",
"next-drupal": "workspace:^",
"postcss-preset-mantine": "^1.13.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-hot-toast": "^2.4.1"
},
"devDependencies": {
"@types/node": "^20.10.0",
Expand Down

0 comments on commit 3a307dd

Please sign in to comment.