Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle committed Apr 10, 2024
2 parents 5e8c961 + 3a5c363 commit 19536f3
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 66 deletions.
2 changes: 1 addition & 1 deletion docs/data/data-grid/localization/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
"languageTag": "sv-SE",
"importName": "svSE",
"localeName": "Swedish",
"missingKeysCount": 3,
"missingKeysCount": 0,
"totalKeysCount": 117,
"githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-data-grid/src/locales/svSE.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion docs/data/date-pickers/localization/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
"languageTag": "sv-SE",
"importName": "svSE",
"localeName": "Swedish",
"missingKeysCount": 22,
"missingKeysCount": 0,
"totalKeysCount": 50,
"githubLink": "https://github.com/mui/mui-x/blob/master/packages/x-date-pickers/src/locales/svSE.ts"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ export const useGridCellSelection = (
cellData = serializeCellValue(cellParams, {
delimiterCharacter: clipboardCopyCellDelimiter,
ignoreValueFormatter,
shouldAppendQuotes: true,
shouldAppendQuotes: false,
});
} else {
cellData = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ function defaultPasteResolver({
const isSingleValuePasted = pastedData.length === 1 && pastedData[0].length === 1;

const cellSelectionModel = apiRef.current.getCellSelectionModel();
if (cellSelectionModel && apiRef.current.getSelectedCellsAsArray().length > 1) {
const selectedCellsArray = apiRef.current.getSelectedCellsAsArray();
if (cellSelectionModel && selectedCellsArray.length > 1) {
Object.keys(cellSelectionModel).forEach((rowId, rowIndex) => {
const rowDataArr = pastedData[isSingleValuePasted ? 0 : rowIndex];
const hasRowData = isSingleValuePasted ? true : rowDataArr !== undefined;
Expand Down Expand Up @@ -275,7 +276,11 @@ function defaultPasteResolver({
return;
}

const selectedCell = gridFocusCellSelector(apiRef);
let selectedCell = gridFocusCellSelector(apiRef);
if (!selectedCell && selectedCellsArray.length === 1) {
selectedCell = selectedCellsArray[0];
}

if (!selectedCell) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,30 @@ describe('<DataGridPremium /> - Clipboard', () => {
fireEvent.keyDown(cell, { key: 'c', keyCode: 67, ctrlKey: true });
expect(writeText.lastCall.firstArg).to.equal(['Adidas', 'Nike', 'Puma'].join('\r\n'));
});

it('should not escape double quotes when copying multiple cells to clipboard', () => {
render(
<DataGridPremium
columns={[{ field: 'value' }]}
rows={[
{ id: 0, value: '1 " 1' },
{ id: 1, value: '2' },
]}
cellSelection
disableRowSelectionOnClick
/>,
);

const cell = getCell(0, 0);
cell.focus();
userEvent.mousePress(cell);

fireEvent.keyDown(cell, { key: 'Ctrl' });
fireEvent.click(getCell(1, 0), { ctrlKey: true });

fireEvent.keyDown(cell, { key: 'c', keyCode: 67, ctrlKey: true });
expect(writeText.lastCall.firstArg).to.equal(['1 " 1', '2'].join('\r\n'));
});
});

describe('paste', () => {
Expand Down
53 changes: 40 additions & 13 deletions packages/x-data-grid-pro/src/tests/clipboard.DataGridPro.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,17 @@ describe('<DataGridPro /> - Clipboard', () => {
apiRef={apiRef}
columns={columns}
rows={[
{
id: 0,
brand: 'Nike',
},
{
id: 1,
brand: 'Adidas',
},
{
id: 2,
brand: 'Puma',
},
{ id: 0, brand: 'Nike' },
{ id: 1, brand: 'Adidas' },
{ id: 2, brand: 'Puma' },
]}
{...props}
/>
</div>
);
}

describe('copySelectedRowsToClipboard', () => {
describe('copy to clipboard', () => {
let writeText: SinonStub;
const originalClipboard = navigator.clipboard;

Expand All @@ -74,5 +65,41 @@ describe('<DataGridPro /> - Clipboard', () => {
expect(writeText.firstCall.args[0]).to.equal(['0\tNike', '1\tAdidas'].join('\r\n'));
});
});

it('should not escape double quotes when copying a single cell to clipboard', () => {
render(
<Test
columns={[{ field: 'value' }]}
rows={[{ id: 0, value: '1 " 1' }]}
disableRowSelectionOnClick
/>,
);

const cell = getCell(0, 0);
cell.focus();
userEvent.mousePress(cell);

fireEvent.keyDown(cell, { key: 'c', keyCode: 67, ctrlKey: true });
expect(writeText.lastCall.firstArg).to.equal('1 " 1');
});

it('should not escape double quotes when copying rows to clipboard', () => {
render(
<Test
columns={[{ field: 'value' }]}
rows={[
{ id: 0, value: '1 " 1' },
{ id: 1, value: '2' },
]}
disableRowSelectionOnClick
/>,
);

act(() => apiRef.current.selectRows([0, 1]));
const cell = getCell(0, 0);
userEvent.mousePress(cell);
fireEvent.keyDown(cell, { key: 'c', keyCode: 67, ctrlKey: true });
expect(writeText.firstCall.args[0]).to.equal(['1 " 1', '2'].join('\r\n'));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { buildWarning } from '../../../../utils/warning';

function sanitizeCellValue(value: any, delimiterCharacter: string, shouldAppendQuotes: boolean) {
if (typeof value === 'string') {
// Make sure value containing delimiter or line break won't be split into multiple rows
if ([delimiterCharacter, '\n', '\r', '"'].some((delimiter) => value.includes(delimiter))) {
if (shouldAppendQuotes) {
return `"${value.replace(/"/g, '""')}"`;
if (shouldAppendQuotes) {
const escapedValue = value.replace(/"/g, '""');
// Make sure value containing delimiter or line break won't be split into multiple rows
if ([delimiterCharacter, '\n', '\r', '"'].some((delimiter) => value.includes(delimiter))) {
return `"${escapedValue}"`;
}
return `${value.replace(/"/g, '""')}`;
return escapedValue;
}

return value;
Expand Down
6 changes: 3 additions & 3 deletions packages/x-data-grid/src/locales/svSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ const svSEGrid: Partial<GridLocaleText> = {
toolbarExportExcel: 'Ladda ner som Excel',

// Columns management text
// columnsManagementSearchTitle: 'Search',
// columnsManagementNoColumns: 'No columns',
// columnsManagementShowHideAllText: 'Show/Hide All',
columnsManagementSearchTitle: 'Sök',
columnsManagementNoColumns: 'Inga kolumner',
columnsManagementShowHideAllText: 'Visa/Dölj alla',

// Filter panel text
filterPanelAddFilter: 'Lägg till filter',
Expand Down
44 changes: 22 additions & 22 deletions packages/x-date-pickers/src/locales/svSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const svSEPickers: Partial<PickersLocaleText<any>> = {
// DateRange labels
start: 'Start',
end: 'Slut',
// startDate: 'Start date',
// startTime: 'Start time',
// endDate: 'End date',
// endTime: 'End time',
startDate: 'Startdatum',
startTime: 'Starttid',
endDate: 'Slutdatum',
endTime: 'Sluttid',

// Action bar
cancelButtonLabel: 'Avbryt',
Expand Down Expand Up @@ -67,34 +67,34 @@ const svSEPickers: Partial<PickersLocaleText<any>> = {
value !== null && utils.isValid(value)
? `Välj tid, vald tid är ${utils.format(value, 'fullTime')}`
: 'Välj tid',
// fieldClearLabel: 'Clear value',
fieldClearLabel: 'Rensa värde',

// Table labels
timeTableLabel: 'välj tid',
dateTableLabel: 'välj datum',

// Field section placeholders
// fieldYearPlaceholder: params => 'Y'.repeat(params.digitAmount),
// fieldMonthPlaceholder: params => params.contentType === 'letter' ? 'MMMM' : 'MM',
// fieldDayPlaceholder: () => 'DD',
// fieldWeekDayPlaceholder: params => params.contentType === 'letter' ? 'EEEE' : 'EE',
// fieldHoursPlaceholder: () => 'hh',
// fieldMinutesPlaceholder: () => 'mm',
// fieldSecondsPlaceholder: () => 'ss',
// fieldMeridiemPlaceholder: () => 'aa',
fieldYearPlaceholder: (params) => 'Å'.repeat(params.digitAmount),
fieldMonthPlaceholder: (params) => (params.contentType === 'letter' ? 'MMMM' : 'MM'),
fieldDayPlaceholder: () => 'DD',
fieldWeekDayPlaceholder: (params) => (params.contentType === 'letter' ? 'EEEE' : 'EE'),
fieldHoursPlaceholder: () => 'tt',
fieldMinutesPlaceholder: () => 'mm',
fieldSecondsPlaceholder: () => 'ss',
fieldMeridiemPlaceholder: () => 'aa',

// View names
// year: 'Year',
// month: 'Month',
// day: 'Day',
// weekDay: 'Week day',
// hours: 'Hours',
// minutes: 'Minutes',
// seconds: 'Seconds',
// meridiem: 'Meridiem',
year: 'År',
month: 'Månad',
day: 'Dag',
weekDay: 'Veckodag',
hours: 'Timmar',
minutes: 'Minuter',
seconds: 'Sekunder',
meridiem: 'Meridiem',

// Common
// empty: 'Empty',
empty: 'Tom',
};

export const svSE = getPickersLocalization(svSEPickers);
38 changes: 20 additions & 18 deletions scripts/releaseChangelog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ async function findLatestTaggedVersion(octokit) {
return data[0].name.trim();
}

function resolvePackageByLabels(labels) {
let resolvedPackage = null;
function resolvePackagesByLabels(labels) {
let resolvedPackages = [];
labels.forEach((label) => {
switch (label.name) {
case 'component: data grid':
resolvedPackage = 'DataGrid';
resolvedPackages.push('DataGrid');
break;
case 'component: pickers':
resolvedPackage = 'pickers';
resolvedPackages.push('pickers');
break;
default:
break;
}
});
return resolvedPackage;
return resolvedPackages;
}

async function main(argv) {
Expand Down Expand Up @@ -203,19 +203,21 @@ async function main(argv) {
case 'l10n':
case '118n': {
const prLabels = prsLabelsMap[commitItem.sha];
const resolvedPackage = resolvePackageByLabels(prLabels);
if (resolvedPackage) {
switch (resolvedPackage) {
case 'DataGrid':
dataGridCommits.push(commitItem);
break;
case 'pickers':
pickersCommits.push(commitItem);
break;
default:
coreCommits.push(commitItem);
break;
}
const resolvedPackages = resolvePackagesByLabels(prLabels);
if (resolvedPackages.length > 0) {
resolvedPackages.forEach((resolvedPackage) => {
switch (resolvedPackage) {
case 'DataGrid':
dataGridCommits.push(commitItem);
break;
case 'pickers':
pickersCommits.push(commitItem);
break;
default:
coreCommits.push(commitItem);
break;
}
});
}
break;
}
Expand Down

0 comments on commit 19536f3

Please sign in to comment.