From 4eb3fbad5fb6234fa120fa1646b69f44b063f68c Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette Date: Thu, 7 Jul 2022 21:33:47 +0200 Subject: [PATCH 1/7] mathch icon, url and tooltip --- src/pages/insights/InsightsGrid.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/insights/InsightsGrid.jsx b/src/pages/insights/InsightsGrid.jsx index cea09a377..f0e0a1951 100644 --- a/src/pages/insights/InsightsGrid.jsx +++ b/src/pages/insights/InsightsGrid.jsx @@ -108,9 +108,9 @@ const columns = [ + } @@ -118,9 +118,9 @@ const columns = [ + } From 5acf845edd775463b36e9e14c255cc728b0c9bcf Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette Date: Thu, 7 Jul 2022 21:49:22 +0200 Subject: [PATCH 2/7] use new translations --- src/i18n/common.json | 8 ++++---- src/pages/insights/FilterInsights.jsx | 3 +++ src/pages/insights/InsightsGrid.jsx | 11 ++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/i18n/common.json b/src/i18n/common.json index be95073e7..546c3964f 100644 --- a/src/i18n/common.json +++ b/src/i18n/common.json @@ -7,7 +7,7 @@ "ingredients": "Ingredients", "product_weight": "product weight", "popularity_sort": "Sort by popularity", - "see_examples":"See examples of this ", + "see_examples": "See examples of this ", "no": "No", "skip": "Skip", "yes": "Yes", @@ -203,8 +203,8 @@ } }, "notfound": { - "nopage":"Whoops! The page you're looking for can't be found.", - "redirect1":"Want to play some games?", - "redirect2":"Click here" + "nopage": "Whoops! The page you're looking for can't be found.", + "redirect1": "Want to play some games?", + "redirect2": "Click here" } } \ No newline at end of file diff --git a/src/pages/insights/FilterInsights.jsx b/src/pages/insights/FilterInsights.jsx index ea5f2f31e..55424739f 100644 --- a/src/pages/insights/FilterInsights.jsx +++ b/src/pages/insights/FilterInsights.jsx @@ -10,6 +10,9 @@ const typeOptions = [ { value: "category", labelKey: "insights.category" }, { value: "expiration_date", labelKey: "insights.expiration_date" }, { value: "packager_code", labelKey: "insights.packager_code" }, + { value: "brand", labelKey: "logos.brand" }, + { value: "packaging", labelKey: "logos.packaging" }, + { value: "qr_code", labelKey: "logos.qr_code" }, ]; const annotationOptions = [ diff --git a/src/pages/insights/InsightsGrid.jsx b/src/pages/insights/InsightsGrid.jsx index f0e0a1951..f499be1c1 100644 --- a/src/pages/insights/InsightsGrid.jsx +++ b/src/pages/insights/InsightsGrid.jsx @@ -46,6 +46,9 @@ const typeKeyToTranslationKey = { category: "insights.category", expiration_date: "insights.expiration_date", packager_code: "insights.packager_code", + brand: "logos.brand", + packaging: "logos.packaging", + qr_code: "logos.qr_code", }; const annotationValueToTranslationKey = { @@ -141,14 +144,16 @@ const columns = [ renderCell: ({ row }) => row.type && row.value_tag ? ( - {row.value_tag} + {row.value_tag} : {row.value} ) : ( - row.value_tag + + {row.value_tag} : {row.value} + ), }, { field: "barcode", minWidth: 180, flex: 1, maxWidth: 200 }, - { field: "id" }, + { field: "id", flex: 1 }, { field: "timestamp", ...dateTimeColumn }, { field: "completed_at", From 6fa581ec1b70ca8ba80ace74e25bf82ef1c1456b Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette Date: Thu, 7 Jul 2022 22:10:51 +0200 Subject: [PATCH 3/7] click on barcode modify the filters --- src/pages/insights/FilterInsights.jsx | 18 +++++++--- src/pages/insights/InsightsGrid.jsx | 47 +++++++++++++++++++++++++-- src/pages/insights/index.jsx | 5 ++- 3 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/pages/insights/FilterInsights.jsx b/src/pages/insights/FilterInsights.jsx index 55424739f..e98a6ffde 100644 --- a/src/pages/insights/FilterInsights.jsx +++ b/src/pages/insights/FilterInsights.jsx @@ -23,19 +23,29 @@ const annotationOptions = [ { value: "not_annotated", labelKey: "insights.not_annotated" }, ]; +const useControled = (exteriorValue) => { + const [innerValue, setInnerValue] = React.useState(exteriorValue ?? ""); + + React.useEffect(() => { + setInnerValue((v) => (v !== exteriorValue ? exteriorValue : v)); + }, [exteriorValue]); + + return [innerValue, setInnerValue]; +}; + const FilterForm = ({ filterState = {}, setFilterState }) => { const { t } = useTranslation(); - const [innerBarcode, setInnerBarcode] = React.useState( + const [innerBarcode, setInnerBarcode] = useControled( filterState.barcode ?? "" ); - const [innerValueTag, setInnerValueTag] = React.useState( + const [innerValueTag, setInnerValueTag] = useControled( filterState.valueTag ?? "" ); - const [innerInsightType, setInnerInsightType] = React.useState( + const [innerInsightType, setInnerInsightType] = useControled( filterState.insightType ?? "" ); - const [innerAnnotationStatus, setInnerAnnotationStatus] = React.useState( + const [innerAnnotationStatus, setInnerAnnotationStatus] = useControled( filterState.annotationStatus ?? "" ); diff --git a/src/pages/insights/InsightsGrid.jsx b/src/pages/insights/InsightsGrid.jsx index f499be1c1..289358f24 100644 --- a/src/pages/insights/InsightsGrid.jsx +++ b/src/pages/insights/InsightsGrid.jsx @@ -8,6 +8,8 @@ import VisibilityIcon from "@mui/icons-material/Visibility"; import CheckCircleOutlineIcon from "@mui/icons-material/CheckCircleOutline"; import CancelOutlinedIcon from "@mui/icons-material/CancelOutlined"; import QuestionMarkOutlinedIcon from "@mui/icons-material/QuestionMarkOutlined"; +import FaceIcon from "@mui/icons-material/Face"; +import SmartToyIcon from "@mui/icons-material/SmartToy"; import Tooltip from "@mui/material/Tooltip"; import Link from "@mui/material/Link"; @@ -17,6 +19,15 @@ import offService from "../../off"; import { useTranslation } from "react-i18next"; import { Typography } from "@mui/material"; +const RenderLink = (props) => { + const { value, ...other } = props; + return ( + + {props.value} + + ); +}; + const getProductUrl = (code) => { if (!code) { return ""; @@ -103,7 +114,7 @@ const dateTimeColumn = { valueGetter: (params) => (params.value ? new Date(params.value) : null), }; -const columns = [ +const staticColumnsDef = [ { field: "actions", type: "actions", @@ -173,18 +184,50 @@ const columns = [ minWidth: 70, flex: 1, maxWidth: 110, + renderCell: ({ value }) => + value ? ( + + + + ) : ( + + + + ), }, ].map((col) => ({ ...col, sortable: false })); const PAGE_SIZE = 25; -const InsightGrid = ({ filterState = {} }) => { +const InsightGrid = ({ filterState = {}, setFilterState }) => { const { t } = useTranslation(); const [pageState, setPageState] = React.useState({ page: 1, rowCount: 0 }); const [isLoading, setIsLoading] = React.useState(false); const [rows, setRows] = React.useState([]); + const columns = React.useMemo(() => { + return staticColumnsDef.map((col) => { + if (col.field !== "barcode") { + return col; + } + return { + ...col, + renderCell: ({ value, tabIndex }) => { + return ( + { + setFilterState((f) => ({ ...f, barcode: value })); + }} + /> + ); + }, + }; + }); + }, [setFilterState]); + React.useEffect(() => { setIsLoading(true); let isValid = true; diff --git a/src/pages/insights/index.jsx b/src/pages/insights/index.jsx index 555c012c6..382225aba 100644 --- a/src/pages/insights/index.jsx +++ b/src/pages/insights/index.jsx @@ -26,7 +26,10 @@ export default function Insights() { />
- +
); From 11a1c40153cf5bc5d661c6836c5c9101eca0be6c Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette Date: Thu, 7 Jul 2022 22:20:42 +0200 Subject: [PATCH 4/7] center the toolbar --- src/components/ResponsiveAppBar.jsx | 85 ++++++++++++++++------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/src/components/ResponsiveAppBar.jsx b/src/components/ResponsiveAppBar.jsx index 6d2315d43..1a0cec794 100644 --- a/src/components/ResponsiveAppBar.jsx +++ b/src/components/ResponsiveAppBar.jsx @@ -114,49 +114,56 @@ const ResponsiveAppBar = () => { {/* Desktop content */} - - OpenFoodFact logo - - - Hunger Games - - - {pages.map((page) => - page.url ? ( - - ) : null - )} + + OpenFoodFact logo + + + Hunger Games + + + {pages.map((page) => + page.url ? ( + + ) : null + )} + From 04e3060a040e4927d32f39662b193a32c1c06d57 Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette Date: Thu, 7 Jul 2022 22:50:04 +0200 Subject: [PATCH 5/7] add dev mode --- src/App.js | 34 +++++++++++++++++------------ src/components/ResponsiveAppBar.jsx | 11 ++++++++-- src/contexts/devMode.jsx | 9 ++++++++ src/localeStorageManager.js | 5 +++++ src/pages/settings/index.jsx | 27 ++++++++++++++++++++--- 5 files changed, 67 insertions(+), 19 deletions(-) create mode 100644 src/contexts/devMode.jsx diff --git a/src/App.js b/src/App.js index 95e770ffa..7a3b1c1c4 100644 --- a/src/App.js +++ b/src/App.js @@ -13,27 +13,33 @@ import { NotFoundPage, } from "./pages"; import ResponsiveAppBar from "./components/ResponsiveAppBar"; +import DevModeContext from "./contexts/devMode"; +import { getIsDevMode } from "./localeStorageManager"; const theme = createTheme({}); export default function App() { + const [devMode, setDevMode] = React.useState(getIsDevMode); + return ( - - - - {/* TODO: put a home page for root url */} - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - + + + + + {/* TODO: put a home page for root url */} + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + ); diff --git a/src/components/ResponsiveAppBar.jsx b/src/components/ResponsiveAppBar.jsx index 1a0cec794..9cae44f83 100644 --- a/src/components/ResponsiveAppBar.jsx +++ b/src/components/ResponsiveAppBar.jsx @@ -12,6 +12,7 @@ import MenuItem from "@mui/material/MenuItem"; import ListSubheader from "@mui/material/ListSubheader"; import MuiLink from "@mui/material/Link"; +import DevModeContext from "../contexts/devMode"; import logo from "../assets/logo.png"; import { Link } from "react-router-dom"; @@ -40,6 +41,12 @@ const ResponsiveAppBar = () => { setAnchorElNav(null); }; + const { devMode: isDevMode } = React.useContext(DevModeContext); + + const displayedPages = pages.filter( + (page) => page.url !== "insights" || isDevMode + ); + return ( @@ -74,7 +81,7 @@ const ResponsiveAppBar = () => { display: { xs: "block", md: "none" }, }} > - {pages.map((page) => + {displayedPages.map((page) => page.url ? ( { Hunger Games - {pages.map((page) => + {displayedPages.map((page) => page.url ? ( - + {/* Image display section */} { )} {valueTagExamplesURL && ( - +
{`${t("questions.see_examples")} ${question.insight_type}`}
-
+ )} From 7a273d2b1de464a1d89490a7f856fe572ca05172 Mon Sep 17 00:00:00 2001 From: Alexandre Fauquette Date: Fri, 8 Jul 2022 23:12:37 +0200 Subject: [PATCH 7/7] feedback --- src/pages/settings/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/index.jsx b/src/pages/settings/index.jsx index b8428a363..e1d9efc67 100644 --- a/src/pages/settings/index.jsx +++ b/src/pages/settings/index.jsx @@ -50,7 +50,7 @@ export default function Settings() {
-

To explore data base content, activate the dev mode

+

To explore the database content, activate the dev mode