Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing casting error at while loading the dashboards #874

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/application/ApplicationThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import { runCypherQuery } from '../report/ReportQueryRunner';
import {
setPageNumberThunk,
updateParametersToNeo4jTypeThunk,
updateGlobalParametersThunk,
updateSessionParameterThunk,
} from '../settings/SettingsThunks';
Expand Down Expand Up @@ -263,12 +262,12 @@
if (urlParams.get('credentials')) {
setWelcomeScreenOpen(false);
const connection = decodeURIComponent(urlParams.get('credentials'));
const protocol = connection.split('://')[0];

Check warning on line 265 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Use array destructuring
const username = connection.split('://')[1].split(':')[0];

Check warning on line 266 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Use array destructuring
const password = connection.split('://')[1].split(':')[1].split('@')[0];

Check warning on line 267 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Use array destructuring
const database = connection.split('@')[1].split(':')[0];

Check warning on line 268 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Use array destructuring
const url = connection.split('@')[1].split(':')[1];

Check warning on line 269 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Use array destructuring
const port = connection.split('@')[1].split(':')[2];

Check warning on line 270 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Use array destructuring
// if (url == password) {
// // Special case where a connect link is generated without a password.
// // Here, the format is parsed incorrectly and we open the connection window instead.
Expand Down Expand Up @@ -499,8 +498,6 @@
);
}
}
// At the load of a dashboard, we want to ensure correct casting types
dispatch(updateParametersToNeo4jTypeThunk());

