Skip to content

Commit b376cf6

Browse files
authored
Improvements to Share Link component behavior (#3387)
Improvements to Share Link component to avoid multiple re-renders during common actions Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent 16bae25 commit b376cf6

File tree

3 files changed

+21
-37
lines changed

3 files changed

+21
-37
lines changed

.github/workflows/vulncheck.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,4 @@ jobs:
5050
working-directory: ./web-app
5151
continue-on-error: false
5252
run: |
53-
# Ignore "pdfjs-dist" advisory, because it's a dependency
54-
# of "react-pdf" that cannot be upgraded. Because the
55-
# "isEvalSupported" value is always set to "false", it
56-
# isn't a security problem. See also
57-
# - https://github.com/wojtekmaj/react-pdf/issues/1789
58-
# - https://github.com/wojtekmaj/react-pdf/discussions/1786
59-
# - https://www.npmjs.com/advisories/1097244
6053
yarn npm audit --recursive --environment production --no-deprecations

web-app/src/screens/Console/Buckets/ListBuckets/Objects/ObjectDetails/ShareFile.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,14 @@ const ShareFile = ({
5656
}: IShareFileProps) => {
5757
const dispatch = useAppDispatch();
5858
const distributedSetup = useSelector(selDistSet);
59-
const maxshareLinkExpTimeVal = useSelector(maxShareLinkExpTime);
59+
const maxShareLinkExpTimeVal = useSelector(maxShareLinkExpTime);
6060
const [shareURL, setShareURL] = useState<string>("");
6161
const [isLoadingVersion, setIsLoadingVersion] = useState<boolean>(true);
6262
const [isLoadingFile, setIsLoadingFile] = useState<boolean>(false);
6363
const [selectedDate, setSelectedDate] = useState<string>("");
6464
const [dateValid, setDateValid] = useState<boolean>(true);
6565
const [versionID, setVersionID] = useState<string>("null");
6666

67-
const initialDate = new Date();
68-
6967
const dateChanged = (newDate: string, isValid: boolean) => {
7068
setDateValid(isValid);
7169
if (isValid) {
@@ -205,18 +203,17 @@ const ShareFile = ({
205203
The following URL lets you share this object without requiring
206204
a login. <br />
207205
The URL expires automatically at the earlier of your
208-
configured time ({niceTimeFromSeconds(maxshareLinkExpTimeVal)}
206+
configured time ({niceTimeFromSeconds(maxShareLinkExpTimeVal)}
209207
) or the expiration of your current web session.
210208
</span>
211209
</Tooltip>
212210
</Grid>
213211
<br />
214212
<Grid item xs={12}>
215213
<DaysSelector
216-
initialDate={initialDate}
217214
id="date"
218215
label="Active for"
219-
maxSeconds={maxshareLinkExpTimeVal}
216+
maxSeconds={maxShareLinkExpTimeVal}
220217
onChange={dateChanged}
221218
entity="Link"
222219
/>

web-app/src/screens/Console/Common/FormComponents/DaysSelector/DaysSelector.tsx

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,23 @@ const HOUR_MINUTES = 60;
2424

2525
interface IDaysSelector {
2626
id: string;
27-
initialDate: Date;
2827
maxSeconds: number;
2928
label: string;
3029
entity: string;
3130
onChange: (newDate: string, isValid: boolean) => void;
3231
}
3332

34-
const calculateNewTime = (
35-
initialDate: Date,
36-
days: number,
37-
hours: number,
38-
minutes: number,
39-
) => {
40-
return DateTime.fromJSDate(initialDate).plus({
41-
hours: hours + days * 24,
42-
minutes,
43-
}); // Lump days into hours to avoid daylight savings causing issues
33+
const calculateNewTime = (days: number, hours: number, minutes: number) => {
34+
return DateTime.now()
35+
.plus({
36+
hours: hours + days * 24,
37+
minutes,
38+
})
39+
.toISO(); // Lump days into hours to avoid daylight savings causing issues
4440
};
4541

4642
const DaysSelector = ({
4743
id,
48-
initialDate,
4944
label,
5045
maxSeconds,
5146
entity,
@@ -59,7 +54,7 @@ const DaysSelector = ({
5954
const [selectedHours, setSelectedHours] = useState<number>(0);
6055
const [selectedMinutes, setSelectedMinutes] = useState<number>(0);
6156
const [validDate, setValidDate] = useState<boolean>(true);
62-
const [dateSelected, setDateSelected] = useState<DateTime>(DateTime.now());
57+
const [dateSelected, setDateSelected] = useState<string | null>(null);
6358

6459
// Set initial values
6560
useEffect(() => {
@@ -75,19 +70,16 @@ const DaysSelector = ({
7570
!isNaN(selectedMinutes)
7671
) {
7772
setDateSelected(
78-
calculateNewTime(
79-
initialDate,
80-
selectedDays,
81-
selectedHours,
82-
selectedMinutes,
83-
),
73+
calculateNewTime(selectedDays, selectedHours, selectedMinutes),
8474
);
8575
}
86-
}, [initialDate, selectedDays, selectedHours, selectedMinutes]);
76+
}, [selectedDays, selectedHours, selectedMinutes]);
8777

8878
useEffect(() => {
89-
if (validDate) {
90-
const formattedDate = dateSelected.toFormat("yyyy-MM-dd HH:mm:ss");
79+
if (validDate && dateSelected) {
80+
const formattedDate = DateTime.fromISO(dateSelected).toFormat(
81+
"yyyy-MM-dd HH:mm:ss",
82+
);
9183
onChange(formattedDate.split(" ").join("T"), true);
9284
} else {
9385
onChange("0000-00-00", false);
@@ -270,12 +262,14 @@ const DaysSelector = ({
270262
},
271263
}}
272264
>
273-
{validDate ? (
265+
{validDate && dateSelected ? (
274266
<div className={"validityText"}>
275267
<LinkIcon />
276268
<div>{entity} will be available until:</div>{" "}
277269
<div className={"validTill"}>
278-
{dateSelected.toFormat("MM/dd/yyyy HH:mm:ss ZZZZ")}
270+
{DateTime.fromISO(dateSelected).toFormat(
271+
"MM/dd/yyyy HH:mm:ss ZZZZ",
272+
)}
279273
</div>
280274
</div>
281275
) : (

0 commit comments

Comments
 (0)