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(TCOMP-2744): add @ReadOnly annotation #897

Merged
merged 2 commits into from
Sep 9, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (C) 2006-2024 Talend Inc. - www.talend.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.talend.sdk.component.api.configuration.ui.widget;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import org.talend.sdk.component.api.configuration.ui.meta.Ui;
import org.talend.sdk.component.api.meta.Documentation;

@Ui
@Documentation("Mark a option as being read-only widget. User cannot modify widget.")
@Retention(RUNTIME)
@Target({ PARAMETER, FIELD })
public @interface ReadOnly {
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,12 @@
if (ctx.getConfiguration().isIncludeDocumentationMetadata()) {
schema.setDescription(ctx.getProperty().getMetadata().get("documentation::value"));
}
if (Boolean.parseBoolean(ctx.getProperty().getMetadata().getOrDefault("documentation::tooltip", "false"))) {

Check failure on line 172 in component-form/component-form-core/src/main/java/org/talend/sdk/component/form/internal/converter/impl/widget/AbstractWidgetConverter.java

View check run for this annotation

sonar-eks / Component Runtime Sonarqube Results

component-form/component-form-core/src/main/java/org/talend/sdk/component/form/internal/converter/impl/widget/AbstractWidgetConverter.java#L172

Define a constant instead of duplicating this literal "false" 3 times.
schema.setTooltip(ctx.getProperty().getMetadata().get("documentation::value"));
}
if (Boolean.parseBoolean(ctx.getProperty().getMetadata().getOrDefault("ui::readonly", "false"))) {
schema.setReadOnly(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

wow, we had this property???

Copy link
Member Author

Choose a reason for hiding this comment

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

It's in the UiSchema specification so already existed.

}
if (actions != null) {
final List<UiSchema.Trigger> triggers = Stream
.concat(Stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -77,6 +78,7 @@ void listOfObject() throws Exception {
void moduleListWithBeanList() throws Exception {
final Map<String, String> metadata = new HashMap<>();
metadata.put("ui::modulelist", "true");
metadata.put("ui::readonly", "true");
final List<SimplePropertyDefinition> properties = asList(
new SimplePropertyDefinition("configuration", "configuration", "configuration", "OBJECT", null, NVAL,
emptyMap(), null, NPROPS),
Expand All @@ -89,13 +91,16 @@ void moduleListWithBeanList() throws Exception {
assertEquals(1, schemas.size());
final UiSchema configuration = schemas.iterator().next();
assertNull(configuration.getKey());
assertNull(configuration.getReadOnly());
assertEquals(1, configuration.getItems().size());
final UiSchema list = configuration.getItems().iterator().next();
assertNull(list.getReadOnly());
assertEquals("configuration.drivers", list.getKey());
assertEquals("collapsibleFieldset", list.getItemWidget());
assertEquals(1, list.getItems().size());
final UiSchema name = list.getItems().iterator().next();
assertEquals("configuration.drivers[].path", name.getKey());
assertTrue(name.getReadOnly());
// use text type in react ui form for the item, it mean ignore @ModuleList which only works for studio now
assertEquals("text", name.getWidget());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.talend.sdk.component.api.configuration.ui.widget.Credential;
import org.talend.sdk.component.api.configuration.ui.widget.DateTime;
import org.talend.sdk.component.api.configuration.ui.widget.ModuleList;
import org.talend.sdk.component.api.configuration.ui.widget.ReadOnly;
import org.talend.sdk.component.api.configuration.ui.widget.Structure;
import org.talend.sdk.component.api.service.configuration.LocalConfiguration;

Expand Down Expand Up @@ -398,4 +399,22 @@ public Class<? extends Annotation> annotationType() {
return true;
}));
}

@Test
void readOnly() {
assertEquals(new HashMap<String, String>() {

{
put("tcomp::ui::readonly", "true");
}
}, enricher.onParameterAnnotation("testParam", String.class, new ReadOnly() {

@Override
public Class<? extends Annotation> annotationType() {
return ReadOnly.class;
}

}));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void getIconIndex() {
.accept(APPLICATION_SVG_XML_TYPE)
.get();
assertNotNull(icons);
assertEquals(406, icons.getStatus());
assertEquals(406, icons.getStatus());
// inexistant theme (no fallback)
icons = base.path("component/icon/index")
.queryParam("theme", "dak")
Expand Down Expand Up @@ -357,7 +357,8 @@ void getIconIndex() {
assertTrue(content.contains(
"data-connector=\"standalone\" data-family=\"chain\" data-theme=\"light\" data-type=\"connector\" id=\"myicon-light\""));
assertTrue(
content.contains("data-family=\"file\" data-theme=\"light\" data-type=\"family\" id=\"file-family-light\""));
content.contains(
"data-family=\"file\" data-theme=\"light\" data-type=\"family\" id=\"file-family-light\""));
// light theme
content = base.path("component/icon/index")
.queryParam("theme", "light")
Expand All @@ -371,7 +372,8 @@ void getIconIndex() {
assertTrue(content.contains(
"data-connector=\"standalone\" data-family=\"chain\" data-theme=\"light\" data-type=\"connector\" id=\"myicon-light\""));
assertTrue(
content.contains("data-family=\"file\" data-theme=\"light\" data-type=\"family\" id=\"file-family-light\""));
content.contains(
"data-family=\"file\" data-theme=\"light\" data-type=\"family\" id=\"file-family-light\""));

// dark theme
content = base.path("component/icon/index")
Expand All @@ -384,9 +386,11 @@ void getIconIndex() {
content.startsWith(
"<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"sr-only\" data-theme=\"dark\" focusable=\"false\">"));
assertTrue(content
.contains("data-connector=\"input\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\""));
.contains(
"data-connector=\"input\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\""));
assertTrue(content
.contains("data-connector=\"output\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\""));
.contains(
"data-connector=\"output\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\""));
// theme = all
content = base.path("component/icon/index")
.queryParam("theme", "all")
Expand All @@ -399,13 +403,16 @@ void getIconIndex() {
content.startsWith(
"<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"sr-only\" data-theme=\"all\" focusable=\"false\">"));
assertTrue(content
.contains("data-connector=\"input\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\""));
.contains(
"data-connector=\"input\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\""));
assertTrue(content
.contains("data-connector=\"output\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\""));
.contains(
"data-connector=\"output\" data-family=\"jdbc\" data-theme=\"dark\" data-type=\"connector\" id=\"db-input-dark\""));
assertTrue(content.contains(
"data-connector=\"standalone\" data-family=\"chain\" data-theme=\"light\" data-type=\"connector\" id=\"myicon-light\""));
assertTrue(
content.contains("data-family=\"file\" data-theme=\"dark\" data-type=\"family\" id=\"file-family-dark\""));
content.contains(
"data-family=\"file\" data-theme=\"dark\" data-type=\"family\" id=\"file-family-dark\""));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ void webSocketDetail() {
assertEquals(1, index.getNodes().size());
final ConfigTypeNode jdbcConnection = index.getNodes().get("amRiYy1jb21wb25lbnQjamRiYyNkYXRhc3RvcmUjamRiYw");
assertNotNull(jdbcConnection);
assertEquals("[{\"description\":\"D1\",\"driver\":\"d1\"},{\"description\":\"D2\",\"driver\":\"d2\"}]",
assertEquals(
"[{\"dependencies\":[\"org.talend.db:zorglub:1.0:jar\"],\"description\":\"D1\",\"driver\":\"d1\"},{\"dependencies\":[\"org.talend.db:zorglub:1.0:jar\",\"a:b:1.0:jar\"],\"description\":\"D2\",\"driver\":\"d2\"}]",

jdbcConnection
.getProperties()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ private File createJdbcPlugin(final File target) {
"Documentation pour configurations description");
put("configuration.connection.configurations[].driver._documentation",
"Documentation pour configurations conducteur");
put("configuration.connection.configurations[].dependencies._documentation",
"Documentation pour configurations dependances");
put("configuration.connection.url._documentation", "Documentation pour hurle...");
put("configuration.driver._documentation", "Documentation pour conducteur...");
put("configuration.query._documentation", "Documentation pour requète...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
package org.talend.sdk.component.server.test.jdbc;

import java.io.Serializable;
import java.util.List;

import org.talend.sdk.component.api.configuration.Option;
import org.talend.sdk.component.api.configuration.ui.widget.ModuleList;
import org.talend.sdk.component.api.configuration.ui.widget.ReadOnly;
import org.talend.sdk.component.api.meta.Documentation;

import lombok.AllArgsConstructor;
Expand All @@ -36,4 +39,10 @@ public class JdbcConfig implements Serializable {
@Option
@Documentation(value = "Documentation for description (jdbcconfig) doc.", tooltip = true)
private String description;

@Option
@Documentation(value = "Documentation for dependencies (jdbcconfig) doc.", tooltip = true)
@ModuleList
@ReadOnly
private List<String> dependencies;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public class JdbcDataStore implements Serializable {

@Option // to test tables
@Documentation(value = "Documentation for Datastore configurations.", tooltip = true)
private List<JdbcConfig> configurations = asList(new JdbcConfig("d1", "D1"), new JdbcConfig("d2", "D2"));
private List<JdbcConfig> configurations =
asList(new JdbcConfig("d1", "D1", List.of("org.talend.db:zorglub:1.0:jar")),
new JdbcConfig("d2", "D2", List.of("org.talend.db:zorglub:1.0:jar", "a:b:1.0:jar")));

@Option
@DateTime(dateFormat = "DD-MM-YYYY", useUTC = false, useSeconds = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ Mark a option as being represented by file or directory widget. Only for studio.
----


= @ReadOnly

Mark a option as being read-only widget. User cannot modify widget.

- API: `@org.talend.sdk.component.api.configuration.ui.widget.ReadOnly`

== Snippets

[source,js]
----
{
"ui::readonly":"true"
}
----


= @Structure

Mark a List<String> or List<Object> field as being represented as the component data selector.
Expand Down
Loading