Skip to content

Commit

Permalink
Revert changes to hide default profile columns with empty values
Browse files Browse the repository at this point in the history
  • Loading branch information
davismcphee committed Aug 12, 2024
1 parent 406528a commit 13c52f1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { BehaviorSubject, combineLatest, filter, firstValueFrom, switchMap } fro
import { reportPerformanceMetricEvent } from '@kbn/ebt-tools';
import { isEqual } from 'lodash';
import { isOfAggregateQueryType } from '@kbn/es-query';
import type { DataTableRecord } from '@kbn/discover-utils';
import type { DiscoverAppState } from '../state_management/discover_app_state_container';
import { updateVolatileSearchSource } from './update_search_source';
import {
Expand Down Expand Up @@ -55,7 +54,7 @@ export function fetchAll(
dataSubjects: SavedSearchData,
reset = false,
fetchDeps: FetchDeps,
onFetchRecordsComplete?: (records: DataTableRecord[]) => Promise<void>
onFetchRecordsComplete?: () => Promise<void>
): Promise<void> {
const {
initialFetchStatus,
Expand Down Expand Up @@ -180,9 +179,7 @@ export function fetchAll(
// Return a promise that will resolve once all the requests have finished or failed
return firstValueFrom(
combineLatest([
isComplete(dataSubjects.documents$).pipe(
switchMap(async ({ result }) => onFetchRecordsComplete?.(result ?? []))
),
isComplete(dataSubjects.documents$).pipe(switchMap(async () => onFetchRecordsComplete?.())),
isComplete(dataSubjects.totalHits$),
])
).then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export function getDataStateContainer({
abortController,
...commonFetchDeps,
},
async (records) => {
async () => {
const { resetDefaultProfileState, dataView } = internalStateContainer.getState();
const { esqlQueryColumns } = dataSubjects.documents$.getValue();
const defaultColumns = uiSettings.get<string[]>(DEFAULT_COLUMNS_SETTING, []);
Expand All @@ -282,7 +282,6 @@ export function getDataStateContainer({
defaultColumns,
dataView,
esqlQueryColumns,
records,
});

if (stateUpdate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import type { DataView } from '@kbn/data-views-plugin/common';
import type { DiscoverGridSettings } from '@kbn/saved-search-plugin/common';
import { uniqBy } from 'lodash';
import type { DataTableRecord } from '@kbn/discover-utils';
import type { DiscoverAppState } from '../discover_app_state_container';
import {
DefaultAppStateColumn,
Expand All @@ -25,14 +24,12 @@ export const getDefaultProfileState = ({
defaultColumns,
dataView,
esqlQueryColumns,
records,
}: {
profilesManager: ProfilesManager;
resetDefaultProfileState: InternalState['resetDefaultProfileState'];
defaultColumns: string[];
dataView: DataView;
esqlQueryColumns: DataDocumentsMsg['esqlQueryColumns'];
records: DataTableRecord[];
}) => {
const stateUpdate: DiscoverAppState = {};
const defaultState = getDefaultState(profilesManager, dataView);
Expand All @@ -44,22 +41,20 @@ export const getDefaultProfileState = ({
defaultState.columns?.concat(mappedDefaultColumns).filter(isValidColumn),
'name'
);
const columnsWithValues = validColumns.filter((column) =>
records.some((record) => record.flattened[column.name] != null)
);

if (columnsWithValues?.length) {
const hasAutoWidthColumn = columnsWithValues.some(({ width }) => !width);
const columns = columnsWithValues.reduce<DiscoverGridSettings['columns']>(
if (validColumns?.length) {
const hasAutoWidthColumn = validColumns.some(({ width }) => !width);
const columns = validColumns.reduce<DiscoverGridSettings['columns']>(
(acc, { name, width }, index) => {
const skipColumnWidth = !hasAutoWidthColumn && index === columnsWithValues.length - 1;
// Ensure there's at least one auto width column so the columns fill the grid
const skipColumnWidth = !hasAutoWidthColumn && index === validColumns.length - 1;
return width && !skipColumnWidth ? { ...acc, [name]: { width } } : acc;
},
undefined
);

stateUpdate.grid = columns ? { columns } : undefined;
stateUpdate.columns = columnsWithValues.map(({ name }) => name);
stateUpdate.columns = validColumns.map(({ name }) => name);
}
}

Expand Down

0 comments on commit 13c52f1

Please sign in to comment.