Skip to content

Commit 244fec2

Browse files
cards refresh when bd is changed and dialog to confirm
1 parent 3c492de commit 244fec2

File tree

9 files changed

+130
-2
lines changed

9 files changed

+130
-2
lines changed

src/card/Card.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
updateReportTypeThunk,
1414
updateReportDatabaseThunk,
1515
} from './CardThunks';
16-
import { toggleReportSettings } from './CardActions';
16+
import { forceRefreshCard, toggleReportSettings } from './CardActions';
1717
import { getReportState } from './CardSelectors';
1818
import {
1919
getDashboardIsEditable,
@@ -149,6 +149,7 @@ const NeoCard = ({
149149
title={report.title}
150150
expanded={expanded}
151151
onToggleCardExpand={onToggleCardExpand}
152+
onForceRefresh={forceRefreshCard(0,id)}
152153
onGlobalParameterUpdate={onGlobalParameterUpdate}
153154
onSelectionUpdate={(selectable, field) => onSelectionUpdate(id, selectable, field)}
154155
onTitleUpdate={(title) => onTitleUpdate(id, title)}

src/card/CardActions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,9 @@ export const updateReportDatabase = (pagenumber: number, id: number, database: a
9191
type: UPDATE_REPORT_DATABASE,
9292
payload: { pagenumber, id, database },
9393
});
94+
95+
export const FORCE_REFRESH_CARD = 'PAGE/CARD/FORCE_REFRESH_CARD';
96+
export const forceRefreshCard = (pagenumber: number, id: number) => ({
97+
type: FORCE_REFRESH_CARD,
98+
payload: { pagenumber, id },
99+
});

src/card/CardReducer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
UPDATE_REPORT_TYPE,
1414
UPDATE_SELECTION,
1515
UPDATE_REPORT_DATABASE,
16+
FORCE_REFRESH_CARD
1617
} from './CardActions';
1718
import { TOGGLE_CARD_SETTINGS } from './CardActions';
1819
import { createUUID } from '../utils/uuid';
@@ -25,6 +26,7 @@ const update = (state, mutations) => Object.assign({}, state, mutations);
2526

2627
export const CARD_INITIAL_STATE = {
2728
id: createUUID(),
29+
forceRefresh: 0,
2830
title: '',
2931
query: '\n\n\n',
3032
settingsOpen: false,
@@ -136,6 +138,10 @@ export const cardReducer = (state = CARD_INITIAL_STATE, action: { type: any; pay
136138
state = update(state, { database: database });
137139
return state;
138140
}
141+
case FORCE_REFRESH_CARD: {
142+
state = update(state, {forceRefresh: state.forceRefresh + 1});
143+
return state;
144+
}
139145
default: {
140146
return state;
141147
}

src/card/view/CardView.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const NeoCardView = ({
4141
onToggleCardSettings,
4242
onTitleUpdate,
4343
onFieldsUpdate,
44+
onForceRefresh,
4445
expanded,
4546
onToggleCardExpand,
4647
}) => {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react';
2+
import { Button, Dialog } from '@neo4j-ndl/react';
3+
import { BackspaceIconOutline, ExclamationTriangleIconOutline } from '@neo4j-ndl/react/icons';
4+
5+
/**
6+
* Configures setting the current Neo4j database connection for the dashboard.
7+
*/
8+
export const NeoDashboardChangeDatabaseConfirm = ({ open, onConfirm, handleClose }) => {
9+
return (
10+
<Dialog size='small' open={open == true} onClose={handleClose} aria-labelledby='form-dialog-title'>
11+
<Dialog.Header id='form-dialog-title'>Change Database For All Reports?</Dialog.Header>
12+
<Dialog.Subtitle>
13+
This will change the database for all reports.
14+
</Dialog.Subtitle>
15+
<Dialog.Actions>
16+
<Button
17+
onClick={() => {
18+
handleClose();
19+
}}
20+
style={{ float: 'right' }}
21+
>
22+
<BackspaceIconOutline className='btn-icon-base-l' />
23+
Cancel
24+
</Button>
25+
<Button
26+
onClick={() => {
27+
onConfirm();
28+
handleClose();
29+
}}
30+
color='danger'
31+
fill='outlined'
32+
style={{ float: 'right', marginRight: '5px' }}
33+
>
34+
Continue
35+
<ExclamationTriangleIconOutline className='btn-icon-base-r' />
36+
</Button>
37+
</Dialog.Actions>
38+
</Dialog>
39+
);
40+
};
41+
42+
export default NeoDashboardChangeDatabaseConfirm;

src/dashboard/header/DashboardHeader.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,21 @@ import { Button } from '@neo4j-ndl/react';
1818
import { CircleStackIconOutline } from '@neo4j-ndl/react/icons';
1919
import { loadDatabaseListFromNeo4jThunk } from '../DashboardThunks';
2020
import NeoDashboardSidebarDatabaseMenu from '../sidebar/menu/DashboardSidebarDatabaseMenu';
21+
import { hardResetAllCardsThunk, setPageNumberThunk } from '../../settings/SettingsThunks';
22+
import { updateAllReportsDatabaseThunk } from '../../page/PageThunks';
23+
import NeoDashboardChangeDatabaseConfirm from './DashboardChangeDatabaseConfirmDialog';
2124

2225
// Which (small) pop-up menu is currently open for the sidebar.
2326
enum Menu {
2427
DATABASE = 0,
2528
NONE = 1,
2629
}
2730

31+
enum Modal {
32+
CHANGE = 0,
33+
NONE = 1,
34+
}
35+
2836
export const NeoDashboardHeader = ({
2937
database,
3038
standaloneSettings,
@@ -40,11 +48,13 @@ export const NeoDashboardHeader = ({
4048
setTheme,
4149
loadDatabaseListFromNeo4j,
4250
readonly,
51+
refreshPage
4352
}) => {
4453
const downloadImageEnabled = settings ? settings.downloadImageEnabled : false;
4554
const [dashboardTitleText, setDashboardTitleText] = React.useState(dashboardTitle);
4655
const [databases, setDatabases] = useState([]);
4756
const [menuOpen, setMenuOpen] = useState(Menu.NONE);
57+
const [modalOpen, setModalOpen] = useState(Modal.NONE);
4858
const [isDarkMode, setDarkMode] = React.useState(themeMode !== 'light');
4959
const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);
5060
const [dataDatabase, setDataDatabase] = React.useState(database ? database : 'neo4j');
@@ -66,6 +76,13 @@ export const NeoDashboardHeader = ({
6676
}, [isDarkMode]);
6777
const content = (
6878
<div className='n-relative n-bg-palette-neutral-bg-weak n-w-full'>
79+
<NeoDashboardChangeDatabaseConfirm
80+
open={modalOpen == Modal.CHANGE}
81+
onConfirm={() => {
82+
setModalOpen(Modal.NONE);
83+
}}
84+
handleClose={() => setModalOpen(Modal.NONE)}
85+
/>
6986
<div className='n-min-w-full'>
7087
<div className='n-flex n-justify-between n-h-16 n-items-center n-py-6 md:n-justify-start md:n-space-x-10 n-mx-4'>
7188
<NeoDashboardHeaderLogo resetApplication={resetApplication} />
@@ -136,7 +153,11 @@ export const NeoDashboardHeader = ({
136153
databases={databases}
137154
selected={dataDatabase}
138155
setSelected={(newDatabase) => {
156+
setModalOpen(Modal.CHANGE);
139157
setDataDatabase(newDatabase);
158+
console.log(newDatabase)
159+
console.log(dataDatabase)
160+
refreshPage(newDatabase)
140161
}}
141162
open={menuOpen == Menu.DATABASE}
142163
anchorEl={menuAnchor}
@@ -177,6 +198,12 @@ const mapDispatchToProps = (dispatch) => ({
177198
loadDatabaseListFromNeo4j: (driver, callback) => {
178199
dispatch(loadDatabaseListFromNeo4jThunk(driver, callback))
179200
},
201+
202+
refreshPage: (database: string) => {
203+
console.log("refreshPage")
204+
// dispatch(hardResetAllCardsThunk());
205+
dispatch(updateAllReportsDatabaseThunk(database));
206+
},
180207
});
181208

182209
export default connect(mapStateToProps, mapDispatchToProps)(NeoDashboardHeader);

src/dashboard/header/DashboardHeaderPageList.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const NeoDashboardHeaderPageList = ({
2626
addPage,
2727
movePage,
2828
selectPage,
29+
refreshPage,
2930
}) => {
3031
const [canSwitchPages, setCanSwitchPages] = React.useState(true);
3132

@@ -114,6 +115,9 @@ const mapDispatchToProps = (dispatch) => ({
114115
onConnectionModalOpen: () => {
115116
dispatch(setConnectionModalOpen(true));
116117
},
118+
refreshPage: () => {
119+
dispatch(setPageNumberThunk(0))
120+
}
117121
});
118122

119123
export default connect(mapStateToProps, mapDispatchToProps)(NeoDashboardHeaderPageList);

src/page/PageThunks.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { createNotification } from '../application/ApplicationActions';
22
import { CARD_INITIAL_STATE } from '../card/CardReducer';
3-
import { createReport, removeReport, updateAllCardPositionsInPage } from './PageActions';
3+
import { createReport, forceRefreshPage, removeReport, updateAllCardPositionsInPage } from './PageActions';
44
import { createUUID } from '../utils/uuid';
5+
import { forceRefreshCard, hardResetCardSettings, toggleCardSettings, updateReportDatabase } from '../card/CardActions';
56

67
export const createNotificationThunk = (title: any, message: any) => (dispatch: any) => {
78
dispatch(createNotification(title, message));
@@ -51,3 +52,24 @@ export const updatePageLayoutThunk = (layout: any) => (dispatch: any, getState:
5152
dispatch(createNotificationThunk('Cannot update page layout', e));
5253
}
5354
};
55+
56+
export const updateAllReportsDatabaseThunk = (database) => (dispatch: any, getState: any) => {
57+
try{
58+
console.log('updateAllReportsDatabaseThunk')
59+
const state = getState();
60+
const { pages } = state.dashboard;
61+
const { pagenumber } = getState().dashboard.settings;
62+
pages.map((page, index) => {
63+
console.log(page);
64+
page.reports.map((report) => {
65+
console.log("page: " + index + " | id: " + report.id);
66+
dispatch(updateReportDatabase(index,report.id, database));
67+
if (pagenumber === index){
68+
dispatch(forceRefreshCard(index,report.id));
69+
}
70+
});
71+
});
72+
} catch (e) {
73+
dispatch(createNotificationThunk('Unable to set database for all cards', e));
74+
}
75+
};

src/settings/SettingsThunks.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { updateDashboardSetting } from './SettingsActions';
66

77
export const setPageNumberThunk = (number) => (dispatch: any, getState: any) => {
88
try {
9+
console.log("setPageNumberThunk")
910
if (number == undefined) {
1011
throw 'The specified page could not be found, was it moved, removed, or renamed?';
1112
}
@@ -17,13 +18,31 @@ export const setPageNumberThunk = (number) => (dispatch: any, getState: any) =>
1718

1819
const page = pages[number];
1920
page.reports.map((report) => {
21+
console.log("pg: " + number + " | " + report.id)
2022
dispatch(hardResetCardSettings(number, report.id));
2123
});
2224
} catch (e) {
2325
dispatch(createNotificationThunk('Unable to set page number', e));
2426
}
2527
};
2628

29+
export const hardResetAllCardsThunk = () => (dispatch: any, getState: any) => {
30+
try{
31+
console.log("hardResetAllCardsThunk")
32+
const { pages } = getState().dashboard;
33+
34+
pages.map((page, index) => {
35+
console.log(page);
36+
page.reports.map((report) => {
37+
console.log("page: " + index + " | id: " + report.id)
38+
dispatch(hardResetCardSettings(index,report.id))
39+
})
40+
});
41+
} catch (e) {
42+
dispatch(createNotificationThunk('Unable to refresh cards', e));
43+
}
44+
}
45+
2746
export const updateGlobalParameterThunk = (key, value) => (dispatch: any, getState: any) => {
2847
try {
2948
const { settings } = getState().dashboard;

0 commit comments

Comments
 (0)