Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added global actions on empty screen #139

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading