Skip to content

Commit

Permalink
Merge pull request #8 from davismcphee/davis-mapping-conflict-link
Browse files Browse the repository at this point in the history
Update local state when "View fields" link is clicked
  • Loading branch information
jughosta authored Oct 25, 2023
2 parents 4f9afbe + 1476de5 commit 74c686f
Show file tree
Hide file tree
Showing 4 changed files with 537 additions and 471 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import React, { useEffect, useState, useCallback } from 'react';
import React, { useEffect, useState, useCallback, useMemo } from 'react';
import { withRouter, RouteComponentProps, useLocation } from 'react-router-dom';
import {
EuiFlexGroup,
Expand All @@ -29,11 +29,13 @@ import {
SavedObjectManagementTypeInfo,
} from '@kbn/saved-objects-management-plugin/public';
import { pickBy } from 'lodash';
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public';
import { IndexPatternManagmentContext } from '../../types';
import { Tabs } from './tabs';
import { Tabs, type TabsApi } from './tabs';
import { IndexHeader } from './index_header';
import { getTags } from '../utils';
import { removeDataView, RemoveDataViewProps } from './remove_data_view';
import { APP_STATE_STORAGE_KEY } from './edit_index_pattern_state_container';

const codeStyle = {
marginLeft: '8px',
Expand Down Expand Up @@ -91,6 +93,20 @@ export const EditIndexPattern = withRouter(
const [showEditDialog, setShowEditDialog] = useState<boolean>(false);
const [relationships, setRelationships] = useState<SavedObjectRelationWithTitle[]>([]);
const [allowedTypes, setAllowedTypes] = useState<SavedObjectManagementTypeInfo[]>([]);
const [tabsApi, setTabsApi] = useState<TabsApi | null>(null);
const conflictFieldsUrl = useMemo(() => {
return setStateToKbnUrl(
APP_STATE_STORAGE_KEY,
{
fieldTypes: ['conflict'],
tab: 'indexedFields',
},
undefined,
application.getUrlForApp('management', {
path: `/kibana/dataViews/dataView/${encodeURIComponent(indexPattern.id!)}`,
})
);
}, [application, indexPattern.id]);

useEffect(() => {
savedObjectsManagement.getAllowedTypes().then((resp) => {
Expand Down Expand Up @@ -269,26 +285,33 @@ export const EditIndexPattern = withRouter(
<EuiSpacer />
<EuiCallOut title={mappingConflictHeader} color="warning" iconType="warning">
<p>{mappingConflictLabel}</p>
<EuiLink
href={application.getUrlForApp('management', {
path: `/kibana/dataViews/dataView/${encodeURIComponent(
indexPattern.id!
)}#/?_a=(fieldTypes:!(conflict),tab:indexedFields)`,
})}
>
{i18n.translate(
'indexPatternManagement.editIndexPattern.viewMappingConflictButton',
{
defaultMessage: 'View fields',
}
)}
</EuiLink>
{
// eslint-disable-next-line @elastic/eui/href-or-on-click
<EuiLink
href={conflictFieldsUrl}
onClick={(e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
e.stopPropagation();
tabsApi?.updateTab({ id: 'indexedFields' });
tabsApi?.updateFieldTypeFilter(['conflict']);
tabsApi?.updateFieldFilter('');
}}
>
{i18n.translate(
'indexPatternManagement.editIndexPattern.viewMappingConflictButton',
{
defaultMessage: 'View fields',
}
)}
</EuiLink>
}
</EuiCallOut>
</>
)}
</IndexHeader>
<EuiSpacer size="xl" />
<Tabs
ref={setTabsApi}
indexPattern={indexPattern}
saveIndexPattern={dataViews.updateSavedObject.bind(dataViews)}
fields={fields}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ interface IEditIndexPatternState {
fieldTypes?: string[];
}

// query param to store app state at
export const APP_STATE_STORAGE_KEY = '_a';

/**
* Create state container with sync config for tab navigation specific for edit_index_pattern page
*/
Expand All @@ -29,8 +32,6 @@ export function createEditIndexPatternPageStateContainer({
useHashedUrl: boolean;
}) {
const history = createHashHistory();
// query param to store app state at
const stateStorageKey = '_a';
// default app state, when there is no initial state in the url
const defaultState = {
tab: defaultTab,
Expand All @@ -40,7 +41,7 @@ export function createEditIndexPatternPageStateContainer({
history,
});
// extract starting app state from URL and use it as starting app state in state container
const initialStateFromUrl = kbnUrlStateStorage.get<IEditIndexPatternState>(stateStorageKey);
const initialStateFromUrl = kbnUrlStateStorage.get<IEditIndexPatternState>(APP_STATE_STORAGE_KEY);
const stateContainer = createStateContainer(
{
...defaultState,
Expand All @@ -60,7 +61,7 @@ export function createEditIndexPatternPageStateContainer({
);

const { start, stop } = syncState({
storageKey: stateStorageKey,
storageKey: APP_STATE_STORAGE_KEY,
stateContainer: {
...stateContainer,
// state syncing utility requires state containers to handle "null"
Expand All @@ -70,7 +71,7 @@ export function createEditIndexPatternPageStateContainer({
});

// makes sure initial url is the same as initial state (this is not really required)
kbnUrlStateStorage.set(stateStorageKey, stateContainer.getState(), { replace: true });
kbnUrlStateStorage.set(APP_STATE_STORAGE_KEY, stateContainer.getState(), { replace: true });

return {
startSyncingState: start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* Side Public License, v 1.
*/

export { Tabs } from './tabs';
export { Tabs, type TabsApi } from './tabs';
Loading

0 comments on commit 74c686f

Please sign in to comment.