Skip to content

Commit

Permalink
Add initialization dirty flag and fix full mode filter bar
Browse files Browse the repository at this point in the history
Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
  • Loading branch information
abbyhu2000 committed Jul 4, 2023
1 parent d5d4304 commit 79a6db9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ export const DashboardEditor = () => {
);

useEffect(() => {
if (appState) {
if (appState && dashboard) {
if (savedDashboardInstance?.id) {
chrome.setBreadcrumbs(
setBreadcrumbsForExistingDashboard(
savedDashboardInstance.title,
appState?.getState().viewMode,
appState?.getState().isDirty
dashboard.isDirty
)
);
chrome.docTitle.change(savedDashboardInstance.title);
} else {
chrome.setBreadcrumbs(
setBreadcrumbsForNewDashboard(appState?.getState().viewMode, appState?.getState().isDirty)
setBreadcrumbsForNewDashboard(appState?.getState().viewMode, dashboard.isDirty)
);
}
}
Expand All @@ -89,7 +89,9 @@ export const DashboardEditor = () => {
console.log('appStateData', appState?.getState());

Check failure on line 89 in src/plugins/dashboard/public/application/components/dashboard_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Windows

Unexpected console statement

Check failure on line 89 in src/plugins/dashboard/public/application/components/dashboard_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux

Unexpected console statement
console.log('currentAppState', currentAppState);

Check failure on line 90 in src/plugins/dashboard/public/application/components/dashboard_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Windows

Unexpected console statement

Check failure on line 90 in src/plugins/dashboard/public/application/components/dashboard_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux

Unexpected console statement
console.log('isEmbeddableRendered', isEmbeddableRendered);

Check failure on line 91 in src/plugins/dashboard/public/application/components/dashboard_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Windows

Unexpected console statement

Check failure on line 91 in src/plugins/dashboard/public/application/components/dashboard_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux

Unexpected console statement
console.log('app state isDirty', appState?.getState().isDirty);
if (dashboard) {
console.log('isDirty', dashboard.isDirty);

Check warning on line 93 in src/plugins/dashboard/public/application/components/dashboard_editor.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/components/dashboard_editor.tsx#L93

Added line #L93 was not covered by tests

Check failure on line 93 in src/plugins/dashboard/public/application/components/dashboard_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Windows

Unexpected console statement

Check failure on line 93 in src/plugins/dashboard/public/application/components/dashboard_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux

Unexpected console statement
}
console.log('dashboardContainer', dashboardContainer);

Check failure on line 95 in src/plugins/dashboard/public/application/components/dashboard_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Windows

Unexpected console statement

Check failure on line 95 in src/plugins/dashboard/public/application/components/dashboard_editor.tsx

View workflow job for this annotation

GitHub Actions / Build and Verify on Linux

Unexpected console statement

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ export function getAppStateDefaults(
query: savedDashboard.getQuery(),
filters: savedDashboard.getFilters(),
viewMode: savedDashboard.id || hideWriteControls ? ViewMode.VIEW : ViewMode.EDIT,
isDirty: false,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export const getNavActions = (
stateContainer.transitions.set('timeRestore', currentTimeRestore);
}

// If the save was successfull, then set the app state isDirty back to false
stateContainer.transitions.set('isDirty', false);
// If the save was successfull, then set the dashboard isDirty back to false
dashboard.isDirty = false;

Check warning on line 118 in src/plugins/dashboard/public/application/utils/get_nav_actions.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/get_nav_actions.tsx#L118

Added line #L118 was not covered by tests
return response;
});
};
Expand Down Expand Up @@ -283,7 +283,7 @@ export const getNavActions = (
sharingData: {
title: savedDashboard.title,
},
isDirty: false, // TODO
isDirty: dashboard.isDirty,
embedUrlParamExtensions: [
{
paramName: 'embed',
Expand All @@ -297,7 +297,7 @@ export const getNavActions = (
function onChangeViewMode(newMode: ViewMode) {
const isPageRefresh = newMode === appState.viewMode;
const isLeavingEditMode = !isPageRefresh && newMode === ViewMode.VIEW;
const willLoseChanges = isLeavingEditMode && stateContainer.getState().isDirty === true;
const willLoseChanges = isLeavingEditMode && dashboard.isDirty === true;

// If there are no changes, do not show the discard window
if (!willLoseChanges) {
Expand Down Expand Up @@ -340,7 +340,7 @@ export const getNavActions = (
}

// Set the isDirty flag back to false since we discard all the changes
stateContainer.transitions.set('isDirty', false);
dashboard.isDirty = false;

Check warning on line 343 in src/plugins/dashboard/public/application/utils/get_nav_actions.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/get_nav_actions.tsx#L343

Added line #L343 was not covered by tests
}

overlays
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ const handleDashboardContainerChanges = (
dashboard: Dashboard
) => {
let dirty = false;
let dirtyBecasuseOfInitialization = false;
const appStateData = appState.getState();
const savedDashboardPanelMap: { [key: string]: SavedDashboardPanel } = {};
const { opensearchDashboardsVersion } = dashboardServices;
Expand Down Expand Up @@ -397,25 +396,11 @@ const handleDashboardContainerChanges = (
// Do not need to care about initial migration here because the version update
// is already handled in migrateAppState() when we create state container
dirty = true;

const oldVersionVis =
savedDashboardPanelMap[panelState.explicitInput.id].embeddableConfig?.vis;
const newVersionVis =
convertedPanelStateMap[panelState.explicitInput.id].embeddableConfig?.vis;

// Some visualizations' embeddable config will get initialized after render is completed
// Ex. update embeddable: {} to embeddable: { vis: null }
// We add this flag to make sure we do not mark dirty because of this initialization
if (oldVersionVis === undefined && newVersionVis === null) {
dirtyBecasuseOfInitialization = true;
}
}
});
if (dirty) {
appState.transitions.set('panels', Object.values(convertedPanelStateMap));
if (!dirtyBecasuseOfInitialization) {
appState.transitions.set('isDirty', true);
}
dashboard.isDirty = true;

Check warning on line 403 in src/plugins/dashboard/public/application/utils/use/use_dashboard_container.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/use/use_dashboard_container.tsx#L403

Added line #L403 was not covered by tests
}
if (input.isFullScreenMode !== appStateData.fullScreenMode) {
appState.transitions.set('fullScreenMode', input.isFullScreenMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const useEditorUpdates = (
dashboardContainer.updateInput(changes);

if (changes.filters || changes.query || changes.timeRange || changes.refreshConfig) {
appState.transitions.set('isDirty', true);
dashboard.isDirty = true;

Check warning on line 47 in src/plugins/dashboard/public/application/utils/use/use_editor_updates.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/dashboard/public/application/utils/use/use_editor_updates.ts#L47

Added line #L47 was not covered by tests
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/plugins/dashboard/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export interface DashboardAppState {
viewMode: ViewMode;
expandedPanelId?: string;
savedQuery?: string;
isDirty: boolean;
}

export type DashboardAppStateDefaults = DashboardAppState & {
Expand Down

0 comments on commit 79a6db9

Please sign in to comment.