Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
ac18cbf8
Unverified
Commit
ac18cbf8
authored
3 years ago
by
Ariya Hidayat
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Remove ScratchApp (#21220)
parent
98761e7e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/metabase/internal/components/ScratchApp.jsx
+0
-108
0 additions, 108 deletions
frontend/src/metabase/internal/components/ScratchApp.jsx
with
0 additions
and
108 deletions
frontend/src/metabase/internal/components/ScratchApp.jsx
deleted
100644 → 0
+
0
−
108
View file @
98761e7e
import
React
from
"
react
"
;
import
ReactDOM
from
"
react-dom
"
;
import
CheckBox
from
"
metabase/core/components/CheckBox
"
;
import
cx
from
"
classnames
"
;
import
AceEditor
from
"
metabase/components/TextEditor
"
;
import
context
from
"
../lib/scratch-context
"
;
export
default
class
ScratchApp
extends
React
.
Component
{
constructor
(
props
)
{
super
(
props
);
const
hash
=
window
.
location
.
hash
.
replace
(
/^#/
,
""
);
this
.
state
=
{
code
:
hash
?
atob
(
hash
)
:
`<Button>Hello World</Button>`
,
error
:
null
,
centered
:
true
,
};
}
handleChange
=
code
=>
{
this
.
setState
({
code
});
history
.
replaceState
({},
null
,
"
/_internal/scratch#
"
+
btoa
(
code
));
};
async
_update
()
{
try
{
const
{
code
}
=
this
.
state
;
let
fn
;
try
{
// if the module is an expression
fn
=
new
Function
(
"
module
"
,
"
context
"
,
`with(context) { \nreturn
${
code
}
\n }`
,
);
}
catch
(
e
)
{
fn
=
new
Function
(
"
module
"
,
"
context
"
,
`with(context) { \n
${
code
}
\n }`
,
);
}
// execute the function with module and context
const
mod
=
{};
const
result
=
fn
(
mod
,
context
);
// get an element/component from the return value or module.exports
const
elementOrComponent
=
mod
.
exports
||
result
;
// make sure it's an element
const
element
=
React
.
isValidElement
(
elementOrComponent
)
?
elementOrComponent
:
React
.
createElement
(
elementOrComponent
);
// render!
ReactDOM
.
unstable_renderSubtreeIntoContainer
(
this
,
element
,
this
.
_container
,
);
this
.
setState
({
error
:
null
});
}
catch
(
e
)
{
console
.
error
(
e
);
this
.
setState
({
error
:
e
});
}
}
componentDidMount
()
{
this
.
_update
();
}
componentDidUpdate
(
prevProps
,
prevState
)
{
if
(
prevState
.
code
!==
this
.
state
.
code
)
{
this
.
_update
();
}
}
render
()
{
const
{
centered
}
=
this
.
state
;
return
(
<
div
className
=
"flex-full flex flex-column"
>
<
div
ref
=
{
r
=>
(
this
.
_container
=
r
)
}
className
=
{
cx
(
"
flex-full relative
"
,
{
"
flex layout-centered
"
:
centered
,
})
}
/>
<
AceEditor
mode
=
"ace/mode/jsx"
theme
=
"ace/theme/metabase"
style
=
{
{
height
:
100
,
outline
:
this
.
state
.
error
?
"
2px solid red
"
:
null
,
}
}
value
=
{
this
.
state
.
code
}
onChange
=
{
this
.
handleChange
}
/>
<
div
className
=
"absolute bottom right flex align-center p1"
>
<
CheckBox
label
=
"Centered"
checked
=
{
centered
}
onChange
=
{
e
=>
this
.
setState
({
centered
:
!
centered
})
}
/>
</
div
>
</
div
>
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment