Skip to content

Commit

Permalink
Merge branch 'fork-release' into feature/log
Browse files Browse the repository at this point in the history
  • Loading branch information
8Rav3n committed Aug 31, 2023
2 parents 7b88f4e + f6f4471 commit 8204105
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 26 deletions.
16 changes: 14 additions & 2 deletions docs/modules/ROOT/pages/developer-guide/configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ will look like this:
"standaloneDashboardDatabase": "dashboards",
"standaloneDashboardURL": "",
"loggingMode": "0",
"loggingDatabase": "logging"
"loggingDatabase": "logs",
"standaloneAllowLoad": false,
"standaloneLoadFromOtherDatabases": false
}
....

Expand Down Expand Up @@ -102,6 +103,17 @@ must be granted to enble any user to create logs.
|loggingDatabase |string |neo4j |When loggingMode is set to anything
else than '0', the database to use for logging. Log records (nodes)
will be created in this database.

|standaloneAllowLoad |boolean |false |If set t yes the "Load Dashboard"
button will be enabled in standalone mode, allowing users to load
additional dashboards from Neo4J.
*NOTE*: when Load is enabled in standalone mode, only Database is available
as a source, not file.

|standaloneLoadFromOtherDatabases|boolean |false |If standaloneAllowLoad is
set to true, this parmeter enables or not users to load dashboards from
other databases than the one deifned in standaloneDashboardDatabase. If
standaloneAllowLoad is set to false this parameters has no effect.
|===

== Configuring SSO
Expand Down
2 changes: 2 additions & 0 deletions docs/modules/ROOT/pages/developer-guide/state-management.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ standalone mode.
"standaloneDashboardDatabase": "dashboards",
"loggingMode": "0",
"loggingDatabase": "logging",
"standaloneAllowLoad": false,
"standaloneLoadFromOtherDatabases ": false,
"notificationIsDismissable": null
}
....
4 changes: 3 additions & 1 deletion public/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
"standaloneDashboardDatabase": "dashboards",
"standaloneDashboardURL": "",
"loggingMode": "0",
"loggingDatabase": "logs"
"loggingDatabase": "logs",
"standaloneAllowLoad": false,
"standaloneLoadFromOtherDatabases": false
}
4 changes: 3 additions & 1 deletion scripts/config-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ echo " \
\"standaloneDashboardDatabase\": \"${standaloneDashboardDatabase:='neo4j'}\", \
\"standaloneDashboardURL\": \"${standaloneDashboardURL:=}\", \
\"loggingMode\": \"${loggingMode:='0'}\", \
\"loggingMode\": \"${loggingDatabase:='logs'}\" \
\"loggingMode\": \"${loggingDatabase:='logs'}\", \
\"standaloneAllowLoad\": \"${standaloneAllowLoad:=false}\", \
\"standaloneLoadFromOtherDatabases\": \"${standaloneLoadFromOtherDatabases:=false}\" \
}" > /usr/share/nginx/html/config.json
6 changes: 5 additions & 1 deletion src/application/ApplicationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ export const setStandaloneEnabled = (
standaloneDashboardDatabase: string,
standaloneDashboardURL: string,
standaloneUsername: string,
standalonePassword: string
standalonePassword: string,
standaloneAllowLoad: boolean,
standaloneLoadFromOtherDatabases: boolean
) => ({
type: SET_STANDALONE_ENABLED,
payload: {
Expand All @@ -157,6 +159,8 @@ export const setStandaloneEnabled = (
standaloneDashboardURL,
standaloneUsername,
standalonePassword,
standaloneAllowLoad,
standaloneLoadFromOtherDatabases,
},
});

Expand Down
4 changes: 4 additions & 0 deletions src/application/ApplicationReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export const applicationReducer = (state = initialState, action: { type: any; pa
standaloneDashboardURL,
standaloneUsername,
standalonePassword,
standaloneAllowLoad,
standaloneLoadFromOtherDatabases
} = payload;
state = update(state, {
standalone: standalone,
Expand All @@ -166,6 +168,8 @@ export const applicationReducer = (state = initialState, action: { type: any; pa
standaloneDashboardURL: standaloneDashboardURL,
standaloneUsername: standaloneUsername,
standalonePassword: standalonePassword,
standaloneAllowLoad: standaloneAllowLoad,
standaloneLoadFromOtherDatabases: standaloneLoadFromOtherDatabases,
});
return state;
}
Expand Down
2 changes: 2 additions & 0 deletions src/application/ApplicationSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export const applicationGetStandaloneSettings = (state: any) => {
standaloneDashboardURL: state.application.standaloneDashboardURL,
standaloneUsername: state.application.standaloneUsername,
standalonePassword: state.application.standalonePassword,
standaloneAllowLoad: state.application.standaloneAllowLoad,
standaloneLoadFromOtherDatabases: state.application.standaloneLoadFromOtherDatabases,
};
};

Expand Down
6 changes: 5 additions & 1 deletion src/application/ApplicationThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState:
loggingMode: '0',
loggingDatabase: 'logs',
logErrorNotification: '3',
standaloneAllowLoad: false,
standaloneLoadFromOtherDatabases: false,
};
try {
config = await (await fetch('config.json')).json();
Expand Down Expand Up @@ -430,7 +432,9 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState:
config.standaloneDashboardDatabase,
config.standaloneDashboardURL,
config.standaloneUsername,
config.standalonePassword
config.standalonePassword,
config.standaloneAllowLoad,
config.standaloneLoadFromOtherDatabases,
)
);

