Skip to content

Commit 128b62a

Browse files
committed
[IMP] format: add custom format side panel
This commit adds a side panel for all number formats. This merges the old date format/currency format panels into a single "More formats" panel, with tabs for each category of formats (number, date, currency). closes #7241 Task: 3149088 Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
1 parent 47a4448 commit 128b62a

File tree

16 files changed

+771
-942
lines changed

16 files changed

+771
-942
lines changed

packages/o-spreadsheet-engine/src/helpers/format/format.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CellValue } from "../../types/cells";
44
import { Currency } from "../../types/currency";
55
import { EvaluationError } from "../../types/errors";
66
import { Format, FormattedValue, LocaleFormat } from "../../types/format";
7-
import { Locale } from "../../types/locale";
7+
import { DEFAULT_LOCALE, Locale } from "../../types/locale";
88
import { FunctionResultObject, Maybe } from "../../types/misc";
99
import { DateTime, INITIAL_1900_DAY, isDateTime, numberToJsDate, parseDateTime } from "../dates";
1010
import {
@@ -25,7 +25,7 @@ import {
2525
convertInternalFormatToFormat,
2626
parseFormat,
2727
} from "./format_parser";
28-
import { FormatToken } from "./format_tokenizer";
28+
import { FormatToken, tokenizeFormat } from "./format_tokenizer";
2929

3030
/**
3131
* Number of digits for the default number format. This number of digit make a number fit well in a cell
@@ -948,3 +948,16 @@ export function formatHasRepeatedChar(value: CellValue, format: Format | undefin
948948

949949
return false;
950950
}
951+
952+
export function isFormatValid(format: Format): boolean {
953+
try {
954+
formatValue(0, { format, locale: DEFAULT_LOCALE });
955+
return true;
956+
} catch {
957+
return false;
958+
}
959+
}
960+
961+
export function getNumberOfFormatParts(format: Format): number {
962+
return tokenizeFormat(format).length;
963+
}

src/actions/format_actions.ts

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const EXAMPLE_DATE = parseLiteral("2023/09/26 10:43:00 PM", DEFAULT_LOCAL
109109
export const formatCustomCurrency: ActionSpec = {
110110
name: _t("Custom currency"),
111111
isVisible: (env) => env.loadCurrencies !== undefined && !env.isSmall,
112-
execute: (env) => env.openSidePanel("CustomCurrency", {}),
112+
execute: (env) => env.openSidePanel("MoreFormats", { category: "currency" }),
113113
};
114114

115115
export const formatNumberDate = createFormatActionSpec({
@@ -139,21 +139,16 @@ export const formatNumberDuration = createFormatActionSpec({
139139
format: "hhhh:mm:ss",
140140
});
141141

142-
export const formatNumberQuarter = createFormatActionSpec({
143-
name: _t("Quarter"),
144-
descriptionValue: EXAMPLE_DATE,
145-
format: "qq yyyy",
146-
});
147-
148-
export const formatNumberFullQuarter = createFormatActionSpec({
149-
name: _t("Full quarter"),
150-
descriptionValue: EXAMPLE_DATE,
151-
format: "qqqq yyyy",
152-
});
142+
export const customDateFormat: ActionSpec = {
143+
name: _t("Custom date and time"),
144+
isVisible: (env) => !env.isSmall,
145+
execute: (env) => env.openSidePanel("MoreFormats", { category: "date" }),
146+
};
153147

154-
export const moreFormats: ActionSpec = {
155-
name: _t("More date formats"),
156-
execute: (env) => env.openSidePanel("MoreFormats", {}),
148+
export const customNumberFormat: ActionSpec = {
149+
name: _t("Custom number format"),
150+
isVisible: (env) => !env.isSmall,
151+
execute: (env) => env.openSidePanel("MoreFormats", { category: "number" }),
157152
};
158153

159154
export const formatNumberFullDateTime = createFormatActionSpec({
@@ -162,54 +157,6 @@ export const formatNumberFullDateTime = createFormatActionSpec({
162157
descriptionValue: EXAMPLE_DATE,
163158
});
164159

165-
export const formatNumberISODate = createFormatActionSpec({
166-
name: _t("ISO Date"),
167-
format: "yyyy-mm-dd",
168-
descriptionValue: EXAMPLE_DATE,
169-
});
170-
171-
export const formatNumberISODateTime = createFormatActionSpec({
172-
name: _t("ISO Date time"),
173-
format: "yyyy-mm-dd hh:mm:ss",
174-
descriptionValue: EXAMPLE_DATE,
175-
});
176-
177-
export const formatNumberFullWeekDayAndMonth = createFormatActionSpec({
178-
name: _t("Full week day and month"),
179-
format: "dddd d mmmm yyyy",
180-
descriptionValue: EXAMPLE_DATE,
181-
});
182-
183-
export const formatNumberDayAndFullMonth = createFormatActionSpec({
184-
name: _t("Day and full month"),
185-
format: "d mmmm yyyy",
186-
descriptionValue: EXAMPLE_DATE,
187-
});
188-
189-
export const formatNumberShortWeekDay = createFormatActionSpec({
190-
name: _t("Short week day"),
191-
format: "ddd d mmm yyyy",
192-
descriptionValue: EXAMPLE_DATE,
193-
});
194-
195-
export const formatNumberDayAndShortMonth = createFormatActionSpec({
196-
name: _t("Day and short month"),
197-
format: "d mmm yyyy",
198-
descriptionValue: EXAMPLE_DATE,
199-
});
200-
201-
export const formatNumberFullMonth = createFormatActionSpec({
202-
name: _t("Full month"),
203-
format: "mmmm yyyy",
204-
descriptionValue: EXAMPLE_DATE,
205-
});
206-
207-
export const formatNumberShortMonth = createFormatActionSpec({
208-
name: _t("Short month"),
209-
format: "mmm yyyy",
210-
descriptionValue: EXAMPLE_DATE,
211-
});
212-
213160
export const increaseDecimalPlaces: ActionSpec = {
214161
name: _t("Increase decimal places"),
215162
icon: "o-spreadsheet-Icon.INCREASE_DECIMAL",

src/components/side_panel/custom_currency/custom_currency.css

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/components/side_panel/custom_currency/custom_currency.ts

Lines changed: 0 additions & 201 deletions
This file was deleted.

0 commit comments

Comments
 (0)