Commit a6788c1a authored by Kushal Pandya's avatar Kushal Pandya

Run through Prettier and remove ESLint disables

Formats the file to match Prettier rules
Removes all blacklisted ESLint rules
parent 02ccbb0a
/* eslint-disable no-new, no-unused-vars, consistent-return, no-else-return */
/* global GitLab */
import $ from 'jquery'; import $ from 'jquery';
import Pikaday from 'pikaday'; import Pikaday from 'pikaday';
import Autosave from './autosave'; import Autosave from './autosave';
...@@ -19,9 +16,11 @@ export default class IssuableForm { ...@@ -19,9 +16,11 @@ export default class IssuableForm {
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
this.wipRegex = /^\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i; this.wipRegex = /^\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i;
new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources).setup(); this.gfmAutoComplete = new GfmAutoComplete(
new UsersSelect(); gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources,
new ZenMode(); ).setup();
this.usersSelect = new UsersSelect();
this.zenMode = new ZenMode();
this.titleField = this.form.find('input[name*="[title]"]'); this.titleField = this.form.find('input[name*="[title]"]');
this.descriptionField = this.form.find('textarea[name*="[description]"]'); this.descriptionField = this.form.find('textarea[name*="[description]"]');
...@@ -57,8 +56,16 @@ export default class IssuableForm { ...@@ -57,8 +56,16 @@ export default class IssuableForm {
} }
initAutosave() { initAutosave() {
new Autosave(this.titleField, [document.location.pathname, document.location.search, 'title']); this.autosave = new Autosave(this.titleField, [
return new Autosave(this.descriptionField, [document.location.pathname, document.location.search, 'description']); document.location.pathname,
document.location.search,
'title',
]);
return new Autosave(this.descriptionField, [
document.location.pathname,
document.location.search,
'description',
]);
} }
handleSubmit() { handleSubmit() {
...@@ -74,7 +81,7 @@ export default class IssuableForm { ...@@ -74,7 +81,7 @@ export default class IssuableForm {
this.$wipExplanation = this.form.find('.js-wip-explanation'); this.$wipExplanation = this.form.find('.js-wip-explanation');
this.$noWipExplanation = this.form.find('.js-no-wip-explanation'); this.$noWipExplanation = this.form.find('.js-no-wip-explanation');
if (!(this.$wipExplanation.length && this.$noWipExplanation.length)) { if (!(this.$wipExplanation.length && this.$noWipExplanation.length)) {
return; return undefined;
} }
this.form.on('click', '.js-toggle-wip', this.toggleWip); this.form.on('click', '.js-toggle-wip', this.toggleWip);
this.titleField.on('keyup blur', this.renderWipExplanation); this.titleField.on('keyup blur', this.renderWipExplanation);
...@@ -89,10 +96,9 @@ export default class IssuableForm { ...@@ -89,10 +96,9 @@ export default class IssuableForm {
if (this.workInProgress()) { if (this.workInProgress()) {
this.$wipExplanation.show(); this.$wipExplanation.show();
return this.$noWipExplanation.hide(); return this.$noWipExplanation.hide();
} else {
this.$wipExplanation.hide();
return this.$noWipExplanation.show();
} }
this.$wipExplanation.hide();
return this.$noWipExplanation.show();
} }
toggleWip(event) { toggleWip(event) {
...@@ -110,7 +116,7 @@ export default class IssuableForm { ...@@ -110,7 +116,7 @@ export default class IssuableForm {
} }
addWip() { addWip() {
this.titleField.val(`WIP: ${(this.titleField.val())}`); this.titleField.val(`WIP: ${this.titleField.val()}`);
} }
initTargetBranchDropdown() { initTargetBranchDropdown() {
......
...@@ -79,39 +79,41 @@ let timeagoInstance; ...@@ -79,39 +79,41 @@ let timeagoInstance;
*/ */
export const getTimeago = () => { export const getTimeago = () => {
if (!timeagoInstance) { if (!timeagoInstance) {
const localeRemaining = (number, index) => [ const localeRemaining = (number, index) =>
[s__('Timeago|just now'), s__('Timeago|right now')], [
[s__('Timeago|%s seconds ago'), s__('Timeago|%s seconds remaining')], [s__('Timeago|just now'), s__('Timeago|right now')],
[s__('Timeago|1 minute ago'), s__('Timeago|1 minute remaining')], [s__('Timeago|%s seconds ago'), s__('Timeago|%s seconds remaining')],
[s__('Timeago|%s minutes ago'), s__('Timeago|%s minutes remaining')], [s__('Timeago|1 minute ago'), s__('Timeago|1 minute remaining')],
[s__('Timeago|1 hour ago'), s__('Timeago|1 hour remaining')], [s__('Timeago|%s minutes ago'), s__('Timeago|%s minutes remaining')],
[s__('Timeago|%s hours ago'), s__('Timeago|%s hours remaining')], [s__('Timeago|1 hour ago'), s__('Timeago|1 hour remaining')],
[s__('Timeago|1 day ago'), s__('Timeago|1 day remaining')], [s__('Timeago|%s hours ago'), s__('Timeago|%s hours remaining')],
[s__('Timeago|%s days ago'), s__('Timeago|%s days remaining')], [s__('Timeago|1 day ago'), s__('Timeago|1 day remaining')],
[s__('Timeago|1 week ago'), s__('Timeago|1 week remaining')], [s__('Timeago|%s days ago'), s__('Timeago|%s days remaining')],
[s__('Timeago|%s weeks ago'), s__('Timeago|%s weeks remaining')], [s__('Timeago|1 week ago'), s__('Timeago|1 week remaining')],
[s__('Timeago|1 month ago'), s__('Timeago|1 month remaining')], [s__('Timeago|%s weeks ago'), s__('Timeago|%s weeks remaining')],
[s__('Timeago|%s months ago'), s__('Timeago|%s months remaining')], [s__('Timeago|1 month ago'), s__('Timeago|1 month remaining')],
[s__('Timeago|1 year ago'), s__('Timeago|1 year remaining')], [s__('Timeago|%s months ago'), s__('Timeago|%s months remaining')],
[s__('Timeago|%s years ago'), s__('Timeago|%s years remaining')], [s__('Timeago|1 year ago'), s__('Timeago|1 year remaining')],
][index]; [s__('Timeago|%s years ago'), s__('Timeago|%s years remaining')],
][index];
const locale = (number, index) => [
[s__('Timeago|just now'), s__('Timeago|right now')], const locale = (number, index) =>
[s__('Timeago|%s seconds ago'), s__('Timeago|in %s seconds')], [
[s__('Timeago|1 minute ago'), s__('Timeago|in 1 minute')], [s__('Timeago|just now'), s__('Timeago|right now')],
[s__('Timeago|%s minutes ago'), s__('Timeago|in %s minutes')], [s__('Timeago|%s seconds ago'), s__('Timeago|in %s seconds')],
[s__('Timeago|1 hour ago'), s__('Timeago|in 1 hour')], [s__('Timeago|1 minute ago'), s__('Timeago|in 1 minute')],
[s__('Timeago|%s hours ago'), s__('Timeago|in %s hours')], [s__('Timeago|%s minutes ago'), s__('Timeago|in %s minutes')],
[s__('Timeago|1 day ago'), s__('Timeago|in 1 day')], [s__('Timeago|1 hour ago'), s__('Timeago|in 1 hour')],
[s__('Timeago|%s days ago'), s__('Timeago|in %s days')], [s__('Timeago|%s hours ago'), s__('Timeago|in %s hours')],
[s__('Timeago|1 week ago'), s__('Timeago|in 1 week')], [s__('Timeago|1 day ago'), s__('Timeago|in 1 day')],
[s__('Timeago|%s weeks ago'), s__('Timeago|in %s weeks')], [s__('Timeago|%s days ago'), s__('Timeago|in %s days')],
[s__('Timeago|1 month ago'), s__('Timeago|in 1 month')], [s__('Timeago|1 week ago'), s__('Timeago|in 1 week')],
[s__('Timeago|%s months ago'), s__('Timeago|in %s months')], [s__('Timeago|%s weeks ago'), s__('Timeago|in %s weeks')],
[s__('Timeago|1 year ago'), s__('Timeago|in 1 year')], [s__('Timeago|1 month ago'), s__('Timeago|in 1 month')],
[s__('Timeago|%s years ago'), s__('Timeago|in %s years')], [s__('Timeago|%s months ago'), s__('Timeago|in %s months')],
][index]; [s__('Timeago|1 year ago'), s__('Timeago|in 1 year')],
[s__('Timeago|%s years ago'), s__('Timeago|in %s years')],
][index];
timeago.register(timeagoLanguageCode, locale); timeago.register(timeagoLanguageCode, locale);
timeago.register(`${timeagoLanguageCode}-remaining`, localeRemaining); timeago.register(`${timeagoLanguageCode}-remaining`, localeRemaining);
...@@ -119,7 +121,7 @@ export const getTimeago = () => { ...@@ -119,7 +121,7 @@ export const getTimeago = () => {
} }
return timeagoInstance; return timeagoInstance;
} };
/** /**
* For the given element, renders a timeago instance. * For the given element, renders a timeago instance.
...@@ -184,7 +186,7 @@ export const getDayDifference = (a, b) => { ...@@ -184,7 +186,7 @@ export const getDayDifference = (a, b) => {
* @param {Number} seconds * @param {Number} seconds
* @return {String} * @return {String}
*/ */
export const timeIntervalInWords = (intervalInSeconds) => { export const timeIntervalInWords = intervalInSeconds => {
const secondsInteger = parseInt(intervalInSeconds, 10); const secondsInteger = parseInt(intervalInSeconds, 10);
const minutes = Math.floor(secondsInteger / 60); const minutes = Math.floor(secondsInteger / 60);
const seconds = secondsInteger - minutes * 60; const seconds = secondsInteger - minutes * 60;
...@@ -196,7 +198,7 @@ export const timeIntervalInWords = (intervalInSeconds) => { ...@@ -196,7 +198,7 @@ export const timeIntervalInWords = (intervalInSeconds) => {
text = `${seconds} ${pluralize('second', seconds)}`; text = `${seconds} ${pluralize('second', seconds)}`;
} }
return text; return text;
} };
export const dateInWords = (date, abbreviated = false, hideYear = false) => { export const dateInWords = (date, abbreviated = false, hideYear = false) => {
if (!date) return date; if (!date) return date;
...@@ -240,7 +242,7 @@ export const dateInWords = (date, abbreviated = false, hideYear = false) => { ...@@ -240,7 +242,7 @@ export const dateInWords = (date, abbreviated = false, hideYear = false) => {
} }
return `${monthName} ${date.getDate()}, ${year}`; return `${monthName} ${date.getDate()}, ${year}`;
} };
/** /**
* Returns month name based on provided date. * Returns month name based on provided date.
...@@ -447,13 +449,13 @@ export const parseSeconds = (seconds, { daysPerWeek = 5, hoursPerDay = 8 } = {}) ...@@ -447,13 +449,13 @@ export const parseSeconds = (seconds, { daysPerWeek = 5, hoursPerDay = 8 } = {})
return periodCount; return periodCount;
}); });
} };
/** /**
* Accepts a timeObject (see parseSeconds) and returns a condensed string representation of it * Accepts a timeObject (see parseSeconds) and returns a condensed string representation of it
* (e.g. '1w 2d 3h 1m' or '1h 30m'). Zero value units are not included. * (e.g. '1w 2d 3h 1m' or '1h 30m'). Zero value units are not included.
*/ */
export const stringifyTime = (timeObject) => { export const stringifyTime = timeObject => {
const reducedTime = _.reduce( const reducedTime = _.reduce(
timeObject, timeObject,
(memo, unitValue, unitName) => { (memo, unitValue, unitName) => {
...@@ -463,10 +465,11 @@ export const stringifyTime = (timeObject) => { ...@@ -463,10 +465,11 @@ export const stringifyTime = (timeObject) => {
'', '',
).trim(); ).trim();
return reducedTime.length ? reducedTime : '0m'; return reducedTime.length ? reducedTime : '0m';
} };
/** /**
* Accepts a time string of any size (e.g. '1w 2d 3h 5m' or '1w 2d') and returns * Accepts a time string of any size (e.g. '1w 2d 3h 5m' or '1w 2d') and returns
* the first non-zero unit/value pair. * the first non-zero unit/value pair.
*/ */
export const abbreviateTime = (timeStr) => timeStr.split(' ').filter(unitStr => unitStr.charAt(0) !== '0')[0]; export const abbreviateTime = timeStr =>
timeStr.split(' ').filter(unitStr => unitStr.charAt(0) !== '0')[0];
<script> <script>
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import { abbreviateTime } from '~/lib/utils/datetime_utility'; import { abbreviateTime } from '~/lib/utils/datetime_utility';
import icon from '~/vue_shared/components/icon.vue'; import icon from '~/vue_shared/components/icon.vue';
import tooltip from '~/vue_shared/directives/tooltip'; import tooltip from '~/vue_shared/directives/tooltip';
export default { export default {
name: 'TimeTrackingCollapsedState', name: 'TimeTrackingCollapsedState',
components: { components: {
icon, icon,
},
directives: {
tooltip,
},
props: {
showComparisonState: {
type: Boolean,
required: true,
}, },
directives: { showSpentOnlyState: {
tooltip, type: Boolean,
required: true,
}, },
props: { showEstimateOnlyState: {
showComparisonState: { type: Boolean,
type: Boolean, required: true,
required: true,
},
showSpentOnlyState: {
type: Boolean,
required: true,
},
showEstimateOnlyState: {
type: Boolean,
required: true,
},
showNoTimeTrackingState: {
type: Boolean,
required: true,
},
timeSpentHumanReadable: {
type: String,
required: false,
default: '',
},
timeEstimateHumanReadable: {
type: String,
required: false,
default: '',
},
}, },
computed: { showNoTimeTrackingState: {
timeSpent() { type: Boolean,
return this.abbreviateTime(this.timeSpentHumanReadable); required: true,
}, },
timeEstimate() { timeSpentHumanReadable: {
return this.abbreviateTime(this.timeEstimateHumanReadable); type: String,
}, required: false,
divClass() { default: '',
if (this.showComparisonState) { },
return 'compare'; timeEstimateHumanReadable: {
} else if (this.showEstimateOnlyState) { type: String,
return 'estimate-only'; required: false,
} else if (this.showSpentOnlyState) { default: '',
return 'spend-only'; },
} else if (this.showNoTimeTrackingState) { },
return 'no-tracking'; computed: {
} timeSpent() {
return this.abbreviateTime(this.timeSpentHumanReadable);
},
timeEstimate() {
return this.abbreviateTime(this.timeEstimateHumanReadable);
},
divClass() {
if (this.showComparisonState) {
return 'compare';
} else if (this.showEstimateOnlyState) {
return 'estimate-only';
} else if (this.showSpentOnlyState) {
return 'spend-only';
} else if (this.showNoTimeTrackingState) {
return 'no-tracking';
}
return '';
},
spanClass() {
if (this.showComparisonState) {
return ''; return '';
}, } else if (this.showEstimateOnlyState || this.showSpentOnlyState) {
spanClass() { return 'bold';
if (this.showComparisonState) { } else if (this.showNoTimeTrackingState) {
return ''; return 'no-value';
} else if (this.showEstimateOnlyState || this.showSpentOnlyState) { }
return 'bold';
} else if (this.showNoTimeTrackingState) {
return 'no-value';
}
return ''; return '';
}, },
text() { text() {
if (this.showComparisonState) { if (this.showComparisonState) {
return `${this.timeSpent} / ${this.timeEstimate}`; return `${this.timeSpent} / ${this.timeEstimate}`;
} else if (this.showEstimateOnlyState) { } else if (this.showEstimateOnlyState) {
return `-- / ${this.timeEstimate}`; return `-- / ${this.timeEstimate}`;
} else if (this.showSpentOnlyState) { } else if (this.showSpentOnlyState) {
return `${this.timeSpent} / --`; return `${this.timeSpent} / --`;
} else if (this.showNoTimeTrackingState) { } else if (this.showNoTimeTrackingState) {
return 'None'; return 'None';
} }
return ''; return '';
}, },
timeTrackedTooltipText() { timeTrackedTooltipText() {
let title; let title;
if (this.showComparisonState) { if (this.showComparisonState) {
title = __('Time remaining'); title = __('Time remaining');
} else if (this.showEstimateOnlyState) { } else if (this.showEstimateOnlyState) {
title = __('Estimated'); title = __('Estimated');
} else if (this.showSpentOnlyState) { } else if (this.showSpentOnlyState) {
title = __('Time spent'); title = __('Time spent');
} }
return sprintf('%{title}: %{text}', ({ title, text: this.text })); return sprintf('%{title}: %{text}', { title, text: this.text });
}, },
tooltipText() { tooltipText() {
return this.showNoTimeTrackingState ? __('Time tracking') : this.timeTrackedTooltipText; return this.showNoTimeTrackingState ? __('Time tracking') : this.timeTrackedTooltipText;
},
}, },
methods: { },
abbreviateTime(timeStr) { methods: {
return abbreviateTime(timeStr); abbreviateTime(timeStr) {
}, return abbreviateTime(timeStr);
}, },
}; },
};
</script> </script>
<template> <template>
......
...@@ -225,7 +225,7 @@ describe('prettyTime methods', () => { ...@@ -225,7 +225,7 @@ describe('prettyTime methods', () => {
expect(obj.hours).toBe(hours); expect(obj.hours).toBe(hours);
expect(obj.days).toBe(days); expect(obj.days).toBe(days);
expect(obj.weeks).toBe(weeks); expect(obj.weeks).toBe(weeks);
} };
describe('parseSeconds', () => { describe('parseSeconds', () => {
it('should correctly parse a negative value', () => { it('should correctly parse a negative value', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment