feat(webapp): handle create item on Accounts select components

This commit is contained in:
a.bouhuolia
2023-05-04 14:24:45 +02:00
parent 981b65349d
commit 6c61a69f10
5 changed files with 56 additions and 26 deletions

View File

@@ -1227,9 +1227,9 @@
} }
}, },
"@blueprintjs-formik/select": { "@blueprintjs-formik/select": {
"version": "0.1.5", "version": "0.2.3",
"resolved": "https://registry.npmjs.org/@blueprintjs-formik/select/-/select-0.1.5.tgz", "resolved": "https://registry.npmjs.org/@blueprintjs-formik/select/-/select-0.2.3.tgz",
"integrity": "sha512-EqGbuoiS1VrWpzjd39uVhBAmfVobdpgqalGcpODyGA+XAYoft1UU12yzTzrEOwBZpQKiC12UQwekUPspYBsVKA==", "integrity": "sha512-j/zkX0B9wgtoHgK6Z/rlowB7F7zemrAajBU+d3caCoEYMMqwAI0XA++GytqrIhv5fEGjkZ1hkxS9j8eqX8vtjA==",
"requires": { "requires": {
"lodash.get": "^4.4.2", "lodash.get": "^4.4.2",
"lodash.keyby": "^4.6.0", "lodash.keyby": "^4.6.0",

View File

@@ -5,7 +5,7 @@
"dependencies": { "dependencies": {
"@blueprintjs-formik/core": "^0.2.1", "@blueprintjs-formik/core": "^0.2.1",
"@blueprintjs-formik/datetime": "^0.3.4", "@blueprintjs-formik/datetime": "^0.3.4",
"@blueprintjs-formik/select": "^0.2.2", "@blueprintjs-formik/select": "^0.2.3",
"@blueprintjs/core": "^3.50.2", "@blueprintjs/core": "^3.50.2",
"@blueprintjs/datetime": "^3.23.12", "@blueprintjs/datetime": "^3.23.12",
"@blueprintjs/popover2": "^0.11.1", "@blueprintjs/popover2": "^0.11.1",

View File

@@ -1,11 +1,23 @@
// @ts-nocheck // @ts-nocheck
import React, { useMemo } from 'react'; import React from 'react';
import { MenuItem } from '@blueprintjs/core'; import { MenuItem } from '@blueprintjs/core';
import { FMultiSelect } from '../Forms'; import { FMultiSelect } from '../Forms';
import { accountPredicate } from './_components'; import { accountPredicate } from './_components';
import { MenuItemNestedText } from '../Menu'; import { MenuItemNestedText } from '../Menu';
import { usePreprocessingAccounts } from './_hooks'; import { usePreprocessingAccounts } from './_hooks';
// Create new account renderer.
const createNewItemRenderer = (query, active, handleClick) => {
return (
<MenuItem
icon="add"
text={intl.get('list.create', { value: `"${query}"` })}
active={active}
onClick={handleClick}
/>
);
};
/** /**
* Default account item renderer of the list. * Default account item renderer of the list.
* @returns {JSX.Element} * @returns {JSX.Element}
@@ -30,13 +42,16 @@ const accountRenderer = (
); );
}; };
// Create new item from the given query string.
const createNewItemFromQuery = (name) => ({ name });
/** /**
* Accounts multi-select field binded with Formik form. * Accounts multi-select field binded with Formik form.
* @param {*} param0
* @returns {JSX.Element} * @returns {JSX.Element}
*/ */
export function AccountsMultiSelect({ export function AccountsMultiSelect({
items, items,
allowCreate,
filterByRootTypes, filterByRootTypes,
filterByParentTypes, filterByParentTypes,
@@ -46,12 +61,22 @@ export function AccountsMultiSelect({
...rest ...rest
}) { }) {
// Filters accounts based on filter props. // Filters accounts based on filter props.
const filteredAccounts = usePreprocessingAccounts(accounts, { const filteredAccounts = usePreprocessingAccounts(items, {
filterByParentTypes, filterByParentTypes,
filterByTypes, filterByTypes,
filterByNormal, filterByNormal,
filterByRootTypes, filterByRootTypes,
}); });
// Maybe inject new item props to select component.
const maybeCreateNewItemRenderer = allowCreate ? createNewItemRenderer : null;
const maybeCreateNewItemFromQuery = allowCreate
? createNewItemFromQuery
: null;
// Handles the create item click.
const handleCreateItemClick = () => {
openDialog(DialogsName.AccountForm);
};
return ( return (
<FMultiSelect <FMultiSelect
@@ -63,6 +88,9 @@ export function AccountsMultiSelect({
popoverProps={{ minimal: true }} popoverProps={{ minimal: true }}
itemPredicate={accountPredicate} itemPredicate={accountPredicate}
itemRenderer={accountRenderer} itemRenderer={accountRenderer}
createNewItemRenderer={maybeCreateNewItemRenderer}
createNewItemFromQuery={maybeCreateNewItemFromQuery}
onCreateItemSelect={handleCreateItemClick}
{...rest} {...rest}
/> />
); );

View File

@@ -5,6 +5,7 @@ import intl from 'react-intl-universal';
import { MenuItem } from '@blueprintjs/core'; import { MenuItem } from '@blueprintjs/core';
import { MenuItemNestedText, FSelect } from '@/components'; import { MenuItemNestedText, FSelect } from '@/components';
import { accountPredicate } from './_components'; import { accountPredicate } from './_components';
import { DialogsName } from '@/constants/dialogs';
import withDialogActions from '@/containers/Dialog/withDialogActions'; import withDialogActions from '@/containers/Dialog/withDialogActions';
import { usePreprocessingAccounts } from './_hooks'; import { usePreprocessingAccounts } from './_hooks';
@@ -75,6 +76,11 @@ function AccountsSelectRoot({
? createNewItemFromQuery ? createNewItemFromQuery
: null; : null;
// Handles the create item click.
const handleCreateItemClick = () => {
openDialog(DialogsName.AccountForm);
};
return ( return (
<FSelect <FSelect
items={filteredAccounts} items={filteredAccounts}
@@ -86,6 +92,7 @@ function AccountsSelectRoot({
itemRenderer={accountRenderer} itemRenderer={accountRenderer}
createNewItemRenderer={maybeCreateNewItemRenderer} createNewItemRenderer={maybeCreateNewItemRenderer}
createNewItemFromQuery={maybeCreateNewItemFromQuery} createNewItemFromQuery={maybeCreateNewItemFromQuery}
onCreateItemSelect={handleCreateItemClick}
{...restProps} {...restProps}
/> />
); );

View File

@@ -52,6 +52,7 @@ body.hide-scrollbar .Pane2 {
} }
.bp3-fill { .bp3-fill {
.bp3-popover-wrapper, .bp3-popover-wrapper,
.bp3-popover-target { .bp3-popover-target {
display: block; display: block;
@@ -68,9 +69,9 @@ body.hide-scrollbar .Pane2 {
margin-right: 6px; margin-right: 6px;
} }
.bp3-select-popover .bp3-menu { .bp3-select-popover .bp3-menu,
.bp3-multi-select-popover .bp3-menu {
max-height: 300px; max-height: 300px;
max-width: 400px;
overflow: auto; overflow: auto;
} }
@@ -103,27 +104,21 @@ body.hide-scrollbar .Pane2 {
background-color: #0066ff; background-color: #0066ff;
} }
.ReactVirtualized__Collection { .ReactVirtualized__Collection {}
}
.ReactVirtualized__Collection__innerScrollContainer { .ReactVirtualized__Collection__innerScrollContainer {}
}
/* Grid default theme */ /* Grid default theme */
.ReactVirtualized__Grid { .ReactVirtualized__Grid {}
}
.ReactVirtualized__Grid__innerScrollContainer { .ReactVirtualized__Grid__innerScrollContainer {}
}
/* Table default theme */ /* Table default theme */
.ReactVirtualized__Table { .ReactVirtualized__Table {}
}
.ReactVirtualized__Table__Grid { .ReactVirtualized__Table__Grid {}
}
.ReactVirtualized__Table__headerRow { .ReactVirtualized__Table__headerRow {
font-weight: 700; font-weight: 700;
@@ -186,8 +181,7 @@ body.hide-scrollbar .Pane2 {
/* List default theme */ /* List default theme */
.ReactVirtualized__List { .ReactVirtualized__List {}
}
.bp3-drawer { .bp3-drawer {
box-shadow: 0 0 0; box-shadow: 0 0 0;
@@ -243,7 +237,7 @@ html[lang^='ar'] {
padding-left: 14px; padding-left: 14px;
padding-right: 14px; padding-right: 14px;
& + .bp3-button { &+.bp3-button {
margin-left: 8px; margin-left: 8px;
} }
} }
@@ -255,7 +249,7 @@ html[lang^='ar'] {
margin: 0; margin: 0;
} }
> .bp3-spinner { >.bp3-spinner {
margin: 20px 0; margin: 20px 0;
} }
} }
@@ -283,6 +277,7 @@ html[lang^='ar'] {
.align-right { .align-right {
text-align: right; text-align: right;
} }
.align-center { .align-center {
text-align: center; text-align: center;
} }
@@ -292,6 +287,6 @@ html[lang^='ar'] {
} }
span.table-tooltip-overview-target{ span.table-tooltip-overview-target {
display: inline; display: inline;
} }