do not mislead user about being able to edit and clean up time in words

This commit is contained in:
burnettk 2022-11-25 02:53:20 -05:00
parent f22af2a85f
commit 5484f6d5d4
6 changed files with 24 additions and 13 deletions

View File

@ -3,15 +3,15 @@ import { TimeAgo } from '../helpers/timeago';
import { convertSecondsToFormattedDateTime } from '../helpers'; import { convertSecondsToFormattedDateTime } from '../helpers';
type OwnProps = { type OwnProps = {
time_in_seconds: number; timeInSeconds: number;
}; };
export default function TableCellWithTimeAgoInWords({ export default function TableCellWithTimeAgoInWords({
time_in_seconds, timeInSeconds,
}: OwnProps) { }: OwnProps) {
return ( return (
<td title={convertSecondsToFormattedDateTime(time_in_seconds) || '-'}> <td title={convertSecondsToFormattedDateTime(timeInSeconds) || '-'}>
{time_in_seconds ? TimeAgo.inWords(time_in_seconds) : '-'} {timeInSeconds ? TimeAgo.inWords(timeInSeconds) : '-'}
</td> </td>
); );
} }

View File

@ -75,7 +75,7 @@ export default function MyOpenProcesses() {
) || '-'} ) || '-'}
</td> </td>
<TableCellWithTimeAgoInWords <TableCellWithTimeAgoInWords
time_in_seconds={rowToUse.updated_at_in_seconds} timeInSeconds={rowToUse.updated_at_in_seconds}
/> />
<td> <td>
<Button <Button

View File

@ -75,7 +75,7 @@ export default function TasksWaitingForMe() {
) || '-'} ) || '-'}
</td> </td>
<TableCellWithTimeAgoInWords <TableCellWithTimeAgoInWords
time_in_seconds={rowToUse.updated_at_in_seconds} timeInSeconds={rowToUse.updated_at_in_seconds}
/> />
<td> <td>
<Button <Button

View File

@ -83,7 +83,7 @@ export default function TasksWaitingForMyGroups() {
) || '-'} ) || '-'}
</td> </td>
<TableCellWithTimeAgoInWords <TableCellWithTimeAgoInWords
time_in_seconds={rowToUse.updated_at_in_seconds} timeInSeconds={rowToUse.updated_at_in_seconds}
/> />
<td> <td>
<Button <Button

View File

@ -1,5 +1,6 @@
/* eslint-disable no-restricted-syntax */
// https://gist.github.com/caiotarifa/30ae974f2293c761f3139dd194abd9e5 // https://gist.github.com/caiotarifa/30ae974f2293c761f3139dd194abd9e5
export const TimeAgo = (function () { export const TimeAgo = (function awesomeFunc() {
const self = {}; const self = {};
// Public Methods // Public Methods
@ -20,9 +21,11 @@ export const TimeAgo = (function () {
years: '%d years', years: '%d years',
}; };
self.inWords = function (timeAgo) { self.inWords = function inWords(timeAgo) {
const milliseconds = timeAgo * 1000; const milliseconds = timeAgo * 1000;
const seconds = Math.floor((new Date() - parseInt(milliseconds)) / 1000); const seconds = Math.floor(
(new Date() - parseInt(milliseconds, 10)) / 1000
);
const separator = this.locales.separator || ' '; const separator = this.locales.separator || ' ';
let words = this.locales.prefix + separator; let words = this.locales.prefix + separator;
let interval = 0; let interval = 0;
@ -36,6 +39,7 @@ export const TimeAgo = (function () {
let distance = this.locales.seconds; let distance = this.locales.seconds;
// eslint-disable-next-line guard-for-in
for (const key in intervals) { for (const key in intervals) {
interval = Math.floor(intervals[key]); interval = Math.floor(intervals[key]);

View File

@ -7,6 +7,7 @@ import {
TrashCan, TrashCan,
Favorite, Favorite,
Edit, Edit,
View,
ArrowRight, ArrowRight,
// @ts-ignore // @ts-ignore
} from '@carbon/icons-react'; } from '@carbon/icons-react';
@ -66,7 +67,7 @@ export default function ProcessModelShow() {
[targetUris.processModelShowPath]: ['PUT', 'DELETE'], [targetUris.processModelShowPath]: ['PUT', 'DELETE'],
[targetUris.processInstanceListPath]: ['GET'], [targetUris.processInstanceListPath]: ['GET'],
[targetUris.processInstanceActionPath]: ['POST'], [targetUris.processInstanceActionPath]: ['POST'],
[targetUris.processModelFileCreatePath]: ['POST', 'GET', 'DELETE'], [targetUris.processModelFileCreatePath]: ['POST', 'PUT', 'GET', 'DELETE'],
}; };
const { ability, permissionsLoaded } = usePermissionFetcher( const { ability, permissionsLoaded } = usePermissionFetcher(
permissionRequestData permissionRequestData
@ -214,12 +215,18 @@ export default function ProcessModelShow() {
isPrimaryBpmnFile: boolean isPrimaryBpmnFile: boolean
) => { ) => {
const elements = []; const elements = [];
let icon = View;
let actionWord = 'View';
if (ability.can('PUT', targetUris.processModelFileCreatePath)) {
icon = Edit;
actionWord = 'Edit';
}
elements.push( elements.push(
<Can I="GET" a={targetUris.processModelFileCreatePath} ability={ability}> <Can I="GET" a={targetUris.processModelFileCreatePath} ability={ability}>
<Button <Button
kind="ghost" kind="ghost"
renderIcon={Edit} renderIcon={icon}
iconDescription="Edit File" iconDescription={`${actionWord} File`}
hasIconOnly hasIconOnly
size="lg" size="lg"
data-qa={`edit-file-${processModelFile.name.replace('.', '-')}`} data-qa={`edit-file-${processModelFile.name.replace('.', '-')}`}