Set a default color to application when application has no color set from FE (#9919)

This commit is contained in:
Nayan 2021-12-24 15:51:42 +06:00 committed by GitHub
parent 792b1e6bd6
commit cd3a2ac1c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,8 @@
package com.appsmith.server.constants;
public class ApplicationConstants {
public static final String [] APP_CARD_COLORS = {
"#FFDEDE", "#FFEFDB", "#F3F1C7", "#F4FFDE", "#C7F3F0", "#D9E7FF", "#E3DEFF", "#F1DEFF",
"#C7F3E3", "#F5D1D1", "#ECECEC", "#FBF4ED", "#D6D1F2", "#FFEBFB", "#EAEDFB"
};
}

View File

@ -58,4 +58,6 @@ public interface ApplicationServiceCE extends CrudService<Application, String> {
Mono<Long> getGitConnectedApplicationCount(String organizationId);
String getRandomAppCardColor();
}

View File

@ -3,6 +3,7 @@ package com.appsmith.server.services.ce;
import com.appsmith.external.models.Policy;
import com.appsmith.git.helpers.StringOutputStream;
import com.appsmith.server.acl.AclPermission;
import com.appsmith.server.constants.ApplicationConstants;
import com.appsmith.server.constants.Assets;
import com.appsmith.server.constants.FieldName;
import com.appsmith.server.domains.Action;
@ -180,6 +181,9 @@ public class ApplicationServiceCEImpl extends BaseService<ApplicationRepository,
public Mono<Application> createDefault(Application application) {
application.setSlug(TextUtils.makeSlug(application.getName()));
application.setLastEditedAt(Instant.now());
if(!StringUtils.hasLength(application.getColor())) {
application.setColor(getRandomAppCardColor());
}
return super.create(application);
}
@ -555,4 +559,9 @@ public class ApplicationServiceCEImpl extends BaseService<ApplicationRepository,
return repository.getGitConnectedApplicationCount(organizationId);
}
public String getRandomAppCardColor() {
int randomColorIndex = (int) (System.currentTimeMillis() % ApplicationConstants.APP_CARD_COLORS.length);
return ApplicationConstants.APP_CARD_COLORS[randomColorIndex];
}
}

View File

@ -224,6 +224,7 @@ public class ApplicationServiceTest {
assertThat(application.getModifiedBy()).isEqualTo("api_user");
assertThat(application.getUpdatedAt()).isNotNull();
assertThat(application.getEvaluationVersion()).isEqualTo(EVALUATION_VERSION);
assertThat(application.getColor()).isNotEmpty();
assertThat(application.getEditModeThemeId()).isEqualTo(defaultThemeId);
assertThat(application.getPublishedModeThemeId()).isEqualTo(defaultThemeId);
})