From 4a768c9d6b4fcc4b321d1a85ca55d232123e7136 Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Fri, 24 Nov 2023 20:17:45 +0100 Subject: [PATCH] feat(frontend): add stat card (#2687) * feat(frontend): add stat card * feat(frontend): fix layout --- .../components/display/AppStatCard.svelte | 92 +++++++++++++++++++ .../apps/editor/component/Component.svelte | 8 ++ .../apps/editor/component/components.ts | 36 +++++++- .../components/apps/editor/component/sets.ts | 3 +- .../componentsPanel/quickStyleProperties.ts | 3 +- 5 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 frontend/src/lib/components/apps/components/display/AppStatCard.svelte diff --git a/frontend/src/lib/components/apps/components/display/AppStatCard.svelte b/frontend/src/lib/components/apps/components/display/AppStatCard.svelte new file mode 100644 index 0000000000..37f35b39f9 --- /dev/null +++ b/frontend/src/lib/components/apps/components/display/AppStatCard.svelte @@ -0,0 +1,92 @@ + + +{#each Object.keys(components['statcomponent'].initialData.configuration) as key (key)} + +{/each} + +{#each Object.keys(css ?? {}) as key (key)} + +{/each} + +{#if render} +
+ {#if resolvedConfig.icon && iconComponent} +
+ +
+ {/if} +
+
{resolvedConfig.title}
+
+
+ {resolvedConfig?.value} +
+ + {#if resolvedConfig?.progress !== undefined && resolvedConfig?.progress !== null && resolvedConfig?.progress !== 0} +
0 + ? 'bg-green-100 text-green-800' + : 'bg-red-100 text-red-800' + )} + > + 0 ? 'transform rotate-180' : 'transform rotate-0'} + /> + {resolvedConfig?.progress}% +
+ {/if} +
+
+
+{/if} diff --git a/frontend/src/lib/components/apps/editor/component/Component.svelte b/frontend/src/lib/components/apps/editor/component/Component.svelte index 3457e1e049..db5f1904df 100644 --- a/frontend/src/lib/components/apps/editor/component/Component.svelte +++ b/frontend/src/lib/components/apps/editor/component/Component.svelte @@ -63,6 +63,7 @@ import AppCarouselList from '../../components/display/AppCarouselList.svelte' import AppAggridTableEe from '../../components/display/table/AppAggridTableEe.svelte' import AppCustomComponent from '../../components/display/AppCustomComponent.svelte' + import AppStatCard from '../../components/display/AppStatCard.svelte' export let component: AppComponent export let selected: boolean @@ -677,6 +678,13 @@ {render} bind:initializing /> + {:else if component.type === 'statcomponent'} + {/if} diff --git a/frontend/src/lib/components/apps/editor/component/components.ts b/frontend/src/lib/components/apps/editor/component/components.ts index 916de88082..4416ff8c6d 100644 --- a/frontend/src/lib/components/apps/editor/component/components.ts +++ b/frontend/src/lib/components/apps/editor/component/components.ts @@ -40,7 +40,8 @@ import { PanelLeft, PanelTopInactive, ListIcon, - Heading1 + Heading1, + FileBarChart } from 'lucide-svelte' import type { Aligned, @@ -162,6 +163,7 @@ export type SelectTabComponent = BaseComponent<'selecttabcomponent'> export type SelectStepComponent = BaseComponent<'selectstepcomponent'> export type CarouselListComponent = BaseComponent<'carousellistcomponent'> +export type StatisticCardComponent = BaseComponent<'statcomponent'> export type TypedComponent = | DisplayComponent @@ -223,6 +225,7 @@ export type TypedComponent = | CarouselListComponent | PlotlyComponentV2 | ChartJsComponentV2 + | StatisticCardComponent export type AppComponent = BaseAppComponent & TypedComponent @@ -2712,6 +2715,37 @@ This is a paragraph. } ] as AppInputSpec<'boolean', boolean>[] } + }, + statcomponent: { + name: 'Statistic card', + icon: FileBarChart, + documentationLink: `${documentationBaseUrl}/statistic_card`, + dims: '2:4-3:4' as AppComponentDimensions, + customCss: {}, + initialData: { + configuration: { + title: { + type: 'static', + value: 'Title', + fieldType: 'text' + }, + value: { + type: 'static', + value: 'Value', + fieldType: 'text' + }, + progress: { + type: 'static', + value: 0, + fieldType: 'number' + }, + icon: { + type: 'static', + value: undefined, + fieldType: 'icon-select' + } + } + } } } as const diff --git a/frontend/src/lib/components/apps/editor/component/sets.ts b/frontend/src/lib/components/apps/editor/component/sets.ts index a0a0ff7770..6af2bd520c 100644 --- a/frontend/src/lib/components/apps/editor/component/sets.ts +++ b/frontend/src/lib/components/apps/editor/component/sets.ts @@ -64,7 +64,8 @@ const display: ComponentSet = { 'displaycomponent', 'jobidlogcomponent', 'jobidflowstatuscomponent', - 'customcomponent' + 'customcomponent', + 'statcomponent' ] } as const diff --git a/frontend/src/lib/components/apps/editor/componentsPanel/quickStyleProperties.ts b/frontend/src/lib/components/apps/editor/componentsPanel/quickStyleProperties.ts index 94df15ed4d..9c4649e091 100644 --- a/frontend/src/lib/components/apps/editor/componentsPanel/quickStyleProperties.ts +++ b/frontend/src/lib/components/apps/editor/componentsPanel/quickStyleProperties.ts @@ -744,5 +744,6 @@ export const quickStyleProperties: Record< allTabs: [typographyGrouping, sizeGrouping], selectedTab: [typographyGrouping, sizeGrouping] }, - selectstepcomponent: {} + selectstepcomponent: {}, + statcomponent: {} }