Expand Down
28 changes: 16 additions & 12 deletions src/dashboard/header/DashboardTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Suspense, useCallback, useEffect, useState } from 'react';
import debounce from 'lodash/debounce';
import { connect } from 'react-redux';
import { setDashboardTitle } from '../DashboardActions';
import { applicationGetConnection, applicationIsStandalone } from '../../application/ApplicationSelectors';
import { applicationGetConnection, applicationGetStandaloneSettings } from '../../application/ApplicationSelectors';
import { getDashboardTitle, getDashboardExtensions, getDashboardSettings } from '../DashboardSelectors';
import { getDashboardIsEditable } from '../../settings/SettingsSelectors';
import { updateDashboardSetting } from '../../settings/SettingsActions';
Expand All @@ -21,7 +21,7 @@ export const NeoDashboardTitle = ({
dashboardTitle,
setDashboardTitle,
editable,
isStandalone,
standaloneSettings,
dashboardSettings,
extensions,
updateDashboardSetting,
Expand Down Expand Up @@ -70,7 +70,8 @@ export const NeoDashboardTitle = ({
return (
<div className='n-flex n-flex-row n-flex-wrap n-justify-between n-items-center'>
{/* TODO : Replace with editable field if dashboard is editable */}
{editing ? (
{/* only allow edit title if dashboard is not standalone - here we are in Title edit mode*/}
{editing && !standaloneSettings.standalone ? (
<div className={'n-flex n-flex-row n-flex-wrap n-justify-between n-items-center'}>
<TextInput
autoFocus={true}
Expand Down Expand Up @@ -99,7 +100,7 @@ export const NeoDashboardTitle = ({
</IconButton>
</Tooltip>
</div>
) : (
) : !standaloneSettings.standalone? ( /* out of edit mode - if Not Standalone we display the edit button */
<div className={'n-flex n-flex-row n-flex-wrap n-justify-between n-items-center'}>
<Typography variant='h3'>{dashboardTitle}</Typography>
<Tooltip title={'Edit'} disableInteractive>
Expand All @@ -118,11 +119,15 @@ export const NeoDashboardTitle = ({
)}
</Tooltip>
</div>
):( /* if we are in Standalone just title is displayed with no edit button */
<div className={'n-flex n-flex-row n-flex-wrap n-justify-between n-items-center'}>
<Typography variant='h3'>{dashboardTitle}</Typography>
</div>
)}
{/* If the app is not running in standalone mode (i.e. in edit mode) always show dashboard settings. */}
{!isStandalone ? (
{!standaloneSettings.standalone ? (
<div className='flex flex-row flex-wrap items-center gap-2'>
{editable ? <NeoExtensionsModal closeMenu={handleSettingsMenuClose} /> : <></>}
{(editable && !standaloneSettings.standalone) ? <NeoExtensionsModal closeMenu={handleSettingsMenuClose} /> : <></>}
<IconButton aria-label='Dashboard actions' onClick={handleSettingsMenuOpen}>
<EllipsisHorizontalIconOutline />
</IconButton>
Expand Down Expand Up @@ -153,23 +158,22 @@ export const NeoDashboardTitle = ({
<NeoShareModal />
{renderExtensionsButtons()}
</>
) : (
<></>
) : ( /* in standalone we allow load is standaloneAllowLoad parameter is enabled */
<></>
)}
</MenuItems>
</Menu>
</div>
) : (
<></>
)}
) : standaloneSettings.standaloneAllowLoad ? <NeoLoadModal /> : <></>
}
</div>
);
};

const mapStateToProps = (state) => ({
dashboardTitle: getDashboardTitle(state),
editable: getDashboardIsEditable(state),
isStandalone: applicationIsStandalone(state),
standaloneSettings: applicationGetStandaloneSettings(state),
dashboardSettings: getDashboardSettings(state),
extensions: getDashboardExtensions(state),
connection: applicationGetConnection(state),
Expand Down
39 changes: 31 additions & 8 deletions src/modal/LoadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,39 @@ import {
} from '../dashboard/DashboardThunks';
import { DataGrid } from '@mui/x-data-grid';
import { Neo4jContext, Neo4jContextState } from 'use-neo4j/dist/neo4j.context';
import { MenuItem, Button, Dialog, Dropdown } from '@neo4j-ndl/react';
import { MenuItem, Button, Dialog, Dropdown, IconButton } from '@neo4j-ndl/react';
import {
CloudArrowUpIconOutline,
PlayIconSolid,
DatabaseAddCircleIcon,
DocumentPlusIconOutline,
} from '@neo4j-ndl/react/icons';
import { applicationGetStandaloneSettings, applicationIsStandalone } from '../application/ApplicationSelectors';
import { Tooltip } from '@mui/material';

/**
* A modal to save a dashboard as a JSON text string.
* The button to open the modal is intended to use in a drawer at the side of the page.
* The button to open the modal is renderedd as:
* - a ListItem to use in a drawer at the side of the page if the app is in Editor Mode.
* - a Button to be diplayed by itself if the app is in Standalone Mode.
*/

export const NeoLoadModal = ({
loadDashboard,
loadDatabaseListFromNeo4j,
loadDashboardFromNeo4j,
loadDashboardListFromNeo4j,
isStandalone,
standaloneSettings
}) => {
const [loadModalOpen, setLoadModalOpen] = React.useState(false);
const [loadFromNeo4jModalOpen, setLoadFromNeo4jModalOpen] = React.useState(false);
const [text, setText] = React.useState('');
const [rows, setRows] = React.useState([]);
const { driver } = useContext<Neo4jContextState>(Neo4jContext);
const [dashboardDatabase, setDashboardDatabase] = React.useState('neo4j');
const [databases, setDatabases] = React.useState(['neo4j']);
//database values are initialized using standalone settings if the app is running in standalone mode
const [dashboardDatabase, setDashboardDatabase] = React.useState(standaloneSettings.standalone ? standaloneSettings.standaloneDashboardDatabase : 'neo4j');
const [databases, setDatabases] = React.useState([standaloneSettings.standalone? standaloneSettings.standaloneDatabase : 'neo4j']);
const loadFromFile = useRef(null);

const handleClickOpen = () => {
Expand Down Expand Up @@ -97,7 +104,17 @@ export const NeoLoadModal = ({

return (
<>
<MenuItem title='Load' onClick={handleClickOpen} icon={<CloudArrowUpIconOutline />} />
{!isStandalone?
(
<MenuItem title='Load' onClick={handleClickOpen} icon={<CloudArrowUpIconOutline />} />
):(
<Tooltip title={'Load Dashboard'}>
<IconButton className='n-mx-1' aria-label='Extensions' onClick={handleClickOpen}>
<CloudArrowUpIconOutline />
</IconButton>
</Tooltip>
)
}

<Dialog size='large' open={loadModalOpen == true} onClose={handleClose} aria-labelledby='form-dialog-title'>
<Dialog.Header id='form-dialog-title'>
Expand All @@ -123,6 +140,7 @@ export const NeoLoadModal = ({
Select from Neo4j
<DatabaseAddCircleIcon className='btn-icon-base-r' />
</Button>
{!isStandalone ?
<Button
onClick={() => {
loadFromFile.current.click();
Expand All @@ -135,8 +153,8 @@ export const NeoLoadModal = ({
<input type='file' ref={loadFromFile} onChange={(e) => uploadDashboard(e)} hidden />
Select From File
<DocumentPlusIconOutline className='btn-icon-base-r' />
</Button>

</Button> : <></>
}
<Button
onClick={text.length > 0 ? handleCloseAndLoad : null}
style={{
Expand Down Expand Up @@ -198,6 +216,8 @@ export const NeoLoadModal = ({
setRows(result);
});
},
//if application is running standalone and standaloneLoadFromOtherDatabases is not enabled, we do not allow changing database
isDisabled: standaloneSettings.standalone&&!standaloneSettings.standaloneLoadFromOtherDatabases?true:false,

Check failure on line 220 in src/modal/LoadModal.tsx

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Unnecessary use of boolean literals in conditional expression
options: databases.map((database) => ({ label: database, value: database })),
value: { label: dashboardDatabase, value: dashboardDatabase },
menuPlacement: 'auto',
Expand All @@ -210,7 +230,10 @@ export const NeoLoadModal = ({
);
};

const mapStateToProps = () => ({});
const mapStateToProps = (state) => ({
isStandalone: applicationIsStandalone(state),
standaloneSettings: applicationGetStandaloneSettings(state),
});

const mapDispatchToProps = (dispatch) => ({
loadDashboard: (text) => dispatch(loadDashboardThunk(text)),
Expand Down

0 comments on commit 8204105

Please sign in to comment.