From 8d10326c443d1f1885e7dad66cf752cd1a265ac8 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Fri, 6 Nov 2020 13:07:08 +0300 Subject: [PATCH 01/34] Web: Common: FilterInput: Fixed hidden elements when screen zooms out --- .../src/components/FilterInput/FilterInput.js | 65 ++++++++++++++++--- .../FilterInput/sub-components/FilterBlock.js | 6 -- .../FilterInput/sub-components/HideFilter.js | 1 + 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index 5af5aa6707..6978c3461a 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -198,7 +198,7 @@ class FilterInput extends React.Component { this.props.getFilterData(), cloneObjectsArray(this.props.selectedFilterData.filterValues) ); - this.updateFilter(internalFilterData); + //this.updateFilter(internalFilterData); } } shouldComponentUpdate(nextProps, nextState) { @@ -330,11 +330,7 @@ class FilterInput extends React.Component { resize = () => { this.isResizeUpdate = true; - this.setState({ - filterValues: this.state.filterValues, - openFilterItems: this.state.filterValues, - hideFilterItems: [], - }); + this.updateFilter(); }; onChangeSortDirection(key) { this.onFilter( @@ -428,17 +424,67 @@ class FilterInput extends React.Component { "" ); } + + calcHiddenItems = (searchWidth, currentFilterItems) => { + const { hideFilterItems } = this.state; + if ( + !searchWidth || + currentFilterItems.length === 0 || + searchWidth > this.minWidth + ) + return hideFilterItems.length; + + let newSearchWidth = searchWidth; + let numberOfHiddenItems = hideFilterItems.length; + + for (let i = 0; i < currentFilterItems.length; i++) { + if (currentFilterItems[i].id === "styled-hide-filter") continue; + const filterItemWidth = currentFilterItems[i].getBoundingClientRect() + .width; + newSearchWidth = newSearchWidth + filterItemWidth; + numberOfHiddenItems++; + if (newSearchWidth > this.minWidth) break; + } + + return numberOfHiddenItems; + }; + updateFilter(inputFilterItems) { const currentFilterItems = inputFilterItems || cloneObjectsArray(this.state.filterValues); const fullWidth = this.searchWrapper.current.getBoundingClientRect().width; const filterWidth = this.filterWrapper.current.getBoundingClientRect() .width; + const filterArr = Array.from( Array.from(this.filterWrapper.current.children).find( (x) => x.id === "filter-items-container" ).children ); + + const searchWidth = fullWidth - filterWidth; + + const numberOfHiddenItems = this.calcHiddenItems(searchWidth, filterArr); + console.log("numberOfHiddenItems: ", numberOfHiddenItems); + if (searchWidth !== 0 && currentFilterItems.length > 0) { + this.setState({ + openFilterItems: numberOfHiddenItems + ? currentFilterItems.slice( + 0, + currentFilterItems.length - numberOfHiddenItems + ) + : currentFilterItems.slice(), + hideFilterItems: numberOfHiddenItems + ? currentFilterItems.slice(-numberOfHiddenItems) + : [], + }); + } + + /*const filterArr = Array.from( + Array.from(this.filterWrapper.current.children).find( + (x) => x.id === "filter-items-container" + ).children + ); const searchFilterButton = Array.from( this.filterWrapper.current.children ).find((x) => x.id != "filter-items-container"); @@ -495,7 +541,7 @@ class FilterInput extends React.Component { openFilterItems: currentFilterItems.slice(), hideFilterItems: [], }); - } + }*/ } onDeleteFilterItem(key) { const currentFilterItems = this.state.filterValues.slice(); @@ -554,7 +600,8 @@ class FilterInput extends React.Component { .width; const filterWidth = this.filterWrapper.current.getBoundingClientRect() .width; - if (fullWidth <= this.minWidth || filterWidth > fullWidth / 2) + const searchWidth = fullWidth - filterWidth; + if (searchWidth !== 0 && searchWidth <= this.minWidth) this.updateFilter(); } } @@ -775,7 +822,7 @@ class FilterInput extends React.Component { id={id} style={style} > -
+
{count} From 3f77abc3c95a5500c7dc2affbd2ad50ef47f0d85 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Fri, 6 Nov 2020 13:28:31 +0300 Subject: [PATCH 02/34] Web: Common: FilterInput: Refactoring, removed unused methods --- .../src/components/FilterInput/FilterInput.js | 346 ++++++------------ 1 file changed, 122 insertions(+), 224 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index 6978c3461a..dd6758ee53 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -85,72 +85,24 @@ class FilterInput extends React.Component { constructor(props) { super(props); + const { selectedFilterData, getSortData, value } = props; + const { sortDirection, sortId, inputValue } = selectedFilterData; + const sortData = getSortData(); + this.isResizeUpdate = false; this.minWidth = 190; - function getDefaultFilterData() { - const filterData = props.getFilterData(); - const filterItems = []; - const selectedFilterData = cloneObjectsArray( - props.selectedFilterData.filterValues - ); - selectedFilterData.forEach((defaultFilterValue) => { - const filterValue = filterData.find( - (x) => - x.key === - defaultFilterValue.key.replace( - defaultFilterValue.group + "_", - "" - ) && x.group === defaultFilterValue.group - ); - let groupLabel = ""; - - const groupFilterItem = filterData.find( - (x) => x.key === defaultFilterValue.group - ); - if (groupFilterItem != undefined) { - groupLabel = groupFilterItem.label; - } else { - const subgroupFilterItem = filterData.find( - (x) => x.subgroup === defaultFilterValue.group - ); - if (subgroupFilterItem != undefined) { - groupLabel = subgroupFilterItem.label; - } - } - - if (filterValue != undefined) { - defaultFilterValue.key = - defaultFilterValue.group + "_" + defaultFilterValue.key; - defaultFilterValue.label = filterValue.label; - defaultFilterValue.groupLabel = groupLabel; - filterItems.push(defaultFilterValue); - } - }); - return filterItems; - } - - let filterValues = props.selectedFilterData ? getDefaultFilterData() : []; - filterValues = [ - ...filterValues, - ...this.convertSelectorToInternalData( - props.getFilterData(), - cloneObjectsArray(props.selectedFilterData.filterValues) - ), - ]; + const filterValues = selectedFilterData ? this.getDefaultFilterData() : []; this.state = { - sortDirection: - props.selectedFilterData.sortDirection === "desc" ? true : false, + sortDirection: sortDirection === "desc" ? true : false, sortId: - props - .getSortData() - .findIndex((x) => x.key === props.selectedFilterData.sortId) != -1 - ? props.selectedFilterData.sortId - : props.getSortData().length > 0 - ? props.getSortData()[0].key + sortData.findIndex((x) => x.key === sortId) != -1 + ? sortId + : sortData.length > 0 + ? sortData[0].key : "", - searchText: props.selectedFilterData.inputValue || props.value, + searchText: inputValue || value, filterValues, openFilterItems: [], @@ -160,25 +112,6 @@ class FilterInput extends React.Component { this.searchWrapper = React.createRef(); this.filterWrapper = React.createRef(); - this.onClickSortItem = this.onClickSortItem.bind(this); - this.onSortDirectionClick = this.onSortDirectionClick.bind(this); - this.onChangeSortDirection = this.onChangeSortDirection.bind(this); - this.onSearch = this.onSearch.bind(this); - this.onChangeFilter = this.onChangeFilter.bind(this); - - this.onSearchChanged = this.onSearchChanged.bind(this); - - this.getDefaultSelectedIndex = this.getDefaultSelectedIndex.bind(this); - - this.updateFilter = this.updateFilter.bind(this); - this.onClickFilterItem = this.onClickFilterItem.bind(this); - this.getFilterData = this.getFilterData.bind(this); - this.onFilterRender = this.onFilterRender.bind(this); - this.onDeleteFilterItem = this.onDeleteFilterItem.bind(this); - this.clearFilter = this.clearFilter.bind(this); - - this.onClickViewSelector = this.onClickViewSelector.bind(this); - this.throttledResize = throttle(this.resize, 300); } @@ -204,80 +137,21 @@ class FilterInput extends React.Component { shouldComponentUpdate(nextProps, nextState) { const { selectedFilterData, - getFilterData, - getSortData, value, id, isDisabled, size, placeholder, } = this.props; - if (!isEqual(selectedFilterData, nextProps.selectedFilterData)) { - let internalFilterData = cloneObjectsArray(this.state.filterValues); - if (nextProps.selectedFilterData.filterValues) { - internalFilterData = convertToInternalData( - getFilterData(), - cloneObjectsArray(nextProps.selectedFilterData.filterValues) - ); - let internalFilterDataSelectors = this.convertSelectorToInternalData( - getFilterData(), - cloneObjectsArray(nextProps.selectedFilterData.filterValues) - ); - internalFilterData = internalFilterData.concat( - internalFilterDataSelectors - ); - this.updateFilter(internalFilterData); - } - this.setState({ - sortDirection: - nextProps.selectedFilterData.sortDirection === "desc" ? true : false, - sortId: - getSortData().findIndex( - (x) => x.key === nextProps.selectedFilterData.sortId - ) != -1 - ? nextProps.selectedFilterData.sortId - : "", - filterValues: internalFilterData, - searchText: nextProps.selectedFilterData.inputValue || value, - }); + + if ( + !isEqual(selectedFilterData, nextProps.selectedFilterData) || + this.props.viewAs !== nextProps.viewAs || + this.props.widthProp !== nextProps.widthProp + ) { return true; } - if (this.props.viewAs !== nextProps.viewAs) { - return true; - } - - if (this.props.isReady !== nextProps.isReady) { - let internalFilterData = cloneObjectsArray(this.state.filterValues); - internalFilterData = convertToInternalData( - getFilterData(), - cloneObjectsArray(nextProps.selectedFilterData.filterValues) - ); - - let internalFilterDataSelectors = this.convertSelectorToInternalData( - getFilterData(), - cloneObjectsArray(nextProps.selectedFilterData.filterValues) - ); - internalFilterData = internalFilterData.concat( - internalFilterDataSelectors - ); - this.updateFilter(internalFilterData); - - this.setState({ - sortDirection: - nextProps.selectedFilterData.sortDirection === "desc" ? true : false, - sortId: - getSortData().findIndex( - (x) => x.key === nextProps.selectedFilterData.sortId - ) != -1 - ? nextProps.selectedFilterData.sortId - : "", - filterValues: internalFilterData, - searchText: nextProps.selectedFilterData.inputValue || value, - }); - // return true; - } - if ( id != nextProps.id || isDisabled != nextProps.isDisabled || @@ -286,92 +160,45 @@ class FilterInput extends React.Component { value != nextProps.value ) return true; - if (this.isResizeUpdate) { - return true; - } + return !isEqual(this.state, nextState); } - convertSelectorToInternalData = (filterData, filterValues) => { - const resultValues = []; - filterValues.forEach((item) => { - const isSelector = item.group.includes("filter-author"); - if (isSelector) { - const typeSelector = item.key.includes("user") - ? "user" - : item.key.includes("group") - ? "group" - : null; - const hasUnderscore = item.key.indexOf("_") !== -1; - const key = hasUnderscore - ? item.key.slice(0, item.key.indexOf("_")) - : item.key; - const finded = filterData.find( - (x) => x.key === key && x.group === item.group - ); - if (!finded) return; - const convertedItem = { - key: item.group + "_" + item.key, - label: finded.label, - group: item.group, - groupLabel: finded.label, - typeSelector, - groupsCaption: finded.groupsCaption, - defaultOptionLabel: finded.defaultOptionLabel, - defaultOption: finded.defaultOption, - defaultSelectLabel: finded.defaultSelectLabel, - selectedItem: finded.selectedItem, - }; - resultValues.push(convertedItem); - } - }); - return resultValues; - }; - resize = () => { this.isResizeUpdate = true; this.updateFilter(); }; - onChangeSortDirection(key) { + onChangeSortDirection = (key) => { this.onFilter( this.state.filterValues, this.state.sortId, key ? "desc" : "asc" ); this.setState({ sortDirection: !!key }); - } - onClickViewSelector(item) { + }; + onClickViewSelector = (item) => { const itemId = (item.target && item.target.dataset.for) || item; const viewAs = itemId.indexOf("row") === -1 ? "tile" : "row"; this.props.onChangeViewAs(viewAs); - } - getDefaultSelectedIndex() { - const sortData = this.props.getSortData(); - if (sortData.length > 0) { - const defaultIndex = sortData.findIndex( - (x) => x.key === this.state.sortId - ); - return defaultIndex != -1 ? defaultIndex : 0; - } - return 0; - } - onClickSortItem(key) { + }; + + onClickSortItem = (key) => { this.setState({ sortId: key }); this.onFilter( this.state.filterValues, key, this.state.sortDirection ? "desc" : "asc" ); - } - onSortDirectionClick() { + }; + onSortDirectionClick = () => { this.onFilter( this.state.filterValues, this.state.sortId, !this.state.sortDirection ? "desc" : "asc" ); this.setState({ sortDirection: !this.state.sortDirection }); - } - onSearchChanged(value) { + }; + onSearchChanged = (value) => { this.setState({ searchText: value }); this.onFilter( this.state.filterValues, @@ -379,15 +206,86 @@ class FilterInput extends React.Component { this.state.sortDirection ? "desc" : "asc", value ); - } - onSearch(result) { + }; + onSearch = (result) => { this.onFilter( result.filterValues, this.state.sortId, this.state.sortDirection ? "desc" : "asc" ); - } - getFilterData() { + }; + getDefaultFilterData = () => { + const { getFilterData, selectedFilterData } = this.props; + const filterData = getFilterData(); + const filterItems = []; + const filterValues = cloneObjectsArray(selectedFilterData.filterValues); + + for (let item of filterValues) { + const filterValue = filterData.find( + (x) => x.key === item.key && x.group === item.group + ); + + if (!filterValue) { + const isSelector = item.group.includes("filter-author"); + + if (isSelector) { + const typeSelector = item.key.includes("user") + ? "user" + : item.key.includes("group") + ? "group" + : null; + const underlined = item.key.indexOf("_") !== -1; + const key = underlined + ? item.key.slice(0, item.key.indexOf("_")) + : item.key; + const filesFilterValue = filterData.find( + (x) => x.key === key && x.group === item.group + ); + + if (filesFilterValue) { + const convertedItem = { + key: item.group + "_" + item.key, + label: filesFilterValue.label, + group: item.group, + groupLabel: filesFilterValue.label, + typeSelector, + groupsCaption: filesFilterValue.groupsCaption, + defaultOptionLabel: filesFilterValue.defaultOptionLabel, + defaultOption: filesFilterValue.defaultOption, + defaultSelectLabel: filesFilterValue.defaultSelectLabel, + selectedItem: filesFilterValue.selectedItem, + }; + filterItems.push(convertedItem); + } + } + } + + let groupLabel = ""; + const groupFilterItem = filterData.find((x) => x.key === item.group); + if (groupFilterItem) { + groupLabel = groupFilterItem.label; + } else { + const subgroupFilterItem = filterData.find( + (x) => x.subgroup === item.group + ); + if (subgroupFilterItem) { + groupLabel = subgroupFilterItem.label; + } + } + + if (filterValue) { + item.key = item.group + "_" + item.key; + item.label = filterValue.selectedItem + ? filterValue.selectedItem.label + : filterValue.label; + item.groupLabel = groupLabel; + filterItems.push(item); + } + } + + return filterItems; + }; + getFilterData = () => { const _this = this; const d = this.props.getFilterData(); const result = []; @@ -395,7 +293,7 @@ class FilterInput extends React.Component { if (!element.inSubgroup) { element.onClick = !element.isSeparator && !element.isHeader && !element.disabled - ? (e) => _this.props.onClickFilterItem(e, element) + ? () => this.onClickFilterItem(element) : undefined; element.key = element.group != element.key @@ -409,8 +307,8 @@ class FilterInput extends React.Component { } }); return result; - } - clearFilter() { + }; + clearFilter = () => { this.setState({ searchText: "", filterValues: [], @@ -423,7 +321,7 @@ class FilterInput extends React.Component { this.state.sortDirection ? "desc" : "asc", "" ); - } + }; calcHiddenItems = (searchWidth, currentFilterItems) => { const { hideFilterItems } = this.state; @@ -449,9 +347,10 @@ class FilterInput extends React.Component { return numberOfHiddenItems; }; - updateFilter(inputFilterItems) { - const currentFilterItems = - inputFilterItems || cloneObjectsArray(this.state.filterValues); + updateFilter = (inputFilterItems) => { + const currentFilterItems = inputFilterItems + ? cloneObjectsArray(inputFilterItems) + : cloneObjectsArray(this.state.filterValues); const fullWidth = this.searchWrapper.current.getBoundingClientRect().width; const filterWidth = this.filterWrapper.current.getBoundingClientRect() .width; @@ -465,7 +364,6 @@ class FilterInput extends React.Component { const searchWidth = fullWidth - filterWidth; const numberOfHiddenItems = this.calcHiddenItems(searchWidth, filterArr); - console.log("numberOfHiddenItems: ", numberOfHiddenItems); if (searchWidth !== 0 && currentFilterItems.length > 0) { this.setState({ openFilterItems: numberOfHiddenItems @@ -542,8 +440,8 @@ class FilterInput extends React.Component { hideFilterItems: [], }); }*/ - } - onDeleteFilterItem(key) { + }; + onDeleteFilterItem = (key) => { const currentFilterItems = this.state.filterValues.slice(); const indexFilterItem = currentFilterItems.findIndex((x) => x.key === key); if (indexFilterItem != -1) { @@ -564,8 +462,8 @@ class FilterInput extends React.Component { this.state.sortId, this.state.sortDirection ? "desc" : "asc" ); - } - onFilter(filterValues, sortId, sortDirection, searchText) { + }; + onFilter = (filterValues, sortId, sortDirection, searchText) => { let cloneFilterValues = cloneObjectsArray(filterValues); cloneFilterValues = cloneFilterValues.map(function (item) { item.key = item.key.replace(item.group + "_", ""); @@ -577,8 +475,8 @@ class FilterInput extends React.Component { sortId: sortId, sortDirection: sortDirection, }); - } - onChangeFilter(result) { + }; + onChangeFilter = (result) => { this.setState({ searchText: result.inputValue, filterValues: result.filterValues, @@ -589,8 +487,8 @@ class FilterInput extends React.Component { this.state.sortDirection ? "desc" : "asc", result.inputValue ); - } - onFilterRender() { + }; + onFilterRender = () => { if (this.isResizeUpdate) { this.isResizeUpdate = false; } @@ -604,8 +502,8 @@ class FilterInput extends React.Component { if (searchWidth !== 0 && searchWidth <= this.minWidth) this.updateFilter(); } - } - onClickFilterItem(event, filterItem) { + }; + onClickFilterItem = (event, filterItem) => { const currentFilterItems = cloneObjectsArray(this.state.filterValues); if (filterItem.isSelector) { @@ -768,7 +666,7 @@ class FilterInput extends React.Component { this.state.sortDirection ? "desc" : "asc" ); } - } + }; render() { /* eslint-disable react/prop-types */ From 20f92245f45be01df5af6650c5434f617444e19a Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Mon, 9 Nov 2020 09:26:03 +0300 Subject: [PATCH 03/34] Web: Common: FilterInput: Fixed adding elements when screen zooms in --- .../src/components/FilterInput/FilterInput.js | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index dd6758ee53..1f05e14544 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -323,15 +323,36 @@ class FilterInput extends React.Component { ); }; - calcHiddenItems = (searchWidth, currentFilterItems) => { - const { hideFilterItems } = this.state; - if ( - !searchWidth || - currentFilterItems.length === 0 || - searchWidth > this.minWidth - ) - return hideFilterItems.length; + calcHiddenItemWidth = (item) => { + if (!item) return; + const numberOfLetters = item.groupLabel.length + item.label.length; + return numberOfLetters * 6.7 + 60; // 60 - sum of padding + }; + AddItems = (searchWidth) => { + const { hideFilterItems } = this.state; + let newSearchWidth = searchWidth; + let numberOfHiddenItems = hideFilterItems.length; + + for (let i = 0; i < hideFilterItems.length; i++) { + const hiddenItemWidth = this.calcHiddenItemWidth( + hideFilterItems[hideFilterItems.length - i - 1] // last hidden element + ); + + newSearchWidth = newSearchWidth - hiddenItemWidth; + if (newSearchWidth >= this.minWidth) { + console.log(hiddenItemWidth); + numberOfHiddenItems--; + } else { + break; + } + } + + return numberOfHiddenItems; + }; + + HideItems = (searchWidth, currentFilterItems) => { + const { hideFilterItems } = this.state; let newSearchWidth = searchWidth; let numberOfHiddenItems = hideFilterItems.length; @@ -347,6 +368,23 @@ class FilterInput extends React.Component { return numberOfHiddenItems; }; + calcHiddenItems = (searchWidth, currentFilterItems) => { + const { hideFilterItems } = this.state; + let numberOfHiddenItems = 0; + + debugger; + + if (!searchWidth || currentFilterItems.length === 0) + return hideFilterItems.length; + + numberOfHiddenItems = + searchWidth < this.minWidth + ? this.HideItems(searchWidth, currentFilterItems) + : this.AddItems(searchWidth); + + return numberOfHiddenItems; + }; + updateFilter = (inputFilterItems) => { const currentFilterItems = inputFilterItems ? cloneObjectsArray(inputFilterItems) From 433d0d399f8e7265a1340b04fe890581bf854eb1 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Mon, 9 Nov 2020 12:12:26 +0300 Subject: [PATCH 04/34] Web: Common: FilterInput: Fixed filter when added/removed filter items --- .../src/components/FilterInput/FilterInput.js | 90 +++---------------- .../FilterInput/sub-components/FilterBlock.js | 18 ++-- 2 files changed, 22 insertions(+), 86 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index 1f05e14544..dfd908fa5a 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -123,15 +123,18 @@ class FilterInput extends React.Component { window.removeEventListener("resize", this.throttledResize); } componentDidUpdate(prevProps, prevState) { + const { selectedFilterData } = this.props; + const { filterWidth } = this.state; + if ( this.props.needForUpdate && this.props.needForUpdate(prevProps, this.props) ) { let internalFilterData = convertToInternalData( this.props.getFilterData(), - cloneObjectsArray(this.props.selectedFilterData.filterValues) + cloneObjectsArray(selectedFilterData.filterValues) ); - //this.updateFilter(internalFilterData); + this.updateFilter(internalFilterData); } } shouldComponentUpdate(nextProps, nextState) { @@ -341,7 +344,6 @@ class FilterInput extends React.Component { newSearchWidth = newSearchWidth - hiddenItemWidth; if (newSearchWidth >= this.minWidth) { - console.log(hiddenItemWidth); numberOfHiddenItems--; } else { break; @@ -372,8 +374,6 @@ class FilterInput extends React.Component { const { hideFilterItems } = this.state; let numberOfHiddenItems = 0; - debugger; - if (!searchWidth || currentFilterItems.length === 0) return hideFilterItems.length; @@ -393,14 +393,14 @@ class FilterInput extends React.Component { const filterWidth = this.filterWrapper.current.getBoundingClientRect() .width; + const searchWidth = fullWidth - filterWidth; + const filterArr = Array.from( Array.from(this.filterWrapper.current.children).find( (x) => x.id === "filter-items-container" ).children ); - const searchWidth = fullWidth - filterWidth; - const numberOfHiddenItems = this.calcHiddenItems(searchWidth, filterArr); if (searchWidth !== 0 && currentFilterItems.length > 0) { this.setState({ @@ -415,70 +415,8 @@ class FilterInput extends React.Component { : [], }); } - - /*const filterArr = Array.from( - Array.from(this.filterWrapper.current.children).find( - (x) => x.id === "filter-items-container" - ).children - ); - const searchFilterButton = Array.from( - this.filterWrapper.current.children - ).find((x) => x.id != "filter-items-container"); - - const filterButton = searchFilterButton - ? Array.from(searchFilterButton.children)[0] - : null; - - if (fullWidth <= this.minWidth && fullWidth > 0) { - this.setState({ - openFilterItems: [], - hideFilterItems: cloneObjectsArray(currentFilterItems), - }); - } else if (filterWidth > fullWidth / 2) { - let newOpenFilterItems = cloneObjectsArray(currentFilterItems); - let newHideFilterItems = []; - - let elementsWidth = 0; - Array.from(filterArr).forEach((element) => { - elementsWidth = elementsWidth + element.getBoundingClientRect().width; - }); - - if ( - filterButton !== null && - elementsWidth >= - fullWidth / 3 - filterButton.getBoundingClientRect().width - ) { - for (let i = 0; i < filterArr.length; i++) { - if ( - elementsWidth > - fullWidth / 3 - filterButton.getBoundingClientRect().width - ) { - elementsWidth = - elementsWidth - filterArr[i].getBoundingClientRect().width; - const hiddenItem = currentFilterItems.find( - (x) => x.key === filterArr[i].getAttribute("id") - ); - if (hiddenItem) newHideFilterItems.push(hiddenItem); - newOpenFilterItems.splice( - newOpenFilterItems.findIndex( - (x) => x.key === filterArr[i].getAttribute("id") - ), - 1 - ); - } - } - } - this.setState({ - openFilterItems: newOpenFilterItems, - hideFilterItems: newHideFilterItems, - }); - } else { - this.setState({ - openFilterItems: currentFilterItems.slice(), - hideFilterItems: [], - }); - }*/ }; + onDeleteFilterItem = (key) => { const currentFilterItems = this.state.filterValues.slice(); const indexFilterItem = currentFilterItems.findIndex((x) => x.key === key); @@ -531,15 +469,7 @@ class FilterInput extends React.Component { this.isResizeUpdate = false; } - if (this.searchWrapper.current && this.filterWrapper.current) { - const fullWidth = this.searchWrapper.current.getBoundingClientRect() - .width; - const filterWidth = this.filterWrapper.current.getBoundingClientRect() - .width; - const searchWidth = fullWidth - filterWidth; - if (searchWidth !== 0 && searchWidth <= this.minWidth) - this.updateFilter(); - } + this.updateFilter(); }; onClickFilterItem = (event, filterItem) => { const currentFilterItems = cloneObjectsArray(this.state.filterValues); @@ -785,7 +715,7 @@ class FilterInput extends React.Component { onClickFilterItem={this.onClickFilterItem} onDeleteFilterItem={this.onDeleteFilterItem} isResizeUpdate={this.isResizeUpdate} - onRender={this.onFilterRender} + onFilterRender={this.onFilterRender} isDisabled={isDisabled} columnCount={filterColumnCount} /> diff --git a/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js b/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js index d8598011d7..a2eca9363d 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js +++ b/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js @@ -268,6 +268,17 @@ class FilterBlock extends React.Component { }; } + componentDidUpdate(prevProps, prevState) { + debugger; + if ( + !isEqual(prevState.openFilterItems, this.state.openFilterItems) || + !isEqual(prevState.hideFilterItems, this.state.hideFilterItems) + ) { + console.log("onFilterRender"); + this.props.onFilterRender(); + } + } + shouldComponentUpdate(nextProps, nextState) { const { hideFilterItems, openFilterItems } = nextProps; @@ -284,9 +295,7 @@ class FilterBlock extends React.Component { } return true; } - if (this.props.isResizeUpdate) { - return true; - } + return !isEqual(this.state, nextState); } @@ -414,9 +423,6 @@ class FilterBlock extends React.Component { return result; }; - onRender = () => { - this.props.onRender(); - }; render() { const _this = this; const filterItems = this.getFilterItems(); From 6bfaae5d2f859546fb5d6354a11197db6252349b Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Mon, 9 Nov 2020 16:01:29 +0300 Subject: [PATCH 05/34] Web: Common: FilterInput: Fixed filter when selected new item filter items, fixed infinite rendering in small mobile devices --- .../src/components/FilterInput/FilterInput.js | 11 ++++++- .../FilterInput/sub-components/FilterBlock.js | 33 ++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index dfd908fa5a..2b6cf13b52 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -107,6 +107,7 @@ class FilterInput extends React.Component { filterValues, openFilterItems: [], hideFilterItems: [], + needUpdateFilter: false, }; this.searchWrapper = React.createRef(); @@ -124,7 +125,6 @@ class FilterInput extends React.Component { } componentDidUpdate(prevProps, prevState) { const { selectedFilterData } = this.props; - const { filterWidth } = this.state; if ( this.props.needForUpdate && @@ -469,11 +469,19 @@ class FilterInput extends React.Component { this.isResizeUpdate = false; } + this.setState({ + needUpdateFilter: false, + }); + this.updateFilter(); }; onClickFilterItem = (event, filterItem) => { const currentFilterItems = cloneObjectsArray(this.state.filterValues); + this.setState({ + needUpdateFilter: true, + }); + if (filterItem.isSelector) { const indexFilterItem = currentFilterItems.findIndex( (x) => x.group === filterItem.group @@ -718,6 +726,7 @@ class FilterInput extends React.Component { onFilterRender={this.onFilterRender} isDisabled={isDisabled} columnCount={filterColumnCount} + needUpdateFilter={this.state.needUpdateFilter} />
diff --git a/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js b/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js index a2eca9363d..86900a5e4e 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js +++ b/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js @@ -39,6 +39,7 @@ class FilterItem extends React.Component { isOpen: false, isOpenSelector: !isOpenSelector, selectedOption, + needUpdate: false, }; } @@ -67,6 +68,11 @@ class FilterItem extends React.Component { selectedOption, }); } + + if (this.state.needUpdate) { + this.props.onFilterRender(); + this.setNeedUpdate(false); + } } onSelect = (option) => { @@ -77,6 +83,7 @@ class FilterItem extends React.Component { group, inSubgroup: !!inSubgroup, }); + this.setNeedUpdate(true); }; onClick = () => { const { isDisabled, id, onClose } = this.props; @@ -85,6 +92,12 @@ class FilterItem extends React.Component { toggleCombobox = (e, isOpen) => this.setState({ isOpen }); + setNeedUpdate = (needUpdate) => { + this.setState({ + needUpdate, + }); + }; + onCancelSelector = (e) => { if ( this.state.isOpenSelector && @@ -265,17 +278,20 @@ class FilterBlock extends React.Component { this.state = { hideFilterItems: hideFilterItems || [], openFilterItems: openFilterItems || [], + needUpdate: false, }; } componentDidUpdate(prevProps, prevState) { - debugger; + const { needUpdate } = this.state; + const { needUpdateFilter } = this.props; if ( - !isEqual(prevState.openFilterItems, this.state.openFilterItems) || - !isEqual(prevState.hideFilterItems, this.state.hideFilterItems) + (needUpdate || needUpdateFilter) && + (!isEqual(prevState.openFilterItems, this.state.openFilterItems) || + !isEqual(prevState.hideFilterItems, this.state.hideFilterItems)) ) { - console.log("onFilterRender"); this.props.onFilterRender(); + this.setNeedUpdate(false); } } @@ -301,6 +317,13 @@ class FilterBlock extends React.Component { onDeleteFilterItem = (key) => { this.props.onDeleteFilterItem(key); + this.setNeedUpdate(true); + }; + + setNeedUpdate = (needUpdate) => { + this.setState({ + needUpdate, + }); }; getFilterItems = () => { const { openFilterItems, hideFilterItems } = this.state; @@ -342,6 +365,7 @@ class FilterBlock extends React.Component { defaultOption={defaultOption} defaultSelectLabel={defaultSelectLabel} selectedItem={selectedItem} + onFilterRender={_this.props.onFilterRender} > ); }); @@ -382,6 +406,7 @@ class FilterBlock extends React.Component { defaultOption={defaultOption} defaultSelectLabel={defaultSelectLabel} selectedItem={selectedItem} + onFilterRender={_this.props.onFilterRender} > ); }); From c19be92b35c7cd0dc97241818f4b1d515c261208 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Mon, 9 Nov 2020 16:05:53 +0300 Subject: [PATCH 06/34] Web: Common: FilterInput: Fixed component initialization --- .../src/components/FilterInput/sub-components/FilterBlock.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js b/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js index 86900a5e4e..8088215b56 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js +++ b/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js @@ -282,6 +282,10 @@ class FilterBlock extends React.Component { }; } + componentDidMount() { + this.setNeedUpdate(true); + } + componentDidUpdate(prevProps, prevState) { const { needUpdate } = this.state; const { needUpdateFilter } = this.props; From 56bdfb982615e4c8626162d59974d557e26e00f8 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Mon, 9 Nov 2020 17:52:24 +0300 Subject: [PATCH 07/34] Web: Common: FilterInput: Fixed reset filter --- .../src/components/FilterInput/FilterInput.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index 2b6cf13b52..5bec949348 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -136,6 +136,17 @@ class FilterInput extends React.Component { ); this.updateFilter(internalFilterData); } + + if ( + !isEqual(prevProps.selectedFilterData, selectedFilterData) && + selectedFilterData.filterValues && + (selectedFilterData.filterValues.length === 0 || + (selectedFilterData.filterValues.length === 1 && + selectedFilterData.filterValues[0].key === "null")) && + !selectedFilterData.inputValue + ) { + this.clearFilter(); + } } shouldComponentUpdate(nextProps, nextState) { const { From 8d43d5efaa113f49b286a013e734a45c7820af18 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Tue, 10 Nov 2020 12:44:04 +0300 Subject: [PATCH 08/34] Web: Common: FilterInput: Fixed transition between mobile and desktop state, and change direction bug --- .../src/components/FilterInput/FilterInput.js | 29 ++++++++++++++----- .../FilterInput/sub-components/FilterBlock.js | 1 - 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index 5bec949348..aa1fd7109b 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -89,7 +89,6 @@ class FilterInput extends React.Component { const { sortDirection, sortId, inputValue } = selectedFilterData; const sortData = getSortData(); - this.isResizeUpdate = false; this.minWidth = 190; const filterValues = selectedFilterData ? this.getDefaultFilterData() : []; @@ -108,6 +107,7 @@ class FilterInput extends React.Component { openFilterItems: [], hideFilterItems: [], needUpdateFilter: false, + windowWidth: 0, }; this.searchWrapper = React.createRef(); @@ -125,6 +125,7 @@ class FilterInput extends React.Component { } componentDidUpdate(prevProps, prevState) { const { selectedFilterData } = this.props; + const { filterValues, searchText } = this.state; if ( this.props.needForUpdate && @@ -138,7 +139,22 @@ class FilterInput extends React.Component { } if ( - !isEqual(prevProps.selectedFilterData, selectedFilterData) && + (!isEqual(selectedFilterData.filterValues, filterValues) || + selectedFilterData.inputValue !== searchText) && + this.state.windowWidth !== prevState.windowWidth + ) { + const filterValues = this.getDefaultFilterData(); + this.setState({ + filterValues: filterValues, + searchText: selectedFilterData.inputValue, + }); + } + + if ( + !isEqual( + prevProps.selectedFilterData.filterValues, + selectedFilterData.filterValues + ) && selectedFilterData.filterValues && (selectedFilterData.filterValues.length === 0 || (selectedFilterData.filterValues.length === 1 && @@ -179,7 +195,9 @@ class FilterInput extends React.Component { } resize = () => { - this.isResizeUpdate = true; + this.setState({ + windowWidth: window.innerWidth, + }); this.updateFilter(); }; onChangeSortDirection = (key) => { @@ -476,10 +494,6 @@ class FilterInput extends React.Component { ); }; onFilterRender = () => { - if (this.isResizeUpdate) { - this.isResizeUpdate = false; - } - this.setState({ needUpdateFilter: false, }); @@ -733,7 +747,6 @@ class FilterInput extends React.Component { getFilterData={getFilterData} onClickFilterItem={this.onClickFilterItem} onDeleteFilterItem={this.onDeleteFilterItem} - isResizeUpdate={this.isResizeUpdate} onFilterRender={this.onFilterRender} isDisabled={isDisabled} columnCount={filterColumnCount} diff --git a/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js b/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js index 8088215b56..2db5a145b1 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js +++ b/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js @@ -485,7 +485,6 @@ FilterBlock.propTypes = { hideFilterItems: PropTypes.array, iconSize: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), isDisabled: PropTypes.bool, - isResizeUpdate: PropTypes.bool, onDeleteFilterItem: PropTypes.func, onRender: PropTypes.func, openFilterItems: PropTypes.array, From a52f07e4e011d7767631083e25286e560fb7da13 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Tue, 10 Nov 2020 14:28:49 +0300 Subject: [PATCH 09/34] Web: Common: FilterInput: Decreased the minimum size of the search field --- web/ASC.Web.Common/src/components/FilterInput/FilterInput.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index aa1fd7109b..969dda2618 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -89,7 +89,7 @@ class FilterInput extends React.Component { const { sortDirection, sortId, inputValue } = selectedFilterData; const sortData = getSortData(); - this.minWidth = 190; + this.minWidth = 120; const filterValues = selectedFilterData ? this.getDefaultFilterData() : []; @@ -358,7 +358,7 @@ class FilterInput extends React.Component { calcHiddenItemWidth = (item) => { if (!item) return; const numberOfLetters = item.groupLabel.length + item.label.length; - return numberOfLetters * 6.7 + 60; // 60 - sum of padding + return numberOfLetters * 6.5 + 60; // 60 - sum of padding }; AddItems = (searchWidth) => { From e29eeb2f4b1c53f1f64eeb40779a9ca4d16851a2 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Wed, 11 Nov 2020 07:27:42 +0300 Subject: [PATCH 10/34] Web: Common/Client: FilterInput: Added sectionWidth prop --- .../pages/Home/Section/Filter/index.js | 42 +++++++++++-------- .../src/components/FilterInput/FilterInput.js | 6 +++ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js b/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js index ae9e653c49..915835cb77 100644 --- a/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js +++ b/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js @@ -17,9 +17,12 @@ import result from "lodash/result"; import { withTranslation } from "react-i18next"; import { withRouter } from "react-router"; import { constants, FilterInput, store, Loaders } from "asc-web-common"; +import { utils } from "asc-web-components"; import isEqual from "lodash/isEqual"; import { isMobileOnly } from "react-device-detect"; +const { Consumer } = utils.context; + const { getCurrentUser, getSettingsCustomNames, @@ -300,23 +303,28 @@ class SectionFilterContent extends React.Component { return firstLoad ? ( ) : ( - + + {(context) => ( + + )} + ); } } diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index 969dda2618..e6dae358f5 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -172,6 +172,7 @@ class FilterInput extends React.Component { isDisabled, size, placeholder, + sectionWidth, } = this.props; if ( @@ -182,6 +183,10 @@ class FilterInput extends React.Component { return true; } + if (sectionWidth !== nextProps.sectionWidth) { + return true; + } + if ( id != nextProps.id || isDisabled != nextProps.isDisabled || @@ -799,6 +804,7 @@ FilterInput.protoTypes = { filterColumnCount: PropTypes.number, onChangeViewAs: PropTypes.func, contextMenuHeader: PropTypes.string, + sectionWidth: PropTypes.number, }; FilterInput.defaultProps = { From 4ee688427f9d830a3458c3eaadaeda1dee3f3363 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Wed, 11 Nov 2020 07:42:38 +0300 Subject: [PATCH 11/34] Web: Common: FilterInput: Page resize is tracked through a prop --- .../src/components/FilterInput/FilterInput.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index e6dae358f5..98f6789915 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -112,19 +112,14 @@ class FilterInput extends React.Component { this.searchWrapper = React.createRef(); this.filterWrapper = React.createRef(); - - this.throttledResize = throttle(this.resize, 300); } componentDidMount() { - window.addEventListener("resize", this.throttledResize); if (this.state.filterValues.length > 0) this.updateFilter(); } - componentWillUnmount() { - window.removeEventListener("resize", this.throttledResize); - } + componentDidUpdate(prevProps, prevState) { - const { selectedFilterData } = this.props; + const { selectedFilterData, sectionWidth } = this.props; const { filterValues, searchText } = this.state; if ( @@ -138,10 +133,14 @@ class FilterInput extends React.Component { this.updateFilter(internalFilterData); } + if (sectionWidth !== prevProps.sectionWidth) { + this.resize(); + } + if ( (!isEqual(selectedFilterData.filterValues, filterValues) || selectedFilterData.inputValue !== searchText) && - this.state.windowWidth !== prevState.windowWidth + sectionWidth !== prevProps.sectionWidth ) { const filterValues = this.getDefaultFilterData(); this.setState({ From b6d0ebad21daa6122c52dc158d60d8d6bf5e713b Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Wed, 11 Nov 2020 09:36:19 +0300 Subject: [PATCH 12/34] Web: Common: FilterInput: Small refactoring --- .../src/components/FilterInput/FilterInput.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index 98f6789915..7fe75f7541 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -107,7 +107,6 @@ class FilterInput extends React.Component { openFilterItems: [], hideFilterItems: [], needUpdateFilter: false, - windowWidth: 0, }; this.searchWrapper = React.createRef(); @@ -134,7 +133,7 @@ class FilterInput extends React.Component { } if (sectionWidth !== prevProps.sectionWidth) { - this.resize(); + this.updateFilter(); } if ( @@ -198,12 +197,6 @@ class FilterInput extends React.Component { return !isEqual(this.state, nextState); } - resize = () => { - this.setState({ - windowWidth: window.innerWidth, - }); - this.updateFilter(); - }; onChangeSortDirection = (key) => { this.onFilter( this.state.filterValues, From b81dc68ef75006b7de5ad58f67765a3be608b21d Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Wed, 11 Nov 2020 09:48:33 +0300 Subject: [PATCH 13/34] Web: Common: FilterInput: Fixed sort comboBox --- .../src/components/FilterInput/FilterInput.js | 4 ++++ .../src/components/FilterInput/StyledFilterInput.js | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index 7fe75f7541..738ba3dfa1 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -684,6 +684,7 @@ class FilterInput extends React.Component { viewAs, contextMenuHeader, isMobile, + sectionWidth, } = this.props; /* eslint-enable react/prop-types */ @@ -696,6 +697,8 @@ class FilterInput extends React.Component { sortDirection, } = this.state; + const smallSectionWidth = sectionWidth ? sectionWidth < 900 : false; + // console.log("filter input render, openFilterItems", openFilterItems, 'hideFilterItems', hideFilterItems); let iconSize = 30; switch (size) { @@ -712,6 +715,7 @@ class FilterInput extends React.Component { } return ( - props.isMobile && - ` + props.isMobile || + (props.smallSectionWidth && + ` width: 50px; .optionalBlock ~ div:first-child{ opacity: 0 } - `} + `)} .combo-button-label { color: #a3a9ae; From 71e4989f5ac0261c674851a9ba2a9584c492a4b3 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Wed, 11 Nov 2020 10:02:00 +0300 Subject: [PATCH 14/34] Web: Common: FilterInput: fixed sort comboBox --- .../src/components/FilterInput/StyledFilterInput.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/StyledFilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/StyledFilterInput.js index 38459516b2..e3cef9b819 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/StyledFilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/StyledFilterInput.js @@ -107,14 +107,13 @@ const StyledFilterInput = styled.div` margin-left: 8px; ${(props) => - props.isMobile || - (props.smallSectionWidth && - ` + (props.isMobile || props.smallSectionWidth) && + ` width: 50px; .optionalBlock ~ div:first-child{ opacity: 0 } - `)} + `} .combo-button-label { color: #a3a9ae; From eb58b760247e1ce2c020e2a6a11ad1a425e945e7 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Wed, 11 Nov 2020 10:42:28 +0300 Subject: [PATCH 15/34] Web: Common: FilterInput: Fixed filter when change orientation on mobile devices --- web/ASC.Web.Common/src/components/FilterInput/FilterInput.js | 1 + 1 file changed, 1 insertion(+) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index 738ba3dfa1..5cd103b5cb 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -146,6 +146,7 @@ class FilterInput extends React.Component { filterValues: filterValues, searchText: selectedFilterData.inputValue, }); + this.updateFilter(filterValues); } if ( From 3cad7a62ad5608f8d8c4d621920b5df594234449 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Wed, 11 Nov 2020 12:36:07 +0300 Subject: [PATCH 16/34] Web: Common: FilterInput: Changed the width calculated method --- .../src/components/FilterInput/FilterInput.js | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index 5cd103b5cb..c79888b369 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -89,7 +89,7 @@ class FilterInput extends React.Component { const { sortDirection, sortId, inputValue } = selectedFilterData; const sortData = getSortData(); - this.minWidth = 120; + this.minWidth = 170; const filterValues = selectedFilterData ? this.getDefaultFilterData() : []; @@ -353,10 +353,32 @@ class FilterInput extends React.Component { ); }; + getTextWidth = (text, font) => { + var canvas = + this.getTextWidth.canvas || + (this.getTextWidth.canvas = document.createElement("canvas")); + var context = canvas.getContext("2d"); + context.font = font; + var metrics = context.measureText(text); + return metrics.width; + }; + calcHiddenItemWidth = (item) => { if (!item) return; - const numberOfLetters = item.groupLabel.length + item.label.length; - return numberOfLetters * 6.5 + 60; // 60 - sum of padding + let label = ""; + if (item.selectedItem) { + label = item.selectedItem.label + ? item.selectedItem.label + : item.defaultSelectLabel; + } else { + label = item.label; + } + const itemWidth = + this.getTextWidth( + item.groupLabel + " " + label, + "bolder 13px sans-serif" + ) + 60; // paddings + margin + return itemWidth; }; AddItems = (searchWidth) => { From 2779c12db99342a5d99a438a4d39f81d1a10a1d9 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Thu, 12 Nov 2020 11:13:12 +0300 Subject: [PATCH 17/34] Web: Common: Fixed hiding/adding filter items --- .../src/components/FilterInput/FilterInput.js | 59 +++++++++++-------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index c79888b369..bc5988d4e9 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -111,6 +111,7 @@ class FilterInput extends React.Component { this.searchWrapper = React.createRef(); this.filterWrapper = React.createRef(); + this.rectComboBoxRef = React.createRef(); } componentDidMount() { @@ -383,14 +384,18 @@ class FilterInput extends React.Component { AddItems = (searchWidth) => { const { hideFilterItems } = this.state; + if (hideFilterItems.length === 0) return 0; + let newSearchWidth = searchWidth; let numberOfHiddenItems = hideFilterItems.length; for (let i = 0; i < hideFilterItems.length; i++) { - const hiddenItemWidth = this.calcHiddenItemWidth( - hideFilterItems[hideFilterItems.length - i - 1] // last hidden element + let hiddenItemWidth = this.calcHiddenItemWidth( + hideFilterItems[i] // last hidden element ); + if (hiddenItemWidth > 260) hiddenItemWidth = 260; + console.log("hiddenItemWidth!!!!!: ", hiddenItemWidth); newSearchWidth = newSearchWidth - hiddenItemWidth; if (newSearchWidth >= this.minWidth) { numberOfHiddenItems--; @@ -407,12 +412,14 @@ class FilterInput extends React.Component { let newSearchWidth = searchWidth; let numberOfHiddenItems = hideFilterItems.length; - for (let i = 0; i < currentFilterItems.length; i++) { + for (let i = currentFilterItems.length - 1; i >= 0; i--) { if (currentFilterItems[i].id === "styled-hide-filter") continue; const filterItemWidth = currentFilterItems[i].getBoundingClientRect() .width; newSearchWidth = newSearchWidth + filterItemWidth; numberOfHiddenItems++; + if (numberOfHiddenItems === 1) newSearchWidth - 40; // subtract the width of hidden block + if (newSearchWidth > this.minWidth) break; } @@ -425,7 +432,6 @@ class FilterInput extends React.Component { if (!searchWidth || currentFilterItems.length === 0) return hideFilterItems.length; - numberOfHiddenItems = searchWidth < this.minWidth ? this.HideItems(searchWidth, currentFilterItems) @@ -435,21 +441,25 @@ class FilterInput extends React.Component { }; updateFilter = (inputFilterItems) => { + const { sectionWidth } = this.props; const currentFilterItems = inputFilterItems ? cloneObjectsArray(inputFilterItems) : cloneObjectsArray(this.state.filterValues); const fullWidth = this.searchWrapper.current.getBoundingClientRect().width; const filterWidth = this.filterWrapper.current.getBoundingClientRect() .width; + const comboBoxWidth = this.rectComboBoxRef.current.getBoundingClientRect() + .width; - const searchWidth = fullWidth - filterWidth; + const searchWidth = sectionWidth + ? sectionWidth - filterWidth - comboBoxWidth - 48 // 48 - paddings + : fullWidth - filterWidth; const filterArr = Array.from( Array.from(this.filterWrapper.current.children).find( (x) => x.id === "filter-items-container" ).children ); - const numberOfHiddenItems = this.calcHiddenItems(searchWidth, filterArr); if (searchWidth !== 0 && currentFilterItems.length > 0) { this.setState({ @@ -779,24 +789,25 @@ class FilterInput extends React.Component {
- - 0 - ? getSortData().find((x) => x.key === sortId) - : {} - } - onButtonClick={this.onSortDirectionClick} - viewAs={viewAs} - sortDirection={+sortDirection} - directionAscLabel={directionAscLabel} - directionDescLabel={directionDescLabel} - /> +
+ 0 + ? getSortData().find((x) => x.key === sortId) + : {} + } + onButtonClick={this.onSortDirectionClick} + viewAs={viewAs} + sortDirection={+sortDirection} + directionAscLabel={directionAscLabel} + directionDescLabel={directionDescLabel} + /> +
{viewAs && ( Date: Thu, 12 Nov 2020 11:23:08 +0300 Subject: [PATCH 18/34] Web: People: Added sectionWidth prop to filterInput --- .../pages/Home/Section/Filter/index.js | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js index 3a5e0704cd..2dcb467957 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js @@ -7,6 +7,7 @@ import { withTranslation } from "react-i18next"; import { withRouter } from "react-router"; import { getFilterByLocation } from "../../../../../helpers/converters"; import { store, FilterInput, Loaders } from "asc-web-common"; +import { utils } from "asc-web-components"; import { isMobileOnly } from "react-device-detect"; import { getFilter, getGroups } from "../../../../../store/people/selectors"; const { @@ -17,6 +18,8 @@ const { getIsLoaded, } = store.auth.selectors; +const { Consumer } = utils.context; + const getEmployeeStatus = (filterValues) => { const employeeStatus = result( find(filterValues, (value) => { @@ -250,19 +253,24 @@ class SectionFilterContent extends React.Component { const selectedFilterData = this.getSelectedFilterData(); const { t, language, isLoaded } = this.props; return isLoaded ? ( - + + {(context) => ( + + )} + ) : ( ); From baa81cc6d0c0cc430bd4e071df371feee740751f Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Thu, 12 Nov 2020 11:47:34 +0300 Subject: [PATCH 19/34] Web: Common: FilterInput: Fixed bug when selecting an option --- .../src/components/FilterInput/sub-components/FilterBlock.js | 1 - 1 file changed, 1 deletion(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js b/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js index 2db5a145b1..1b5be4b3b0 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js +++ b/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js @@ -83,7 +83,6 @@ class FilterItem extends React.Component { group, inSubgroup: !!inSubgroup, }); - this.setNeedUpdate(true); }; onClick = () => { const { isDisabled, id, onClose } = this.props; From 9d6ad1538e4550760fe779fead10cd2192b0c8a9 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Thu, 12 Nov 2020 14:18:36 +0300 Subject: [PATCH 20/34] Web: Common: FilterInput: Fixed warning --- web/ASC.Web.Common/src/components/FilterInput/FilterInput.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index bc5988d4e9..d4155a4bc6 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -145,7 +145,7 @@ class FilterInput extends React.Component { const filterValues = this.getDefaultFilterData(); this.setState({ filterValues: filterValues, - searchText: selectedFilterData.inputValue, + searchText: selectedFilterData.inputValue || "", }); this.updateFilter(filterValues); } @@ -395,7 +395,6 @@ class FilterInput extends React.Component { ); if (hiddenItemWidth > 260) hiddenItemWidth = 260; - console.log("hiddenItemWidth!!!!!: ", hiddenItemWidth); newSearchWidth = newSearchWidth - hiddenItemWidth; if (newSearchWidth >= this.minWidth) { numberOfHiddenItems--; From 969f7e5c4f47da6d08a7f129585f1c643ce3a397 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Fri, 13 Nov 2020 10:26:14 +0300 Subject: [PATCH 21/34] Web: Common: FilterInput: Refactoring --- .../src/components/FilterInput/FilterInput.js | 94 ++++++++++--------- .../FilterInput/sub-components/FilterBlock.js | 22 ++--- 2 files changed, 60 insertions(+), 56 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index d4155a4bc6..3dc54d729d 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -81,6 +81,11 @@ const convertToInternalData = function (fullDataArray, inputDataArray) { return filterItems; }; +const minWidth = 170; +const filterItemPadding = 60; +const maxFilterItemWidth = 260; +const itemsContainerWidth = 40; + class FilterInput extends React.Component { constructor(props) { super(props); @@ -89,8 +94,6 @@ class FilterInput extends React.Component { const { sortDirection, sortId, inputValue } = selectedFilterData; const sortData = getSortData(); - this.minWidth = 170; - const filterValues = selectedFilterData ? this.getDefaultFilterData() : []; this.state = { @@ -105,7 +108,7 @@ class FilterInput extends React.Component { filterValues, openFilterItems: [], - hideFilterItems: [], + hiddenFilterItems: [], needUpdateFilter: false, }; @@ -178,15 +181,12 @@ class FilterInput extends React.Component { if ( !isEqual(selectedFilterData, nextProps.selectedFilterData) || this.props.viewAs !== nextProps.viewAs || - this.props.widthProp !== nextProps.widthProp + this.props.widthProp !== nextProps.widthProp || + sectionWidth !== nextProps.sectionWidth ) { return true; } - if (sectionWidth !== nextProps.sectionWidth) { - return true; - } - if ( id != nextProps.id || isDisabled != nextProps.isDisabled || @@ -344,7 +344,7 @@ class FilterInput extends React.Component { searchText: "", filterValues: [], openFilterItems: [], - hideFilterItems: [], + hiddenFilterItems: [], }); this.onFilter( [], @@ -366,37 +366,30 @@ class FilterInput extends React.Component { calcHiddenItemWidth = (item) => { if (!item) return; - let label = ""; - if (item.selectedItem) { - label = item.selectedItem.label - ? item.selectedItem.label - : item.defaultSelectLabel; - } else { - label = item.label; - } + let label = this.getItemLabel(item); + const itemWidth = this.getTextWidth( item.groupLabel + " " + label, "bolder 13px sans-serif" - ) + 60; // paddings + margin + ) + filterItemPadding; return itemWidth; }; AddItems = (searchWidth) => { - const { hideFilterItems } = this.state; - if (hideFilterItems.length === 0) return 0; + const { hiddenFilterItems } = this.state; + if (hiddenFilterItems.length === 0) return 0; let newSearchWidth = searchWidth; - let numberOfHiddenItems = hideFilterItems.length; + let numberOfHiddenItems = hiddenFilterItems.length; - for (let i = 0; i < hideFilterItems.length; i++) { - let hiddenItemWidth = this.calcHiddenItemWidth( - hideFilterItems[i] // last hidden element - ); + for (let i = 0; i < hiddenFilterItems.length; i++) { + let hiddenItemWidth = this.calcHiddenItemWidth(hiddenFilterItems[i]); - if (hiddenItemWidth > 260) hiddenItemWidth = 260; + if (hiddenItemWidth > maxFilterItemWidth) + hiddenItemWidth = maxFilterItemWidth; newSearchWidth = newSearchWidth - hiddenItemWidth; - if (newSearchWidth >= this.minWidth) { + if (newSearchWidth >= minWidth) { numberOfHiddenItems--; } else { break; @@ -407,9 +400,9 @@ class FilterInput extends React.Component { }; HideItems = (searchWidth, currentFilterItems) => { - const { hideFilterItems } = this.state; + const { hiddenFilterItems } = this.state; let newSearchWidth = searchWidth; - let numberOfHiddenItems = hideFilterItems.length; + let numberOfHiddenItems = hiddenFilterItems.length; for (let i = currentFilterItems.length - 1; i >= 0; i--) { if (currentFilterItems[i].id === "styled-hide-filter") continue; @@ -417,22 +410,21 @@ class FilterInput extends React.Component { .width; newSearchWidth = newSearchWidth + filterItemWidth; numberOfHiddenItems++; - if (numberOfHiddenItems === 1) newSearchWidth - 40; // subtract the width of hidden block + if (numberOfHiddenItems === 1) newSearchWidth - itemsContainerWidth; // subtract the width of hidden block - if (newSearchWidth > this.minWidth) break; + if (newSearchWidth > minWidth) break; } return numberOfHiddenItems; }; calcHiddenItems = (searchWidth, currentFilterItems) => { - const { hideFilterItems } = this.state; - let numberOfHiddenItems = 0; + const { hiddenFilterItems } = this.state; if (!searchWidth || currentFilterItems.length === 0) - return hideFilterItems.length; - numberOfHiddenItems = - searchWidth < this.minWidth + return hiddenFilterItems.length; + const numberOfHiddenItems = + searchWidth < minWidth ? this.HideItems(searchWidth, currentFilterItems) : this.AddItems(searchWidth); @@ -468,13 +460,26 @@ class FilterInput extends React.Component { currentFilterItems.length - numberOfHiddenItems ) : currentFilterItems.slice(), - hideFilterItems: numberOfHiddenItems + hiddenFilterItems: numberOfHiddenItems ? currentFilterItems.slice(-numberOfHiddenItems) : [], }); } }; + getItemLabel = (item) => { + let label = ""; + + if (item.selectedItem) { + label = item.selectedItem.label + ? item.selectedItem.label + : item.defaultSelectLabel; + } else { + label = item.label; + } + return label; + }; + onDeleteFilterItem = (key) => { const currentFilterItems = this.state.filterValues.slice(); const indexFilterItem = currentFilterItems.findIndex((x) => x.key === key); @@ -484,7 +489,7 @@ class FilterInput extends React.Component { this.setState({ filterValues: currentFilterItems, openFilterItems: currentFilterItems, - hideFilterItems: [], + hiddenFilterItems: [], }); let filterValues = cloneObjectsArray(currentFilterItems); filterValues = filterValues.map(function (item) { @@ -576,7 +581,7 @@ class FilterInput extends React.Component { this.setState({ filterValues: currentFilterItems, openFilterItems: currentFilterItems, - hideFilterItems: [], + hiddenFilterItems: [], }); if (selectFilterItem.selectedItem.key) { @@ -622,7 +627,7 @@ class FilterInput extends React.Component { this.setState({ filterValues: currentFilterItems, openFilterItems: currentFilterItems, - hideFilterItems: [], + hiddenFilterItems: [], }); } else if (subgroupItems.length === 1) { const selectFilterItem = { @@ -653,7 +658,7 @@ class FilterInput extends React.Component { this.setState({ filterValues: currentFilterItems, openFilterItems: currentFilterItems, - hideFilterItems: [], + hiddenFilterItems: [], }); } } else { @@ -680,7 +685,7 @@ class FilterInput extends React.Component { this.setState({ filterValues: currentFilterItems, openFilterItems: currentFilterItems, - hideFilterItems: [], + hiddenFilterItems: [], }); const clone = cloneObjectsArray( @@ -724,14 +729,13 @@ class FilterInput extends React.Component { searchText, filterValues, openFilterItems, - hideFilterItems, + hiddenFilterItems, sortId, sortDirection, } = this.state; const smallSectionWidth = sectionWidth ? sectionWidth < 900 : false; - // console.log("filter input render, openFilterItems", openFilterItems, 'hideFilterItems', hideFilterItems); let iconSize = 30; switch (size) { case "base": @@ -775,7 +779,7 @@ class FilterInput extends React.Component { { - const { openFilterItems, hideFilterItems } = this.state; + const { openFilterItems, hiddenFilterItems } = this.state; const _this = this; let result = []; let openItems = []; @@ -373,9 +373,9 @@ class FilterBlock extends React.Component { ); }); } - if (hideFilterItems.length > 0) { + if (hiddenFilterItems.length > 0) { let open = false; - let hideFilterItemsList = hideFilterItems.map(function (item) { + let hideFilterItemsList = hiddenFilterItems.map(function (item) { const { key, group, @@ -416,7 +416,7 @@ class FilterBlock extends React.Component { hideItems.push( @@ -481,7 +481,7 @@ class FilterBlock extends React.Component { } FilterBlock.propTypes = { getFilterData: PropTypes.func, - hideFilterItems: PropTypes.array, + hiddenFilterItems: PropTypes.array, iconSize: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), isDisabled: PropTypes.bool, onDeleteFilterItem: PropTypes.func, From bfecfc31d319c6c3178a48bbd9b444d9b3152d05 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Fri, 13 Nov 2020 10:58:50 +0300 Subject: [PATCH 22/34] web: common: bump version --- web/ASC.Web.Common/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Common/package.json b/web/ASC.Web.Common/package.json index aa3b8a8e21..75e0614b8f 100644 --- a/web/ASC.Web.Common/package.json +++ b/web/ASC.Web.Common/package.json @@ -1,6 +1,6 @@ { "name": "asc-web-common", - "version": "1.0.271", + "version": "1.0.272", "description": "Ascensio System SIA common components and solutions library", "license": "AGPL-3.0", "files": [ From 4b2848d639fa5722bfb1565f310c25a3ad956176 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Mon, 16 Nov 2020 08:10:07 +0300 Subject: [PATCH 23/34] Web: Common: FilterInput: Fixed bug with reset sorting --- .../src/components/FilterInput/FilterInput.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index 3dc54d729d..717f88572d 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -85,6 +85,7 @@ const minWidth = 170; const filterItemPadding = 60; const maxFilterItemWidth = 260; const itemsContainerWidth = 40; +const sectionPaddings = 48; class FilterInput extends React.Component { constructor(props) { @@ -122,8 +123,9 @@ class FilterInput extends React.Component { } componentDidUpdate(prevProps, prevState) { - const { selectedFilterData, sectionWidth } = this.props; + const { selectedFilterData, sectionWidth, getSortData } = this.props; const { filterValues, searchText } = this.state; + const { sortDirection, sortId, inputValue } = selectedFilterData; if ( this.props.needForUpdate && @@ -142,11 +144,19 @@ class FilterInput extends React.Component { if ( (!isEqual(selectedFilterData.filterValues, filterValues) || - selectedFilterData.inputValue !== searchText) && + inputValue !== searchText) && sectionWidth !== prevProps.sectionWidth ) { + const sortData = getSortData(); const filterValues = this.getDefaultFilterData(); this.setState({ + sortDirection: sortDirection === "desc" ? true : false, + sortId: + sortData.findIndex((x) => x.key === sortId) != -1 + ? sortId + : sortData.length > 0 + ? sortData[0].key + : "", filterValues: filterValues, searchText: selectedFilterData.inputValue || "", }); @@ -443,7 +453,7 @@ class FilterInput extends React.Component { .width; const searchWidth = sectionWidth - ? sectionWidth - filterWidth - comboBoxWidth - 48 // 48 - paddings + ? sectionWidth - filterWidth - comboBoxWidth - sectionPaddings : fullWidth - filterWidth; const filterArr = Array.from( From c58d720db2661c973cc133e5312e7dcbf10ba798 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Mon, 16 Nov 2020 09:05:54 +0300 Subject: [PATCH 24/34] web: common: bump version --- web/ASC.Web.Common/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Common/package.json b/web/ASC.Web.Common/package.json index 75e0614b8f..6060a4a6b4 100644 --- a/web/ASC.Web.Common/package.json +++ b/web/ASC.Web.Common/package.json @@ -1,6 +1,6 @@ { "name": "asc-web-common", - "version": "1.0.272", + "version": "1.0.273", "description": "Ascensio System SIA common components and solutions library", "license": "AGPL-3.0", "files": [ From 32e633cee976e91456a9486c259ebd80b746594c Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Tue, 17 Nov 2020 06:29:24 +0300 Subject: [PATCH 25/34] Web: Common: Added HOC withLayoutSize --- web/ASC.Web.Common/src/utils/index.js | 2 ++ web/ASC.Web.Common/src/utils/withLayoutSize.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 web/ASC.Web.Common/src/utils/withLayoutSize.js diff --git a/web/ASC.Web.Common/src/utils/index.js b/web/ASC.Web.Common/src/utils/index.js index e7eafe4697..5e287d558f 100644 --- a/web/ASC.Web.Common/src/utils/index.js +++ b/web/ASC.Web.Common/src/utils/index.js @@ -107,3 +107,5 @@ export function showLoader() { document.body.classList.add("loading"); }, 1000); } + +export { withLayoutSize } from "./withLayoutSize"; diff --git a/web/ASC.Web.Common/src/utils/withLayoutSize.js b/web/ASC.Web.Common/src/utils/withLayoutSize.js new file mode 100644 index 0000000000..3f4ad8e987 --- /dev/null +++ b/web/ASC.Web.Common/src/utils/withLayoutSize.js @@ -0,0 +1,15 @@ +import * as React from "react"; +import { utils } from "asc-web-components"; +const { Consumer } = utils.context; + +export function withLayoutSize(Component) { + return function LayoutSizeComponent(props) { + return ( + + {(context) => { + return ; + }} + + ); + }; +} From e65f2b36c7ee6d22a1ffb145d2238464027e8c9c Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Tue, 17 Nov 2020 06:33:34 +0300 Subject: [PATCH 26/34] Web: Files: Filter: Changed Consumer to HOC --- .../pages/Home/Section/Filter/index.js | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js b/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js index 915835cb77..2c0ad2bf5f 100644 --- a/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js +++ b/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js @@ -16,12 +16,11 @@ import find from "lodash/find"; import result from "lodash/result"; import { withTranslation } from "react-i18next"; import { withRouter } from "react-router"; -import { constants, FilterInput, store, Loaders } from "asc-web-common"; -import { utils } from "asc-web-components"; +import { constants, FilterInput, store, Loaders, utils } from "asc-web-common"; import isEqual from "lodash/isEqual"; import { isMobileOnly } from "react-device-detect"; -const { Consumer } = utils.context; +const { withLayoutSize } = utils; const { getCurrentUser, @@ -290,41 +289,39 @@ class SectionFilterContent extends React.Component { this.props.selectedFolderId !== nextProps.selectedFolderId || this.state.isReady !== nextState.isReady || this.props.viewAs !== nextProps.viewAs || - this.props.firstLoad !== nextProps.firstLoad + this.props.firstLoad !== nextProps.firstLoad || + !isEqual(this.props.context, nextProps.context) ); } render() { console.log("Filter render"); const selectedFilterData = this.getSelectedFilterData(); - const { t, language, firstLoad } = this.props; + const { t, language, firstLoad, context } = this.props; + const { sectionWidth } = context; const filterColumnCount = window.innerWidth < 500 ? {} : { filterColumnCount: 3 }; return firstLoad ? ( ) : ( - - {(context) => ( - - )} - + ); } } @@ -346,4 +343,4 @@ export default connect(mapStateToProps, { fetchFiles, setViewAs, setIsLoading, -})(withRouter(withTranslation()(SectionFilterContent))); +})(withRouter(withLayoutSize(withTranslation()(SectionFilterContent)))); From 99ae4dba203884cf82d6d616d69eaa94a94d4e18 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Tue, 17 Nov 2020 06:39:08 +0300 Subject: [PATCH 27/34] Web: People: Changed Consumer to HOC --- .../pages/Home/Section/Filter/index.js | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js index 2dcb467957..fc455c643e 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js @@ -6,8 +6,7 @@ import result from "lodash/result"; import { withTranslation } from "react-i18next"; import { withRouter } from "react-router"; import { getFilterByLocation } from "../../../../../helpers/converters"; -import { store, FilterInput, Loaders } from "asc-web-common"; -import { utils } from "asc-web-components"; +import { store, FilterInput, Loaders, utils } from "asc-web-common"; import { isMobileOnly } from "react-device-detect"; import { getFilter, getGroups } from "../../../../../store/people/selectors"; const { @@ -18,7 +17,7 @@ const { getIsLoaded, } = store.auth.selectors; -const { Consumer } = utils.context; +const { withLayoutSize } = utils; const getEmployeeStatus = (filterValues) => { const employeeStatus = result( @@ -251,26 +250,23 @@ class SectionFilterContent extends React.Component { render() { const selectedFilterData = this.getSelectedFilterData(); - const { t, language, isLoaded } = this.props; + const { t, language, isLoaded, context } = this.props; + const { sectionWidth } = context; return isLoaded ? ( - - {(context) => ( - - )} - + ) : ( ); @@ -290,5 +286,5 @@ function mapStateToProps(state) { } export default connect(mapStateToProps, { fetchPeople })( - withRouter(withTranslation()(SectionFilterContent)) + withRouter(withLayoutSize(withTranslation()(SectionFilterContent))) ); From 8db2b5b3d0dd9452bd33c9346f448d28b87a0d95 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Tue, 17 Nov 2020 08:05:47 +0300 Subject: [PATCH 28/34] Web: Common: Code cleaning --- .../src/components/FilterInput/FilterInput.js | 12 ++++++------ .../FilterInput/sub-components/FilterBlock.js | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js index 717f88572d..4b3d1cd4c8 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js +++ b/web/ASC.Web.Common/src/components/FilterInput/FilterInput.js @@ -2,7 +2,6 @@ import React from "react"; import PropTypes from "prop-types"; import { SearchInput } from "asc-web-components"; import isEqual from "lodash/isEqual"; -import throttle from "lodash/throttle"; import FilterBlock from "./sub-components/FilterBlock"; import SortComboBox from "./sub-components/SortComboBox"; import ViewSelector from "./sub-components/ViewSelector"; @@ -327,7 +326,6 @@ class FilterInput extends React.Component { return filterItems; }; getFilterData = () => { - const _this = this; const d = this.props.getFilterData(); const result = []; d.forEach((element) => { @@ -386,7 +384,7 @@ class FilterInput extends React.Component { return itemWidth; }; - AddItems = (searchWidth) => { + addItems = (searchWidth) => { const { hiddenFilterItems } = this.state; if (hiddenFilterItems.length === 0) return 0; @@ -409,7 +407,7 @@ class FilterInput extends React.Component { return numberOfHiddenItems; }; - HideItems = (searchWidth, currentFilterItems) => { + hideItems = (searchWidth, currentFilterItems) => { const { hiddenFilterItems } = this.state; let newSearchWidth = searchWidth; let numberOfHiddenItems = hiddenFilterItems.length; @@ -435,8 +433,8 @@ class FilterInput extends React.Component { return hiddenFilterItems.length; const numberOfHiddenItems = searchWidth < minWidth - ? this.HideItems(searchWidth, currentFilterItems) - : this.AddItems(searchWidth); + ? this.hideItems(searchWidth, currentFilterItems) + : this.addItems(searchWidth); return numberOfHiddenItems; }; @@ -848,6 +846,8 @@ FilterInput.protoTypes = { onChangeViewAs: PropTypes.func, contextMenuHeader: PropTypes.string, sectionWidth: PropTypes.number, + getSortData: PropTypes.func, + value: PropTypes.string, }; FilterInput.defaultProps = { diff --git a/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js b/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js index 2b48810e1d..e2e63f315b 100644 --- a/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js +++ b/web/ASC.Web.Common/src/components/FilterInput/sub-components/FilterBlock.js @@ -49,7 +49,6 @@ class FilterItem extends React.Component { if ( selectedItem && selectedItem.key !== this.state.selectedOption.key && - selectedItem.key !== this.state.selectedOption.key && selectedItem.key !== prevProps.selectedItem.key ) { const selectedOption = selectedItem.key From ee26c7c1481c12401d545e32f663635376e877f2 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Tue, 17 Nov 2020 08:11:11 +0300 Subject: [PATCH 29/34] web: common: bump version --- web/ASC.Web.Common/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Common/package.json b/web/ASC.Web.Common/package.json index 6060a4a6b4..b248c4ecbe 100644 --- a/web/ASC.Web.Common/package.json +++ b/web/ASC.Web.Common/package.json @@ -1,6 +1,6 @@ { "name": "asc-web-common", - "version": "1.0.273", + "version": "1.0.274", "description": "Ascensio System SIA common components and solutions library", "license": "AGPL-3.0", "files": [ From 3702bd597db42450d66451b064354747a18386f3 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Tue, 17 Nov 2020 10:32:02 +0300 Subject: [PATCH 30/34] Web: Common: Refactoring HOC withLayoutSize --- .../Client/src/components/pages/Home/Section/Filter/index.js | 5 ++--- .../Client/src/components/pages/Home/Section/Filter/index.js | 3 +-- web/ASC.Web.Common/src/utils/withLayoutSize.js | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js b/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js index 2c0ad2bf5f..7f7ceee278 100644 --- a/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js +++ b/products/ASC.Files/Client/src/components/pages/Home/Section/Filter/index.js @@ -290,15 +290,14 @@ class SectionFilterContent extends React.Component { this.state.isReady !== nextState.isReady || this.props.viewAs !== nextProps.viewAs || this.props.firstLoad !== nextProps.firstLoad || - !isEqual(this.props.context, nextProps.context) + this.props.sectionWidth !== nextProps.sectionWidth ); } render() { console.log("Filter render"); const selectedFilterData = this.getSelectedFilterData(); - const { t, language, firstLoad, context } = this.props; - const { sectionWidth } = context; + const { t, language, firstLoad, sectionWidth } = this.props; const filterColumnCount = window.innerWidth < 500 ? {} : { filterColumnCount: 3 }; return firstLoad ? ( diff --git a/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js b/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js index fc455c643e..0d07aebd86 100644 --- a/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js +++ b/products/ASC.People/Client/src/components/pages/Home/Section/Filter/index.js @@ -250,8 +250,7 @@ class SectionFilterContent extends React.Component { render() { const selectedFilterData = this.getSelectedFilterData(); - const { t, language, isLoaded, context } = this.props; - const { sectionWidth } = context; + const { t, language, isLoaded, sectionWidth } = this.props; return isLoaded ? ( {(context) => { - return ; + return ; }} ); From a46806ae24b0ecb4f2d24b968aef2d18ced93920 Mon Sep 17 00:00:00 2001 From: Alexey Kostenko Date: Tue, 17 Nov 2020 10:32:14 +0300 Subject: [PATCH 31/34] web: common: bump version --- web/ASC.Web.Common/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ASC.Web.Common/package.json b/web/ASC.Web.Common/package.json index b248c4ecbe..b3ce27bf1e 100644 --- a/web/ASC.Web.Common/package.json +++ b/web/ASC.Web.Common/package.json @@ -1,6 +1,6 @@ { "name": "asc-web-common", - "version": "1.0.274", + "version": "1.0.275", "description": "Ascensio System SIA common components and solutions library", "license": "AGPL-3.0", "files": [ From 6cb92946beca86182fe78dba4d860d50a2728857 Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Tue, 17 Nov 2020 18:01:34 +0300 Subject: [PATCH 32/34] fix uploadmemberphoto --- .../Server/Controllers/PeopleController.cs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/products/ASC.People/Server/Controllers/PeopleController.cs b/products/ASC.People/Server/Controllers/PeopleController.cs index a01ad413b2..8e463d526a 100644 --- a/products/ASC.People/Server/Controllers/PeopleController.cs +++ b/products/ASC.People/Server/Controllers/PeopleController.cs @@ -864,21 +864,8 @@ namespace ASC.Employee.Core.Controllers return new ThumbnailsDataWrapper(user.ID, UserPhotoManager); } - [Create("{userid}/photo")] - public FileUploadResult UploadMemberPhotoFromBody(string userid, [FromBody]IFormCollection model) - { - return UploadMemberPhoto(userid, model); - } - - [Create("{userid}/photo")] - [Consumes("application/x-www-form-urlencoded")] - public FileUploadResult UploadMemberPhotoFromForm(string userid, [FromForm] IFormCollection model) - { - return UploadMemberPhoto(userid, model); - } - - private FileUploadResult UploadMemberPhoto(string userid, IFormCollection model) + public FileUploadResult UploadMemberPhoto(string userid, IFormCollection model) { var result = new People.Models.FileUploadResult(); var autosave = bool.Parse(model["Autosave"]); From 0c520416fa32f9535be3df86bad68a733f9bc14c Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Tue, 17 Nov 2020 21:17:23 +0300 Subject: [PATCH 33/34] Files: remove cache --- .../Core/Core/Dao/Interfaces/IProviderDao.cs | 2 +- .../Core/Core/Thirdparty/Box/BoxDaoBase.cs | 2 +- .../Core/Thirdparty/Box/BoxProviderInfo.cs | 4 +- .../Thirdparty/CachedProviderAccountDao.cs | 125 ------------------ .../Core/Thirdparty/Dropbox/DropboxDaoBase.cs | 2 +- .../Thirdparty/Dropbox/DropboxProviderInfo.cs | 4 +- .../GoogleDrive/GoogleDriveDaoBase.cs | 2 +- .../GoogleDrive/GoogleDriveProviderInfo.cs | 4 +- .../Core/Thirdparty/IThirdPartyProviderDao.cs | 10 +- .../Thirdparty/OneDrive/OneDriveDaoBase.cs | 2 +- .../OneDrive/OneDriveProviderInfo.cs | 4 +- .../Core/Thirdparty/RegexDaoSelectorBase.cs | 2 +- .../SharePoint/SharePointDaoBase.cs | 2 +- .../Thirdparty/Sharpbox/SharpBoxDaoBase.cs | 2 +- 14 files changed, 21 insertions(+), 146 deletions(-) delete mode 100644 products/ASC.Files/Core/Core/Thirdparty/CachedProviderAccountDao.cs diff --git a/products/ASC.Files/Core/Core/Dao/Interfaces/IProviderDao.cs b/products/ASC.Files/Core/Core/Dao/Interfaces/IProviderDao.cs index 2a21eca0f8..008687347c 100644 --- a/products/ASC.Files/Core/Core/Dao/Interfaces/IProviderDao.cs +++ b/products/ASC.Files/Core/Core/Dao/Interfaces/IProviderDao.cs @@ -32,7 +32,7 @@ using ASC.Files.Thirdparty; namespace ASC.Files.Core { - [Scope(typeof(CachedProviderAccountDao), Additional = typeof(ProviderAccountDaoExtension))] + [Scope(typeof(ProviderAccountDao), Additional = typeof(ProviderAccountDaoExtension))] public interface IProviderDao { IProviderInfo GetProviderInfo(int linkId); diff --git a/products/ASC.Files/Core/Core/Thirdparty/Box/BoxDaoBase.cs b/products/ASC.Files/Core/Core/Thirdparty/Box/BoxDaoBase.cs index e0953a095b..ba0aff47b2 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/Box/BoxDaoBase.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/Box/BoxDaoBase.cs @@ -48,7 +48,7 @@ namespace ASC.Files.Thirdparty.Box { internal abstract class BoxDaoBase : ThirdPartyProviderDao { - public override string Id { get => "box"; } + protected override string Id { get => "box"; } public BoxDaoBase( IServiceProvider serviceProvider, diff --git a/products/ASC.Files/Core/Core/Thirdparty/Box/BoxProviderInfo.cs b/products/ASC.Files/Core/Core/Thirdparty/Box/BoxProviderInfo.cs index 819d4183da..ad28353120 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/Box/BoxProviderInfo.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/Box/BoxProviderInfo.cs @@ -183,7 +183,7 @@ namespace ASC.Files.Thirdparty.Box internal BoxStorage CreateStorage(OAuth20Token token, int id) { - if (Storage != null) return Storage; + if (Storage != null && Storage.IsOpened) return Storage; var boxStorage = new BoxStorage(); CheckToken(token, id); @@ -199,7 +199,7 @@ namespace ASC.Files.Thirdparty.Box { token = OAuth20TokenHelper.RefreshToken(ConsumerFactory, token); - var dbDao = ServiceProvider.GetService(); + var dbDao = ServiceProvider.GetService(); dbDao.UpdateProviderInfo(id, new AuthData(token: token.ToJson())); } } diff --git a/products/ASC.Files/Core/Core/Thirdparty/CachedProviderAccountDao.cs b/products/ASC.Files/Core/Core/Thirdparty/CachedProviderAccountDao.cs deleted file mode 100644 index da4083507f..0000000000 --- a/products/ASC.Files/Core/Core/Thirdparty/CachedProviderAccountDao.cs +++ /dev/null @@ -1,125 +0,0 @@ -/* - * - * (c) Copyright Ascensio System Limited 2010-2018 - * - * This program is freeware. You can redistribute it and/or modify it under the terms of the GNU - * General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html). - * In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that - * Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights. - * - * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR - * FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html - * - * You can contact Ascensio System SIA by email at sales@onlyoffice.com - * - * The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display - * Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3. - * - * Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains - * relevant author attributions when distributing the software. If the display of the logo in its graphic - * form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE" - * in every copy of the program you distribute. - * Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks. - * -*/ - - -using System; -using System.Collections.Concurrent; -using System.Globalization; - -using ASC.Common; -using ASC.Common.Caching; -using ASC.Common.Logging; -using ASC.Core; -using ASC.Core.Common.Configuration; -using ASC.Core.Common.EF; -using ASC.Core.Tenants; -using ASC.Files.Core; -using ASC.Files.Core.EF; -using ASC.Security.Cryptography; - -using Microsoft.Extensions.Options; - -namespace ASC.Files.Thirdparty -{ - [Singletone] - internal class CachedProviderAccountDaoNotify - { - public ConcurrentDictionary Cache { get; private set; } - internal ICacheNotify CacheNotify { get; set; } - - public CachedProviderAccountDaoNotify(ICacheNotify cacheNotify) - { - Cache = new ConcurrentDictionary(); - CacheNotify = cacheNotify; - cacheNotify.Subscribe((i) => RemoveFromCache(i.Key), CacheNotifyAction.Any); - } - private void RemoveFromCache(string key) - { - Cache.TryRemove(key, out _); - } - } - - [Scope] - internal class CachedProviderAccountDao : ProviderAccountDao - { - private readonly ConcurrentDictionary cache; - private readonly ICacheNotify cacheNotify; - - private string _rootKey { get => TenantID.ToString(CultureInfo.InvariantCulture); } - - public CachedProviderAccountDao( - IServiceProvider serviceProvider, - TenantUtil tenantUtil, - TenantManager tenantManager, - InstanceCrypto instanceCrypto, - SecurityContext securityContext, - ConsumerFactory consumerFactory, - DbContextManager dbContextManager, - IOptionsMonitor options, - CachedProviderAccountDaoNotify cachedProviderAccountDaoNotify) - : base(serviceProvider, tenantUtil, tenantManager, instanceCrypto, securityContext, consumerFactory, dbContextManager, options) - { - cache = cachedProviderAccountDaoNotify.Cache; - cacheNotify = cachedProviderAccountDaoNotify.CacheNotify; - } - - public override IProviderInfo GetProviderInfo(int linkId) - { - var key = _rootKey + linkId.ToString(CultureInfo.InvariantCulture); - if (!cache.TryGetValue(key, out var value)) - { - value = base.GetProviderInfo(linkId); - cache.TryAdd(key, value); - } - return value; - } - - public override void RemoveProviderInfo(int linkId) - { - base.RemoveProviderInfo(linkId); - - var key = _rootKey + linkId.ToString(CultureInfo.InvariantCulture); - cacheNotify.Publish(new ProviderAccountCacheItem { Key = key }, CacheNotifyAction.Any); - } - - public override int UpdateProviderInfo(int linkId, string customerTitle, AuthData authData, FolderType folderType, Guid? userId = null) - { - var result = base.UpdateProviderInfo(linkId, customerTitle, authData, folderType, userId); - - var key = _rootKey + linkId.ToString(CultureInfo.InvariantCulture); - cacheNotify.Publish(new ProviderAccountCacheItem { Key = key }, CacheNotifyAction.Any); - return result; - } - - public override int UpdateProviderInfo(int linkId, AuthData authData) - { - var result = base.UpdateProviderInfo(linkId, authData); - - var key = _rootKey + linkId.ToString(CultureInfo.InvariantCulture); - cacheNotify.Publish(new ProviderAccountCacheItem { Key = key }, CacheNotifyAction.Any); - return result; - } - } -} \ No newline at end of file diff --git a/products/ASC.Files/Core/Core/Thirdparty/Dropbox/DropboxDaoBase.cs b/products/ASC.Files/Core/Core/Thirdparty/Dropbox/DropboxDaoBase.cs index 888d1abac1..d2ac60aa2a 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/Dropbox/DropboxDaoBase.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/Dropbox/DropboxDaoBase.cs @@ -48,7 +48,7 @@ namespace ASC.Files.Thirdparty.Dropbox { internal abstract class DropboxDaoBase : ThirdPartyProviderDao { - public override string Id { get => "dropbox"; } + protected override string Id { get => "dropbox"; } public DropboxDaoBase(IServiceProvider serviceProvider, UserManager userManager, TenantManager tenantManager, TenantUtil tenantUtil, DbContextManager dbContextManager, SetupInfo setupInfo, IOptionsMonitor monitor, FileUtility fileUtility) : base(serviceProvider, userManager, tenantManager, tenantUtil, dbContextManager, setupInfo, monitor, fileUtility) { diff --git a/products/ASC.Files/Core/Core/Thirdparty/Dropbox/DropboxProviderInfo.cs b/products/ASC.Files/Core/Core/Thirdparty/Dropbox/DropboxProviderInfo.cs index bfac801b62..368df65d88 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/Dropbox/DropboxProviderInfo.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/Dropbox/DropboxProviderInfo.cs @@ -161,8 +161,8 @@ namespace ASC.Files.Thirdparty.Dropbox } public DropboxStorage CreateStorage(OAuth20Token token) - { - if (Storage != null) return Storage; + { + if (Storage != null && Storage.IsOpened) return Storage; var dropboxStorage = new DropboxStorage(); dropboxStorage.Open(token); diff --git a/products/ASC.Files/Core/Core/Thirdparty/GoogleDrive/GoogleDriveDaoBase.cs b/products/ASC.Files/Core/Core/Thirdparty/GoogleDrive/GoogleDriveDaoBase.cs index 11d54a316f..77d0a5b968 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/GoogleDrive/GoogleDriveDaoBase.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/GoogleDrive/GoogleDriveDaoBase.cs @@ -49,7 +49,7 @@ namespace ASC.Files.Thirdparty.GoogleDrive { internal abstract class GoogleDriveDaoBase : ThirdPartyProviderDao { - public override string Id { get => "drive"; } + protected override string Id { get => "drive"; } public GoogleDriveDaoBase(IServiceProvider serviceProvider, UserManager userManager, TenantManager tenantManager, TenantUtil tenantUtil, DbContextManager dbContextManager, SetupInfo setupInfo, IOptionsMonitor monitor, FileUtility fileUtility) : base(serviceProvider, userManager, tenantManager, tenantUtil, dbContextManager, setupInfo, monitor, fileUtility) { diff --git a/products/ASC.Files/Core/Core/Thirdparty/GoogleDrive/GoogleDriveProviderInfo.cs b/products/ASC.Files/Core/Core/Thirdparty/GoogleDrive/GoogleDriveProviderInfo.cs index 461a785438..47bf67ef0b 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/GoogleDrive/GoogleDriveProviderInfo.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/GoogleDrive/GoogleDriveProviderInfo.cs @@ -196,7 +196,7 @@ namespace ASC.Files.Thirdparty.GoogleDrive public GoogleDriveStorage CreateStorage(OAuth20Token token, int id) { - if (Storage != null) return Storage; + if (Storage != null && Storage.IsOpened) return Storage; var driveStorage = ServiceProvider.GetService(); @@ -213,7 +213,7 @@ namespace ASC.Files.Thirdparty.GoogleDrive { token = OAuth20TokenHelper.RefreshToken(ConsumerFactory, token); - var dbDao = ServiceProvider.GetService(); + var dbDao = ServiceProvider.GetService(); var authData = new AuthData(token: token.ToJson()); dbDao.UpdateProviderInfo(id, authData); } diff --git a/products/ASC.Files/Core/Core/Thirdparty/IThirdPartyProviderDao.cs b/products/ASC.Files/Core/Core/Thirdparty/IThirdPartyProviderDao.cs index 38181f5612..be951557cb 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/IThirdPartyProviderDao.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/IThirdPartyProviderDao.cs @@ -28,14 +28,14 @@ namespace ASC.Files.Thirdparty protected TenantUtil TenantUtil { get; } protected FilesDbContext FilesDbContext { get; } protected SetupInfo SetupInfo { get; } - public ILog Log { get; } + protected ILog Log { get; } protected FileUtility FileUtility { get; } - public RegexDaoSelectorBase DaoSelector { get; set; } - public T ProviderInfo { get; set; } - public string PathPrefix { get; private set; } + protected RegexDaoSelectorBase DaoSelector { get; set; } + protected T ProviderInfo { get; set; } + protected string PathPrefix { get; private set; } - public abstract string Id { get; } + protected abstract string Id { get; } public ThirdPartyProviderDao( IServiceProvider serviceProvider, diff --git a/products/ASC.Files/Core/Core/Thirdparty/OneDrive/OneDriveDaoBase.cs b/products/ASC.Files/Core/Core/Thirdparty/OneDrive/OneDriveDaoBase.cs index 9698273698..fcddaf924f 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/OneDrive/OneDriveDaoBase.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/OneDrive/OneDriveDaoBase.cs @@ -47,7 +47,7 @@ namespace ASC.Files.Thirdparty.OneDrive { internal abstract class OneDriveDaoBase : ThirdPartyProviderDao { - public override string Id { get => "onedrive"; } + protected override string Id { get => "onedrive"; } public OneDriveDaoBase(IServiceProvider serviceProvider, UserManager userManager, TenantManager tenantManager, TenantUtil tenantUtil, DbContextManager dbContextManager, SetupInfo setupInfo, IOptionsMonitor monitor, FileUtility fileUtility) : base(serviceProvider, userManager, tenantManager, tenantUtil, dbContextManager, setupInfo, monitor, fileUtility) { diff --git a/products/ASC.Files/Core/Core/Thirdparty/OneDrive/OneDriveProviderInfo.cs b/products/ASC.Files/Core/Core/Thirdparty/OneDrive/OneDriveProviderInfo.cs index 99b46face7..4bb20ddb83 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/OneDrive/OneDriveProviderInfo.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/OneDrive/OneDriveProviderInfo.cs @@ -157,7 +157,7 @@ namespace ASC.Files.Thirdparty.OneDrive public OneDriveStorage CreateStorage(OAuth20Token token, int id) { - if (Storage != null) return Storage; + if (Storage != null && Storage.IsOpened) return Storage; var onedriveStorage = ServiceProvider.GetService(); @@ -174,7 +174,7 @@ namespace ASC.Files.Thirdparty.OneDrive { token = OAuth20TokenHelper.RefreshToken(ConsumerFactory, token); - var dbDao = ServiceProvider.GetService(); + var dbDao = ServiceProvider.GetService(); var authData = new AuthData(token: token.ToJson()); dbDao.UpdateProviderInfo(id, authData); } diff --git a/products/ASC.Files/Core/Core/Thirdparty/RegexDaoSelectorBase.cs b/products/ASC.Files/Core/Core/Thirdparty/RegexDaoSelectorBase.cs index b25676a8aa..db31f4fee5 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/RegexDaoSelectorBase.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/RegexDaoSelectorBase.cs @@ -149,7 +149,7 @@ namespace ASC.Files.Thirdparty public void RenameProvider(T provider, string newTitle) { - var dbDao = ServiceProvider.GetService(); + var dbDao = ServiceProvider.GetService(); dbDao.UpdateProviderInfo(provider.ID, newTitle, null, provider.RootFolderType); provider.UpdateTitle(newTitle); //This will update cached version too } diff --git a/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointDaoBase.cs b/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointDaoBase.cs index 1cff9c77e3..6d17d8b18e 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointDaoBase.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointDaoBase.cs @@ -44,7 +44,7 @@ namespace ASC.Files.Thirdparty.SharePoint { internal class SharePointDaoBase : ThirdPartyProviderDao { - public override string Id { get => "spoint"; } + protected override string Id { get => "spoint"; } public SharePointDaoBase(IServiceProvider serviceProvider, UserManager userManager, TenantManager tenantManager, TenantUtil tenantUtil, DbContextManager dbContextManager, SetupInfo setupInfo, IOptionsMonitor monitor, FileUtility fileUtility) : base(serviceProvider, userManager, tenantManager, tenantUtil, dbContextManager, setupInfo, monitor, fileUtility) { diff --git a/products/ASC.Files/Core/Core/Thirdparty/Sharpbox/SharpBoxDaoBase.cs b/products/ASC.Files/Core/Core/Thirdparty/Sharpbox/SharpBoxDaoBase.cs index 7f9f88d615..acdaae34c6 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/Sharpbox/SharpBoxDaoBase.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/Sharpbox/SharpBoxDaoBase.cs @@ -50,7 +50,7 @@ namespace ASC.Files.Thirdparty.Sharpbox { internal abstract class SharpBoxDaoBase : ThirdPartyProviderDao { - public override string Id { get => "sbox"; } + protected override string Id { get => "sbox"; } public SharpBoxDaoBase(IServiceProvider serviceProvider, UserManager userManager, TenantManager tenantManager, TenantUtil tenantUtil, DbContextManager dbContextManager, SetupInfo setupInfo, IOptionsMonitor monitor, FileUtility fileUtility) : base(serviceProvider, userManager, tenantManager, tenantUtil, dbContextManager, setupInfo, monitor, fileUtility) { From 20d37596cf960d7a0b837a6883382944ee850330 Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Tue, 17 Nov 2020 22:36:27 +0300 Subject: [PATCH 34/34] Files: fix share --- products/ASC.Files/Core/Core/EF/DbFilesThirdpartyIdMapping.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/products/ASC.Files/Core/Core/EF/DbFilesThirdpartyIdMapping.cs b/products/ASC.Files/Core/Core/EF/DbFilesThirdpartyIdMapping.cs index 0e3bc069b7..e870febd40 100644 --- a/products/ASC.Files/Core/Core/EF/DbFilesThirdpartyIdMapping.cs +++ b/products/ASC.Files/Core/Core/EF/DbFilesThirdpartyIdMapping.cs @@ -19,7 +19,7 @@ namespace ASC.Files.Core.EF public override object[] GetKeys() { - return new object[] { Id }; + return new object[] { HashId }; } }