Skip to content

Commit

Permalink
[Discover] Remove discover:searchFieldsFromSource setting (elastic#20…
Browse files Browse the repository at this point in the history
…2679)

- Closes elastic#196501

## Summary

The PR removes `discover:searchFieldsFromSource` Advanced Setting and
the associated code.
This breaking change is planned for v9.

The setting was marked as deprecated in v8.15
elastic#185871

### Checklist

- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
jughosta authored and CAWilson94 committed Dec 12, 2024
1 parent dbdc44f commit a19b79a
Show file tree
Hide file tree
Showing 82 changed files with 182 additions and 2,474 deletions.
6 changes: 0 additions & 6 deletions docs/management/advanced-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,6 @@ Limits the number of rows per page in the document table.
[[discover-sample-size]]`discover:sampleSize`::
Sets the maximum number of rows for the entire document table. This is the maximum number of documents fetched from {es}.

[[discover-searchFieldsFromSource]]`discover:searchFieldsFromSource`::
deprecated:[8.15.0]
Load fields from the original JSON {ref}/mapping-source-field.html[`_source`].
When disabled, *Discover* loads fields using the {es} search API's
{ref}/search-fields.html#search-fields-param[`fields`] parameter.

[[discover-searchonpageload]]`discover:searchOnPageLoad`::
Controls whether a search is executed when *Discover* first loads. This setting
does not have an effect when loading a saved search.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export const getDataTableFactory = (
dataView={dataView}
sampleSizeState={100}
columns={fields ?? []}
useNewFieldsApi={true}
services={allServices}
onSetColumns={() => {}}
ariaLabelledBy="dataTableReactEmbeddableAria"
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-discover-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export {
SAMPLE_ROWS_PER_PAGE_SETTING,
SAMPLE_SIZE_SETTING,
SEARCH_EMBEDDABLE_TYPE,
SEARCH_FIELDS_FROM_SOURCE,
SEARCH_ON_PAGE_LOAD_SETTING,
SHOW_FIELD_STATISTICS,
SHOW_MULTIFIELDS,
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-discover-utils/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const ROW_HEIGHT_OPTION = 'discover:rowHeightOption';
export const SAMPLE_ROWS_PER_PAGE_SETTING = 'discover:sampleRowsPerPage';
export const SAMPLE_SIZE_SETTING = 'discover:sampleSize';
export const SEARCH_EMBEDDABLE_TYPE = 'search';
export const SEARCH_FIELDS_FROM_SOURCE = 'discover:searchFieldsFromSource';
export const SEARCH_ON_PAGE_LOAD_SETTING = 'discover:searchOnPageLoad';
export const SHOW_FIELD_STATISTICS = 'discover:showFieldStatistics';
export const SHOW_MULTIFIELDS = 'discover:showMultiFields';
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-management/settings/setting_ids/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export const DISCOVER_MODIFY_COLUMNS_ON_SWITCH_ID = 'discover:modifyColumnsOnSwi
export const DISCOVER_ROW_HEIGHT_OPTION_ID = 'discover:rowHeightOption';
export const DISCOVER_SAMPLE_ROWS_PER_PAGE_ID = 'discover:sampleRowsPerPage';
export const DISCOVER_SAMPLE_SIZE_ID = 'discover:sampleSize';
export const DISCOVER_SEARCH_FIELDS_FROM_SOURCE_ID = 'discover:searchFieldsFromSource';
export const DISCOVER_SEARCH_ON_PAGE_LOAD_ID = 'discover:searchOnPageLoad';
export const DISCOVER_SHOW_FIELD_STATISTICS_ID = 'discover:showFieldStatistics';
export const DISCOVER_SHOW_MULTI_FIELDS_ID = 'discover:showMultiFields';
Expand Down
3 changes: 0 additions & 3 deletions packages/kbn-unified-data-table/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Props description:
| **showFullScreenButton** | (optional)boolean | Determines whether the full screen button should be displayed. |
| **isSortEnabled** | (optional)boolean | Manage user sorting control. |
| **sort** | SortOrder[] | Current sort setting. |
| **useNewFieldsApi** | boolean | How the data is fetched. |
| **isPaginationEnabled** | (optional)boolean | Manage pagination control. |
| **controlColumnIds** | (optional)string[] | List of used control columns (available: 'openDetails', 'select'). |
| **rowHeightState** | (optional)number | Row height from state. |
Expand Down Expand Up @@ -145,7 +144,6 @@ Usage example:
renderCustomGridBody={renderCustomGridBody}
rowsPerPageOptions={[10, 30, 40, 100]}
showFullScreenButton={false}
useNewFieldsApi={true}
maxDocFieldsDisplayed={50}
consumer="timeline"
totalHits={
Expand Down Expand Up @@ -210,7 +208,6 @@ const {
dataView,
dataViews,
setAppState: stateContainer.appState.update,
useNewFieldsApi,
columns,
sort,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function getStateColumnAction(
} as unknown as Capabilities,
dataView: dataViewMock,
dataViews: dataViewsMock,
useNewFieldsApi: true,
setAppState,
columns: state.columns,
sort: state.sort,
Expand Down
22 changes: 8 additions & 14 deletions packages/kbn-unified-data-table/src/components/actions/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export function getStateColumnActions({
capabilities,
dataView,
dataViews,
useNewFieldsApi,
setAppState,
columns,
sort,
Expand All @@ -28,7 +27,6 @@ export function getStateColumnActions({
capabilities: Capabilities;
dataView: DataView;
dataViews: DataViewsContract;
useNewFieldsApi: boolean;
setAppState: (state: {
columns: string[];
sort?: string[][];
Expand All @@ -41,15 +39,15 @@ export function getStateColumnActions({
}) {
function onAddColumn(columnName: string) {
popularizeField(dataView, columnName, dataViews, capabilities);
const nextColumns = addColumn(columns || [], columnName, useNewFieldsApi);
const nextColumns = addColumn(columns || [], columnName);
const nextSort = columnName === '_score' && !sort?.length ? [['_score', defaultOrder]] : sort;
setAppState({ columns: nextColumns, sort: nextSort, settings });
}

function onRemoveColumn(columnName: string) {
popularizeField(dataView, columnName, dataViews, capabilities);

const nextColumns = removeColumn(columns || [], columnName, useNewFieldsApi);
const nextColumns = removeColumn(columns || [], columnName);
// The state's sort property is an array of [sortByColumn,sortDirection]
const nextSort = sort && sort.length ? sort.filter((subArr) => subArr[0] !== columnName) : [];

Expand Down Expand Up @@ -98,32 +96,28 @@ export function getStateColumnActions({
* Helper function to provide a fallback to a single _source column if the given array of columns
* is empty, and removes _source if there are more than 1 columns given
* @param columns
* @param useNewFieldsApi should a new fields API be used
*/
function buildColumns(columns: string[], useNewFieldsApi = false) {
function buildColumns(columns: string[]) {
if (columns.length > 1 && columns.indexOf('_source') !== -1) {
return columns.filter((col) => col !== '_source');
} else if (columns.length !== 0) {
return columns;
}
return useNewFieldsApi ? [] : ['_source'];
return [];
}

function addColumn(columns: string[], columnName: string, useNewFieldsApi?: boolean) {
function addColumn(columns: string[], columnName: string) {
if (columns.includes(columnName)) {
return columns;
}
return buildColumns([...columns, columnName], useNewFieldsApi);
return buildColumns([...columns, columnName]);
}

function removeColumn(columns: string[], columnName: string, useNewFieldsApi?: boolean) {
function removeColumn(columns: string[], columnName: string) {
if (!columns.includes(columnName)) {
return columns;
}
return buildColumns(
columns.filter((col) => col !== columnName),
useNewFieldsApi
);
return buildColumns(columns.filter((col) => col !== columnName));
}

function moveColumn(columns: string[], columnName: string, newIndex: number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ function getProps(): UnifiedDataTableProps {
settings: {},
showTimeCol: true,
sort: [],
useNewFieldsApi: true,
services: {
fieldFormats: services.fieldFormats,
uiSettings: services.uiSettings,
Expand Down Expand Up @@ -124,7 +123,6 @@ const renderDataTable = async (props: Partial<UnifiedDataTableProps>) => {
setSettings(state.settings);
}
}, []),
useNewFieldsApi: true,
columns,
settings,
});
Expand Down
7 changes: 0 additions & 7 deletions packages/kbn-unified-data-table/src/components/data_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ export interface UnifiedDataTableProps {
* Current sort setting
*/
sort: SortOrder[];
/**
* How the data is fetched
*/
useNewFieldsApi: boolean;
/**
* Manage pagination control
*/
Expand Down Expand Up @@ -454,7 +450,6 @@ export const UnifiedDataTable = ({
showTimeCol,
showFullScreenButton = true,
sort,
useNewFieldsApi,
isSortEnabled = true,
isPaginationEnabled = true,
cellActionsTriggerId,
Expand Down Expand Up @@ -716,7 +711,6 @@ export const UnifiedDataTable = ({
getRenderCellValueFn({
dataView,
rows: displayedRows,
useNewFieldsApi,
shouldShowFieldHandler,
closePopover: () => dataGridRef.current?.closeCellPopover(),
fieldFormats,
Expand All @@ -728,7 +722,6 @@ export const UnifiedDataTable = ({
[
dataView,
displayedRows,
useNewFieldsApi,
shouldShowFieldHandler,
maxDocFieldsDisplayed,
fieldFormats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('useColumns', () => {
dataViews: dataViewsMock,
setAppState: () => {},
columns: ['Time', 'message'],
useNewFieldsApi: false,
};

test('should return valid result', () => {
Expand All @@ -37,12 +36,11 @@ describe('useColumns', () => {
expect(result.current.onSetColumns).toBeInstanceOf(Function);
});

test('should skip _source column when useNewFieldsApi is set to true', () => {
test('should skip _source column', () => {
const { result } = renderHook(() => {
return useColumns({
...defaultProps,
columns: ['Time', '_source'],
useNewFieldsApi: true,
});
});

Expand Down
25 changes: 6 additions & 19 deletions packages/kbn-unified-data-table/src/hooks/use_data_grid_columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export interface UseColumnsProps {
capabilities: Capabilities;
dataView: DataView;
dataViews: DataViewsContract;
useNewFieldsApi: boolean;
setAppState: (state: {
columns: string[];
sort?: string[][];
Expand All @@ -36,44 +35,32 @@ export const useColumns = ({
dataView,
dataViews,
setAppState,
useNewFieldsApi,
columns,
sort,
defaultOrder = 'desc',
settings,
}: UseColumnsProps) => {
const [usedColumns, setUsedColumns] = useState(getColumns(columns, useNewFieldsApi));
const [usedColumns, setUsedColumns] = useState(getColumns(columns));
useEffect(() => {
const nextColumns = getColumns(columns, useNewFieldsApi);
const nextColumns = getColumns(columns);
if (isEqual(usedColumns, nextColumns)) {
return;
}
setUsedColumns(nextColumns);
}, [columns, useNewFieldsApi, usedColumns]);
}, [columns, usedColumns]);
const { onAddColumn, onRemoveColumn, onSetColumns, onMoveColumn } = useMemo(
() =>
getStateColumnActions({
capabilities,
dataView,
dataViews,
setAppState,
useNewFieldsApi,
columns: usedColumns,
sort,
defaultOrder,
settings,
}),
[
capabilities,
dataView,
dataViews,
defaultOrder,
setAppState,
settings,
sort,
useNewFieldsApi,
usedColumns,
]
[capabilities, dataView, dataViews, defaultOrder, setAppState, settings, sort, usedColumns]
);

return {
Expand All @@ -85,9 +72,9 @@ export const useColumns = ({
};
};

function getColumns(columns: string[] | undefined, useNewFieldsApi: boolean) {
function getColumns(columns: string[] | undefined) {
if (!columns) {
return [];
}
return useNewFieldsApi ? columns.filter((col) => col !== '_source') : columns;
return columns.filter((col) => col !== '_source');
}
Loading

0 comments on commit a19b79a

Please sign in to comment.