Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add license expiration date to UI #147

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/components/DatePanel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
*
* Copyright 2018 Odysseus Data Services, inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Company: Odysseus Data Services, Inc.
* Product Owner/Architecture: Gregory Klebanov
* Authors: Pavel Grafkin, Alexander Saltykov, Vitaly Koulakov, Anton Gackovka, Alexandr Ryabokon, Mikhail Mironov
* Created: July 25, 2017
*
*/

import DatePanel from './presenter';

export default DatePanel;
96 changes: 96 additions & 0 deletions src/components/DatePanel/presenter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
*
* Copyright 2018 Odysseus Data Services, inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Company: Odysseus Data Services, Inc.
* Product Owner/Architecture: Gregory Klebanov
* Authors: Pavel Grafkin, Alexander Saltykov, Vitaly Koulakov, Anton Gackovka, Alexandr Ryabokon, Mikhail Mironov
* Created: July 25, 2017
*
*/

import React, { Component, PropTypes } from "react";
import BEMHelper from "services/BemHelper";
import { Datepicker } from "arachne-ui-components";
import * as moment from "moment";

require("./style.scss");

// NOTE: Datepicker requires DateInput to be a class
/**
* @param {any} options.className
* @param {string} options.value Value passed by datepicker.
* @param {string} options.displayValue Value passed by parent component.
* @param {function} options.onClick Function that should be called to open datepicker.
*/
class DateInput extends Component {
render() {
const classes = new BEMHelper("study-date-input");
const { className, displayValue, onClick } = this.props;

// NOTE:
// We should be able to render custom caption (e.g., 'Empty'),
// that's why we cannot use value passed by datepicker which is always a date
return (
<span {...classes({ extra: className })} onClick={onClick}>
<span {...classes("ico")}>
<span {...classes({ element: "icon", extra: `${className}--disabled` })}>date_range</span>
</span>
<span {...classes("value")}>{displayValue}</span>
</span>
);
}
}

DateInput.propTypes = {
className: PropTypes.any,
displayValue: PropTypes.string.isRequired,
onClick: PropTypes.func,
};

function DatePanel({ title, selected, dateFormat, minDate, maxDate, isEditable, onChange, className }) {
const classes = new BEMHelper("study-date-panel");
const displayDate = selected ? moment(selected).format(dateFormat) : "Empty";

return (
<div {...classes({ extra: className })}>
<span {...classes("title")}>{title}</span>
{isEditable ? (
<Datepicker
{...classes("picker")}
selected={selected || moment()}
customInput={<DateInput displayValue={displayDate} />}
minDate={minDate}
maxDate={maxDate}
onChange={onChange}
/>
) : (
<DateInput displayValue={displayDate} />
)}
</div>
);
}

DatePanel.propTypes = {
dateFormat: PropTypes.string.isRequired,
isEditable: PropTypes.bool.isRequired,
maxDate: PropTypes.any,
minDate: PropTypes.any,
onChange: PropTypes.func,
selected: PropTypes.any,
title: PropTypes.string.isRequired,
className: PropTypes.string,
};

export default DatePanel;
58 changes: 58 additions & 0 deletions src/components/DatePanel/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
*
* Copyright 2018 Odysseus Data Services, inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Company: Odysseus Data Services, Inc.
* Product Owner/Architecture: Gregory Klebanov
* Authors: Pavel Grafkin, Alexander Saltykov, Vitaly Koulakov, Anton Gackovka, Alexandr Ryabokon, Mikhail Mironov
* Created: July 25, 2017
*
*/

@import "styles/vars-and-mixins.scss";

.#{$namespace} {
&study-date-panel {
display: flex;
align-items: center;
background: $white;
border-radius: $block-border-radius;
padding: 12px 20px;
@include block-shadow();

&__title {
@include title();
margin-right: auto;
}

&__picker {
cursor: pointer;
}
}

&study-date-input {
&__icon {
@include material-icon();
margin-right: 1rem;
}
display: flex;
align-items: center;
&__ico {
color: $grey-placeholder;
margin-right: 7px;
}
&__value {
}
}
}
3 changes: 2 additions & 1 deletion src/modules/Admin/actions/licenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ function create(userId: number, vocabularyV4Ids: Array<number>) {
});
}

function resolve(id: number, accepted: boolean) {
function resolve(id: number, accepted: boolean, expiredDate: any) {
return services.licenseAccept.create({
id,
accepted,
expiredDate,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ import { get, difference } from 'lodash';
import presenter from './presenter';
import selectors from './selectors';
import { VocabularyOption, User, Vocabulary } from 'modules/Admin/components/Licenses/types';
import * as moment from 'moment';
import { commonDateFormat } from 'const/formats';

interface IModalStateProps {
vocabularies: Array<VocabularyOption>;
initialValues: {
vocabularies: Array<string>;
expiredDates: Array<string>;
};
user: User;
pendingVocabularies: Array<Vocabulary>;
Expand All @@ -43,7 +46,7 @@ interface IModalDispatchProps {
close: () => (dispatch: Function) => any;
remove: (id: string) => (dispatch: Function) => any;
loadLicenses: () => (dispatch: Function) => any;
resolveLicense: (id: number, allow: boolean) => (dispatch: Function) => any;
resolveLicense: (id: number, allow: boolean, expiredDate: any) => (dispatch: Function) => any;
};
interface IModalProps extends IModalStateProps, IModalDispatchProps {
doSubmit: (vocabs: Array<VocabularyOption>) => Promise<any>;
Expand All @@ -58,6 +61,12 @@ class ModalEditPermissions extends Component<IModalProps, {}> {
function mapStateToProps(state: any): IModalStateProps {
const vocabularies = selectors.getVocabularies(state);
const pendingVocabularies = selectors.getPendingVocabularies(state);
const expiredDates = []
pendingVocabularies.forEach((vocab) => {
expiredDates[vocab.licenseId] = vocab.expiredDate ? moment(vocab.expiredDate).format() : moment(new Date().setFullYear(new Date().getFullYear() + 2)).format()
})


const user = get(state, 'modal.editPermission.data.user.name', {
id: -1,
name: 'Anonymous',
Expand All @@ -68,6 +77,7 @@ function mapStateToProps(state: any): IModalStateProps {
vocabularies,
initialValues: {
vocabularies: vocabularies.map(v => v.value.toString()),
expiredDates: expiredDates
},
user,
pendingVocabularies,
Expand All @@ -90,13 +100,13 @@ function mergeProps(
...stateProps,
...ownProps,
...dispatchProps,
doSubmit: ({ vocabularies = [], pendingVocabs = [] }) => {
doSubmit: ({ vocabularies = [], pendingVocabs = [], expiredDates = [] }) => {
const promises = [];
difference(stateProps.initialValues.vocabularies, vocabularies).forEach((licenseId) => {
promises.push(dispatchProps.remove(licenseId));
});
pendingVocabs.forEach((isAllowed: boolean, licenseId: number) => {
promises.push(dispatchProps.resolveLicense(licenseId, isAllowed));
promises.push(dispatchProps.resolveLicense(licenseId, isAllowed, expiredDates[licenseId]));
});
const promise = Promise.all(promises);
promise
Expand Down
Loading