-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
638 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { promises: fs } = require("fs"); | ||
const path = require("path"); | ||
const filename = | ||
process.env.DUMP || path.join(__dirname, "..", "data", "dump.json"); | ||
const { updateSource, insertAlert } = require("./update-alerts"); | ||
|
||
async function main() { | ||
const fileContent = (await fs.readFile(filename)).toString(); | ||
const data = JSON.parse(fileContent); | ||
|
||
for (const result of data) { | ||
if (result.changes.length === 0) { | ||
console.log(`no update for ${result.repository}`); | ||
continue; | ||
} | ||
const inserts = await Promise.all( | ||
result.changes.map((diff) => insertAlert(result.repository, diff)) | ||
); | ||
inserts.forEach((insert) => { | ||
console.log("insert alert", insert.returning[0]); | ||
}); | ||
const update = await updateSource(result.repository, result.newRef); | ||
console.log(`update source ${update.repository} to ${update.tag}`); | ||
} | ||
return Promise.resolve(); | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** @jsx jsx */ | ||
|
||
import { jsx, Flex, Box } from "theme-ui"; | ||
import PropTypes from "prop-types"; | ||
import { AlertStatus } from "./Status"; | ||
|
||
export function AlertTitle({ alertId, ...props }) { | ||
return ( | ||
<Flex sx={{ my: "large", alignItems: "center" }}> | ||
<AlertStatus alertId={alertId} /> | ||
<Box as="h2" sx={{ flex: "1 1 auto" }} {...props} /> | ||
</Flex> | ||
); | ||
} | ||
|
||
AlertTitle.propTypes = { | ||
alertId: PropTypes.string.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** @jsx jsx */ | ||
|
||
import { IoIosCheckmark, IoIosClose } from "react-icons/io"; | ||
import { MenuButton, MenuItem } from "../button"; | ||
import { jsx } from "theme-ui"; | ||
import PropTypes from "prop-types"; | ||
import { useMutation } from "urql"; | ||
|
||
export const alertMutation = ` | ||
mutation updateAlertStatus($id:uuid!, $status:String!) { | ||
update_alerts_by_pk( | ||
pk_columns: { | ||
id: $id | ||
} | ||
_set: { status: $status } | ||
){ | ||
__typename | ||
} | ||
} | ||
`; | ||
|
||
export function AlertStatus({ alertId }) { | ||
const [, executeUpdate] = useMutation(alertMutation); | ||
function updateStatus(status) { | ||
console.log("update statys", alertId, status); | ||
executeUpdate({ id: alertId, status }); | ||
} | ||
return ( | ||
<MenuButton variant="secondary"> | ||
<MenuItem onSelect={() => updateStatus("doing")}> | ||
<span sx={{ display: "inline-block", width: "1.5em" }} /> | ||
En cours | ||
</MenuItem> | ||
<MenuItem onSelect={() => updateStatus("done")}> | ||
<IoIosCheckmark style={{ width: "1.5em", height: "1.5em" }} /> Traité | ||
</MenuItem> | ||
<MenuItem onSelect={() => updateStatus("rejected")}> | ||
<IoIosClose style={{ width: "1.5em", height: "1.5em" }} /> Rejeté | ||
</MenuItem> | ||
</MenuButton> | ||
); | ||
} | ||
AlertStatus.propTypes = { | ||
alertId: PropTypes.string.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { AccordionButton } from "src/components/button"; | ||
import { AccordionItem, AccordionPanel } from "@reach/accordion"; | ||
|
||
export const ChangesGroup = ({ changes, label, renderChange }) => { | ||
return changes.length > 0 ? ( | ||
<AccordionItem> | ||
<AccordionButton>{label}</AccordionButton> | ||
<AccordionPanel> | ||
<ul>{changes.map(renderChange)}</ul> | ||
</AccordionPanel> | ||
</AccordionItem> | ||
) : null; | ||
}; | ||
|
||
ChangesGroup.propTypes = { | ||
label: PropTypes.string.isRequired, | ||
renderChange: PropTypes.func.isRequired, | ||
changes: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
added: PropTypes.object, | ||
removed: PropTypes.object, | ||
modified: PropTypes.object, | ||
}) | ||
), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// adapted from https://github.com/davidmason/react-stylable-diff/blob/master/lib/react-diff.js | ||
/** @jsx jsx */ | ||
|
||
import { useState, useMemo } from "react"; | ||
import { jsx } from "theme-ui"; | ||
var jsdiff = require("diff"); | ||
|
||
const fnMap = { | ||
chars: jsdiff.diffChars, | ||
words: jsdiff.diffWords, | ||
sentences: jsdiff.diffSentences, | ||
json: jsdiff.diffJson, | ||
}; | ||
|
||
export const ViewDiff = ({ sx, type, inputA, inputB }) => { | ||
const [mode, setMode] = useState(type); | ||
const diff = fnMap[mode](inputA, inputB); | ||
|
||
const groupName = useMemo(() => Math.random()); | ||
|
||
const result = diff.map((part, index) => { | ||
if (part.added) { | ||
return ( | ||
<ins sx={{ bg: "positive" }} key={index}> | ||
{part.value} | ||
</ins> | ||
); | ||
} | ||
if (part.removed) { | ||
return ( | ||
<del sx={{ bg: "critical" }} key={index}> | ||
{part.value} | ||
</del> | ||
); | ||
} | ||
return <span key={index}>{part.value}</span>; | ||
}); | ||
return ( | ||
<div sx={sx}> | ||
<div sx={{ marginBottom: 20 }}> | ||
Diff mode : | ||
<input | ||
type="radio" | ||
name={groupName} | ||
onClick={() => setMode("words")} | ||
style={{ marginLeft: 10 }} | ||
checked={mode === "words"} | ||
/>{" "} | ||
Mots | ||
<input | ||
type="radio" | ||
name={groupName} | ||
onClick={() => setMode("sentences")} | ||
style={{ marginLeft: 10 }} | ||
checked={mode === "sentences"} | ||
/>{" "} | ||
Phrases | ||
</div> | ||
{result} | ||
</div> | ||
); | ||
}; | ||
|
||
ViewDiff.defaultProps = { | ||
inputA: "", | ||
inputB: "", | ||
type: "chars", | ||
className: "Difference", | ||
}; |
Oops, something went wrong.