github.com/minio/console@v1.4.1/web-app/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ListObjectsHelpers.tsx (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2022 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 import { DateTime } from "luxon"; 18 import { BucketObjectItem } from "./types"; 19 import { niceBytes } from "../../../../../../common/utils"; 20 import { displayFileIconName } from "./utils"; 21 22 // Functions 23 24 export const displayParsedDate = (object: BucketObjectItem) => { 25 if (object.name.endsWith("/")) { 26 return ""; 27 } 28 29 const currTime = DateTime.now(); 30 const objectTime = DateTime.fromISO(object.last_modified); 31 32 const isToday = 33 currTime.hasSame(objectTime, "day") && 34 currTime.hasSame(objectTime, "month") && 35 currTime.hasSame(objectTime, "year"); 36 37 if (isToday) { 38 return `Today, ${objectTime.toFormat("HH:mm")}`; 39 } 40 41 return objectTime.toFormat("ccc, LLL dd yyyy HH:mm (ZZZZ)"); 42 }; 43 44 export const displayNiceBytes = (object: BucketObjectItem) => { 45 if (object.name.endsWith("/") || !object.size) { 46 return "-"; 47 } 48 return niceBytes(String(object.size)); 49 }; 50 51 export const displayDeleteFlag = (state: boolean) => { 52 return state ? "Yes" : "No"; 53 }; 54 55 // Table Props 56 57 export const listModeColumns = [ 58 { 59 label: "Name", 60 elementKey: "name", 61 renderFunction: displayFileIconName, 62 enableSort: true, 63 }, 64 { 65 label: "Last Modified", 66 elementKey: "last_modified", 67 renderFunction: displayParsedDate, 68 renderFullObject: true, 69 enableSort: true, 70 }, 71 { 72 label: "Size", 73 elementKey: "size", 74 renderFunction: displayNiceBytes, 75 renderFullObject: true, 76 width: 100, 77 enableSort: true, 78 }, 79 ]; 80 81 export const rewindModeColumns = [ 82 { 83 label: "Name", 84 elementKey: "name", 85 renderFunction: displayFileIconName, 86 enableSort: true, 87 }, 88 { 89 label: "Object Date", 90 elementKey: "last_modified", 91 renderFunction: displayParsedDate, 92 renderFullObject: true, 93 enableSort: true, 94 }, 95 { 96 label: "Size", 97 elementKey: "size", 98 renderFunction: displayNiceBytes, 99 renderFullObject: true, 100 width: 100, 101 enableSort: true, 102 }, 103 { 104 label: "Deleted", 105 elementKey: "delete_flag", 106 renderFunction: displayDeleteFlag, 107 width: 60, 108 }, 109 ];