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

Implement JSON formatting and syntax highlighting #443

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AmerMesanovic
Copy link
Contributor

@AmerMesanovic AmerMesanovic commented Jul 5, 2024

Enhance UX in Dashboard with JSON text editor using Monaco Editor (@monaco-editor/react) for improved formatting, syntax highlighting, and validation error reporting.

Screenshot from 2024-07-05 09-28-54
Screenshot from 2024-07-05 09-28-34
Screenshot from 2024-07-05 09-28-23
Screenshot from 2024-07-05 09-28-18

src/components/InterfaceEditor.tsx Show resolved Hide resolved
src/components/JsonEditor.tsx Outdated Show resolved Hide resolved
@AmerMesanovic AmerMesanovic force-pushed the json-editor branch 2 times, most recently from 2148e57 to e493080 Compare July 11, 2024 13:12
@AmerMesanovic AmerMesanovic requested a review from Pavinati July 11, 2024 13:30
package-lock.json Outdated Show resolved Hide resolved
src/components/TriggerEditor/index.tsx Show resolved Hide resolved
src/schemas/jsonSchemas.tsx Show resolved Hide resolved
cypress/e2e/interface_builder.cy.js Outdated Show resolved Hide resolved
cypress/e2e/interface_builder.cy.js Outdated Show resolved Hide resolved
cypress/e2e/interface_builder.cy.js Outdated Show resolved Hide resolved
cypress/e2e/interface_builder.cy.js Outdated Show resolved Hide resolved
cypress/e2e/trigger_builder.cy.js Outdated Show resolved Hide resolved
src/components/JsonEditor.tsx Outdated Show resolved Hide resolved
cypress/e2e/trigger_builder.cy.js Outdated Show resolved Hide resolved
cypress/e2e/trigger_builder.cy.js Outdated Show resolved Hide resolved
@AmerMesanovic AmerMesanovic requested a review from Pavinati August 8, 2024 09:29
@AmerMesanovic AmerMesanovic force-pushed the json-editor branch 2 times, most recently from 00f7438 to a095ea6 Compare August 9, 2024 06:52
cypress/e2e/trigger_builder.cy.js Outdated Show resolved Hide resolved
cypress/e2e/trigger_builder.cy.js Outdated Show resolved Hide resolved
cypress/e2e/trigger_builder.cy.js Outdated Show resolved Hide resolved
cypress/e2e/trigger_builder.cy.js Outdated Show resolved Hide resolved
Enhance UX in Dashboard with JSON text editor using Monaco Editor
(@monaco-editor/react) for improved formatting, syntax highlighting,
and validation error reporting.

Signed-off-by: AmerMesanovic <amer.mesanovic@secomind.com>
utilizing MonacoEditor.

- Updated test selectors to target JSONEditor
component.
- Used force option for clicks to handle overlays
in the editor.
- Increased timeouts where necessary to account
for MonacoEditor's loading times

Signed-off-by: AmerMesanovic <amer.mesanovic@secomind.com>
databaseTTL,
} = parseMappingOptions(_.get(iface.mappings, '0'));
const { reliability, explicitTimestamp, retention, expiry, databaseRetention, databaseTTL } =
parseMappingOptions(_.get(iface.mappings, '0'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there are no changes, please avoid to change code format as this will introduce undesired noise to the pr.
Same goes for unnecessary ; at the end of a line

there are multiple occurrences in this PR that only changes how the code is styled but add nothing, it's better to move a restyling in another PR

@@ -128,7 +128,7 @@ const checkMappingEditorUIValues = ({ mapping, type, aggregation = 'individual'
.should('be.visible')
.within(() => {
cy.contains(mapping.endpoint);
cy.get('button').contains('Edit...').click();
cy.get('button').contains('Edit...').should('have.length', 1).click({ force: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could possible have more that one edit button? There is a necessity to check that?

interfaceFixtures.forEach((interfaceFixture) => {
cy.fixture(interfaceFixture).then(({ data: iface }) => {
setupInterfaceEditorFromUI(iface);
checkInterfaceEditorUIValues(iface);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above, avoid newlines if not necessary

Comment on lines +86 to +116
if (win.monaco && win.monaco.editor) {
const editor = win.monaco.editor.getModels()[0];
const editorContent = editor.getValue();
const editorJson = JSON.parse(editorContent);

expect(editorJson.simple_triggers[0].interface_name).to.equal(iface);
} else {
throw new Error('Monaco Editor instance is not available');
}
});
cy.window().then((win) => {
if (win.monaco && win.monaco.editor) {
const editor = win.monaco.editor.getModels()[0];
const editorContent = editor.getValue();
const editorJson = JSON.parse(editorContent);

expect(editorJson.simple_triggers[0].interface_major).to.equal(simpleTrigger.interface_major);
} else {
throw new Error('Monaco Editor instance is not available');
}
});
cy.window().then((win) => {
if (win.monaco && win.monaco.editor) {
const editor = win.monaco.editor.getModels()[0];
const editorContent = editor.getValue();
const editorJson = JSON.parse(editorContent);

expect(editorJson.simple_triggers[0].match_path).to.equal(simpleTrigger.match_path);
} else {
throw new Error('Monaco Editor instance is not available');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here there is a repetition of

      cy.window().then((win) => {
        if (win.monaco && win.monaco.editor) {
          const editor = win.monaco.editor.getModels()[0];
          const editorContent = editor.getValue();
          const editorJson = JSON.parse(editorContent);

all of that can be merged in a single if clause

.scrollIntoView()
.should('be.visible')
.contains(simpleTrigger.interface_major)
.contains(triggerOperatorToLabel[simpleTrigger.value_match_operator])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to check for more than one property, but

.contains(simpleTrigger.interface_major)

got removed

.scrollIntoView()
.should('be.visible')
.contains(simpleTrigger.interface_major)
.contains(triggerOperatorToLabel[simpleTrigger.value_match_operator])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to check for more than one property, but

.contains(simpleTrigger.interface_major)

got removed entirely

Comment on lines +338 to +342
cy.get('#triggerSource', { timeout: 1000 }).scrollIntoView().should('be.visible');
cy.get('button').contains('Hide source', { timeout: 1000 }).scrollIntoView().click();
cy.get('#triggerSource', { timeout: 1000 }).should('not.exist');
cy.get('button').contains('Show source', { timeout: 1000 }).scrollIntoView().click();
cy.get('#triggerSource', { timeout: 1000 }).scrollIntoView().should('be.visible');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not required, all of those timeouts would only prolong the duration of this already long tests

This apply for the entire PR, check and be sure the timeouts/cy.wait functions are really needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants