From e3a80b80ca04d07b535ccd81eac6d33bb7964e93 Mon Sep 17 00:00:00 2001 From: sujoykd Date: Thu, 11 Jan 2024 15:03:52 +0200 Subject: [PATCH] check and add header components in column when entering from refresh event --- .gitignore | 4 ++ enhanced-grid-flow-demo/frontend/index.html | 23 +++++++++++ .../enhancedgrid/SimpleSingleSelectView.java | 2 + enhanced-grid-flow-demo/tsconfig.json | 39 +++++++++++++++++++ enhanced-grid-flow-demo/types.d.ts | 10 +++++ enhanced-grid-flow-demo/vite.config.ts | 9 +++++ .../enhancedgrid/EnhancedColumn.java | 19 +++++++-- 7 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 enhanced-grid-flow-demo/frontend/index.html create mode 100644 enhanced-grid-flow-demo/tsconfig.json create mode 100644 enhanced-grid-flow-demo/types.d.ts create mode 100644 enhanced-grid-flow-demo/vite.config.ts diff --git a/.gitignore b/.gitignore index e797fb9..33b52ca 100644 --- a/.gitignore +++ b/.gitignore @@ -35,9 +35,13 @@ package-lock.json package.json webpack.config.js webpack.generated.js +vite.generated.ts enhanced-grid-flow/src/main/resources/rebel.xml .classpath .project .settings .vscode/settings.json + +enhanced-grid-flow-demo/frontend/generated +enhanced-grid-flow-demo/src/main/dev-bundle \ No newline at end of file diff --git a/enhanced-grid-flow-demo/frontend/index.html b/enhanced-grid-flow-demo/frontend/index.html new file mode 100644 index 0000000..a5cdd40 --- /dev/null +++ b/enhanced-grid-flow-demo/frontend/index.html @@ -0,0 +1,23 @@ + + + + + + + + + + + + +
+ + diff --git a/enhanced-grid-flow-demo/src/main/java/com/vaadin/componentfactory/enhancedgrid/SimpleSingleSelectView.java b/enhanced-grid-flow-demo/src/main/java/com/vaadin/componentfactory/enhancedgrid/SimpleSingleSelectView.java index d2f2e2a..9e4d984 100644 --- a/enhanced-grid-flow-demo/src/main/java/com/vaadin/componentfactory/enhancedgrid/SimpleSingleSelectView.java +++ b/enhanced-grid-flow-demo/src/main/java/com/vaadin/componentfactory/enhancedgrid/SimpleSingleSelectView.java @@ -19,6 +19,7 @@ import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.data.binder.Binder; import com.vaadin.flow.data.renderer.NumberRenderer; +import com.vaadin.flow.router.PreserveOnRefresh; import com.vaadin.flow.router.Route; import com.vaadin.flow.router.RouteAlias; @@ -27,6 +28,7 @@ */ @Route(value = "", layout = MainLayout.class) @RouteAlias(value = "single-grid", layout = MainLayout.class) +@PreserveOnRefresh public class SimpleSingleSelectView extends Div { public SimpleSingleSelectView() { diff --git a/enhanced-grid-flow-demo/tsconfig.json b/enhanced-grid-flow-demo/tsconfig.json new file mode 100644 index 0000000..37f32e7 --- /dev/null +++ b/enhanced-grid-flow-demo/tsconfig.json @@ -0,0 +1,39 @@ +// This TypeScript configuration file is generated by vaadin-maven-plugin. +// This is needed for TypeScript compiler to compile your TypeScript code in the project. +// It is recommended to commit this file to the VCS. +// You might want to change the configurations to fit your preferences +// For more information about the configurations, please refer to http://www.typescriptlang.org/docs/handbook/tsconfig-json.html +{ + "flow_version": "23.3.4", + "compilerOptions": { + "sourceMap": true, + "jsx": "react-jsx", + "inlineSources": true, + "module": "esNext", + "target": "es2020", + "moduleResolution": "node", + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "noImplicitAny": true, + "noImplicitThis": true, + "noUnusedLocals": false, + "noUnusedParameters": false, + "experimentalDecorators": true, + "useDefineForClassFields": false, + "baseUrl": "frontend", + "paths": { + "@vaadin/flow-frontend": ["generated/jar-resources"], + "@vaadin/flow-frontend/*": ["generated/jar-resources/*"], + "Frontend/*": ["*"] + } + }, + "include": [ + "frontend/**/*", + "types.d.ts" + ], + "exclude": [ + "frontend/generated/jar-resources/**" + ] +} diff --git a/enhanced-grid-flow-demo/types.d.ts b/enhanced-grid-flow-demo/types.d.ts new file mode 100644 index 0000000..250302b --- /dev/null +++ b/enhanced-grid-flow-demo/types.d.ts @@ -0,0 +1,10 @@ +// This TypeScript modules definition file is generated by vaadin-maven-plugin. +// You can not directly import your different static files into TypeScript, +// This is needed for TypeScript compiler to declare and export as a TypeScript module. +// It is recommended to commit this file to the VCS. +// You might want to change the configurations to fit your preferences +declare module '*.css' { + import { CSSResultGroup } from 'lit'; + const content: CSSResultGroup; + export default content; +} diff --git a/enhanced-grid-flow-demo/vite.config.ts b/enhanced-grid-flow-demo/vite.config.ts new file mode 100644 index 0000000..4d6a022 --- /dev/null +++ b/enhanced-grid-flow-demo/vite.config.ts @@ -0,0 +1,9 @@ +import { UserConfigFn } from 'vite'; +import { overrideVaadinConfig } from './vite.generated'; + +const customConfig: UserConfigFn = (env) => ({ + // Here you can add custom Vite parameters + // https://vitejs.dev/config/ +}); + +export default overrideVaadinConfig(customConfig); diff --git a/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedgrid/EnhancedColumn.java b/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedgrid/EnhancedColumn.java index 73ae4c8..e6c6560 100644 --- a/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedgrid/EnhancedColumn.java +++ b/enhanced-grid-flow/src/main/java/com/vaadin/componentfactory/enhancedgrid/EnhancedColumn.java @@ -21,8 +21,7 @@ */ import java.util.Comparator; - -import org.apache.commons.lang3.StringUtils; +import java.util.Optional; import com.vaadin.flow.component.Component; import com.vaadin.flow.component.HasValueAndElement; @@ -38,7 +37,8 @@ import com.vaadin.flow.component.icon.Icon; import com.vaadin.flow.data.renderer.Renderer; import com.vaadin.flow.function.ValueProvider; -import com.vaadin.flow.internal.HtmlUtils; +import com.vaadin.flow.router.BeforeEnterEvent; +import com.vaadin.flow.router.BeforeEnterObserver; /** * @@ -48,7 +48,7 @@ */ @Uses(Icon.class) @JsModule(value = "./src/enhanced-grid-sorter.js") -public class EnhancedColumn extends Grid.Column { +public class EnhancedColumn extends Grid.Column implements BeforeEnterObserver { private HasValueAndElement filter; @@ -285,4 +285,15 @@ protected void setFilterIcon(Icon icon) { public EnhancedColumn setKey(String key) { return (EnhancedColumn) super.setKey(key); } + + @Override + public void beforeEnter(BeforeEnterEvent beforeEnterEvent) { + if (beforeEnterEvent.isRefreshEvent()) { + Optional.ofNullable(this.getHeaderComponent()) + .ifPresent(headerComponent -> { + this.setHeader(headerComponent); + this.updateFilterButtonStyle(); + }); + } + } }