Skip to content

Commit 69fb4aa

Browse files
committed
fix theme footer styles, and infinite rerendering issue
1 parent 046cee3 commit 69fb4aa

4 files changed

Lines changed: 52 additions & 50 deletions

File tree

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3454,7 +3454,7 @@ export const en = {
34543454
"exportTheme": "Export Theme",
34553455
"importTheme": "Import Theme",
34563456
"importSuccessMsg": "Theme Imported Successfully",
3457-
"importError": "Failed to Import Theme: {{message}}",
3457+
"importError": "Failed to Import Theme: {message}",
34583458
"importParseError": "Invalid Theme File: Could Not Parse JSON",
34593459
"importFormatError": "Invalid Theme File: Missing Required Theme Data",
34603460
"importFileError": "Failed to Read Theme File",

client/packages/lowcoder/src/pages/setting/theme/detail/index.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { Card, Divider, Flex, List, Tooltip } from 'antd';
4545
import { ThemeCompPanel } from "pages/setting/theme/ThemeCompPanel";
4646
import { JSONObject } from "@lowcoder-ee/util/jsonTypes";
4747
import { exportThemeAsJSONFile } from "../themeImportExport";
48+
import _ from "lodash";
4849

4950
const ThemeSettingsView = styled.div`
5051
font-size: 14px;
@@ -130,7 +131,7 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
130131
}
131132

132133
componentDidUpdate(prevProps: ThemeDetailPageProps, prevState: ThemeDetailPageState) {
133-
if (prevProps.themeList?.length !== this.props.themeList?.length) {
134+
if (prevProps.themeList !== this.props.themeList && prevProps.themeList?.length !== this.props.themeList?.length) {
134135
this.findCurrentTheme();
135136
}
136137
}
@@ -170,10 +171,17 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
170171
configChange(params: configChangeParams) {
171172
if (!this.state.theme) return;
172173

174+
const { themeSettingKey, ...rest } = params;
175+
const value = _.find(_.values(rest), (v) => v !== undefined);
176+
177+
if (_.isEqual(this.state.theme[themeSettingKey as keyof typeof this.state.theme], value)) {
178+
return;
179+
}
180+
173181
this.setState({
174182
theme: {
175183
...this.state.theme,
176-
[params.themeSettingKey]: params.color || params.radius || params.chart || params.margin || params.padding || params.borderWidth || params.borderStyle || params.fontFamily || params.showComponentLoadingIndicators || params.showDataLoadingIndicators || params.dataLoadingIndicator || params.gridColumns || params.gridRowHeight || params.gridRowCount || params.gridPaddingX || params.gridPaddingY || params.gridBgImage || params.gridBgImageRepeat || params.gridBgImageSize || params.gridBgImagePosition || params.gridBgImageOrigin,
184+
[themeSettingKey]: value,
177185
},
178186
});
179187
}
@@ -904,17 +912,20 @@ class ThemeDetailPage extends React.Component<ThemeDetailPageProps, ThemeDetailP
904912
>
905913
{trans("reset")}
906914
</ResetButton>
907-
<ResetButton onClick={this.handleExport} disabled={!this.state.name || !this.state.theme}>
908-
{trans("theme.exportTheme")}
909-
</ResetButton>
910915
<SaveButton
911916
type="primary"
912917
disabled={this.isThemeNotChange() || !this.state.name}
913918
onClick={() => this.handleSave()}
914-
style={{ marginLeft: "auto" }}
915919
>
916920
{trans("theme.saveBtn")}
917921
</SaveButton>
922+
<ResetButton
923+
onClick={this.handleExport}
924+
disabled={!this.state.name || !this.state.theme}
925+
style={{ marginLeft: "auto" }}
926+
>
927+
{trans("theme.exportTheme")}
928+
</ResetButton>
918929
</Footer>
919930
</DetailContainer>
920931
</>

client/packages/lowcoder/src/pages/setting/theme/styledComponents.tsx

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export const Footer = styled.div`
124124
padding: 24px;
125125
position: fixed;
126126
bottom: 0;
127-
width: calc(100vw - 492px);
127+
width: calc(100% - 520px);
128128
background-color: #fff;
129129
z-index: 1000;
130130
margin-right: 10px;
@@ -659,44 +659,43 @@ export const CustomModalStyled = styled(CustomModal)`
659659
}
660660
`;
661661

662-
export const Margin = styled.div<{ $margin: string }>`
663-
> div {
664-
margin: 3px;
665-
overflow: hidden;
666-
> svg {
667-
fill: currentColor;
668-
}
669-
}
670-
}
671-
`;
672-
export const Padding = styled.div<{ $padding: string }>`
673-
> div {
674-
margin: 3px;
675-
overflow: hidden;
676-
> svg {
677-
fill: currentColor;
678-
}
679-
}
680-
}`
662+
export const Margin = styled.div<{ $margin: string }>`
663+
> div {
664+
margin: 3px;
665+
overflow: hidden;
666+
> svg {
667+
fill: currentColor;
668+
}
669+
}
670+
`;
671+
672+
export const Padding = styled.div<{ $padding: string }>`
673+
> div {
674+
margin: 3px;
675+
overflow: hidden;
676+
> svg {
677+
fill: currentColor;
678+
}
679+
}
680+
`;
681+
681682
// Added By Aqib Mirza
682-
export const GridColumns = styled.div<{ $gridColumns: string }>`
683+
export const GridColumns = styled.div<{ $gridColumns: string }>`
683684
> div {
684685
margin: 3px;
685686
overflow: hidden;
686-
> svg {
687-
fill: currentColor;
688-
}
687+
> svg {
688+
fill: currentColor;
689689
}
690690
}
691691
`;
692692

693-
export const BorderStyle = styled.div<{ $borderStyle: string }>`
693+
export const BorderStyle = styled.div<{ $borderStyle: string }>`
694694
> div {
695695
margin: 3px;
696696
overflow: hidden;
697-
> svg {
698-
fill: currentColor;
699-
}
697+
> svg {
698+
fill: currentColor;
700699
}
701700
}
702701
`;
@@ -705,9 +704,8 @@ export const BorderWidth = styled.div<{ $borderWidth: string }>`
705704
> div {
706705
margin: 3px;
707706
overflow: hidden;
708-
> svg {
709-
fill: currentColor;
710-
}
707+
> svg {
708+
fill: currentColor;
711709
}
712710
}
713711
`;

client/packages/lowcoder/src/pages/setting/theme/themeImportExport.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ThemeDetail, ThemeType } from "api/commonSettingApi";
22
import { genQueryId } from "comps/utils/idGenerator";
33
import { trans } from "i18n";
4+
import { saveDataAsFile } from "util/fileUtils";
45

56
export const THEME_EXPORT_VERSION = 1;
67
export const THEME_EXPORT_TYPE = "lowcoder-theme";
@@ -95,19 +96,11 @@ export function exportThemeAsJSONFile(theme: ThemeType) {
9596
type: THEME_EXPORT_TYPE,
9697
theme,
9798
};
98-
99-
const link = document.createElement("a");
100-
const blob = new Blob([JSON.stringify(exportObj, null, 2)], {
101-
type: "application/json",
99+
void saveDataAsFile({
100+
data: exportObj,
101+
filename: `${theme.name}.json`,
102+
fileType: "json",
102103
});
103-
const url = URL.createObjectURL(blob);
104-
link.href = url;
105-
const safeName = theme.name.replace(/[^\w\s-]/g, "").trim() || "theme";
106-
link.download = `${safeName}.json`;
107-
document.body.appendChild(link);
108-
link.click();
109-
link.remove();
110-
URL.revokeObjectURL(url);
111104
}
112105

113106
export function readThemeFile(file: File): Promise<ThemeType> {

0 commit comments

Comments
 (0)