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 5 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 @@ -261,8 +261,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 { REPORT_LOADING_ICON } from '../../../report/Report';
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 NeoForm = (props: ChartProps) => {
});
}

const isParametersDefined = (cypherQuery: string | undefined) => {
const parameterNames = extractAllParameterNames(cypherQuery);
if (props.parameters) {
return checkParametersNameInGlobalParameter(parameterNames, props.parameters);
}
return false;
};

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 @@ const NeoForm = (props: ChartProps) => {
<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
22 changes: 22 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,22 @@
export const extractAllParameterNames = (cypherQuery) => {
// A regular expression pattern to match parameter names following '$'
const pattern = /\$([A-Za-z_]\w*)/g;

const parameterNames: string[] = [];
let match: any;

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

return parameterNames;
}

export const checkParametersNameInGlobalParameter = (parameterNames: string[], globalParameterNames: any) => {
for (const key of parameterNames) {
if (!globalParameterNames[key] || (Array.isArray(globalParameterNames[key]) && globalParameterNames[key].length === 0) || globalParameterNames[key] === '') {
return true;
}
}
return false;
}
Loading