Skip to content

Commit

Permalink
EPMRPP-91778 || Update the view of available actions based on permiss… (
Browse files Browse the repository at this point in the history
#3994)

* EPMRPP-91778 || Update the view of available actions based on permissions. Dashboards, Filters pages

* EPMRPP-91778 || fix sonarcloud
  • Loading branch information
BlazarQSO authored Sep 2, 2024
1 parent 5634c09 commit 6a5d8b6
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 110 deletions.
2 changes: 2 additions & 0 deletions app/localization/translated/be.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@
"DashboardEmptyResults.currentUserDashboardsActionText": "Дадаць новую панэль кіравання",
"DashboardEmptyResults.currentUserDashboardsHeadline": "У вас няма панэляў кіравання",
"DashboardEmptyResults.currentUserDashboardsText": "Дадайце сваю першую панэль кіравання, каб прааналізаваць статыстыку",
"DashboardEmptyResults.currentUserDashboardsTextViewer": "Пасля стварэння вашай камандай тут з'явяцца панэлі кіравання",
"DashboardEmptyResults.noDashboardFound": "Панэляў кіравання для \"{filter}\" не знойдзена",
"DashboardForm.addModalSubmitButtonText": "Дадаць",
"DashboardForm.addModalTitle": "Дадаць новую панэль кіравання",
Expand All @@ -465,6 +466,7 @@
"DashboardItemPage.addNewWidget": "Дадаць новы віджэт",
"DashboardItemPage.addWidgetSuccess": "Віджэт дададзены",
"DashboardItemPage.dashboardEmptyText": "Дадайце Ваш першы віджэт каб прааналізаваць статыстыку",
"DashboardItemPage.dashboardEmptyTextViewer": "Віджэты з'явяцца тут пасля стварэння вашай камандай",
"DashboardItemPage.delete": "Выдаліць",
"DashboardItemPage.editDashboard": "Рэдагаваць",
"DashboardItemPage.fullscreen": "Поўнаэкранны рэжым",
Expand Down
4 changes: 3 additions & 1 deletion app/localization/translated/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@
"DashboardEmptyResults.currentUserDashboardsActionText": "Agregar nuevo panel de control",
"DashboardEmptyResults.currentUserDashboardsHeadline": "No tienes paneles de control",
"DashboardEmptyResults.currentUserDashboardsText": "Añade tu primer panel de control para analizar las estadísticas",
"DashboardEmptyResults.currentUserDashboardsTextViewer": "Dashboards will appear here once created by your team",
"DashboardEmptyResults.noDashboardFound": "No se encontraron paneles de control para \"{filter}\"",
"DashboardForm.addModalSubmitButtonText": "Añadir",
"DashboardForm.addModalTitle": "Añadir nuevo panel de control",
Expand All @@ -464,6 +465,7 @@
"DashboardItemPage.addNewWidget": "Añadir nuevo widget",
"DashboardItemPage.addWidgetSuccess": "Widget añadido",
"DashboardItemPage.dashboardEmptyText": "Añade el primer widget para analizar las estadísticas",
"DashboardItemPage.dashboardEmptyTextViewer": "Widgets will appear here once created by your team",
"DashboardItemPage.delete": "Eliminar",
"DashboardItemPage.editDashboard": "Editar",
"DashboardItemPage.fullscreen": "Modo pantalla completa",
Expand Down Expand Up @@ -2263,4 +2265,4 @@
"usersGrid.roleNonAdmin": "No Admin",
"usersGrid.type": "Tipo",
"usersGrid.user": "Usuario"
}
}
2 changes: 2 additions & 0 deletions app/localization/translated/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@
"DashboardEmptyResults.currentUserDashboardsActionText": "Добавить новую Панель управления",
"DashboardEmptyResults.currentUserDashboardsHeadline": "У вас нет Панелей управления",
"DashboardEmptyResults.currentUserDashboardsText": "Добавьте свою первую Панель управления, чтобы проанализировать статистику",
"DashboardEmptyResults.currentUserDashboardsTextViewer": "После создания вашей командой здесь появятся панели управления",
"DashboardEmptyResults.noDashboardFound": "Панелей управления для \"{filter}\" не найдено",
"DashboardForm.addModalSubmitButtonText": "Добавить",
"DashboardForm.addModalTitle": "Добавить новую Панель управления",
Expand All @@ -465,6 +466,7 @@
"DashboardItemPage.addNewWidget": "Добавить новый виджет",
"DashboardItemPage.addWidgetSuccess": "Виджет добавлен",
"DashboardItemPage.dashboardEmptyText": "Добавьте первый виджет, чтобы проанализировать статистику",
"DashboardItemPage.dashboardEmptyTextViewer": "Виджеты появятся здесь после того, как они будут созданы вашей командой",
"DashboardItemPage.delete": "Удалить",
"DashboardItemPage.editDashboard": "Редактировать",
"DashboardItemPage.fullscreen": "Полноэкранный режим",
Expand Down
2 changes: 2 additions & 0 deletions app/localization/translated/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@
"DashboardEmptyResults.currentUserDashboardsActionText": "Додати нову Панель управління",
"DashboardEmptyResults.currentUserDashboardsHeadline": "У вас немає Панелей управління",
"DashboardEmptyResults.currentUserDashboardsText": "Додайте свою першу Панель управління, щоб проаналізувати статистику",
"DashboardEmptyResults.currentUserDashboardsTextViewer": "Після створення вашою командою тут з'являться панелі управління",
"DashboardEmptyResults.noDashboardFound": "Панель керування для \"{filter}\" не знайдено",
"DashboardForm.addModalSubmitButtonText": "Додати",
"DashboardForm.addModalTitle": "Додати нову Панель управління",
Expand All @@ -465,6 +466,7 @@
"DashboardItemPage.addNewWidget": "Додати новий віджет",
"DashboardItemPage.addWidgetSuccess": "Доданий віджет",
"DashboardItemPage.dashboardEmptyText": "Додайте перший віджет, щоб проаналізувати статистику",
"DashboardItemPage.dashboardEmptyTextViewer": "Віджети з'являться тут після того, як вони будуть створені вашою командою",
"DashboardItemPage.delete": "Видалити",
"DashboardItemPage.editDashboard": "Редагувати",
"DashboardItemPage.fullscreen": "Повноекранний Режим",
Expand Down
2 changes: 2 additions & 0 deletions app/localization/translated/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@
"DashboardEmptyResults.currentUserDashboardsActionText": "添加新报告面板",
"DashboardEmptyResults.currentUserDashboardsHeadline": "您没有报告面板",
"DashboardEmptyResults.currentUserDashboardsText": "添加您的第一个报告面板以分析统计数据",
"DashboardEmptyResults.currentUserDashboardsTextViewer": "Dashboards will appear here once created by your team",
"DashboardEmptyResults.noDashboardFound": "未找到\"{filter}\"的报告面板",
"DashboardForm.addModalSubmitButtonText": "添加",
"DashboardForm.addModalTitle": "添加新报告面板",
Expand All @@ -465,6 +466,7 @@
"DashboardItemPage.addNewWidget": "添加新小部件",
"DashboardItemPage.addWidgetSuccess": "小部件已添加",
"DashboardItemPage.dashboardEmptyText": "添加您的第一个小部件以分析统计数据",
"DashboardItemPage.dashboardEmptyTextViewer": "Widgets will appear here once created by your team",
"DashboardItemPage.delete": "删除",
"DashboardItemPage.editDashboard": "编辑",
"DashboardItemPage.fullscreen": "全屏化",
Expand Down
11 changes: 7 additions & 4 deletions app/src/layouts/projectLayout/projectSidebar/projectSidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { useTracking } from 'react-tracking';
import { userRolesSelector, urlOrganizationAndProjectSelector } from 'controllers/pages';
import { SIDEBAR_EVENTS } from 'components/main/analytics/events';
import { FormattedMessage, useIntl } from 'react-intl';
import { canSeeMembers } from 'common/utils/permissions';
import { canSeeMembers, canWorkWithFilters } from 'common/utils/permissions';
import { ALL } from 'common/constants/reservedFilterIds';
import {
PROJECT_DASHBOARD_PAGE,
Expand Down Expand Up @@ -95,13 +95,16 @@ export const ProjectSidebar = ({ onClickNavBtn }) => {
icon: DebugIcon,
message: <FormattedMessage id={'Sidebar.debugBtn'} defaultMessage={'Debug Mode'} />,
},
{
];

if (canWorkWithFilters(userRoles)) {
sidebarItems.push({
onClick: () => onClickButton(SIDEBAR_EVENTS.CLICK_FILTERS_BTN),
link: { type: PROJECT_FILTERS_PAGE, payload: { organizationSlug, projectSlug } },
icon: FiltersIcon,
message: <FormattedMessage id={'Sidebar.filtersBtn'} defaultMessage={'Filters'} />,
},
];
});
}

