Skip to content

Commit 4bdc469

Browse files
authored
fix: dont encourage deadend navigation (#3998)
1 parent 0432182 commit 4bdc469

File tree

6 files changed

+54
-34
lines changed

6 files changed

+54
-34
lines changed

cypress/e2e/shared/flows.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,12 @@ describe('Flows', () => {
487487
.first()
488488
.click()
489489

490-
const defaultMenuItems = ['Delete', 'Share', 'Duplicate', 'Hide panel']
490+
const defaultMenuItems = [
491+
'Delete',
492+
'Link to Panel',
493+
'Duplicate',
494+
'Hide Panel',
495+
]
491496
const items = [
492497
{
493498
panel: 'queryBuilder',

src/flows/components/Sidebar.tsx

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ const Sidebar: FC = () => {
131131
const {getPanelQueries} = useContext(FlowQueryContext)
132132
const {id, hide, menu, showSub} = useContext(SidebarContext)
133133
const dispatch = useDispatch()
134+
const {source, visual} = getPanelQueries(id)
134135

135136
const sections = ([
136137
{
@@ -145,24 +146,6 @@ const Sidebar: FC = () => {
145146
remove(id)
146147
},
147148
},
148-
{
149-
title: 'Share',
150-
action: () => {
151-
const {type} = flow.data.byID[id]
152-
event('notebook_share_panel', {notebooksCellType: type})
153-
const url = new URL(
154-
`${window.location.origin}${window.location.pathname}?panel=${id}`
155-
).toString()
156-
try {
157-
navigator.clipboard.writeText(url)
158-
event('panel_share_success', {notebooksCellType: type})
159-
dispatch(notify(panelCopyLinkSuccess()))
160-
} catch {
161-
event('panel_share_failure', {notebooksCellType: type})
162-
dispatch(notify(panelCopyLinkFail()))
163-
}
164-
},
165-
},
166149
{
167150
title: 'Duplicate',
168151
action: () => {
@@ -179,13 +162,13 @@ const Sidebar: FC = () => {
179162
{
180163
title: () => {
181164
if (!flow.meta.allIDs.includes(id)) {
182-
return 'Hide panel'
165+
return 'Hide Panel'
183166
}
184167

185168
if (flow.meta.byID[id].visible) {
186-
return 'Hide panel'
169+
return 'Hide Panel'
187170
}
188-
return 'Show panel'
171+
return 'Show Panel'
189172
},
190173
action: () => {
191174
event('Panel Visibility Toggled', {
@@ -199,6 +182,9 @@ const Sidebar: FC = () => {
199182
},
200183
{
201184
title: 'Convert to |> Flux',
185+
disable: () => {
186+
return !source
187+
},
202188
hidden: () => {
203189
if (!flow.data.allIDs.includes(id)) {
204190
return true
@@ -222,8 +208,6 @@ const Sidebar: FC = () => {
222208

223209
event('Convert Cell To Flux', {from: type})
224210

225-
const {source, visual} = getPanelQueries(id)
226-
227211
const init = JSON.parse(
228212
JSON.stringify(PIPE_DEFINITIONS['rawFluxEditor'].initial)
229213
)
@@ -239,6 +223,9 @@ const Sidebar: FC = () => {
239223
{
240224
title: 'Export to Client Library',
241225
menu: <ClientList />,
226+
disable: () => {
227+
return !source
228+
},
242229
hidden: () => {
243230
if (!flow.data.allIDs.includes(id)) {
244231
return true
@@ -253,8 +240,29 @@ const Sidebar: FC = () => {
253240
return false
254241
},
255242
},
243+
{
244+
title: 'Link to Panel',
245+
action: () => {
246+
const {type} = flow.data.byID[id]
247+
event('notebook_share_panel', {notebooksCellType: type})
248+
const url = new URL(
249+
`${window.location.origin}${window.location.pathname}?panel=${id}`
250+
).toString()
251+
try {
252+
navigator.clipboard.writeText(url)
253+
event('panel_share_success', {notebooksCellType: type})
254+
dispatch(notify(panelCopyLinkSuccess()))
255+
} catch {
256+
event('panel_share_failure', {notebooksCellType: type})
257+
dispatch(notify(panelCopyLinkFail()))
258+
}
259+
},
260+
},
256261
{
257262
title: 'Link to Source',
263+
disable: () => {
264+
return !source
265+
},
258266
hidden: () => {
259267
if (!flow.data.allIDs.includes(id)) {
260268
return true
@@ -283,6 +291,9 @@ const Sidebar: FC = () => {
283291
},
284292
{
285293
title: 'Link to Results',
294+
disable: () => {
295+
return !source
296+
},
286297
hidden: () => {
287298
if (!flow.data.allIDs.includes(id)) {
288299
return true

src/flows/components/panel/InsertCellButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const InsertCellButton: FC<Props> = ({id}) => {
6363
margin={ComponentSize.Small}
6464
className="insert-cell-menu always-on"
6565
>
66-
<p className="insert-cell-menu--title">Add Another Cell</p>
66+
<p className="insert-cell-menu--title">Add Another Panel</p>
6767
<AddButtons index={index} />
6868
</FlexBox>
6969
)
@@ -94,7 +94,7 @@ const InsertCellButton: FC<Props> = ({id}) => {
9494
margin={ComponentSize.Small}
9595
className="insert-cell-menu"
9696
>
97-
<p className="insert-cell-menu--title">Insert Cell Here</p>
97+
<p className="insert-cell-menu--title">Insert Panel Here</p>
9898
<AddButtons index={index} onInsert={onHide} />
9999
</FlexBox>
100100
)}

src/flows/pipes/Notification/view.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ const Notification: FC<PipeProp> = ({Context}) => {
9797
intervalError = 'Required'
9898
} else if (
9999
data.interval !==
100-
data.interval.match(/(?:(\d+(y|mo|s|m|w|h){1}))/g)?.join('')
100+
data.interval.match(/(?:(\d+(ns|us|µs|ms|s|m|h|d|w|mo|y){1}))/g)?.join('')
101101
) {
102102
intervalError = 'Invalid Time'
103103
}
104104

105105
if (
106106
data.offset &&
107-
data.offset !== data.offset.match(/(?:(\d+(y|mo|s|m|w|h){1}))/g)?.join('')
107+
data.offset !==
108+
data.offset.match(/(?:(\d+(ns|us|µs|ms|s|m|h|d|w|mo|y){1}))/g)?.join('')
108109
) {
109110
offsetError = 'Invalid Time'
110111
}

src/flows/pipes/Schedule/view.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,18 @@ const Schedule: FC<PipeProp> = ({Context}) => {
148148
intervalError = 'Required'
149149
} else if (
150150
data.interval !==
151-
data.interval?.match(/(?:(\d+(y|mo|s|m|w|h){1}))/g)?.join('') &&
151+
data.interval
152+
?.match(/(?:(\d+(ns|us|µs|ms|s|m|h|d|w|mo|y){1}))/g)
153+
?.join('') &&
152154
!validCron(data.interval)
153155
) {
154156
intervalError = 'Invalid Time'
155157
}
156158

157159
if (
158160
data.offset &&
159-
data.offset !== data.offset.match(/(?:(\d+(y|mo|s|m|w|h){1}))/g)?.join('')
161+
data.offset !==
162+
data.offset.match(/(?:(\d+(ns|us|µs|ms|s|m|h|d|w|mo|y){1}))/g)?.join('')
160163
) {
161164
offsetError = 'Invalid Time'
162165
}

src/flows/pipes/Time/view.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ const Time: FC<PipeProp> = ({Context}) => {
2727
if (!data.start) {
2828
startError = 'Required'
2929
} else if (
30-
!/^-(?:(\d+(y|mo|s|m|w|h){1}))+$/g.test(data.start) &&
31-
!/^((?:(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}(?:\.\d+)?))(Z|[\+-]\d{2}:\d{2})?)$/g.test(
30+
!/^-(?:(\d+(ns|us|µs|ms|s|m|h|d|w|mo|y){1}))+$/g.test(data.start) &&
31+
!/^([0-9]{4})-([0-9]{2})-([0-9]{2})([Tt]([0-9]{2}):([0-9]{2}):([0-9]{2})(\\.[0-9]+)?)?(([Zz]|([+-])([0-9]{2}):([0-9]{2})))?/g.test(
3232
data.start
3333
)
3434
) {
@@ -39,8 +39,8 @@ const Time: FC<PipeProp> = ({Context}) => {
3939
stopError = 'Required'
4040
} else if (
4141
!/^now\(\)$/g.test(data.stop) &&
42-
!/^-(?:(\d+(y|mo|s|m|w|h){1}))+$/g.test(data.stop) &&
43-
!/^((?:(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}(?:\.\d+)?))(Z|[\+-]\d{2}:\d{2})?)$/g.test(
42+
!/^-(?:(\d+(ns|us|µs|ms|s|m|h|d|w|mo|y){1}))+$/g.test(data.stop) &&
43+
!/^([0-9]{4})-([0-9]{2})-([0-9]{2})([Tt]([0-9]{2}):([0-9]{2}):([0-9]{2})(\\.[0-9]+)?)?(([Zz]|([+-])([0-9]{2}):([0-9]{2})))?/g.test(
4444
data.stop
4545
)
4646
) {

0 commit comments

Comments
 (0)