Skip to content

Commit

Permalink
Merge pull request #1467 from Adslot/fix-minor
Browse files Browse the repository at this point in the history
[ADS-7093] fix: code scanner related fixes
  • Loading branch information
xiaofan2406 authored Aug 23, 2022
2 parents d5b800e + 73ef9e3 commit 763c61b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 35 deletions.
7 changes: 6 additions & 1 deletion src/components/DatePicker/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const momentToDate = (date) => (!date || date instanceof Date ? date : date.toDa
const withMoment = (DatePickerComponent) =>
React.forwardRef(
({ selected, onChange, startDate, endDate, minDate, maxDate, dateFormat, disableMomentFormat, ...props }, ref) => {
const _dateFormat = React.useMemo(
() => (disableMomentFormat ? dateFormat : transform(dateFormat)),
[dateFormat, disableMomentFormat]
);

const isDate = selected instanceof Date;
const handleChange = React.useCallback(
(newDate) => {
Expand All @@ -27,7 +32,7 @@ const withMoment = (DatePickerComponent) =>
endDate={momentToDate(endDate)}
minDate={momentToDate(minDate)}
maxDate={momentToDate(maxDate)}
dateFormat={disableMomentFormat ? dateFormat : transform(dateFormat)}
dateFormat={_dateFormat}
onChange={handleChange}
/>
);
Expand Down
6 changes: 0 additions & 6 deletions src/components/DatePicker/transformFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const momentFormattingTokensRegExp = new RegExp(

const dateFnsformattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;

const cache = new Map();

const tokenMapping = {
YY: 'yy',
YYYY: 'yyyy',
Expand Down Expand Up @@ -136,7 +134,3 @@ export function transform(format) {

return result;
}

export function clearCache() {
cache.clear();
}
6 changes: 1 addition & 5 deletions src/components/DatePicker/transformFormat.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import moment from 'moment';
import { format } from 'date-fns';
import { transform, clearCache } from './transformFormat';
import { transform } from './transformFormat';

describe('<DatePicker />', () => {
const date = new Date('2021-11-10T02:42:58.797Z');

beforeEach(() => {
clearCache();
});

it('should format common format correctly', () => {
const formats = [
'YYYY-MM-DD',
Expand Down
8 changes: 3 additions & 5 deletions src/components/ListPicker/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ const ListPicker = ({
const [disableApplyButton, setDisableApplyButton] = React.useState(getApplyButtonState(initialSelection));

const selectItem = (item) => {
if (!allowMultiSelection) selectedItems.length = 0;

selectedItems.push(item);
setSelectedItems(selectedItems);
setDisableApplyButton(getApplyButtonState(selectedItems));
const newSelectedItems = allowMultiSelection ? [...selectedItems, item] : [item];
setSelectedItems(newSelectedItems);
setDisableApplyButton(getApplyButtonState(newSelectedItems));
};

const deselectItem = (item) => {
Expand Down
21 changes: 4 additions & 17 deletions src/components/ListPickerPure/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,18 @@ const ListPickerPure = ({
const handleChange = (item) => {
return () => {
const isSelected = isItemSelected(item);
updateSelectedItems(item, isSelected);
if (isSelected) {
setSelectedItems((_selectedItems) =>
allowMultiSelection ? _.reject(_selectedItems, { id: item.id }) : [item]
);
deselectItem(item, allowMultiSelection);
} else {
setSelectedItems((_selectedItems) => (allowMultiSelection ? [..._selectedItems, item] : [item]));
selectItem(item, allowMultiSelection);
}
};
};

const updateSelectedItems = (item, isSelected) => {
const newSelectedItemsArray = _.clone(selectedItems);

if (allowMultiSelection) {
if (isSelected) {
_.remove(newSelectedItemsArray, { id: item.id });
} else {
newSelectedItemsArray.push(item);
}

setSelectedItems(newSelectedItemsArray);
} else {
setSelectedItems([item]);
}
};

const ToggleComponent = allowMultiSelection ? Checkbox : Radio;

return (
Expand Down
3 changes: 2 additions & 1 deletion src/styles/bootstrap-custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -4688,7 +4688,7 @@ button.close {
height: auto;
line-height: 1;
}
@media all and (transform-3d), (-webkit-transform-3d) {
@media all and (-webkit-transform-3d) {
.carousel-inner > .item {
-webkit-transition: -webkit-transform 0.6s ease-in-out;
-moz-transition: -moz-transform 0.6s ease-in-out;
Expand Down Expand Up @@ -4937,6 +4937,7 @@ button.close {

.text-hide {
font: 0/0 a;
font-family: inherit;
color: transparent;
text-shadow: none;
background-color: transparent;
Expand Down

0 comments on commit 763c61b

Please sign in to comment.