Skip to content

Commit 0c8c778

Browse files
authored
Disable spreadsheet csv and filter exports when no data available (#3290)
Signed-off-by: David BRAQUART <[email protected]>
1 parent 2fe6d0d commit 0c8c778

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

src/components/spreadsheet-view/spreadsheet/spreadsheet-toolbar/row-counter/use-filtered-row-counter.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export type UseFilteredRowCounterInfoReturn = {
2626
rowCountLabel: string | undefined;
2727
tooltipContent: ReactElement | undefined;
2828
registerRowCounterEvents: (params: RowDataUpdatedEvent) => void;
29+
displayedRows: number | null;
2930
};
3031

3132
export function useFilteredRowCounterInfo({
@@ -101,8 +102,8 @@ export function useFilteredRowCounterInfo({
101102
if (displayedRows === 0 && isAnyFilterPresent) {
102103
return intl.formatMessage({ id: 'NoMatch' });
103104
} else {
104-
const plural = `${intl.formatMessage({ id: 'Rows' })}${totalRows === 1 ? '' : 's'}`;
105-
return displayedRows !== totalRows ? `${displayedRows} / ${totalRows} ${plural}` : `${totalRows} ${plural}`;
105+
const plural = intl.formatMessage({ id: 'Rows' }, { count: totalRows });
106+
return displayedRows === totalRows ? `${totalRows} ${plural}` : `${displayedRows} / ${totalRows} ${plural}`;
106107
}
107108
}, [displayedRows, totalRows, intl, isAnyFilterPresent]);
108109

@@ -119,16 +120,15 @@ export function useFilteredRowCounterInfo({
119120
const lines: string[] = [`${intl.formatMessage({ id: 'ClickToReset' })}`];
120121
if (Object.keys(gsFilterByType)?.length > 0) {
121122
lines.push(`${intl.formatMessage({ id: 'ExternalFilters' })} : `);
122-
123-
Object.entries(gsFilterByType).forEach(([filterType, labels]) => {
123+
for (const [filterType, labels] of Object.entries(gsFilterByType)) {
124124
const formattedLabels = labels.map((label) => intl.formatMessage({ id: label })).join(', ');
125125
lines.push(`- ${intl.formatMessage({ id: filterType })} : "${formattedLabels}"`);
126-
});
126+
}
127127
}
128128

129129
if (spreadsheetColumnsFiltersState?.length > 0) {
130130
lines.push(`${intl.formatMessage({ id: 'ColumnsFilters' })} : `);
131-
spreadsheetColumnsFiltersState.forEach((filterModel) => {
131+
for (const filterModel of spreadsheetColumnsFiltersState) {
132132
const headerName =
133133
gridRef.current?.api.getColumn(filterModel.column)?.getColDef()?.headerName ?? filterModel.column;
134134
lines.push(
@@ -137,7 +137,7 @@ export function useFilteredRowCounterInfo({
137137
', '
138138
)
139139
);
140-
});
140+
}
141141
}
142142
return <span style={{ whiteSpace: 'pre-line' }}>{lines.join('\n')}</span>;
143143
}, [globalFilterSpreadsheetState, gridRef, intl, isAnyFilterPresent, isLoading, spreadsheetColumnsFiltersState]);
@@ -158,5 +158,6 @@ export function useFilteredRowCounterInfo({
158158
rowCountLabel,
159159
tooltipContent,
160160
registerRowCounterEvents,
161+
displayedRows,
161162
};
162163
}

src/components/spreadsheet-view/spreadsheet/spreadsheet-toolbar/save/save-spreadsheet-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface SaveSpreadsheetButtonProps {
3939
columns: ColDef[];
4040
disabled: boolean;
4141
tableDefinition: SpreadsheetTabDefinition;
42-
dataSize?: number;
42+
dataSize: number;
4343
nodeAliases: NodeAlias[] | undefined;
4444
}
4545

src/components/spreadsheet-view/spreadsheet/spreadsheet-toolbar/spreadsheet-toolbar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const SpreadsheetToolbar = ({
7676
columns={columns}
7777
disabled={disabled}
7878
nodeAliases={nodeAliases}
79+
dataSize={rowCounterInfos.displayedRows ?? 0}
7980
/>
8081
</Grid>
8182
</Grid>

src/translations/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@
15721572
"DiagramLayoutStoreSuccess": "Diagrams successfully stored",
15731573
"MaxNumberOfNadDiagramsReached": "You need to close at least one network area diagram to open a new one",
15741574
"NoMatch": "No match",
1575-
"Rows": "row",
1575+
"Rows": "{count, plural,=1 {row} other {rows}}",
15761576
"ExternalFilters": "External filters",
15771577
"ColumnsFilters": "Columns filters",
15781578
"genericFilter": "Generic",

src/translations/fr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@
15681568
"DiagramLayoutStoreSuccess": "Images mémorisées avec succès",
15691569
"MaxNumberOfNadDiagramsReached": "Vous devez fermer au moins une image nodale existante pour en ouvrir une nouvelle",
15701570
"NoMatch": "Pas de correspondance",
1571-
"Rows": "ligne",
1571+
"Rows": "{count, plural,=1 {ligne} other {lignes}}",
15721572
"ExternalFilters": "Filtres externes",
15731573
"ColumnsFilters": "Filtres de colonnes",
15741574
"genericFilter": "Générique",

0 commit comments

Comments
 (0)