Skip to content

Commit

Permalink
fix(front): don't use word diff when section is new (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnbearableBear committed Dec 1, 2020
1 parent fc15d26 commit e253fdf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
3 changes: 2 additions & 1 deletion targets/alert-cli/src/exportContributionAlerts.js
Expand Up @@ -48,7 +48,8 @@ function computeDiff(node) {
const textFieldname =
node.context.containerId === "LEGITEXT000006072050" ? "texte" : "content";
const content = node.data[textFieldname] || "";
const previousContent = node.previous?.data[textFieldname] || "";
const previousContent =
(node.previous && node.previous.data[textFieldname]) || "";
const showDiff = content !== previousContent;
const showNotaDiff = node.previous.data.nota !== node.data.nota;
const texts = [];
Expand Down
37 changes: 19 additions & 18 deletions targets/frontend/src/components/changes/FicheTravailDataChange.js
@@ -1,6 +1,6 @@
/** @jsx jsx */
import PropTypes from "prop-types";
import { useState } from "react";
import React, { useState } from "react";
import { IoIosArrowDown, IoIosArrowForward } from "react-icons/io";
import { Button as TButton, Card, jsx, Text } from "theme-ui";

Expand Down Expand Up @@ -52,22 +52,23 @@ export function FicheTravailDiffchange({ change }) {
)}
{change.sections.map(({ title, text, previousText }, index) => {
return (
<>
<React.Fragment key={`${change.pubId}-section-${index}`}>
<Text>Section {title}</Text>
<ViewDiff
key={`${change.pubId}-section-${index}`}
inputA={previousText}
inputB={text}
type={"words"}
style={{
background: "#fff",
border: "1px solid silver",
borderRadius: 3,
padding: 5,
whiteSpace: "pre-line",
}}
/>
</>
{
<ViewDiff
inputA={previousText}
inputB={text}
type={"sentences"}
style={{
background: "#fff",
border: "1px solid silver",
borderRadius: 3,
padding: 5,
whiteSpace: "pre-line",
}}
/>
}
</React.Fragment>
);
})}
</Card>
Expand All @@ -78,8 +79,8 @@ export function FicheTravailDiffchange({ change }) {

FicheTravailDiffchange.propTypes = {
change: PropTypes.shape({
intro: PropTypes.string.isRequired,
previousIntro: PropTypes.string.isRequired,
intro: PropTypes.string,
previousIntro: PropTypes.string,
pubId: PropTypes.string.isRequired,
sections: PropTypes.arrayOf(
PropTypes.shape({
Expand Down
5 changes: 4 additions & 1 deletion targets/frontend/src/components/changes/ViewDiff.js
Expand Up @@ -15,7 +15,8 @@ const fnMap = {
};

export const ViewDiff = ({ sx, type, inputA, inputB }) => {
const [mode, setMode] = useState(type);
const isSentencesForced = !inputA || !inputB;
const [mode, setMode] = useState(isSentencesForced ? "sentences" : type);
const diff = fnMap[mode](inputA, inputB);

const groupName = Math.random();
Expand Down Expand Up @@ -47,6 +48,7 @@ export const ViewDiff = ({ sx, type, inputA, inputB }) => {
onChange={() => setMode("words")}
style={{ marginLeft: 10 }}
checked={mode === "words"}
disabled={isSentencesForced}
/>{" "}
Mots
<input
Expand All @@ -55,6 +57,7 @@ export const ViewDiff = ({ sx, type, inputA, inputB }) => {
onChange={() => setMode("sentences")}
style={{ marginLeft: 10 }}
checked={mode === "sentences"}
disabled={isSentencesForced}
/>{" "}
Phrases
</div>
Expand Down

0 comments on commit e253fdf

Please sign in to comment.