if (canSeeMembers(userRoles)) {
sidebarItems.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ export class DashboardPageHeader extends Component {

render() {
const { activeItemId, isLoading, totalDashboards, userRoles } = this.props;

const isAboveLimit = totalDashboards >= DASHBOARDS_LIMIT;
const disabled = isLoading || isAboveLimit || !canWorkWithDashboard(userRoles);
const disabled = isLoading || isAboveLimit;

return (
<div className={cx('dashboard-page-header')}>
Expand All @@ -145,7 +144,7 @@ export class DashboardPageHeader extends Component {
value={activeItemId || DASHBOARD_PAGE_ITEM_VALUE}
/>
</div>
<AddDashboardButton disabled={disabled} />
{canWorkWithDashboard(userRoles) && <AddDashboardButton disabled={disabled} />}
</div>
);
}
Expand Down
30 changes: 17 additions & 13 deletions app/src/pages/inside/dashboardItemPage/dashboardItemPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ export class DashboardItemPage extends Component {
userRoles,
} = this.props;

const isWorkWithWidgets = canWorkWithWidgets(userRoles);

return (
<PageLayout>
<PageHeader breadcrumbs={this.getBreadcrumbs()}>
Expand All @@ -341,24 +343,26 @@ export class DashboardItemPage extends Component {
<div className={cx('dashboard-item')}>
<div className={cx('buttons-container')}>
<div className={cx('buttons-block')}>
<GhostButton
icon={AddWidgetIcon}
onClick={this.showWidgetWizard}
disabled={!canWorkWithWidgets(userRoles)}
>
{formatMessage(messages.addNewWidget)}
</GhostButton>
{isWorkWithWidgets && (
<GhostButton icon={AddWidgetIcon} onClick={this.showWidgetWizard}>
{formatMessage(messages.addNewWidget)}
</GhostButton>
)}
</div>
<div className={cx('buttons-block')}>
<GhostButton icon={EditIcon} onClick={this.onEditDashboardItem}>
{formatMessage(messages.editDashboard)}
</GhostButton>
{isWorkWithWidgets && (
<GhostButton icon={EditIcon} onClick={this.onEditDashboardItem}>
{formatMessage(messages.editDashboard)}
</GhostButton>
)}
<GhostButton icon={FullscreenIcon} onClick={this.toggleFullscreen}>
{formatMessage(messages.fullscreen)}
</GhostButton>
<GhostButton icon={CancelIcon} onClick={this.onDeleteDashboard}>
{formatMessage(messages.delete)}
</GhostButton>
{isWorkWithWidgets && (
<GhostButton icon={CancelIcon} onClick={this.onDeleteDashboard}>
{formatMessage(messages.delete)}
</GhostButton>
)}
<Link
to={{
type: PROJECT_DASHBOARD_PRINT_PAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const messages = defineMessages({
id: 'DashboardItemPage.dashboardEmptyText',
defaultMessage: 'Add your first widget to analyse statistics',
},
dashboardEmptyTextViewer: {
id: 'DashboardItemPage.dashboardEmptyTextViewer',
defaultMessage: 'Widgets will appear here once created by your team',
},
notMyDashboardEmptyHeader: {
id: 'DashboardItemPage.notMyDashboardEmptyHeader',
defaultMessage: 'There are no widgets on this dashboard',
Expand All @@ -62,6 +66,7 @@ export class EmptyWidgetGrid extends Component {

render() {
const { action, intl, isDisable, userRoles } = this.props;
const isWorkWithDashboard = canWorkWithWidgets(userRoles);

return (
<div className={cx('empty-widget')}>
Expand All @@ -72,17 +77,17 @@ export class EmptyWidgetGrid extends Component {
{!isDisable && (
<Fragment>
<p className={cx('empty-widget-text')}>
{intl.formatMessage(messages.dashboardEmptyText)}
{isWorkWithDashboard
? intl.formatMessage(messages.dashboardEmptyText)
: intl.formatMessage(messages.dashboardEmptyTextViewer)}
</p>
<div className={cx('empty-widget-content')}>
<GhostButton
icon={AddDashboardIcon}
onClick={action}
disabled={!canWorkWithWidgets(userRoles)}
>
{intl.formatMessage(messages.addNewWidget)}
</GhostButton>
</div>
{isWorkWithDashboard && (
<div className={cx('empty-widget-content')}>
<GhostButton icon={AddDashboardIcon} onClick={action}>
{intl.formatMessage(messages.addNewWidget)}
</GhostButton>
</div>
)}
</Fragment>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const messages = defineMessages({
id: 'DashboardEmptyResults.currentUserDashboardsText',
defaultMessage: 'Add your first dashboard to analyse statistics',
},
currentUserDashboardsTextViewer: {
id: 'DashboardEmptyResults.currentUserDashboardsTextViewer',
defaultMessage: 'Dashboards will appear here once created by your team',
},
currentUserDashboardsActionText: {
id: 'DashboardEmptyResults.currentUserDashboardsActionText',
defaultMessage: 'Add New Dashboard',
Expand Down Expand Up @@ -83,6 +87,7 @@ export class EmptyDashboards extends Component {

render() {
const { intl, filter, userRoles } = this.props;
const isWorkWithDashboard = canWorkWithDashboard(userRoles);

if (filter)
return <NoResultsForFilter filter={filter} notFoundMessage={messages.noDashboardFound} />;
Expand All @@ -94,17 +99,17 @@ export class EmptyDashboards extends Component {
{intl.formatMessage(messages.currentUserDashboardsHeadline)}
</p>
<p className={cx('empty-dashboard-text')}>
{intl.formatMessage(messages.currentUserDashboardsText)}
{isWorkWithDashboard
? intl.formatMessage(messages.currentUserDashboardsText)
: intl.formatMessage(messages.currentUserDashboardsTextViewer)}
</p>
<div className={cx('empty-dashboard-content')}>
<GhostButton
icon={AddDashboardIcon}
onClick={this.handleAddDashboardAction}
disabled={!canWorkWithDashboard(userRoles)}
>
{intl.formatMessage(messages.currentUserDashboardsActionText)}
</GhostButton>
</div>
{isWorkWithDashboard && (
<div className={cx('empty-dashboard-content')}>
<GhostButton icon={AddDashboardIcon} onClick={this.handleAddDashboardAction}>
{intl.formatMessage(messages.currentUserDashboardsActionText)}
</GhostButton>
</div>
)}
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ export class DashboardTable extends Component {
slugs: { organizationSlug, projectSlug },
} = this.props;

const disabled = !canWorkWithDashboard(userRoles);

return [
const columns = [
{
title: {
full: intl.formatMessage(messages.dashboardName),
Expand Down Expand Up @@ -131,31 +129,36 @@ export class DashboardTable extends Component {
formatter: (value) => value.owner,
component: OwnerColumn,
},
{
title: {
full: intl.formatMessage(messages.edit),
short: intl.formatMessage(messages.edit),
},
component: EditColumn,
customProps: {
onEdit: onEditItem,
disabled,
},
align: ALIGN_CENTER,
},
{
title: {
full: intl.formatMessage(messages.deleteDashboard),
short: intl.formatMessage(messages.deleteDashboard),
];

if (canWorkWithDashboard(userRoles)) {
columns.push(
{
title: {
full: intl.formatMessage(messages.edit),
short: intl.formatMessage(messages.edit),
},
component: EditColumn,
customProps: {
onEdit: onEditItem,
},
align: ALIGN_CENTER,
},
component: DeleteColumn,
customProps: {
onDelete: onDeleteItem,
disabled,
{
title: {
full: intl.formatMessage(messages.deleteDashboard),
short: intl.formatMessage(messages.deleteDashboard),
},
component: DeleteColumn,
customProps: {
onDelete: onDeleteItem,
},
align: ALIGN_CENTER,
},
align: ALIGN_CENTER,
},
];
);
}

return columns;
}

render() {
Expand Down
14 changes: 9 additions & 5 deletions app/src/pages/inside/filtersPage/filterGrid/filterGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class FilterGrid extends Component {
const { userRoles } = this.props;
const editable = canWorkWithFilters(userRoles);

return [
const columns = [
{
id: 'name',
title: {
Expand Down Expand Up @@ -245,7 +245,10 @@ export class FilterGrid extends Component {
readOnly: !editable,
},
},
{
];

if (editable) {
columns.push({
id: 'delete',
title: {
full: this.props.intl.formatMessage(messages.deleteCol),
Expand All @@ -257,10 +260,11 @@ export class FilterGrid extends Component {
this.props.onDelete(filter);
this.props.tracking.trackEvent(FILTERS_PAGE_EVENTS.CLICK_DELETE_FILTER_ICON);
},
disabled: !editable,
},
},
];
});
}

return columns;
};

render() {
Expand Down
Loading

0 comments on commit 6a5d8b6

Please sign in to comment.