// SSO - specific case starts here.
if (state.application.waitForSSO) {
Expand Down Expand Up @@ -575,7 +572,7 @@
dispatch(initializeApplicationAsEditorThunk(config, paramsToSetAfterConnecting));
}
} catch (e) {
console.log(e);

Check warning on line 575 in src/application/ApplicationThunks.ts

View workflow job for this annotation

GitHub Actions / build-test (18.x)

Unexpected console statement
dispatch(setWelcomeScreenOpen(false));
dispatch(
createNotificationThunk(
Expand Down Expand Up @@ -642,8 +639,8 @@
} else {
dispatch(setDashboardToLoadAfterConnecting(`name:${config.standaloneDashboardName}`));
}

dispatch(setParametersToLoadAfterConnecting(paramsToSetAfterConnecting));
dispatch(updateGlobalParametersThunk(paramsToSetAfterConnecting));

if (clearNotificationAfterLoad) {
dispatch(clearNotification());
Expand Down
6 changes: 3 additions & 3 deletions src/chart/ChartUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export function replaceDashboardParameters(str, parameters) {
let type = getRecordType(val);

// Arrays weren't playing nicely with RenderSubValue(). Each object would be passed separately and return [oject Object].
if (type === 'string' || type == 'link' ) {
if (type === 'string' || type == 'link') {
return val;
} else if (type === 'array') {
return RenderSubValue(val.join(', '));
Expand Down Expand Up @@ -415,7 +415,7 @@ export function isCastableToNeo4jDate(value: object) {
return false;
}
let keys = Object.keys(value);
return keys.length == 3 && keys.includes('day') && keys.includes('month') && keys.includes('year');
return keys.includes('day') && keys.includes('month') && keys.includes('year');
}

/**
Expand All @@ -425,7 +425,7 @@ export function isCastableToNeo4jDate(value: object) {
*/
export function castToNeo4jDate(value: object) {
if (isCastableToNeo4jDate(value)) {
return new Neo4jDate(value.year, value.month, value.day);
return new Neo4jDate(toNumber(value.year), toNumber(value.month), toNumber(value.day));
}
throw new Error(`Invalid input for castToNeo4jDate: ${value}`);
}
Expand Down
16 changes: 2 additions & 14 deletions src/dashboard/DashboardThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { updateDashboardSetting } from '../settings/SettingsActions';
import { addPage, movePage, removePage, resetDashboardState, setDashboard, setDashboardUuid } from './DashboardActions';
import { QueryStatus, runCypherQuery } from '../report/ReportQueryRunner';
import { setDraft, setParametersToLoadAfterConnecting, setWelcomeScreenOpen } from '../application/ApplicationActions';
import { updateGlobalParametersThunk, updateParametersToNeo4jTypeThunk } from '../settings/SettingsThunks';
import { updateGlobalParametersThunk } from '../settings/SettingsThunks';
import { createUUID } from '../utils/uuid';
import { createLogThunk } from '../application/logging/LoggingThunk';
import { applicationGetConnectionUser, applicationIsStandalone } from '../application/ApplicationSelectors';
import { applicationGetLoggingSettings } from '../application/logging/LoggingSelectors';
import { NEODASH_VERSION, VERSION_TO_MIGRATE } from './DashboardReducer';
import { Date as Neo4jDate } from 'neo4j-driver-core/lib/temporal-types.js';

export const removePageThunk = (number) => (dispatch: any, getState: any) => {
try {
Expand Down Expand Up @@ -113,16 +112,6 @@ export const loadDashboardThunk = (uuid, text) => (dispatch: any, getState: any)
throw `Invalid dashboard version: ${dashboard.version}. Try restarting the application, or retrieve your cached dashboard using a debug report.`;
}

// Cast dashboard parameters from serialized format to correct types
Object.keys(dashboard.settings.parameters).forEach((key) => {
const value = dashboard.settings.parameters[key];

// Serialized Date to Neo4jDate
if (value && value.year && value.month && value.day) {
dashboard.settings.parameters[key] = new Neo4jDate(value.year, value.month, value.day);
}
});

// Reverse engineer the minimal set of fields from the selection loaded.
dashboard.pages.forEach((p) => {
p.reports.forEach((r) => {
Expand All @@ -140,9 +129,8 @@ export const loadDashboardThunk = (uuid, text) => (dispatch: any, getState: any)
const { application } = getState();

dispatch(updateGlobalParametersThunk(application.parametersToLoadAfterConnecting));
dispatch(updateGlobalParametersThunk(dashboard.settings.parameters));
dispatch(setParametersToLoadAfterConnecting(null));
dispatch(updateParametersToNeo4jTypeThunk());

// Pre-2.3.4 dashboards might now always have a UUID. Set it if not present.
if (!dashboard.uuid) {
dispatch(setDashboardUuid(uuid));
Expand Down
3 changes: 1 addition & 2 deletions src/extensions/advancedcharts/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { valueIsArray } from '../../chart/ChartUtils';
import { useDispatch, useSelector } from 'react-redux';
import { useSelector } from 'react-redux';
import { getPageNumbersAndNames } from '../../dashboard/DashboardSelectors';
import { updateDashboardSetting } from '../../settings/SettingsActions';

export const getRule = (e, rules, type) => {
let r = getRuleWithFieldPropertyName(e, rules, type, null);
Expand Down
6 changes: 4 additions & 2 deletions src/settings/SettingsThunks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { setSessionParameters } from '../application/ApplicationActions';
import { hardResetCardSettings } from '../card/CardActions';
import { castToNeo4jDate, isCastableToNeo4jDate, valueIsNode } from '../chart/ChartUtils';
import { castToNeo4jDate, isCastableToNeo4jDate, toNumber, valueIsNode } from '../chart/ChartUtils';
import { createNotificationThunk } from '../page/PageThunks';
import { updateDashboardSetting } from './SettingsActions';

Expand Down Expand Up @@ -73,6 +73,7 @@ export const updateGlobalParametersThunk = (newParameters) => (dispatch: any, ge
}
});
dispatch(updateDashboardSetting('parameters', { ...parameters }));
dispatch(updateParametersToNeo4jTypeThunk());
}
} catch (e) {
dispatch(createNotificationThunk('Unable to update global parameters', e));
Expand All @@ -86,12 +87,13 @@ export const updateParametersToNeo4jTypeThunk = () => (dispatch: any, getState:
try {
const { settings } = getState().dashboard;
const parameters = settings.parameters ? settings.parameters : {};

// if new parameters are set...
// iterate over the key value pairs in parameters
Object.keys(parameters).forEach((key) => {
if (isCastableToNeo4jDate(parameters[key])) {
parameters[key] = castToNeo4jDate(parameters[key]);
} else if (parameters[key] && typeof toNumber(parameters[key]) === 'number') {
parameters[key] = toNumber(parameters[key]);
} else if (parameters[key] == undefined) {
delete parameters[key];
}
Expand Down
Loading