From 3a0867d0276832f4e41cb3163e2f4d49f777b9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Yepes?= <23552631+ivnnv@users.noreply.github.com> Date: Mon, 11 Mar 2024 05:32:38 -0500 Subject: [PATCH] compactMode: add collapsible functionality + reog job card layout (#697) * compactMode: add collapsible functionality + reog job card layout * update highlight component + improved collapsible * fix arrowup icon * revert attempt condition * implement global setting * modify highlt prop name + allow live job collapse setting update * fix regression bug + button inside button * f * handle global collapse state live * revert spacings --------- Co-authored-by: Felix Mosheev <9304194+felixmosh@users.noreply.github.com> --- packages/ui/package.json | 1 + .../ui/src/components/Icons/ArrowUpIcon.tsx | 5 + .../Details/DetailsContent/DetailsContent.tsx | 4 +- .../src/components/JobCard/JobCard.module.css | 28 ++++- .../ui/src/components/JobCard/JobCard.tsx | 113 ++++++++++++------ .../SettingsModal/SettingsModal.tsx | 7 ++ packages/ui/src/hooks/useSettings.ts | 2 + .../ui/src/static/locales/en-US/messages.json | 2 + .../ui/src/static/locales/pt-BR/messages.json | 2 + yarn.lock | 15 +++ 10 files changed, 136 insertions(+), 43 deletions(-) create mode 100644 packages/ui/src/components/Icons/ArrowUpIcon.tsx diff --git a/packages/ui/package.json b/packages/ui/package.json index cc9a62d1..456be105 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -42,6 +42,7 @@ "@babel/runtime": "^7.17.9", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5", "@radix-ui/react-alert-dialog": "^1.0.4", + "@radix-ui/react-collapsible": "^1.0.3", "@radix-ui/react-dialog": "^1.0.4", "@radix-ui/react-dropdown-menu": "^2.0.5", "@radix-ui/react-switch": "^1.0.3", diff --git a/packages/ui/src/components/Icons/ArrowUpIcon.tsx b/packages/ui/src/components/Icons/ArrowUpIcon.tsx new file mode 100644 index 00000000..be710af0 --- /dev/null +++ b/packages/ui/src/components/Icons/ArrowUpIcon.tsx @@ -0,0 +1,5 @@ +import React from 'react'; + +export const ArrowUpIcon = () => ( + +); diff --git a/packages/ui/src/components/JobCard/Details/DetailsContent/DetailsContent.tsx b/packages/ui/src/components/JobCard/Details/DetailsContent/DetailsContent.tsx index 3687f960..c3305cd5 100644 --- a/packages/ui/src/components/JobCard/Details/DetailsContent/DetailsContent.tsx +++ b/packages/ui/src/components/JobCard/Details/DetailsContent/DetailsContent.tsx @@ -20,7 +20,7 @@ export const DetailsContent = ({ selectedTab, job, actions }: DetailsContentProp const { t } = useTranslation(); const { collapseJobData, collapseJobOptions, collapseJobError } = useSettingsStore(); const [collapseState, setCollapse] = useState({ data: false, options: false, error: false }); - const { stacktrace, data, returnValue, opts, failedReason } = job; + const { stacktrace, data: jobData, returnValue, opts, failedReason } = job; switch (selectedTab) { case 'Data': @@ -29,7 +29,7 @@ export const DetailsContent = ({ selectedTab, job, actions }: DetailsContentProp {t('JOB.SHOW_DATA_BTN')} ) : ( - + ); case 'Options': return collapseJobOptions && !collapseState.options ? ( diff --git a/packages/ui/src/components/JobCard/JobCard.module.css b/packages/ui/src/components/JobCard/JobCard.module.css index 20aab078..ae8da6ff 100644 --- a/packages/ui/src/components/JobCard/JobCard.module.css +++ b/packages/ui/src/components/JobCard/JobCard.module.css @@ -5,7 +5,6 @@ border-radius: 0.25rem; padding: 1em; display: flex; - min-height: 320px; max-height: 500px; } @@ -21,7 +20,14 @@ .title { display: flex; + align-items: baseline; justify-content: space-between; + padding-bottom: 0.5rem; + border-bottom: 1px solid #e2e8f0; +} + +.attempts { + margin-left: '0.5rem' } .title h4, @@ -38,6 +44,19 @@ font-size: 0.694em; } +.header { + display: flex; + width: 100%; + justify-content: space-between; + align-items: center; +} + +.details { + display: flex; + margin-top: 1rem; + width: 100%; +} + .sideInfo { width: 200px; padding-right: 2rem; @@ -57,6 +76,10 @@ padding-right: 1rem; } +.collapseBtn { + padding: 0.15rem; +} + .content { position: relative; flex: 1; @@ -70,5 +93,6 @@ } .jobLink { - text-decoration: none; + color: #4a5568; + font-size: large; } diff --git a/packages/ui/src/components/JobCard/JobCard.tsx b/packages/ui/src/components/JobCard/JobCard.tsx index f4baa8aa..4e9328f8 100644 --- a/packages/ui/src/components/JobCard/JobCard.tsx +++ b/packages/ui/src/components/JobCard/JobCard.tsx @@ -4,6 +4,11 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import { Link } from 'react-router-dom'; import { Card } from '../Card/Card'; +import { ArrowDownIcon } from '../Icons/ArrowDownIcon'; +import { useSettingsStore } from '../../hooks/useSettings'; +import { ArrowUpIcon } from '../Icons/ArrowUpIcon'; +import { Button } from '../Button/Button'; +import * as Collapsible from '@radix-ui/react-collapsible'; import { Details } from './Details/Details'; import { JobActions } from './JobActions/JobActions'; import s from './JobCard.module.css'; @@ -35,49 +40,79 @@ export const JobCard = ({ jobUrl, }: JobCardProps) => { const { t } = useTranslation(); + const { collapseJob } = useSettingsStore(); + + const [localCollapse, setLocalCollapse] = React.useState(); + + const isExpandedCard = !jobUrl || (localCollapse || !collapseJob); + + const JobTitle =

#{job.id}

; + return ( -
- {jobUrl ? ( - - #{job.id} - - ) : ( - #{job.id} - )} - -
-
-
-

- {job.name} - {job.attempts > 1 && {t('JOB.ATTEMPTS', { attempts: job.attempts })}} - {!!job.opts?.repeat?.count && ( - - {t(`JOB.REPEAT${!!job.opts?.repeat?.limit ? '_WITH_LIMIT' : ''}`, { - count: job.opts.repeat.count, - limit: job.opts?.repeat?.limit, - })} - - )} -

- {!readOnlyMode && ( - - )} -
-
-
- {typeof job.progress === 'number' && ( - + +
+ {jobUrl ? ( + + {JobTitle} + + ) : JobTitle} + + {jobUrl && ( + )}
-
+ + +
+
+ +
+ +
+
+
+ {t('JOB.NAME')}: {job.name} + {job.attempts > 1 && ( + + - {t('JOB.ATTEMPTS', { attempts: job.attempts })} + + )} + + {!!job.opts?.repeat?.count && ( + + {t(`JOB.REPEAT${!!job.opts?.repeat?.limit ? '_WITH_LIMIT' : ''}`, { + count: job.opts.repeat.count, + limit: job.opts?.repeat?.limit, + })} + + )} +
+ + {!readOnlyMode && ( + + )} +
+ +
+
+ + {typeof job.progress === 'number' && ( + + )} +
+
+
+
+ ); }; diff --git a/packages/ui/src/components/SettingsModal/SettingsModal.tsx b/packages/ui/src/components/SettingsModal/SettingsModal.tsx index 274d99e1..c9e1c302 100644 --- a/packages/ui/src/components/SettingsModal/SettingsModal.tsx +++ b/packages/ui/src/components/SettingsModal/SettingsModal.tsx @@ -21,6 +21,7 @@ export const SettingsModal = ({ open, onClose }: SettingsModalProps) => { jobsPerPage, confirmQueueActions, confirmJobActions, + collapseJob, collapseJobData, collapseJobOptions, collapseJobError, @@ -81,6 +82,12 @@ export const SettingsModal = ({ open, onClose }: SettingsModalProps) => { checked={confirmJobActions} onCheckedChange={(checked) => setSettings({ confirmJobActions: checked })} /> + setSettings({ collapseJob: checked })} + /> ()( jobsPerPage: 10, confirmJobActions: true, confirmQueueActions: true, + collapseJob: false, collapseJobData: false, collapseJobOptions: false, collapseJobError: false, diff --git a/packages/ui/src/static/locales/en-US/messages.json b/packages/ui/src/static/locales/en-US/messages.json index f9d50797..22afbf94 100644 --- a/packages/ui/src/static/locales/en-US/messages.json +++ b/packages/ui/src/static/locales/en-US/messages.json @@ -10,6 +10,7 @@ "JOBS_COUNT": "{{count}} Jobs" }, "JOB": { + "NAME": "Name", "NOT_FOUND": "Job Not found", "STATUS": "Status: {{status}}", "ADDED_AT": "Added at", @@ -109,6 +110,7 @@ "JOBS_PER_PAGE": "Jobs per page (1-50)", "CONFIRM_QUEUE_ACTIONS": "Confirm queue actions", "CONFIRM_JOB_ACTIONS": "Confirm job actions", + "COLLAPSE_JOB": "Collapse job", "COLLAPSE_JOB_DATA": "Collapse job data", "COLLAPSE_JOB_OPTIONS": "Collapse job options", "COLLAPSE_JOB_ERROR": "Collapse job error" diff --git a/packages/ui/src/static/locales/pt-BR/messages.json b/packages/ui/src/static/locales/pt-BR/messages.json index 81ba261f..363da38f 100644 --- a/packages/ui/src/static/locales/pt-BR/messages.json +++ b/packages/ui/src/static/locales/pt-BR/messages.json @@ -12,6 +12,7 @@ "JOBS_COUNT": "{{count}} Tarefas" }, "JOB": { + "NAME": "Nome", "NOT_FOUND": "Tarefa não encontrada", "STATUS": "Status: {{status}}", "ADDED_AT": "Adicionado em", @@ -113,6 +114,7 @@ "JOBS_PER_PAGE": "Tarefas por página (1-50)", "CONFIRM_QUEUE_ACTIONS": "Confirma ações da fila", "CONFIRM_JOB_ACTIONS": "Confirma ações da tarefa", + "COLLAPSE_JOB": "Recolher tarefa", "COLLAPSE_JOB_DATA": "Recolher dados da tarefa", "COLLAPSE_JOB_OPTIONS": "Recolher opções da tarefa", "COLLAPSE_JOB_ERROR": "Recolher erros da tarefa" diff --git a/yarn.lock b/yarn.lock index c8d35683..4fbc7d87 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3369,6 +3369,21 @@ "@babel/runtime" "^7.13.10" "@radix-ui/react-primitive" "1.0.3" +"@radix-ui/react-collapsible@^1.0.3": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@radix-ui/react-collapsible/-/react-collapsible-1.0.3.tgz#df0e22e7a025439f13f62d4e4a9e92c4a0df5b81" + integrity sha512-UBmVDkmR6IvDsloHVN+3rtx4Mi5TFvylYXpluuv0f37dtaz3H99bp8No0LGXRigVpl3UAT4l9j6bIchh42S/Gg== + dependencies: + "@babel/runtime" "^7.13.10" + "@radix-ui/primitive" "1.0.1" + "@radix-ui/react-compose-refs" "1.0.1" + "@radix-ui/react-context" "1.0.1" + "@radix-ui/react-id" "1.0.1" + "@radix-ui/react-presence" "1.0.1" + "@radix-ui/react-primitive" "1.0.3" + "@radix-ui/react-use-controllable-state" "1.0.1" + "@radix-ui/react-use-layout-effect" "1.0.1" + "@radix-ui/react-collection@1.0.3": version "1.0.3" resolved "https://registry.yarnpkg.com/@radix-ui/react-collection/-/react-collection-1.0.3.tgz#9595a66e09026187524a36c6e7e9c7d286469159"