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

Feat/forms button improvements #822

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions cypress/e2e/start_page.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ describe('NeoDash E2E Tests', () => {

cy.get('main .react-grid-item:eq(2) button[aria-label="run"]').scrollIntoView().should('be.visible').click();
cy.wait(500);
cy.get('#form-submit').should('be.disabled');
cy.get('#autocomplete').type('The Matrix');
cy.get('#autocomplete-option-0').click();
cy.get('#form-submit').should('not.be.disabled');
cy.get('#form-submit').click();
cy.wait(500);
cy.get('.form-submitted-message').should('have.text', 'Form Submitted.Reset Form');
Expand Down
11 changes: 10 additions & 1 deletion src/extensions/forms/chart/NeoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import debounce from 'lodash/debounce';
import { RUN_QUERY_DELAY_MS } from '../../../config/ReportConfig';
import NeoParameterSelectionChart from '../../../chart/parameter/ParameterSelectionChart';
import { checkParametersNameInGlobalParameter, extractAllParameterNames } from '../../../utils/parameterUtils';

enum FormStatus {
DATA_ENTRY = 0, // The user is filling in the form.
Expand Down Expand Up @@ -42,6 +43,14 @@
});
}

const isParametersDefined = (cypherQuery: string | undefined) => {
const parameterNames = extractAllParameterNames(cypherQuery);

Check warning on line 47 in src/extensions/forms/chart/NeoForm.tsx

View check run for this annotation

Codecov / codecov/patch

src/extensions/forms/chart/NeoForm.tsx#L46-L47

Added lines #L46 - L47 were not covered by tests
if (props.parameters) {
return checkParametersNameInGlobalParameter(parameterNames, props.parameters);

Check warning on line 49 in src/extensions/forms/chart/NeoForm.tsx

View check run for this annotation

Codecov / codecov/patch

src/extensions/forms/chart/NeoForm.tsx#L49

Added line #L49 was not covered by tests
}
return false;

Check warning on line 51 in src/extensions/forms/chart/NeoForm.tsx

View check run for this annotation

Codecov / codecov/patch

src/extensions/forms/chart/NeoForm.tsx#L51

Added line #L51 was not covered by tests
};

useEffect(() => {
// If the parameters change after the form is completed, reset it, as there might be another submission.
if (status == FormStatus.SUBMITTED) {
Expand Down Expand Up @@ -77,7 +86,7 @@
<Button
style={{ marginLeft: 15 }}
id='form-submit'
disabled={!submitButtonActive}
disabled={!submitButtonActive || isParametersDefined(props.query)}
onClick={() => {
if (!props.query || !props.query.trim()) {
props.createNotification(
Expand Down
35 changes: 35 additions & 0 deletions src/utils/parameterUtils.ts
m-o-n-i-s-h marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Extracts all parameter names from a given Cypher query string.
*
* @param {string} cypherQuery The Cypher query string to extract parameter names from.
* @returns {string[]} An array containing all extracted parameter names.
*/
export const extractAllParameterNames = (cypherQuery: string): string[] => {
// A regular expression pattern to match parameter names following '$'
const pattern = /\$([A-Za-z_]\w*)/g;

Check warning on line 9 in src/utils/parameterUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/parameterUtils.ts#L9

Added line #L9 was not covered by tests

const parameterNames: string[] = [];

Check warning on line 11 in src/utils/parameterUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/parameterUtils.ts#L11

Added line #L11 was not covered by tests
let match: any;

while ((match = pattern.exec(cypherQuery)) !== null) {
parameterNames.push(match[1]);

Check warning on line 15 in src/utils/parameterUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/parameterUtils.ts#L14-L15

Added lines #L14 - L15 were not covered by tests
}

return parameterNames;

Check warning on line 18 in src/utils/parameterUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/parameterUtils.ts#L18

Added line #L18 was not covered by tests
}

/**
* Checks if all parameter names are present in the global parameter names.
*
* @param {string[]} parameterNames An array of parameter names to be checked.
* @param {object} globalParameterNames The object containing global parameter names to compare against.
* @returns {boolean} A boolean indicating whether all parameters are present in the global parameters.
*/
export const checkParametersNameInGlobalParameter = (parameterNames: string[], globalParameterNames: any): boolean => {
for (const key of parameterNames) {

Check warning on line 29 in src/utils/parameterUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/parameterUtils.ts#L29

Added line #L29 was not covered by tests
if (!globalParameterNames[key] || (Array.isArray(globalParameterNames[key]) && globalParameterNames[key].length === 0) || globalParameterNames[key] === '') {
return true;

Check warning on line 31 in src/utils/parameterUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/parameterUtils.ts#L31

Added line #L31 was not covered by tests
}
}
return false;

Check warning on line 34 in src/utils/parameterUtils.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/parameterUtils.ts#L34

Added line #L34 was not covered by tests
}
Loading