Skip to content

Commit

Permalink
fix: start page add more tabs dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-mng committed Nov 28, 2024
1 parent 65a18b5 commit c7fbc5c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 29 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/web/pages/start/confirmremovedialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import PropTypes from 'web/utils/proptypes';

import Dialog from 'web/components/dialog/dialog';
import DialogContent from 'web/components/dialog/content';
import DialogTwoButtonFooter from 'web/components/dialog/twobuttonfooter';
import DialogTwoButtonFooter, {
DELETE_ACTION,
} from 'web/components/dialog/twobuttonfooter';

import useTranslation from 'web/hooks/useTranslation';

Expand Down Expand Up @@ -43,6 +45,7 @@ const ConfirmRemoveDialog = ({
rightButtonTitle={_('Remove')}
onLeftButtonClick={onDeny}
onRightButtonClick={() => onConfirm(dashboardId)}
rightButtonAction={DELETE_ACTION}
/>
</DialogContent>
</Dialog>
Expand Down
60 changes: 32 additions & 28 deletions src/web/pages/start/newdashboarddialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import React from 'react';

import PropTypes from 'web/utils/proptypes';

import SaveDialog from 'web/components/dialog/savedialog';
Expand Down Expand Up @@ -71,12 +69,9 @@ const EMPTY_DISPLAYS = [];

const NewDashboardDialog = ({additionalDisplayChoices, onClose, onSave}) => {
const [_] = useTranslation();
const defaultDisplayChoices = [
{
label: _('Default'),
key: 'default',
value: DEFAULT_DISPLAYS,
},

const uniqueDisplayChoices = [
{label: _('Default'), key: 'default', value: DEFAULT_DISPLAYS},
{
label: _('Scan Displays'),
key: 'scan-displays',
Expand All @@ -92,26 +87,34 @@ const NewDashboardDialog = ({additionalDisplayChoices, onClose, onSave}) => {
key: 'secinfo-displays',
value: SECINFO_DEFAULT_DISPLAYS,
},
{
label: _('Empty'),
key: 'empty',
value: EMPTY_DISPLAYS,
},
...additionalDisplayChoices,
];
{label: _('Empty'), key: 'empty', value: EMPTY_DISPLAYS},
...additionalDisplayChoices.map(choice => ({
label: choice.label,
key: `${choice.label}-${JSON.stringify(choice.value)}`,
value: choice.value,
})),
].filter(
(choice, index, self) =>
index === self.findIndex(item => item.key === choice.key),
);

return (
<SaveDialog
buttonTitle={_('Add')}
title={_('Add new Dashboard')}
defaultValues={{
title: _('Unnamed'),
defaultDisplays: DEFAULT_DISPLAYS,
}}
defaultValues={{title: _('Unnamed'), defaultDisplays: 'default'}}
onClose={onClose}
onSave={onSave}
onSave={values =>
onSave({
...values,
defaultDisplays: uniqueDisplayChoices.find(
choice => choice.key === values.defaultDisplays,
)?.value,
})
}
>
{({values, onValueChange}) => (
<React.Fragment>
<>
<FormGroup title={_('Dashboard Title')}>
<TextField
name="title"
Expand All @@ -123,12 +126,15 @@ const NewDashboardDialog = ({additionalDisplayChoices, onClose, onSave}) => {
<FormGroup title={_('Initial Displays')}>
<Select
name="defaultDisplays"
items={defaultDisplayChoices}
items={uniqueDisplayChoices.map(({label, key}) => ({
label,
value: key,
}))}
value={values.defaultDisplays}
onChange={onValueChange}
/>
</FormGroup>
</React.Fragment>
</>
)}
</SaveDialog>
);
Expand All @@ -137,14 +143,12 @@ const NewDashboardDialog = ({additionalDisplayChoices, onClose, onSave}) => {
NewDashboardDialog.propTypes = {
additionalDisplayChoices: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.toString,
value: PropTypes.array,
label: PropTypes.string.isRequired,
value: PropTypes.array.isRequired,
}),
),
).isRequired,
onClose: PropTypes.func.isRequired,
onSave: PropTypes.func.isRequired,
};

export default NewDashboardDialog;

// vim: set ts=2 sw=2 tw=80:

0 comments on commit c7fbc5c

Please sign in to comment.