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(frontend): update change on master #162

Merged
merged 1 commit into from
Nov 6, 2020
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
1 change: 1 addition & 0 deletions targets/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "frontend",
"version": "1.0.0",
"dependencies": {
"@elastic/elasticsearch": "^7.9.1",
"@hapi/boom": "^9.1.0",
"@hapi/joi": "^17.1.1",
"@hookform/error-message": "^0.0.4",
Expand Down
29 changes: 29 additions & 0 deletions targets/frontend/src/pages/api/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Client } from "@elastic/elasticsearch";

export default async function (req, res) {
if (!process.env.ELASTICSEARCH_API_KEY || !process.env.ELASTICSEARCH_URL) {
res.status(304).json({ message: "not modified" });
}

const client = new Client({
auth: {
apiKey: process.env.ELASTICSEARCH_API_KEY,
},
node: `${process.env.ELASTICSEARCH_URL}`,
});

const { cdtnId, document } = req.body;
try {
await client.update({
body: {
doc: document,
},
id: cdtnId,
index: `cdtn_master_documents`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je pense que ce serait plus safe d'aller récup le nom de l'index plutôt que de le mettre en dur ici

Copy link
Contributor Author

@lionelB lionelB Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oui on peut récupérer les index après on fait comment pour choisir ?

Copy link
Contributor

@UnbearableBear UnbearableBear Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En fait je pensais juste à aller le récupérer le suffix de l'index du côté de cdtn data dans le fichier esIndexName, le préfixe est dynamique, my bad. Mais je sais plus trop pourquoi on a deux indexes et qu'on change les alias plutôt qu'update directement les indexes ? Il y a une logique côté cdtn - data qu'on zappe un peu ici je sais pas si c'est volontaire c'est assez flou dans ma mémoire

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on a variabilisé esIndexName, car on l'utilise a plusieurs endroits dans cdtn. la on l'utilise qu'une fois mais oui ca crée une adhérence entre les 2 projets. je pense qu'on peut pour l'instant rester comme ça, et plutard, exporter un nouveau package cdtn-config pour partager certaines conig entre les 2 projets

Pour l'histoire d'avoir 2 index, en fait on utilise un système d'alias qui permet d'éviter d'avoir un index vide / qui se remploi lorsqu'on lance l'indexation des document (qui prend un bonne dizaine de minute)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui pas soucis laissons ça comme ça pour le moment, ce n'est absolument pas problématique pour l'instant

});
res.json({ message: "doc updated!" });
} catch (response) {
console.error(response.body.error);
res.status(response.statusCode).json({ message: response.body.error });
}
}
9 changes: 7 additions & 2 deletions targets/frontend/src/pages/contenus/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Inline } from "src/components/layout/Inline";
import { Stack } from "src/components/layout/Stack";
import { withCustomUrqlClient } from "src/hoc/CustomUrqlClient";
import { withUserProvider } from "src/hoc/UserProvider";
import { request } from "src/lib/request";
import { Card, jsx, Message, NavLink } from "theme-ui";
import { useMutation, useQuery } from "urql";

Expand Down Expand Up @@ -46,7 +47,7 @@ mutation updateDocument($cdtnId: String!, $metaDescription: String!, $title: Str
cdtn_id: $cdtnId
}
){
cdtn_id
cdtnId:cdtn_id, title, metaDescription: meta_description, document
}
}`;

Expand Down Expand Up @@ -78,7 +79,11 @@ export function DocumentsPage() {
document: jsonDoc.current.document,
metaDescription: jsonDoc.current.meta_description,
title: jsonDoc.current.title,
}).then((result) => {
}).then(({ data }) => {
const { cdtnId, title, metaDescription, document } = data.document;
request("/api/preview", {
body: { cdtnId, document: { ...document, metaDescription, title } },
});
if (result.error) {
console.error(result.error);
}
Expand Down
23 changes: 23 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,17 @@
enabled "2.0.x"
kuler "^2.0.0"

"@elastic/elasticsearch@^7.9.1":
version "7.9.1"
resolved "https://registry.yarnpkg.com/@elastic/elasticsearch/-/elasticsearch-7.9.1.tgz#40f1c38e8f70d783851c13be78a7cb346891c15e"
integrity sha512-NfPADbm9tRK/4ohpm9+aBtJ8WPKQqQaReyBKT225pi2oKQO1IzRlfM+OPplAvbhoH1efrSj1NKk27L+4BCrzXQ==
dependencies:
debug "^4.1.1"
decompress-response "^4.2.0"
ms "^2.1.1"
pump "^3.0.0"
secure-json-parse "^2.1.0"

"@emotion/cache@^10.0.27":
version "10.0.29"
resolved "https://registry.yarnpkg.com/@emotion/cache/-/cache-10.0.29.tgz#87e7e64f412c060102d589fe7c6dc042e6f9d1e0"
Expand Down Expand Up @@ -5962,6 +5973,13 @@ decode-uri-component@^0.2.0:
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=

decompress-response@^4.2.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-4.2.1.tgz#414023cc7a302da25ce2ec82d0d5238ccafd8986"
integrity sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==
dependencies:
mimic-response "^2.0.0"

decompress-response@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-5.0.0.tgz#7849396e80e3d1eba8cb2f75ef4930f76461cb0f"
Expand Down Expand Up @@ -12826,6 +12844,11 @@ section-iterator@^2.0.0:
resolved "https://registry.yarnpkg.com/section-iterator/-/section-iterator-2.0.0.tgz#bf444d7afeeb94ad43c39ad2fb26151627ccba2a"
integrity sha1-v0RNev7rlK1Dw5rS+yYVFifMuio=

secure-json-parse@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/secure-json-parse/-/secure-json-parse-2.1.0.tgz#ae76f5624256b5c497af887090a5d9e156c9fb20"
integrity sha512-GckO+MS/wT4UogDyoI/H/S1L0MCcKS1XX/vp48wfmU7Nw4woBmb8mIpu4zPBQjKlRT88/bt9xdoV4111jPpNJA==

semver-compare@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"
Expand Down