Skip to content

Commit

Permalink
Merge pull request #139 from irontec/CDL-62-additional-action-buttons…
Browse files Browse the repository at this point in the history
…-in-no-items-window

Added global actions on empty screen
  • Loading branch information
rbatistadev authored Sep 25, 2024
2 parents e8abf20 + c2f0a97 commit f101a28
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@irontec/ivoz-ui",
"version": "1.5.1",
"version": "1.6.0",
"description": "UI library used in ivozprovider",
"license": "GPL-3.0",
"main": "index.js",
Expand Down
8 changes: 8 additions & 0 deletions library/src/components/List/Content/Empty.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@ export const StyledEmpty = styled(Empty)(() => {
'& img': {
maxWidth: '100%',
},

'& .empty-actions': {
display: 'flex',
flexDirection: 'row',
'& a': {
marginLeft: '8px',
},
},
};
});
48 changes: 41 additions & 7 deletions library/src/components/List/Content/Empty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import EntityService from '../../../services/entity/EntityService';
import _ from '../../../services/translations/translate';
import { SolidButton } from '../../shared/Button/Button.styles';
import { useTranslation } from 'react-i18next';
import { Fade } from '@mui/material';
import { Box, Fade } from '@mui/material';
import { useStoreState } from '../../../store';
import { GlobalFunctionComponent, MultiSelectFunctionComponent } from 'router';
import { MultiselectMoreChildEntityLinks } from './Shared/MultiselectMoreChildEntityLinks';

export interface EmptyProps {
entityService: EntityService;
Expand All @@ -16,7 +18,6 @@ export const Empty = (props: EmptyProps): JSX.Element => {
const { t } = useTranslation();

const entity = entityService.getEntity();

const parentRow = useStoreState((state) => state.list.parentRow);
const acls = entityService.getAcls(parentRow);
const { create = false } = acls;
Expand All @@ -30,6 +31,9 @@ export const Empty = (props: EmptyProps): JSX.Element => {
singularTitle = t(translationKey, { count: 1 }).toLowerCase();
pluralTitle = t(translationKey, { count: 2 }).toLowerCase();
}
const globalActions = Object.values(entity.customActions).filter(
(action) => action.global
);

return (
<Fade
Expand All @@ -48,11 +52,41 @@ export const Empty = (props: EmptyProps): JSX.Element => {
})}
</p>
{create && (
<Link to={location.pathname + '/create'}>
<SolidButton>
{_('New {{entity}}', { entity: singularTitle })}
</SolidButton>
</Link>
<Box className='empty-actions'>
{globalActions &&
globalActions.length < 2 &&
globalActions
.map(
(item) =>
item.action as
| MultiSelectFunctionComponent
| GlobalFunctionComponent
)
.map((Action, key) => {
return (
<Action
key={key}
rows={[]}
selectedValues={[]}
entityService={entityService}
/>
);
})}
{globalActions && globalActions.length > 1 && (
<MultiselectMoreChildEntityLinks
childActions={globalActions}
selectedValues={[]}
rows={[]}
entityService={entityService}
/>
)}

<Link to={location.pathname + '/create'}>
<SolidButton>
{_('New {{entity}}', { entity: singularTitle })}
</SolidButton>
</Link>
</Box>
)}
</section>
</Fade>
Expand Down

0 comments on commit f101a28

Please sign in to comment.