[DX] Upgrade prettier to v2.4.0 (#112359)

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
This commit is contained in:
Tyler Smalley 2021-09-19 22:34:30 -07:00 committed by GitHub
parent f1e9668aa2
commit 4681a80317
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2937 changed files with 28631 additions and 30518 deletions

View file

@ -49,9 +49,8 @@ function getItemIdToExpandedRowMap(
export const FieldsStatsGrid: FC<Props> = ({ results }) => {
const restorableDefaults = getDefaultDataVisualizerListState();
const [dataVisualizerListState, setDataVisualizerListState] = useState<DataVisualizerTableState>(
restorableDefaults
);
const [dataVisualizerListState, setDataVisualizerListState] =
useState<DataVisualizerTableState>(restorableDefaults);
const visibleFieldTypes =
dataVisualizerListState.visibleFieldTypes ?? restorableDefaults.visibleFieldTypes;

View file

@ -40,13 +40,8 @@ function getPercentLabel(docCount: number, topValuesSampleSize: number): string
export const TopValues: FC<Props> = ({ stats, fieldFormat, barColor, compressed }) => {
if (stats === undefined) return null;
const {
topValues,
topValuesSampleSize,
topValuesSamplerShardSize,
count,
isTopValuesSampled,
} = stats;
const { topValues, topValuesSampleSize, topValuesSamplerShardSize, count, isTopValuesSampled } =
stats;
const progressBarMax = isTopValuesSampled === true ? topValuesSampleSize : count;
return (
<EuiFlexItem data-test-subj={'dataVisualizerFieldDataTopValues'}>

View file

@ -48,14 +48,8 @@ export class EditFlyout extends Component {
};
render() {
const {
isFlyoutVisible,
closeEditFlyout,
setOverrides,
overrides,
originalSettings,
fields,
} = this.props;
const { isFlyoutVisible, closeEditFlyout, setOverrides, overrides, originalSettings, fields } =
this.props;
return (
<React.Fragment>

View file

@ -103,21 +103,22 @@ function getDefaultPageState(): DataVisualizerPageState {
documentCountStats: undefined,
};
}
export const getDefaultDataVisualizerListState = (): Required<DataVisualizerIndexBasedAppState> => ({
pageIndex: 0,
pageSize: 10,
sortField: 'fieldName',
sortDirection: 'asc',
visibleFieldTypes: [],
visibleFieldNames: [],
samplerShardSize: 5000,
searchString: '',
searchQuery: defaultSearchQuery,
searchQueryLanguage: SEARCH_QUERY_LANGUAGE.KUERY,
showDistributions: true,
showAllFields: false,
showEmptyFields: false,
});
export const getDefaultDataVisualizerListState =
(): Required<DataVisualizerIndexBasedAppState> => ({
pageIndex: 0,
pageSize: 10,
sortField: 'fieldName',
sortDirection: 'asc',
visibleFieldTypes: [],
visibleFieldNames: [],
samplerShardSize: 5000,
searchString: '',
searchQuery: defaultSearchQuery,
searchQueryLanguage: SEARCH_QUERY_LANGUAGE.KUERY,
showDistributions: true,
showAllFields: false,
showEmptyFields: false,
});
export interface IndexDataVisualizerViewProps {
currentIndexPattern: IndexPattern;
@ -163,10 +164,10 @@ export const IndexDataVisualizerView: FC<IndexDataVisualizerViewProps> = (dataVi
autoRefreshSelector: true,
});
const dataLoader = useMemo(() => new DataLoader(currentIndexPattern, toasts), [
currentIndexPattern,
toasts,
]);
const dataLoader = useMemo(
() => new DataLoader(currentIndexPattern, toasts),
[currentIndexPattern, toasts]
);
useEffect(() => {
if (globalState?.time !== undefined) {

View file

@ -31,7 +31,8 @@ export function DataVisualizerIndexPatternManagement(
} = useDataVisualizerKibana();
const { useNewFieldsApi, currentIndexPattern } = props;
const indexPatternFieldEditPermission = indexPatternFieldEditor?.userPermissions.editIndexPattern();
const indexPatternFieldEditPermission =
indexPatternFieldEditor?.userPermissions.editIndexPattern();
const canEditIndexPatternField = !!indexPatternFieldEditPermission && useNewFieldsApi;
const [isAddIndexPatternFieldPopoverOpen, setIsAddIndexPatternFieldPopoverOpen] = useState(false);

View file

@ -39,159 +39,150 @@ export interface DataVisualizerUrlStateContextProviderProps {
additionalLinks: ResultLink[];
}
export const DataVisualizerUrlStateContextProvider: FC<DataVisualizerUrlStateContextProviderProps> = ({
IndexDataVisualizerComponent,
additionalLinks,
}) => {
const {
services: {
data: { indexPatterns },
savedObjects: { client: savedObjectsClient },
notifications: { toasts },
},
} = useDataVisualizerKibana();
const history = useHistory();
export const DataVisualizerUrlStateContextProvider: FC<DataVisualizerUrlStateContextProviderProps> =
({ IndexDataVisualizerComponent, additionalLinks }) => {
const {
services: {
data: { indexPatterns },
savedObjects: { client: savedObjectsClient },
notifications: { toasts },
},
} = useDataVisualizerKibana();
const history = useHistory();
const [currentIndexPattern, setCurrentIndexPattern] = useState<IndexPattern | undefined>(
undefined
);
const [currentSavedSearch, setCurrentSavedSearch] = useState<SimpleSavedObject<unknown> | null>(
null
);
const { search: searchString } = useLocation();
const [currentIndexPattern, setCurrentIndexPattern] = useState<IndexPattern | undefined>(
undefined
);
const [currentSavedSearch, setCurrentSavedSearch] = useState<SimpleSavedObject<unknown> | null>(
null
);
const { search: searchString } = useLocation();
useEffect(() => {
const prevSearchString = searchString;
const parsedQueryString = parse(prevSearchString, { sort: false });
const getIndexPattern = async () => {
if (typeof parsedQueryString?.savedSearchId === 'string') {
const savedSearchId = parsedQueryString.savedSearchId;
try {
const savedSearch = await savedObjectsClient.get('search', savedSearchId);
const indexPatternId = savedSearch.references.find((ref) => ref.type === 'index-pattern')
?.id;
if (indexPatternId !== undefined && savedSearch) {
try {
const indexPattern = await indexPatterns.get(indexPatternId);
setCurrentSavedSearch(savedSearch);
setCurrentIndexPattern(indexPattern);
} catch (e) {
toasts.addError(e, {
title: i18n.translate('xpack.dataVisualizer.index.indexPatternErrorMessage', {
defaultMessage: 'Error finding index pattern',
}),
});
}
}
} catch (e) {
toasts.addError(e, {
title: i18n.translate('xpack.dataVisualizer.index.savedSearchErrorMessage', {
defaultMessage: 'Error retrieving saved search {savedSearchId}',
values: { savedSearchId },
}),
});
}
}
if (typeof parsedQueryString?.index === 'string') {
const indexPattern = await indexPatterns.get(parsedQueryString.index);
setCurrentIndexPattern(indexPattern);
}
};
getIndexPattern();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [savedObjectsClient, toasts, indexPatterns]);
const setUrlState: SetUrlState = useCallback(
(
accessor: Accessor,
attribute: string | Dictionary<any>,
value?: any,
replaceState?: boolean
) => {
useEffect(() => {
const prevSearchString = searchString;
const urlState = parseUrlState(prevSearchString);
const parsedQueryString = parse(prevSearchString, { sort: false });
if (!Object.prototype.hasOwnProperty.call(urlState, accessor)) {
urlState[accessor] = {};
}
if (typeof attribute === 'string') {
if (isEqual(getNestedProperty(urlState, `${accessor}.${attribute}`), value)) {
return prevSearchString;
}
urlState[accessor][attribute] = value;
} else {
const attributes = attribute;
Object.keys(attributes).forEach((a) => {
urlState[accessor][a] = attributes[a];
});
}
try {
const oldLocationSearchString = stringify(parsedQueryString, {
sort: false,
encode: false,
});
Object.keys(urlState).forEach((a) => {
if (isRisonSerializationRequired(a)) {
parsedQueryString[a] = encode(urlState[a]);
} else {
parsedQueryString[a] = urlState[a];
}
});
const newLocationSearchString = stringify(parsedQueryString, {
sort: false,
encode: false,
});
if (oldLocationSearchString !== newLocationSearchString) {
const newSearchString = stringify(parsedQueryString, { sort: false });
if (replaceState) {
history.replace({ search: newSearchString });
} else {
history.push({ search: newSearchString });
const getIndexPattern = async () => {
if (typeof parsedQueryString?.savedSearchId === 'string') {
const savedSearchId = parsedQueryString.savedSearchId;
try {
const savedSearch = await savedObjectsClient.get('search', savedSearchId);
const indexPatternId = savedSearch.references.find(
(ref) => ref.type === 'index-pattern'
)?.id;
if (indexPatternId !== undefined && savedSearch) {
try {
const indexPattern = await indexPatterns.get(indexPatternId);
setCurrentSavedSearch(savedSearch);
setCurrentIndexPattern(indexPattern);
} catch (e) {
toasts.addError(e, {
title: i18n.translate('xpack.dataVisualizer.index.indexPatternErrorMessage', {
defaultMessage: 'Error finding index pattern',
}),
});
}
}
} catch (e) {
toasts.addError(e, {
title: i18n.translate('xpack.dataVisualizer.index.savedSearchErrorMessage', {
defaultMessage: 'Error retrieving saved search {savedSearchId}',
values: { savedSearchId },
}),
});
}
}
} catch (error) {
// eslint-disable-next-line no-console
console.error('Could not save url state', error);
}
},
[history, searchString]
);
return (
<UrlStateContextProvider value={{ searchString, setUrlState }}>
{currentIndexPattern ? (
<IndexDataVisualizerComponent
currentIndexPattern={currentIndexPattern}
currentSavedSearch={currentSavedSearch}
additionalLinks={additionalLinks}
/>
) : (
<div />
)}
</UrlStateContextProvider>
);
};
if (typeof parsedQueryString?.index === 'string') {
const indexPattern = await indexPatterns.get(parsedQueryString.index);
setCurrentIndexPattern(indexPattern);
}
};
getIndexPattern();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [savedObjectsClient, toasts, indexPatterns]);
const setUrlState: SetUrlState = useCallback(
(
accessor: Accessor,
attribute: string | Dictionary<any>,
value?: any,
replaceState?: boolean
) => {
const prevSearchString = searchString;
const urlState = parseUrlState(prevSearchString);
const parsedQueryString = parse(prevSearchString, { sort: false });
if (!Object.prototype.hasOwnProperty.call(urlState, accessor)) {
urlState[accessor] = {};
}
if (typeof attribute === 'string') {
if (isEqual(getNestedProperty(urlState, `${accessor}.${attribute}`), value)) {
return prevSearchString;
}
urlState[accessor][attribute] = value;
} else {
const attributes = attribute;
Object.keys(attributes).forEach((a) => {
urlState[accessor][a] = attributes[a];
});
}
try {
const oldLocationSearchString = stringify(parsedQueryString, {
sort: false,
encode: false,
});
Object.keys(urlState).forEach((a) => {
if (isRisonSerializationRequired(a)) {
parsedQueryString[a] = encode(urlState[a]);
} else {
parsedQueryString[a] = urlState[a];
}
});
const newLocationSearchString = stringify(parsedQueryString, {
sort: false,
encode: false,
});
if (oldLocationSearchString !== newLocationSearchString) {
const newSearchString = stringify(parsedQueryString, { sort: false });
if (replaceState) {
history.replace({ search: newSearchString });
} else {
history.push({ search: newSearchString });
}
}
} catch (error) {
// eslint-disable-next-line no-console
console.error('Could not save url state', error);
}
},
[history, searchString]
);
return (
<UrlStateContextProvider value={{ searchString, setUrlState }}>
{currentIndexPattern ? (
<IndexDataVisualizerComponent
currentIndexPattern={currentIndexPattern}
currentSavedSearch={currentSavedSearch}
additionalLinks={additionalLinks}
/>
) : (
<div />
)}
</UrlStateContextProvider>
);
};
export const IndexDataVisualizer: FC<{ additionalLinks: ResultLink[] }> = ({ additionalLinks }) => {
const coreStart = getCoreStart();
const {
data,
maps,
embeddable,
share,
security,
fileUpload,
lens,
indexPatternFieldEditor,
} = getPluginsStart();
const { data, maps, embeddable, share, security, fileUpload, lens, indexPatternFieldEditor } =
getPluginsStart();
const services = {
data,
maps,

View file

@ -46,7 +46,8 @@ export class DataVisualizerPlugin
DataVisualizerPluginStart,
DataVisualizerSetupDependencies,
DataVisualizerStartDependencies
> {
>
{
public setup(core: CoreSetup, plugins: DataVisualizerSetupDependencies) {
if (plugins.home) {
registerHomeAddData(plugins.home);

View file

@ -143,46 +143,44 @@ export const getHistogramsForFields = async (
const aggsPath = getSamplerAggregationsResponsePath(samplerShardSize);
const aggregations = aggsPath.length > 0 ? get(body.aggregations, aggsPath) : body.aggregations;
const chartsData: ChartData[] = fields.map(
(field): ChartData => {
const fieldName = field.fieldName;
const fieldType = field.type;
const id = stringHash(field.fieldName);
if (fieldType === KBN_FIELD_TYPES.NUMBER || fieldType === KBN_FIELD_TYPES.DATE) {
if (aggIntervals[id] === undefined) {
return {
type: 'numeric',
data: [],
interval: 0,
stats: [0, 0],
id: fieldName,
};
}
const chartsData: ChartData[] = fields.map((field): ChartData => {
const fieldName = field.fieldName;
const fieldType = field.type;
const id = stringHash(field.fieldName);
if (fieldType === KBN_FIELD_TYPES.NUMBER || fieldType === KBN_FIELD_TYPES.DATE) {
if (aggIntervals[id] === undefined) {
return {
data: aggregations[`${id}_histogram`].buckets,
interval: aggIntervals[id].interval,
stats: [aggIntervals[id].min, aggIntervals[id].max],
type: 'numeric',
id: fieldName,
};
} else if (fieldType === KBN_FIELD_TYPES.STRING || fieldType === KBN_FIELD_TYPES.BOOLEAN) {
return {
type: fieldType === KBN_FIELD_TYPES.STRING ? 'ordinal' : 'boolean',
cardinality:
fieldType === KBN_FIELD_TYPES.STRING ? aggregations[`${id}_cardinality`].value : 2,
data: aggregations[`${id}_terms`].buckets,
data: [],
interval: 0,
stats: [0, 0],
id: fieldName,
};
}
return {
type: 'unsupported',
data: aggregations[`${id}_histogram`].buckets,
interval: aggIntervals[id].interval,
stats: [aggIntervals[id].min, aggIntervals[id].max],
type: 'numeric',
id: fieldName,
};
} else if (fieldType === KBN_FIELD_TYPES.STRING || fieldType === KBN_FIELD_TYPES.BOOLEAN) {
return {
type: fieldType === KBN_FIELD_TYPES.STRING ? 'ordinal' : 'boolean',
cardinality:
fieldType === KBN_FIELD_TYPES.STRING ? aggregations[`${id}_cardinality`].value : 2,
data: aggregations[`${id}_terms`].buckets,
id: fieldName,
};
}
);
return {
type: 'unsupported',
id: fieldName,
};
});
return chartsData;
};