Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Sep 5, 2023
2 parents af03460 + 8e980fb commit 6287e3a
Show file tree
Hide file tree
Showing 44 changed files with 536 additions and 294 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ used the CLI, you don't get overwhelmed.

- [Documentation](https://nx.dev/core-features/integrate-with-editors) - Official documentation with video tutorials
- [nx.dev](http://nx.dev) - Documentation, Guides and Interactive Tutorials on Nx
- [Learn more about the team at Nrwl](https://nx.app/company) - The team at Nrwl led the development of Nx Console,
- [Join the community](http://go.nx.dev/community) - Chat about Nx & Nx Console on the official discord server
- [Learn more about the team at Nx](https://nx.app/company) - The team at Nx led the development of Nx Console,
after working with many Enterprise clients.

# Contributing
Expand Down
65 changes: 5 additions & 60 deletions apps/generate-ui-v2-e2e/src/e2e/generator-context.cy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { GeneratorSchema } from '@nx-console/shared/generate-ui-types';
import {
expectConsoleLogToHaveBeenCalledWith,
spyOnConsoleLog,
} from '../support/console-spy';
import { clickShowMore, getFieldByName } from '../support/get-elements';
import { getFieldByName } from '../support/get-elements';
import { visitGenerateUi } from '../support/visit-generate-ui';
import { GeneratorSchema } from '@nx-console/shared/generate-ui-types';

const schemaProj: GeneratorSchema = {
collectionName: '@nx/test',
Expand All @@ -21,40 +21,14 @@ const schemaProj: GeneratorSchema = {
context: {
project: 'project3',
directory: 'nested/nested2',
},
};
const schemaDir: GeneratorSchema = {
collectionName: '@nx/test',
generatorName: 'test',
description: 'description',
options: [{ name: 'directory', isRequired: false, aliases: [] }],
context: {
project: 'project3',
directory: 'nested/nested2',
},
};

const schemaBoth: GeneratorSchema = {
collectionName: '@nx/test',
generatorName: 'test',
description: 'description',
options: [
{
name: 'project',
isRequired: true,
aliases: [],
items: ['project1', 'project2', 'project3'],
prefillValues: {
project: 'project3',
},
{ name: 'directory', isRequired: false, aliases: [] },
],
context: {
project: 'project3',
directory: 'nested/nested2',
},
};

describe('generator context', () => {
it('should correctly use the context to autofill project', () => {
it('should correctly use the context to prefill values', () => {
visitGenerateUi(schemaProj);
getFieldByName('project').should('have.value', 'project3');

Expand All @@ -65,35 +39,6 @@ describe('generator context', () => {
});
});

it('should correctly use the context to autofill directory', () => {
visitGenerateUi(schemaDir);

getFieldByName('directory').should('have.value', 'nested/nested2');

spyOnConsoleLog().then((consoleLog) => {
cy.get("[data-cy='generate-button']").click();
expectConsoleLogToHaveBeenCalledWith(consoleLog, 'run-generator');
expectConsoleLogToHaveBeenCalledWith(
consoleLog,
'--directory=nested/nested2'
);
});
});

it('should only fill project if both directory and project exist', () => {
visitGenerateUi(schemaBoth);
clickShowMore();

getFieldByName('project').should('have.value', 'project3');
getFieldByName('directory').should('be.empty');

spyOnConsoleLog().then((consoleLog) => {
cy.get("[data-cy='generate-button']").click();
expectConsoleLogToHaveBeenCalledWith(consoleLog, 'run-generator');
expectConsoleLogToHaveBeenCalledWith(consoleLog, '--project=project3');
});
});

const schemaFixed: GeneratorSchema = {
collectionName: '@nx/test',
generatorName: 'test',
Expand Down
10 changes: 8 additions & 2 deletions apps/generate-ui-v2/src/components/banner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class Banner extends EditorContext(LitElement) {
render() {
const bannerClass =
this.type === 'error' ? 'bg-bannerError' : 'bg-bannerWarning';

if (this.dismissed) {
return html``;
}
Expand All @@ -27,8 +28,13 @@ export class Banner extends EditorContext(LitElement) {
<p class="grow">${this.message}</p>
<div @click="${this.dismiss}" class="px-2 py-1">
${this.editor === 'intellij'
? html`x`
: html` <codicon-element icon="close"></codicon-element>`}
? html`<icon-element
icon="close"
color="${getComputedStyle(this).getPropertyValue(
'--banner-text-color'
)}"
></icon-element>`
: html`<icon-element icon="close"></icon-element>`}
</div>
</div>
`;
Expand Down
19 changes: 5 additions & 14 deletions apps/generate-ui-v2/src/components/fields/mixins/field-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,11 @@ export const Field = <T extends Constructor<LitElement>>(superClass: T) => {
): void {
super.updated(_changedProperties);
if (this.generatorContext) {
if (
this.generatorContext.project &&
(this.option.name === 'project' || this.option.name === 'projectName')
) {
this.setFieldValue(this.generatorContext.project);
this.dispatchValue(this.generatorContext.project);
return;
}
if (
this.generatorContext.directory &&
this.option.name === 'directory'
) {
this.setFieldValue(this.generatorContext.directory);
this.dispatchValue(this.generatorContext.directory);
const prefillValue =
this.generatorContext.prefillValues?.[this.option.name];
if (prefillValue) {
this.setFieldValue(prefillValue);
this.dispatchValue(prefillValue);
return;
}
}
Expand Down
31 changes: 30 additions & 1 deletion apps/generate-ui-v2/src/components/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,49 @@ export class Icon extends EditorContext(LitElement) {
@property()
icon: string;

@property()
color = '';

render() {
if (this.editor === 'intellij') {
return html`<img
src="./icons/${this.icon}.svg"
class="h-[1.25rem]"
@load="${this.applyColorToSVG}"
></img>`;
} else {
return html`<span
class="codicon codicon-${this.icon}"
style="text-align: center; font-size: 0.9rem;"
style="text-align: center; font-size: 0.9rem; color: ${this.color}"
></span>`;
}
}

// we have to parse the svg file and forcefully update the color for intellij
async applyColorToSVG() {
if (!this.color) {
return;
}
const svgResponse = await fetch(`./icons/${this.icon}.svg`);
const svgData = await svgResponse.text();
const parser = new DOMParser();
const parsedSvg = parser.parseFromString(svgData, 'image/svg+xml');

const allPaths = parsedSvg.querySelectorAll('path');
allPaths.forEach((path) => {
path.setAttribute('fill', this.color);
path.setAttribute('stroke', this.color);
});

const imgElement = this.querySelector('img');
if (imgElement) {
imgElement.remove();
}

parsedSvg.documentElement.classList.add('h-[1.25rem]');
this.appendChild(parsedSvg.documentElement);
}

protected createRenderRoot(): Element | ShadowRoot {
return this;
}
Expand Down
30 changes: 3 additions & 27 deletions apps/generate-ui-v2/src/ide-communication.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
GeneratorSchema,
ValidationResults,
} from '@nx-console/shared/generate-ui-types';
import { Option } from '@nx-console/shared/schema';
import { ReactiveController, ReactiveElement } from 'lit';

import type { WebviewApi } from 'vscode-webview';
Expand Down Expand Up @@ -132,35 +131,11 @@ export class IdeCommunicationController implements ReactiveController {
}

private handleInputMessage(message: GenerateUiInputMessage) {
const optionFilter = (option: Option) =>
option['x-priority'] !== 'internal';

// THIS IS A FIX UNTIL DIR & PATH OPTIONS ARE PROPERLY HANDLED
// WE DON'T WANT TO PREFILL DIR WHEN THERE'S A PROJECT
const transformContext = (
schema: GeneratorSchema,
context: GeneratorContext | undefined
) => {
if (schema.options.find((opt) => opt.name === 'project')) {
return {
...context,
directory: undefined,
};
} else {
return context;
}
};

switch (message.payloadType) {
case 'generator': {
const schema = message.payload;
const schemaWithFilteredOptions = {
...schema,
options: schema.options.filter(optionFilter),
};
this.generatorSchema = schemaWithFilteredOptions;
this.generatorSchema = message.payload;
this.generatorContextContextProvider.setValue(
transformContext(schema, this.generatorSchema.context)
this.generatorSchema.context
);

this.host.requestUpdate();
Expand Down Expand Up @@ -209,6 +184,7 @@ export class IdeCommunicationController implements ReactiveController {
--active-selection-background-color: ${styles.activeSelectionBackgroundColor};
--focus-border-color: ${styles.focusBorderColor};
--banner-warning-color: ${styles.bannerWarningBackgroundColor};
--banner-text-color: ${styles.bannerTextColor};
--badge-background-color: ${styles.badgeBackgroundColor};
--separator-color: ${styles.separatorColor};
--field-nav-hover-color: ${styles.fieldNavHoverColor};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ data class GenerateUiStyles(
val focusBorderColor: String,
val badgeBackgroundColor: String,
val bannerWarningBackgroundColor: String,
val bannerTextColor: String,
val separatorColor: String,
val fieldNavHoverColor: String,
val scrollbarThumbColor: String,
Expand All @@ -94,11 +95,12 @@ data class GenerateUiStyles(

@Serializable
@SerialName("banner")
data class GenerateUiBannerInputMessage(override val payload: GenerateUiBanner) :
GenerateUiInputMessage {}
data class GenerateUiStartupMessageDefinitionInputMessage(
override val payload: GenerateUiStartupMessageDefinition
) : GenerateUiInputMessage {}

@Serializable
data class GenerateUiBanner(val message: String, val type: String) {
data class GenerateUiStartupMessageDefinition(val message: String, val type: String) {
init {
require(type == "warning" || type == "error")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,17 @@ class V2NxGenerateUiFile(name: String, private val project: Project) :
if (messageParsed.payloadType == "output-init") {
this.generatorToDisplay?.let { schema ->
CoroutineScope(Dispatchers.Default).launch {
val transformedSchema =
NxlsService.getInstance(project).transformedGeneratorSchema(schema)
postMessageToBrowser(GenerateUiGeneratorSchemaInputMessage(transformedSchema))
NxlsService.getInstance(project).transformedGeneratorSchema(schema).apply {
postMessageToBrowser(GenerateUiGeneratorSchemaInputMessage(this))
}
}
CoroutineScope(Dispatchers.Default).launch {
NxlsService.getInstance(project).startupMessage(schema)?.apply {
postMessageToBrowser(GenerateUiStartupMessageDefinitionInputMessage(this))
}
}
}

return
}
if (messageParsed.payloadType == "run-generator") {
Expand Down Expand Up @@ -137,6 +143,7 @@ class V2NxGenerateUiFile(name: String, private val project: Project) :
val badgeBackgroundColor = selectFieldBackgroundColor
val bannerWarningBackgroundColor =
getHexColor(UIManager.getColor("Component.warningFocusColor"))
val bannerTextColor = getHexColor(UIManager.getColor("Button.foreground"))
val statusBarBorderColor = getHexColor(UIManager.getColor("StatusBar.borderColor"))
val fieldNavHoverColor = getHexColor(UIManager.getColor("TabbedPane.hoverColor"))

Expand All @@ -157,6 +164,7 @@ class V2NxGenerateUiFile(name: String, private val project: Project) :
focusBorderColor = focusBorderColor,
badgeBackgroundColor = badgeBackgroundColor,
bannerWarningBackgroundColor = bannerWarningBackgroundColor,
bannerTextColor = bannerTextColor,
separatorColor = statusBarBorderColor,
fieldNavHoverColor = fieldNavHoverColor,
scrollbarThumbColor = scrollbarThumbColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package dev.nx.console.graph.actions
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.CustomShortcutSet
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.keymap.KeymapUtil
import com.intellij.openapi.project.DumbAwareAction
import dev.nx.console.NxIcons
import dev.nx.console.graph.NxGraphService
import dev.nx.console.nx_toolwindow.tree.NxSimpleNode
import dev.nx.console.nx_toolwindow.tree.NxTreeNodeKey
Expand All @@ -17,11 +20,17 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class NxGraphFocusProjectAction : DumbAwareAction("Nx Graph: Focus Project") {

init {
useKeyMapShortcutSetOrDefault()
}
override fun update(e: AnActionEvent) {
useKeyMapShortcutSetOrDefault()
val nxTreeNode = e.getData(NxTreeNodeKey) ?: return
if (nxTreeNode !is NxSimpleNode.Project) {
e.presentation.isEnabledAndVisible = false
}
e.presentation.icon = NxIcons.Action
}
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
Expand Down Expand Up @@ -72,4 +81,19 @@ class NxGraphFocusProjectAction : DumbAwareAction("Nx Graph: Focus Project") {

return selectNxProject(project, e.dataContext, currentlyOpenedProject)
}

private fun useKeyMapShortcutSetOrDefault() {
val keyMapSet = KeymapUtil.getActiveKeymapShortcuts(ID)

if (keyMapSet.shortcuts.isEmpty()) {
shortcutSet = CustomShortcutSet.fromString(DEFAULT_SHORTCUT)
} else {
shortcutSet = keyMapSet
}
}

companion object {
const val DEFAULT_SHORTCUT = "control shift G"
const val ID = "dev.nx.console.graph.actions.NxGraphFocusProjectAction"
}
}
Loading

0 comments on commit 6287e3a

Please sign in to comment.