Skip to content

Commit 512692b

Browse files
committed
fix: add support for enabled tools
1 parent 0e70f25 commit 512692b

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

src/components/MainLayout/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ const Container = styled("div")(({ themeColors, width }) => ({
1919
backgroundColor: themeColors.bg,
2020
}))
2121

22+
const defaultEnabledTools = [
23+
"create-durations",
24+
"label-durations",
25+
"create-timestamps",
26+
"label-timestamps",
27+
]
28+
2229
export const MainLayout = ({
2330
curveGroups,
2431
timeFormat,
@@ -31,6 +38,7 @@ export const MainLayout = ({
3138
width = 500,
3239
graphHeight = 300,
3340
onChangeTimestamps,
41+
enabledTools = defaultEnabledTools,
3442
}) => {
3543
const themeColors = useColors()
3644
const [activeDurationGroup, setActiveDurationGroup] = useState(null)
@@ -47,6 +55,7 @@ export const MainLayout = ({
4755
)
4856

4957
const onDragDuration = useEventCallback((startTime, endTime) => {
58+
if (!enabledTools.includes("create-durations")) return
5059
if (activeDurationGroup === null) return
5160
;[startTime, endTime] =
5261
startTime < endTime ? [startTime, endTime] : [endTime, startTime]
@@ -66,6 +75,7 @@ export const MainLayout = ({
6675
)
6776
})
6877
const onDragDurationStart = useEventCallback((startTime) => {
78+
if (!enabledTools.includes("create-durations")) return
6979
if (activeDurationGroup === null) return
7080
const lastIndex = durationGroups[activeDurationGroup].durations.length
7181
setDraggedDurationIndex(lastIndex)
@@ -77,10 +87,12 @@ export const MainLayout = ({
7787
)
7888
})
7989
const onDragDurationEnd = useEventCallback(() => {
90+
if (!enabledTools.includes("create-durations")) return
8091
setSelectedDurationIndex(draggedDurationIndex)
8192
setDraggedDurationIndex(null)
8293
})
8394
const onCreateTimestamp = useEventCallback((time) => {
95+
if (!enabledTools.includes("create-timestamps")) return
8496
onChangeTimestamps(
8597
timestamps.concat([
8698
{

src/components/MouseTransformHandler/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import { styled } from "@material-ui/core/styles"
33
import useEventCallback from "use-event-callback"
44
import useToolMode from "../../hooks/use-tool-mode"
55

6-
const Container = styled("div")({
7-
// width: 500,
8-
// height: 200,
9-
})
6+
const Container = styled("div")({})
107

118
export const MouseTransformHandler = ({
129
children,

src/components/ReactTimeSeries/ReactTimeSeries.stories.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,39 @@ export const PredefinedLabelsOnly = () => {
9696
/>
9797
)
9898
}
99+
100+
export const CreateTimestampsOnly = () => {
101+
const [sample, setSample] = useState({
102+
audioUrl:
103+
"https://s3.amazonaws.com/datasets.workaround.online/voice-samples/001/voice.mp3",
104+
})
105+
return (
106+
<ReactTimeSeries
107+
interface={{
108+
durationLabels: ["duration1", "duration2"],
109+
timestampLabels: ["ts1", "ts2"],
110+
enabledTools: ["create-timestamps"],
111+
}}
112+
sample={sample}
113+
onModifySample={setSample}
114+
/>
115+
)
116+
}
117+
118+
export const CreateDurationsOnly = () => {
119+
const [sample, setSample] = useState({
120+
audioUrl:
121+
"https://s3.amazonaws.com/datasets.workaround.online/voice-samples/001/voice.mp3",
122+
})
123+
return (
124+
<ReactTimeSeries
125+
interface={{
126+
durationLabels: ["duration1", "duration2"],
127+
timestampLabels: ["ts1", "ts2"],
128+
enabledTools: ["create-durations"],
129+
}}
130+
sample={sample}
131+
onModifySample={setSample}
132+
/>
133+
)
134+
}

src/components/ReactTimeSeries/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export const ReactTimeSeriesWithoutContext = ({
3737
const getRandomColorUsingHash = useGetRandomColorUsingHash()
3838
const {
3939
timeFormat,
40-
// eslint-disable-next-line
4140
enabledTools = defaultEnabledTools,
4241
durationLabels = emptyAr,
4342
timestampLabels = emptyAr,
@@ -205,6 +204,7 @@ export const ReactTimeSeriesWithoutContext = ({
205204
timestampLabels={timestampLabels}
206205
durationLabels={durationLabels}
207206
allowCustomLabels={allowCustomLabels}
207+
enabledTools={enabledTools}
208208
/>
209209
</div>
210210
)}

0 commit comments

Comments
 (0)