Skip to content

Commit e444020

Browse files
Merge pull request #99 from linked-planet/dev
added crypto.randomUUID for time table item keys default
2 parents 3363147 + d44eb09 commit e444020

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

library/src/components/timetable/CreateNewItem.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const CreateNewTimeTableItemDialog = function CreateNewTimeTableItemDialog({
2121
onCancel: () => void
2222
timeSteps: number
2323
}) {
24+
const [key, setKey] = useState<string>(crypto.randomUUID())
2425
const [title, setTitle] = useState("new time slot booking")
2526
const [startDateUsed, setStartDate] = useState(startDate)
2627
const [endDateUsed, setEndDate] = useState(endDate)
@@ -34,12 +35,13 @@ const CreateNewTimeTableItemDialog = function CreateNewTimeTableItemDialog({
3435
<form
3536
onSubmit={(e) => {
3637
e.preventDefault()
37-
if (!title) {
38-
setError("The title cannot be empty.")
38+
if (!key) {
39+
setError("The key cannot be empty.")
3940
return
4041
}
4142
if (!title) {
4243
setError("The title cannot be empty.")
44+
return
4345
}
4446
if (!startDate) {
4547
setError("The start date cannot be empty.")
@@ -57,6 +59,7 @@ const CreateNewTimeTableItemDialog = function CreateNewTimeTableItemDialog({
5759
return
5860
}
5961
const newBookingItem: TimeSlotBooking = {
62+
key,
6063
title,
6164
startDate,
6265
endDate,
@@ -77,6 +80,19 @@ const CreateNewTimeTableItemDialog = function CreateNewTimeTableItemDialog({
7780
gap: "1rem",
7881
}}
7982
>
83+
<label htmlFor="keyinput">Key</label>
84+
<input
85+
id="keyinput"
86+
name="keyinput"
87+
type="text"
88+
value={key}
89+
onChange={(e) => {
90+
setError("")
91+
setKey(e.target.value)
92+
}}
93+
minLength={1}
94+
/>
95+
<label htmlFor="startDate">Start</label>
8096
<label htmlFor="title">Title</label>
8197
<input
8298
id="title"

showcase/public/showcase-sources.txt

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7794,6 +7794,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
77947794
},
77957795
items: [
77967796
{
7797+
key: crypto.randomUUID(),
77977798
// expected to be on group row 0
77987799
startDate: dayjs()
77997800
.startOf("day")
@@ -7806,12 +7807,14 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
78067807
title: "Item 1-1",
78077808
},
78087809
{
7810+
key: crypto.randomUUID(),
78097811
// expected to be on group row 0
78107812
startDate: dayjs().startOf("day").add(13, "hours"),
78117813
endDate: dayjs().startOf("day").add(15, "hours"),
78127814
title: "Item 1-2",
78137815
},
78147816
{
7817+
key: crypto.randomUUID(),
78157818
// expected to be on group row 0
78167819
startDate: dayjs()
78177820
.startOf("day")
@@ -7821,6 +7824,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
78217824
title: "Item 1-3",
78227825
},
78237826
{
7827+
key: crypto.randomUUID(),
78247828
// expected to be on group row 0
78257829
startDate: dayjs().startOf("day").add(7, "hours"),
78267830
endDate: dayjs()
@@ -7830,18 +7834,21 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
78307834
title: "Item 1-3-1",
78317835
},
78327836
{
7837+
key: crypto.randomUUID(),
78337838
// expected to be on group row 0
78347839
startDate: dayjs().startOf("day").add(1, "day").add(8, "hours"),
78357840
endDate: dayjs().startOf("day").add(1, "day").add(9, "hours"),
78367841
title: "Item 1-4",
78377842
},
78387843
{
7844+
key: crypto.randomUUID(),
78397845
// expected to be on group row 1
78407846
startDate: dayjs().startOf("day").add(9, "hours"),
78417847
endDate: dayjs().startOf("day").add(15, "hours"),
78427848
title: "Item 1-5",
78437849
},
78447850
{
7851+
key: crypto.randomUUID(),
78457852
// expected to be on group row 2
78467853
startDate: dayjs()
78477854
.startOf("day")
@@ -7854,6 +7861,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
78547861
title: "Item 1-6",
78557862
},
78567863
{
7864+
key: crypto.randomUUID(),
78577865
// expected to be on group row 0
78587866
startDate: dayjs()
78597867
.startOf("day")
@@ -7866,6 +7874,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
78667874
title: "Item 1-1-2",
78677875
},
78687876
{
7877+
key: crypto.randomUUID(),
78697878
// expected to be on group row 0
78707879
startDate: dayjs().startOf("day").add(13, "hours"),
78717880
endDate: dayjs().startOf("day").add(15, "hours"),
@@ -7881,6 +7890,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
78817890
},
78827891
items: [
78837892
{
7893+
key: crypto.randomUUID(),
78847894
startDate: dayjs()
78857895
.startOf("day")
78867896
.add(8, "hours")
@@ -7892,6 +7902,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
78927902
title: "Item 2-1",
78937903
},
78947904
{
7905+
key: crypto.randomUUID(),
78957906
startDate: dayjs()
78967907
.startOf("day")
78977908
.add(8, "hours")
@@ -7903,6 +7914,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
79037914
title: "Item 2-2",
79047915
},
79057916
{
7917+
key: crypto.randomUUID(),
79067918
startDate: dayjs()
79077919
.startOf("day")
79087920
.add(8, "hours")
@@ -7914,6 +7926,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
79147926
title: "Item 2-3",
79157927
},
79167928
{
7929+
key: crypto.randomUUID(),
79177930
startDate: dayjs()
79187931
.startOf("day")
79197932
.add(8, "hours")
@@ -7925,6 +7938,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
79257938
title: "Item 2-3-1",
79267939
},
79277940
{
7941+
key: crypto.randomUUID(),
79287942
startDate: dayjs().startOf("day").add(8, "hours"),
79297943
endDate: dayjs().startOf("day").add(10, "hours"),
79307944
title: "Item 2-4",
@@ -7939,17 +7953,20 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
79397953
},
79407954
items: [
79417955
{
7956+
key: crypto.randomUUID(),
79427957
// this entry is totally before the available slots of the day
79437958
startDate: dayjs().startOf("day").add(5, "hours"),
79447959
endDate: dayjs().startOf("day").add(6, "hours"),
79457960
title: "Item 3-1",
79467961
},
79477962
{
7963+
key: crypto.randomUUID(),
79487964
startDate: dayjs().startOf("day").add(1, "day").add(9, "hours"),
79497965
endDate: dayjs().startOf("day").add(2, "days").add(9, "hours"),
79507966
title: "Item 3-2",
79517967
},
79527968
{
7969+
key: crypto.randomUUID(),
79537970
// this entry is totally after the available slots of the day
79547971
startDate: dayjs().startOf("day").add(17, "hours"),
79557972
endDate: dayjs().startOf("day").add(20, "hours"),
@@ -7965,6 +7982,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
79657982
},
79667983
items: [
79677984
{
7985+
key: crypto.randomUUID(),
79687986
// this case ends after the end of the day
79697987
startDate: dayjs()
79707988
.startOf("day")
@@ -7974,6 +7992,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
79747992
title: "Item 4-1",
79757993
},
79767994
{
7995+
key: crypto.randomUUID(),
79777996
startDate: dayjs()
79787997
.startOf("day")
79797998
.add(-1, "day")
@@ -7985,6 +8004,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
79858004
title: "Item 4-2",
79868005
},
79878006
{
8007+
key: crypto.randomUUID(),
79888008
// this case starts before the start of the day
79898009
startDate: dayjs()
79908010
.startOf("day")
@@ -7997,6 +8017,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
79978017
title: "Item 4-3",
79988018
},
79998019
{
8020+
key: crypto.randomUUID(),
80008021
startDate: dayjs()
80018022
.startOf("day")
80028023
.add(-1, "day")
@@ -8008,6 +8029,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
80088029
title: "Item 4-4",
80098030
},
80108031
{
8032+
key: crypto.randomUUID(),
80118033
startDate: dayjs().startOf("day").add(-1, "day"),
80128034
endDate: dayjs().startOf("day").add(3, "day"),
80138035
title: "Item 4-4-5",
@@ -8022,18 +8044,21 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
80228044
},
80238045
items: [
80248046
{
8047+
key: crypto.randomUUID(),
80258048
// this case ends after the end of the day and starts before
80268049
startDate: dayjs().startOf("day").add(-2, "day"),
80278050
endDate: dayjs().startOf("day").add(7, "days"),
80288051
title: "Item 5-1",
80298052
},
80308053
{
8054+
key: crypto.randomUUID(),
80318055
// this case ends after the end of the day and starts before
80328056
startDate: dayjs().startOf("day").add(12, "hours"),
80338057
endDate: dayjs().startOf("day").add(1, "day").add(12, "hours"),
80348058
title: "Item 5-2",
80358059
},
80368060
{
8061+
key: crypto.randomUUID(),
80378062
startDate: dayjs().startOf("day").add(1, "day"), // 00:00-00:00
80388063
endDate: dayjs().startOf("day").add(1, "day"),
80398064
title: "Item 5-3",
@@ -8048,23 +8073,27 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
80488073
},
80498074
items: [
80508075
{
8076+
key: crypto.randomUUID(),
80518077
// this case ends after the end of the day and starts before
80528078
startDate: dayjs().startOf("day").add(7, "hours"),
80538079
endDate: dayjs().startOf("day").add(12, "hours"),
80548080
title: "Item 6-1",
80558081
},
80568082
{
8083+
key: crypto.randomUUID(),
80578084
// this case ends after the end of the day and starts before
80588085
startDate: dayjs().startOf("day").add(12, "hours"),
80598086
endDate: dayjs().startOf("day").add(16, "hours"),
80608087
title: "Item 6-1-1",
80618088
},
80628089
{
8090+
key: crypto.randomUUID(),
80638091
startDate: dayjs().startOf("day").add(1, "day"),
80648092
endDate: dayjs().startOf("day").add(2, "day"),
80658093
title: "Item 6-2-1",
80668094
},
80678095
{
8096+
key: crypto.randomUUID(),
80688097
startDate: dayjs().startOf("day").add(2, "day"),
80698098
endDate: dayjs().startOf("day").add(3, "day"),
80708099
title: "Item 6-2-2",
@@ -8079,6 +8108,7 @@ const exampleEntries: TimeTableTypes.TimeTableEntry<
80798108
},
80808109
items: [
80818110
{
8111+
key: randomUUID(),
80828112
// this case ends after the end of the day and starts before
80838113
startDate: dayjs().startOf("day"),
80848114
endDate: dayjs().endOf("day"),
@@ -8106,6 +8136,7 @@ function createTestItems(
81068136
.add(addStartMinutes, "minutes")
81078137
const itemEndDate = itemStartDate.add(addEndMinutes, "minutes")
81088138
ret.push({
8139+
key: crypto.randomUUID(),
81098140
startDate: itemStartDate,
81108141
endDate: itemEndDate,
81118142
title: `Random Item ${groupNumber}-${i}`,
@@ -8161,7 +8192,7 @@ function createMoreTestGroups(
81618192
return newGroups
81628193
}
81638194

8164-
const startDateInitial = dayjs().startOf("day").add(-1, "day")
8195+
const startDateInitial = dayjs().startOf("day").add(-1, "day").add(8, "hours")
81658196
const endDateInitial = dayjs().startOf("day").add(6, "days")
81668197

81678198
function TestCustomHeaderRowTimeSlot<

0 commit comments

Comments
 (0)