Skip to content

Commit

Permalink
Merge branch 'release' into lagoon-waku
Browse files Browse the repository at this point in the history
  • Loading branch information
pmelab committed Jul 3, 2024
2 parents bb72b96 + 9bac782 commit 499791d
Show file tree
Hide file tree
Showing 51 changed files with 694 additions and 60 deletions.
6 changes: 5 additions & 1 deletion INIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ replace(
process.env.PROJECT_NAME_MACHINE,
);
replace(
['apps/cms/.lagoon.env', 'apps/website/.lagoon.env'],
[
'apps/cms/.lagoon.env',
'apps/website/.lagoon.env',
'apps/preview/.lagoon.env',
],
'PROJECT_NAME=example',
'PROJECT_NAME=' + process.env.PROJECT_NAME_MACHINE,
);
Expand Down
1 change: 1 addition & 0 deletions apps/cms/.lagoon.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PROJECT_NAME=example
PUBLISHER_URL="https://build.${LAGOON_ENVIRONMENT}.${LAGOON_PROJECT}.ch4.amazee.io"
NETLIFY_URL="https://build.${LAGOON_ENVIRONMENT}.${LAGOON_PROJECT}.ch4.amazee.io"
PREVIEW_URL="https://preview.${LAGOON_ENVIRONMENT}.${LAGOON_PROJECT}.ch4.amazee.io"
Expand Down
3 changes: 3 additions & 0 deletions apps/cms/.lagoon.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PUBLISHER_URL="https://${LAGOON_GIT_BRANCH}-${PROJECT_NAME}.build.amazeelabs.dev"
NETLIFY_URL="https://${LAGOON_GIT_BRANCH}-${PROJECT_NAME}.amazeelabs.dev"
PREVIEW_URL="https://${LAGOON_GIT_BRANCH}-${PROJECT_NAME}.preview.amazeelabs.dev"
10 changes: 3 additions & 7 deletions apps/cms/.lagoon.env.prod
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
PROJECT_NAME=example
PUBLISHER_URL="https://example.build.amazeelabs.dev"
NETLIFY_URL="https://example.amazeelabs.dev"
PREVIEW_URL="https://example.preview.amazeelabs.dev"

# Used to set the original client secret.
PUBLISHER_OAUTH2_CLIENT_SECRET=REPLACE_ME
PUBLISHER_URL="https://${PROJECT_NAME}.build.amazeelabs.dev"
NETLIFY_URL="https://${PROJECT_NAME}.amazeelabs.dev"
PREVIEW_URL="https://${PROJECT_NAME}.preview.amazeelabs.dev"
4 changes: 0 additions & 4 deletions apps/cms/.lagoon.env.stage
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
PROJECT_NAME=example
PUBLISHER_URL="https://${LAGOON_GIT_BRANCH}-${PROJECT_NAME}.build.amazeelabs.dev"
NETLIFY_URL="https://${LAGOON_GIT_BRANCH}-${PROJECT_NAME}.amazeelabs.dev"
PREVIEW_URL="https://${LAGOON_GIT_BRANCH}-${PROJECT_NAME}.preview.amazeelabs.dev"

