MM 60222 - apply filter to export csv (#28212)
* MM-60222_apply filter to export csv * get the report exporting with the filters ready * add unit tests * cover one more file with some tests * style the confirm modal note * add translations * remove unnecessary print line * disable export button if there is no data to export * fix linter issues * fix linter errors --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
@@ -2,7 +2,7 @@
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import type {ServerError} from '@mattermost/types/errors';
|
||||
import type {UserReportOptions, UserReport, UserReportFilter, ReportDuration} from '@mattermost/types/reports';
|
||||
import type {UserReportOptions, UserReport, UserReportFilter} from '@mattermost/types/reports';
|
||||
|
||||
import {logError} from 'mattermost-redux/actions/errors';
|
||||
import {forceLogoutIfNecessary} from 'mattermost-redux/actions/helpers';
|
||||
@@ -67,10 +67,10 @@ export function getUserCountForReporting(filter = {} as UserReportFilter): Actio
|
||||
};
|
||||
}
|
||||
|
||||
export function startUsersBatchExport(dateRange: ReportDuration): ActionFuncAsync {
|
||||
export function startUsersBatchExport(tableFilters = {} as UserReportOptions): ActionFuncAsync {
|
||||
return async (dispatch, getState) => {
|
||||
try {
|
||||
await Client4.startUsersBatchExport(dateRange);
|
||||
await Client4.startUsersBatchExport(tableFilters);
|
||||
} catch (error) {
|
||||
forceLogoutIfNecessary(error, dispatch, getState);
|
||||
dispatch(logError(error));
|
||||
|
||||
@@ -564,7 +564,7 @@ function SystemUsers(props: Props) {
|
||||
/>
|
||||
<SystemUsersExport
|
||||
currentUserId={props.currentUser.id}
|
||||
dateRange={props.tablePropertyDateRange}
|
||||
usersLenght={userReports.length}
|
||||
/>
|
||||
</div>
|
||||
<AdminConsoleListTable<UserReport>
|
||||
|
||||
@@ -17,7 +17,8 @@ type Props = {
|
||||
}
|
||||
|
||||
export function ExportUserDataModal({onConfirm, onExited}: Props) {
|
||||
const dateRange = useSelector(getAdminConsoleUserManagementTableProperties).dateRange ?? ReportDuration.AllTime;
|
||||
const tableFilterProps = useSelector(getAdminConsoleUserManagementTableProperties);
|
||||
const dateRange = tableFilterProps.dateRange ?? ReportDuration.AllTime;
|
||||
|
||||
const title = (
|
||||
<FormattedMessage
|
||||
@@ -55,6 +56,21 @@ export function ExportUserDataModal({onConfirm, onExited}: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
const tableFiltersAreSet = tableFilterProps.filterRole !== '' || tableFilterProps.filterStatus || tableFilterProps.filterTeam !== '';
|
||||
if (tableFiltersAreSet) {
|
||||
message = (
|
||||
<>
|
||||
{message}
|
||||
<p className='mt-3 text-muted'>
|
||||
<FormattedMessage
|
||||
id='export_user_data_modal.export_data.table_filters_note'
|
||||
defaultMessage={'Note: The exported data will use the filters you have set in the users list. To export all data first remove the filters.'}
|
||||
/>
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const exportDataButton = (
|
||||
<FormattedMessage
|
||||
id='export_user_data_modal.export_data'
|
||||
|
||||
@@ -5,7 +5,7 @@ import React from 'react';
|
||||
import {FormattedMessage, useIntl} from 'react-intl';
|
||||
import {useDispatch, useSelector} from 'react-redux';
|
||||
|
||||
import type {ReportDuration} from '@mattermost/types/reports';
|
||||
import {ReportDuration} from '@mattermost/types/reports';
|
||||
import type {GlobalState} from '@mattermost/types/store';
|
||||
import type {UserProfile} from '@mattermost/types/users';
|
||||
|
||||
@@ -16,6 +16,7 @@ import {get} from 'mattermost-redux/selectors/entities/preferences';
|
||||
|
||||
import {startUsersBatchExport} from 'actions/views/admin';
|
||||
import {openModal} from 'actions/views/modals';
|
||||
import {getAdminConsoleUserManagementTableProperties} from 'selectors/views/admin';
|
||||
|
||||
import WithTooltip from 'components/with_tooltip';
|
||||
|
||||
@@ -25,11 +26,12 @@ import {ExportErrorModal} from './export_error_modal';
|
||||
import {ExportUserDataModal} from './export_user_data_modal';
|
||||
import {UpgradeExportDataModal} from './upgrade_export_data_modal';
|
||||
|
||||
import {convertTableOptionsToUserReportOptions} from '../utils';
|
||||
import './system_users_export.scss';
|
||||
|
||||
interface Props {
|
||||
currentUserId: UserProfile['id'];
|
||||
dateRange: ReportDuration;
|
||||
usersLenght: number;
|
||||
}
|
||||
|
||||
export function SystemUsersExport(props: Props) {
|
||||
@@ -38,12 +40,17 @@ export function SystemUsersExport(props: Props) {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const skipDialog = useSelector((state: GlobalState) => get(state, Preferences.CATEGORY_REPORTING, Preferences.HIDE_BATCH_EXPORT_CONFIRM_MODAL, '')) === 'true';
|
||||
const tableFilterProps = useSelector(getAdminConsoleUserManagementTableProperties);
|
||||
const tableOptionsToUserReport = convertTableOptionsToUserReportOptions(tableFilterProps);
|
||||
if (tableOptionsToUserReport.date_range === undefined) {
|
||||
tableOptionsToUserReport.date_range = ReportDuration.AllTime;
|
||||
}
|
||||
|
||||
const license = useSelector(getLicense);
|
||||
const isLicensed = license.IsLicensed === 'true' && (license.SkuShortName === LicenseSkus.Professional || license.SkuShortName === LicenseSkus.Enterprise);
|
||||
|
||||
async function doExport(checked?: boolean) {
|
||||
const {error} = await dispatch(startUsersBatchExport(props.dateRange));
|
||||
const {error} = await dispatch(startUsersBatchExport(tableOptionsToUserReport));
|
||||
if (error) {
|
||||
dispatch(openModal({
|
||||
modalId: ModalIdentifiers.EXPORT_ERROR_MODAL,
|
||||
@@ -64,6 +71,9 @@ export function SystemUsersExport(props: Props) {
|
||||
}
|
||||
|
||||
function handleExport() {
|
||||
if (!props.usersLenght) {
|
||||
return;
|
||||
}
|
||||
if (!isLicensed) {
|
||||
dispatch(openModal({
|
||||
modalId: ModalIdentifiers.UPGRADE_EXPORT_DATA_MODAL,
|
||||
@@ -89,6 +99,7 @@ export function SystemUsersExport(props: Props) {
|
||||
<button
|
||||
onClick={handleExport}
|
||||
className='btn btn-md btn-tertiary'
|
||||
disabled={!props.usersLenght}
|
||||
>
|
||||
<span className='icon icon-download-outline'/>
|
||||
<FormattedMessage
|
||||
|
||||
@@ -3639,6 +3639,7 @@
|
||||
"export_user_data_modal.dange_range.previous_month": "You're about to export user data for the previous month. When the export is ready, a CSV file will be sent to you in a Mattermost direct message. This export will take a few minutes.",
|
||||
"export_user_data_modal.do_not_show": "Do not show this again",
|
||||
"export_user_data_modal.export_data": "Export data",
|
||||
"export_user_data_modal.export_data.table_filters_note": "Note: The exported data will use the filters you have set in the users list. To export all data first remove the filters.",
|
||||
"export_user_data_modal.title": "Export user data",
|
||||
"feature_restricted_modal.agreement": "By selecting <highlight>Try free for {trialLength} days</highlight>, I agree to the <linkEvaluation>Mattermost Software Evaluation Agreement</linkEvaluation>, <linkPrivacy>Privacy Policy</linkPrivacy>, and receiving product emails.",
|
||||
"feature_restricted_modal.button.notify": "Notify admin",
|
||||
|
||||
@@ -1025,8 +1025,8 @@ export default class Client4 {
|
||||
);
|
||||
};
|
||||
|
||||
startUsersBatchExport = (dateRange: string) => {
|
||||
const queryString = buildQueryString({date_range: dateRange});
|
||||
startUsersBatchExport = (filter: UserReportFilter) => {
|
||||
const queryString = buildQueryString(filter);
|
||||
return this.doFetch<StatusOK>(
|
||||
`${this.getReportsRoute()}/users/export${queryString}`,
|
||||
{method: 'post'},
|
||||
|
||||
Ссылка в новой задаче
Block a user