2020-05-29 09:38:07 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { i18n } from '@kbn/i18n';
|
|
|
|
import { LensFilterEvent } from './types';
|
|
|
|
|
|
|
|
/** replaces the value `(empty) to empty string for proper filtering` */
|
|
|
|
export const desanitizeFilterContext = (
|
|
|
|
context: LensFilterEvent['data']
|
|
|
|
): LensFilterEvent['data'] => {
|
|
|
|
const emptyTextValue = i18n.translate('xpack.lens.indexpattern.emptyTextColumnValue', {
|
|
|
|
defaultMessage: '(empty)',
|
|
|
|
});
|
2020-10-13 17:00:38 +02:00
|
|
|
const result: LensFilterEvent['data'] = {
|
2020-05-29 09:38:07 +02:00
|
|
|
...context,
|
|
|
|
data: context.data.map((point) =>
|
|
|
|
point.value === emptyTextValue
|
|
|
|
? {
|
|
|
|
...point,
|
|
|
|
value: '',
|
|
|
|
table: {
|
|
|
|
...point.table,
|
|
|
|
rows: point.table.rows.map((row, index) =>
|
|
|
|
index === point.row
|
|
|
|
? {
|
|
|
|
...row,
|
|
|
|
[point.table.columns[point.column].id]: '',
|
|
|
|
}
|
|
|
|
: row
|
|
|
|
),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: point
|
|
|
|
),
|
|
|
|
};
|
2020-10-13 17:00:38 +02:00
|
|
|
if (context.timeFieldName) {
|
|
|
|
result.timeFieldName = context.timeFieldName;
|
|
|
|
}
|
|
|
|
return result;
|
2020-05-29 09:38:07 +02:00
|
|
|
};
|