# Used to set the original client secret.
PUBLISHER_OAUTH2_CLIENT_SECRET=REPLACE_ME
3 changes: 2 additions & 1 deletion apps/cms/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
"Autosave preview": "./patches/fetch-entity.patch"
},
"drupal/gutenberg": {
"Gutenberg enabled hook": "https://www.drupal.org/files/issues/2024-05-07/gutenberg_enabled_hook_3445677-2.patch"
"Gutenberg enabled hook": "https://www.drupal.org/files/issues/2024-05-07/gutenberg_enabled_hook_3445677-2.patch",
"Remove !important from sidebar": "./patches/gutenberg_remove-important-sidebar.patch"
}
},
"patchLevel": {
Expand Down
7 changes: 3 additions & 4 deletions apps/cms/config/sync/silverback_autosave.settings.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
_core:
default_config_hash: HaTNbtQe6_A0WF-ZElHNWcv0VK_aqOj5lBEFhAgY85s
interval: 2000
interval: 500
only_on_form_change: false
active_on:
content_entity_forms: true
config_entity_forms: false
notification:
active: true
active: false
message: 'Updating preview...'
delay: 1000
delay: 500
allowed_content_entity_types:
node:
bundles:
Expand Down
3 changes: 1 addition & 2 deletions apps/cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
"prep:database": "./prep-database.sh",
"prep:schema": "pnpm drush silverback-gatsby:schema-export ../../../tests/schema || true",
"fix-premissions": "chmod +w web/sites/default/files/.htaccess && chmod +w web/sites/default/files/private/.htaccess",
"ensure-working-db": "pnpm drush sqlq 'select * from node'",
"drush": "SB_ENVIRONMENT=1 SIMPLETEST_DB=sqlite://localhost/sites/default/files/.sqlite DRUSH_OPTIONS_URI=http://127.0.0.1:8888 vendor/bin/drush",
"silverback": "SB_ENVIRONMENT=1 SIMPLETEST_DB=sqlite://localhost/sites/default/files/.sqlite SB_ADMIN_USER=admin SB_ADMIN_PASS=admin vendor/bin/silverback",
"drupal-install": "SB_SETUP=1 pnpm silverback setup --profile minimal && pnpm content:import && pnpm drush php-eval 'node_access_rebuild();' && rm -rf install-cache.zip && pnpm fix-premissions && pnpm ensure-working-db",
"drupal-install": "SB_SETUP=1 pnpm silverback setup --profile minimal && pnpm content:import && pnpm drush php-eval 'node_access_rebuild();' && rm -rf install-cache.zip && pnpm fix-premissions",
"export-webforms": "pnpm turbo --filter '@custom-tests/e2e' webform-snapshots",
"start": "cd web; SB_ENVIRONMENT=1 SIMPLETEST_DB=sqlite://localhost/sites/default/files/.sqlite DRUSH_OPTIONS_URI=http://127.0.0.1:8888 php -S 0.0.0.0:8888 .ht.router.php # no drush to avoid the drush server timeout",
"dev": "pnpm start",
Expand Down
16 changes: 16 additions & 0 deletions apps/cms/patches/gutenberg_remove-important-sidebar.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/css/claro.css b/css/claro.css
index 720c3a8..9c5ad05 100644
--- a/css/claro.css
+++ b/css/claro.css
@@ -44,8 +44,8 @@

@media screen and (min-width: 85.375rem) {
.interface-complementary-area.edit-post-sidebar {
- width: 380px !important;
+ width: 380px;
}
}

-/*# sourceMappingURL=claro.css.map */
\ No newline at end of file
+/*# sourceMappingURL=claro.css.map */
4 changes: 2 additions & 2 deletions apps/cms/turbo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": ["//"],
"pipeline": {
"tasks": {
"prep": {
"dependsOn": ["prep:schema"]
},
Expand All @@ -27,7 +27,7 @@
"outputs": [
"drush/**",
"vendor/**",
"!**/.git/**",
"!*/**/.git/**",
"web/**",
"!web/modules/custom/**",
"!web/themes/custom/**",
Expand Down
10 changes: 4 additions & 6 deletions apps/decap/src/helpers/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { buildResponsiveImage } from '@amazeelabs/cloudinary-responsive-image';
import { createResolveConfig } from '@amazeelabs/graphql-directives';
import {
AnyOperationId,
ImageSource,
OperationId,
OperationResult,
OperationVariables,
} from '@custom/schema';
Expand Down Expand Up @@ -51,7 +51,7 @@ const responsiveImage: GraphQLFieldResolver<
) as ImageSource;
};

export async function query<TOperation extends OperationId<any, any>>(
export async function query<TOperation extends AnyOperationId>(
operation: TOperation,
rootValue: any,
variables: OperationVariables<TOperation> = {},
Expand Down Expand Up @@ -84,7 +84,7 @@ export async function query<TOperation extends OperationId<any, any>>(
return result.data;
}

export function useQuery<TOperation extends OperationId<any, any>>(
export function useQuery<TOperation extends AnyOperationId>(
operation: TOperation,
rootValue: any,
variables: OperationVariables<TOperation> = {},
Expand Down Expand Up @@ -114,9 +114,7 @@ export function useQuery<TOperation extends OperationId<any, any>>(

export type useQueryType = typeof useQuery;

export function createPreview<
TOperation extends OperationId<{ preview?: any }, any>,
>(
export function createPreview<TOperation extends AnyOperationId>(
query: TOperation,
schema: ZodType<any, ZodTypeDef, unknown>,
Component: React.FC<{
Expand Down
2 changes: 1 addition & 1 deletion apps/decap/turbo.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://turborepo.org/schema.json",
"extends": ["//"],
"pipeline": {
"tasks": {
"prep:vite": {
"dependsOn": ["^prep"],
"inputs": ["src/**", "vite.config.ts", "index.html"],
Expand Down
1 change: 1 addition & 0 deletions apps/preview/.lagoon.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PROJECT_NAME=example
DRUPAL_URL="https://nginx.${LAGOON_ENVIRONMENT}.${LAGOON_PROJECT}.ch4.amazee.io"
2 changes: 1 addition & 1 deletion apps/preview/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare global {
}
}

const updates$ = webSocket({
const updates$ = webSocket<any>({
url: `${window.location.origin.replace('http', 'ws')}/__preview`,
}).pipe(
retry({
Expand Down
2 changes: 1 addition & 1 deletion apps/preview/turbo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": ["//"],
"pipeline": {
"tasks": {
"prep": {
"dependsOn": ["prep:app", "prep:server"]
},
Expand Down
33 changes: 33 additions & 0 deletions apps/website/src/locale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// TODO: straight copy of the same file in the UI package
import { Locale, useLocation } from '@custom/schema';

const locales = Object.values(Locale);
export const defaultLocale: Locale = 'en';

export function isLocale(input: any): input is Locale {
return locales.includes(input);
}

/**
* Extract the current locale from the path prefix.
*/
export function useLocale() {
const [{ pathname }] = useLocation();
const prefix = pathname.split('/')[1];
return isLocale(prefix) ? prefix : defaultLocale;
}

type Localized = { locale: Locale };

/**
* Select the most appropriate of localization from a list of options.
*/
export function useLocalized<T extends Localized>(
options?: Array<T | undefined>,
): T | undefined {
const locale = useLocale();
return (
options?.filter((option) => option?.locale === locale).pop() ||
options?.filter((option) => option?.locale === defaultLocale).pop()
);
}
2 changes: 1 addition & 1 deletion apps/website/turbo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": ["//"],
"pipeline": {
"tasks": {
"dev": {
"persistent": true,
"dependsOn": ["prep", "^prep"]
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"node": "^18.19.0",
"pnpm": "8.6.12"
},
"packageManager": "[email protected]",
"scripts": {
"postinstall": "husky install || true",
"commit": "git-cz",
Expand All @@ -16,11 +17,11 @@
"test:format:root": "pnpm prettier --ignore-unknown '**/**'",
"test:format:workspaces": "pnpm --workspace-concurrency=1 -r exec prettier --ignore-unknown '**/**'",
"turbo:local": "if [ -z $CI ]; then echo $(date)$RANDOM > apps/cms/turbo-seed.txt; fi",
"turbo:test": "pnpm turbo:local && pnpm tb test:unit --no-daemon --go-fallback --output-logs=new-only && pnpm tb test:integration --no-daemon --go-fallback --output-logs=new-only --concurrency=1",
"turbo:test:force": "pnpm tb test:unit --no-daemon --go-fallback --output-logs=new-only --force && pnpm tb test:integration --no-daemon --go-fallback --output-logs=new-only --concurrency=1 --force",
"turbo:test:quick": "pnpm turbo:local && pnpm tb test:unit --no-daemon --go-fallback --output-logs=new-only",
"turbo:prep": "pnpm turbo:local && pnpm tb prep --no-daemon --go-fallback --output-logs=new-only",
"turbo:prep:force": "rm -f apps/cms/web/sites/default/files/.sqlite && pnpm tb prep --no-daemon --go-fallback --force",
"turbo:test": "pnpm turbo:local && pnpm turbo test:unit --output-logs=new-only && pnpm turbo test:integration --output-logs=new-only --concurrency=1",
"turbo:test:force": "pnpm turbo test:unit --output-logs=new-only --force && pnpm turbo test:integration --output-logs=new-only --concurrency=1 --force",
"turbo:test:quick": "pnpm turbo:local && pnpm turbo test:unit --output-logs=new-only",
"turbo:prep": "pnpm turbo:local && pnpm turbo prep --output-logs=new-only",
"turbo:prep:force": "rm -f apps/cms/web/sites/default/files/.sqlite && pnpm turbo prep --force",
"gutenberg:generate": "pnpm run --filter \"@custom/gutenberg_blocks\" gutenberg:generate"
},
"private": true,
Expand All @@ -39,7 +40,7 @@
"eslint-plugin-simple-import-sort": "^10.0.0",
"husky": "^8.0.3",
"prettier": "^3.2.5",
"turbo": "^1.11.2",
"turbo": "^2.0.6",
"typescript": "^5.3.3",
"vitest": "^1.1.1"
}
Expand Down
6 changes: 6 additions & 0 deletions packages/drupal/custom/custom.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ services:
custom.translatables:
class: Drupal\custom\Translatables
arguments: ['@language_manager', '@locale.storage', '@database']

custom.entity_language_redirect_subscriber:
class: Drupal\custom\EventSubscriber\EntityLanguageRedirectSubscriber
arguments: ['@language_manager', '@current_route_match']
tags:
- { name: event_subscriber }
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Drupal\custom\EventSubscriber;

use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\Core\Url;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class EntityLanguageRedirectSubscriber implements EventSubscriberInterface {

protected LanguageManagerInterface $languageManager;

protected RouteMatchInterface $routeMatch;

public function __construct(LanguageManagerInterface $language_manager, RouteMatchInterface $route_match) {
$this->languageManager = $language_manager;
$this->routeMatch = $route_match;
}

public static function getSubscribedEvents() {
// We need this subscriber to run after the router_listener service (which
// has priority 32) so that the parameters are set into the request, but
// before the EntityCanonicalViewSubscriber one (with the priority 28). So,
// we set the priority to 30.
return [
KernelEvents::REQUEST => [
['onKernelRequest', 30],
]
];
}

public function onKernelRequest(RequestEvent $event): void {
// In case the user tries to access a node in a language entity is not
// translated to, we redirect to the entity in the original language and
// display a warning message.
if ($this->routeMatch->getRouteName() === 'entity.node.canonical') {
$entity = $this->routeMatch->getCurrentRouteMatch()->getParameter('node');
$requestedLanguageId = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
if ($entity->language()->getId() != $requestedLanguageId) {
$routeOptions = [
'language' => $entity->language(),
];
$routeParameters = [
'node' => $entity->id(),
];
$url = Url::fromRoute('entity.node.canonical', $routeParameters, $routeOptions);
// Make sure we keep any query strings.
$queryString = (string) $event->getRequest()->getQueryString();
if ($queryString !== '') {
$queryString .= '&';
}
$urlString = $url->toString() . '?' . $queryString . 'content_language_not_available=true&requested_language=' . $requestedLanguageId;

// Add the necessary cache contexts to the response, as redirect
// responses are cached as well.
$metadata = new CacheableMetadata();
$metadata->addCacheContexts(['languages:language_interface', 'url.query_args']);
$response = new TrustedRedirectResponse($urlString);
$response->addCacheableDependency($entity);
$response->addCacheableDependency($metadata);

$event->setResponse($response);
}
}
}
}
29 changes: 29 additions & 0 deletions packages/drupal/gutenberg_blocks/css/edit.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,32 @@
.gutenberg__editor .edit-post-visual-editor__content-area a.no-underline {
text-decoration: none;
}

.gutenberg__editor .drupal-preview-sidebar {
min-width: 350px;
border-right: 1px solid #e0e0e0;
display: flex;
flex-direction: column;
flex-grow: 1;
}

.gutenberg__editor .drupal-preview-sidebar--iframe-wrapper iframe {
height: 100vh;
border: none;
}

.gutenberg__editor .drupal-preview-sidebar .interface-complementary-area-header,
.gutenberg__editor
.drupal-preview-sidebar
.interface-complementary-area.edit-post-sidebar {
width: 100%;
}

.gutenberg__editor .drupal-preview-sidebar--header {
padding: 10px;
border-bottom: 1px solid #e0e0e0;
}

.gutenberg__editor .drupal-preview-sidebar--header button {
margin-right: 5px;
}
Loading

0 comments on commit 499791d

Please sign in to comment.