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

fix(front): force sentence diff when section is new / removed #203

Merged
merged 1 commit into from
Dec 1, 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
3 changes: 2 additions & 1 deletion targets/alert-cli/src/exportContributionAlerts.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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