Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into release/2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek committed Sep 8, 2023
2 parents e39ae17 + e750740 commit 473623f
Show file tree
Hide file tree
Showing 24 changed files with 267 additions and 221 deletions.
4 changes: 2 additions & 2 deletions assets/agenda/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ const isBetweenDay = (day: moment.Moment, start: moment.Moment, end: moment.Mome
return day.isSameOrAfter(start) && testDay.isSameOrBefore(endDate);
}

return day.isBetween(startDate, endDate, 'day', '[]');
return testDay.isBetween(startDate, endDate, 'day', '[]');
};

/**
Expand Down Expand Up @@ -757,7 +757,7 @@ export function groupItems(items: any, activeDate: any, activeGrouping: any, fea
}

let key = null;
end = moment.min(end, minStart.clone().add(10, 'd')); // show each event for 10 days max not to destroy the UI
end = moment.min(end, start.clone().add(10, 'd')); // show each event for 10 days max not to destroy the UI

// use clone otherwise it would modify start and potentially also maxStart, moments are mutable
for (const day = start.clone(); day.isSameOrBefore(end, 'day'); day.add(1, 'd')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import React, {useState} from 'react';
import PropTypes from 'prop-types';

export function FormSection({name, testId, children}) {
const [opened, setOpened] = useState(name == null);
interface IProps {
initiallyOpen?: boolean;
name: string;
dataTestId?: string;
children: JSX.Element;
}

export function FormSection({initiallyOpen, name, children, dataTestId}: IProps) {
const [opened, setOpened] = useState(initiallyOpen ?? name == null);

return (
<div className="nh-flex__column" data-test-id={testId}>
<div className="nh-flex__column" data-test-id={dataTestId}>
<div
className="list-item__preview-collapsible"
data-test-id="toggle-btn"
Expand All @@ -26,9 +32,3 @@ export function FormSection({name, testId, children}) {
</div>
);
}

FormSection.propTypes = {
name: PropTypes.string.isRequired,
testId: PropTypes.string,
children: PropTypes.node,
};
131 changes: 69 additions & 62 deletions assets/home/components/HomeApp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import {connect} from 'react-redux';
import {gettext, isDisplayed, isMobilePhone} from 'utils';
import {getConfig, gettext, isDisplayed, isMobilePhone} from 'utils';
import {get} from 'lodash';
import {getCard} from 'components/cards/utils';
import getItemActions from 'wire/item-actions';
Expand All @@ -22,6 +22,8 @@ import {getCurrentUser} from 'company-admin/selectors';
import {IPersonalizedDashboardsWithData} from 'home/reducers';
import {ITopic} from 'interfaces/topic';

export const WIRE_SECTION = 'wire';

const modals: any = {
shareItem: ShareItemModal,
downloadItems: DownloadItemsModal,
Expand Down Expand Up @@ -61,6 +63,7 @@ interface IProps {
filterGroupLabels: any;
currentUser: any;
fetchItems: () => any;
userSections: any;
}

class HomeApp extends React.Component<IProps, IState> {
Expand Down Expand Up @@ -230,6 +233,7 @@ class HomeApp extends React.Component<IProps, IState> {

renderContent(children?: any): any {
const {cards} = this.props;
const isWireSectionConfigured = this.props.userSections[WIRE_SECTION] != null;

return (
<React.Fragment>
Expand All @@ -243,67 +247,69 @@ class HomeApp extends React.Component<IProps, IState> {
ref={(elem: any) => this.elem = elem}
>
<div className="container-fluid">
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: 8,
}}
>
{
!this.hasPersonalDashboard ? (
<div className="home-tools">
<button
onClick={() => {
this.props.personalizeHome();
}}
type="button"
className="nh-button nh-button--secondary nh-button--small"
title={gettext('Personalize Home')}
>
{gettext('Personalize Home')}
</button>
</div>
) : (

<div className="home-tools">
<RadioButtonGroup
size='small'
options={[
{
_id: 'default',
name: gettext('Default')
},
{
_id: 'my-home',
name: gettext('My home')
},
]}
activeOptionId={this.state.activeOptionId}
switchOptions={(optionId) => {
if (optionId === 'default' || optionId === 'my-home') {
this.setState({
activeOptionId: optionId
});
}
}}
/>
<button
onClick={() => {
this.props.personalizeHome();
}}
type="button"
className="icon-button icon-button--small icon-button--tertiary icon-button--bordered"
title={gettext('Edit personal Home')}
>
<i className="icon--settings"></i>
</button>
</div>

)
}
</div>
{
isWireSectionConfigured && (
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: 8,
}}
>
{
!this.hasPersonalDashboard ? (
<div className="home-tools">
<button
onClick={() => {
this.props.personalizeHome();
}}
type="button"
className="nh-button nh-button--secondary nh-button--small"
title={gettext('Personalize Home')}
>
{gettext('Personalize Home')}
</button>
</div>
) : (
<div className="home-tools">
<RadioButtonGroup
size='small'
options={[
{
_id: 'default',
name: gettext('Default')
},
{
_id: 'my-home',
name: gettext('My home')
},
]}
activeOptionId={this.state.activeOptionId}
switchOptions={(optionId) => {
if (optionId === 'default' || optionId === 'my-home') {
this.setState({
activeOptionId: optionId
});
}
}}
/>
<button
onClick={() => {
this.props.personalizeHome();
}}
type="button"
className="icon-button icon-button--small icon-button--tertiary icon-button--bordered"
title={gettext('Edit personal Home')}
>
<i className="icon--settings"></i>
</button>
</div>
)
}
</div>
)
}
{
this.props.modal?.modal === 'personalizeHome' && (
<PersonalizeHomeSettingsModal
Expand Down Expand Up @@ -396,6 +402,7 @@ const mapStateToProps = (state: any) => ({
products: state.products,
user: state.user,
userType: state.userType,
userSections: state.userSections,
company: state.company,
itemToOpen: state.itemToOpen,
modal: state.modal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function SearchResultsTopicRow({
);
}

if (get(searchParams, 'navigation.length', 0)) {
if ((searchParams.navigation?.length ?? 0) > 0 && (Object.keys(navigations ?? []).length > 0)) {
searchParams.navigation.forEach((navId) => {
const navigation = navigations[navId];

Expand Down
44 changes: 28 additions & 16 deletions assets/search/components/SearchResultsBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,35 @@ import NewItemsIcon from '../NewItemsIcon';


class SearchResultsBarComponent extends React.Component<any, any> {
sortValues = [
{
label: gettext('Date (Newest)'),
sortFunction: () => this.setSortQuery('versioncreated:desc'),
},
{
label: gettext('Date (Oldest)'),
sortFunction: () => this.setSortQuery('versioncreated:asc'),
},
{
label: gettext('Relevance'),
sortFunction: () => this.setSortQuery('_score'),
},
];
private sortValues: Array<{label: string; sortFunction: () => void;}>;
private topicNotNull: boolean;

static propTypes: any;
static defaultProps: any;
constructor(props: any) {
super(props);

const urlParams = new URLSearchParams(window.location.search);
this.topicNotNull = new URLSearchParams(window.location.search).get('topic') != null;
this.sortValues = [
{
label: gettext('Date (Newest)'),
sortFunction: () => this.setSortQuery('versioncreated:desc'),
},
{
label: gettext('Date (Oldest)'),
sortFunction: () => this.setSortQuery('versioncreated:asc'),
},
{
label: gettext('Relevance'),
sortFunction: () => this.setSortQuery('_score'),
},
];

this.state = {
isTagSectionShown: urlParams.get('topic') != null,
isTagSectionShown: this.props.initiallyOpen || this.topicNotNull,
sortValue: this.sortValues[0].label,
};

this.toggleTagSection = this.toggleTagSection.bind(this);
this.toggleNavigation = this.toggleNavigation.bind(this);
this.setQuery = this.setQuery.bind(this);
Expand All @@ -63,6 +66,14 @@ class SearchResultsBarComponent extends React.Component<any, any> {
this.resetFilter = this.resetFilter.bind(this);
}

componentDidUpdate(prevProps: any): void {
if (prevProps.initiallyOpen != this.props.initiallyOpen) {
this.setState({
isTagSectionShown: this.props.initiallyOpen || this.topicNotNull,
});
}
}

toggleTagSection() {
this.setState((prevState: any) => ({isTagSectionShown: !prevState.isTagSectionShown}));
}
Expand Down Expand Up @@ -224,6 +235,7 @@ class SearchResultsBarComponent extends React.Component<any, any> {

SearchResultsBarComponent.propTypes = {
user: PropTypes.object,
initiallyOpen: PropTypes.bool,

minimizeSearchResults: PropTypes.bool,
showTotalItems: PropTypes.bool,
Expand Down
Loading

0 comments on commit 473623f

Please sign in to comment.