Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mirador Video
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IIIF
Mirador
Mirador Video
Commits
98c72ea9
Commit
98c72ea9
authored
Jan 30, 2019
by
Chris Beer
Browse files
Options
Downloads
Patches
Plain Diff
Refactor WorkspaceMenu with less boiler plate for opening submenus
parent
66d56ca1
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
__tests__/src/components/WorkspaceMenu.test.js
+4
-36
4 additions, 36 deletions
__tests__/src/components/WorkspaceMenu.test.js
src/components/WorkspaceMenu.js
+33
-68
33 additions, 68 deletions
src/components/WorkspaceMenu.js
with
37 additions
and
104 deletions
__tests__/src/components/WorkspaceMenu.test.js
+
4
−
36
View file @
98c72ea9
...
...
@@ -19,51 +19,19 @@ describe('WorkspaceMenu', () => {
expect
(
handleClose
).
toBeCalled
();
});
describe
(
'
handle
WindowList
Click
'
,
()
=>
{
describe
(
'
handle
MenuItem
Click
'
,
()
=>
{
it
(
'
sets the anchor state
'
,
()
=>
{
wrapper
.
instance
().
handle
W
indowList
Click
(
{
currentTarget
:
true
});
wrapper
.
instance
().
handle
MenuItemClick
(
'
w
indowList
'
,
{
currentTarget
:
true
});
expect
(
wrapper
.
find
(
'
Connect(WithStyles(WindowList))
'
).
props
().
open
).
toBe
(
true
);
});
});
describe
(
'
handle
WindowList
Close
'
,
()
=>
{
describe
(
'
handle
MenuItem
Close
'
,
()
=>
{
it
(
'
resets the anchor state
'
,
()
=>
{
wrapper
.
instance
().
handle
W
indowList
Close
();
wrapper
.
instance
().
handle
MenuItemClose
(
'
w
indowList
'
)
();
expect
(
wrapper
.
find
(
'
Connect(WithStyles(WindowList))
'
).
props
().
open
).
toBe
(
false
);
});
});
describe
(
'
handleSettingsClick
'
,
()
=>
{
it
(
'
sets the anchor state
'
,
()
=>
{
wrapper
.
instance
().
handleSettingsClick
({
currentTarget
:
true
});
expect
(
wrapper
.
find
(
'
Connect(WithStyles(WorkspaceSettings))
'
).
props
().
open
).
toBe
(
true
);
});
});
describe
(
'
handleSettingsClose
'
,
()
=>
{
it
(
'
resets the anchor state
'
,
()
=>
{
wrapper
.
instance
().
handleSettingsClose
();
expect
(
wrapper
.
find
(
'
Connect(WithStyles(WorkspaceSettings))
'
).
props
().
open
).
toBe
(
false
);
});
});
describe
(
'
handleExportClick
'
,
()
=>
{
it
(
'
sets the anchor state
'
,
()
=>
{
wrapper
.
instance
().
handleExportClick
({
currentTarget
:
true
});
expect
(
wrapper
.
find
(
'
Connect(WithStyles(WorkspaceExport))
'
).
props
().
open
).
toBe
(
true
);
});
});
describe
(
'
handleExportClose
'
,
()
=>
{
it
(
'
resets the anchor state
'
,
()
=>
{
wrapper
.
instance
().
handleExportClose
();
expect
(
wrapper
.
find
(
'
Connect(WithStyles(WorkspaceExport))
'
).
props
().
open
).
toBe
(
false
);
});
});
});
This diff is collapsed.
Click to expand it.
src/components/WorkspaceMenu.js
+
33
−
68
View file @
98c72ea9
...
...
@@ -24,88 +24,53 @@ export class WorkspaceMenu extends Component {
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
windowList
AnchorEl
:
null
,
settings
AnchorEl
:
null
,
export
AnchorEl
:
null
,
windowList
:
{}
,
settings
:
{}
,
export
Workspace
:
{}
,
};
this
.
handleWindowListClick
=
this
.
handleWindowListClick
.
bind
(
this
);
this
.
handleWindowListClose
=
this
.
handleWindowListClose
.
bind
(
this
);
this
.
handleSettingsClick
=
this
.
handleSettingsClick
.
bind
(
this
);
this
.
handleSettingsClose
=
this
.
handleSettingsClose
.
bind
(
this
);
this
.
handleExportClick
=
this
.
handleExportClick
.
bind
(
this
);
this
.
handleExportClose
=
this
.
handleExportClose
.
bind
(
this
);
this
.
handleMenuItemClick
=
this
.
handleMenuItemClick
.
bind
(
this
);
this
.
handleMenuItemClose
=
this
.
handleMenuItemClose
.
bind
(
this
);
}
/**
* @private
*/
handleWindowListClick
(
event
)
{
this
.
setState
({
windowListAnchorEl
:
event
.
currentTarget
,
});
}
/**
* @private
*/
handleWindowListClose
()
{
this
.
setState
({
windowListAnchorEl
:
null
,
});
}
/**
* @private
*/
handleSettingsClick
(
event
)
{
this
.
setState
({
settingsAnchorEl
:
event
.
currentTarget
,
});
}
/**
* @private
*/
handleSettingsClose
()
{
this
.
setState
({
settingsAnchorEl
:
null
,
});
}
/**
* @private
*/
handleExportClick
(
event
)
{
this
.
setState
({
exportAnchorEl
:
event
.
currentTarget
,
});
handleMenuItemClick
(
item
,
event
)
{
const
obj
=
{};
obj
[
item
]
=
{};
obj
[
item
].
open
=
true
;
obj
[
item
].
anchorEl
=
event
.
currentTarget
;
this
.
setState
(
obj
);
}
/**
* @private
*/
handleExportClose
()
{
this
.
setState
({
exportAnchorEl
:
null
,
});
handleMenuItemClose
(
item
)
{
return
(
event
)
=>
{
const
obj
=
{};
obj
[
item
]
=
{};
obj
[
item
].
open
=
false
;
obj
[
item
].
anchorEl
=
null
;
this
.
setState
(
obj
);
};
}
/**
* render
* @return
*/
render
()
{
const
{
handleClose
,
anchorEl
}
=
this
.
props
;
const
{
windowList
AnchorEl
,
settings
AnchorEl
,
exportAnchorEl
}
=
this
.
state
;
const
{
windowList
,
settings
,
exportWorkspace
}
=
this
.
state
;
return
(
<>
<
Menu
id
=
"
workspace-menu
"
anchorEl
=
{
anchorEl
}
open
=
{
Boolean
(
anchorEl
)}
onClose
=
{
handleClose
}
>
<
MenuItem
aria
-
haspopup
=
"
true
"
onClick
=
{(
e
)
=>
{
this
.
handle
W
indowList
Click
(
e
);
handleClose
(
e
);
}}
aria
-
owns
=
{
windowList
A
nchorEl
?
'
window-list-menu
'
:
undefined
}
onClick
=
{(
e
)
=>
{
this
.
handle
MenuItemClick
(
'
w
indowList
'
,
e
);
handleClose
(
e
);
}}
aria
-
owns
=
{
windowList
.
a
nchorEl
?
'
window-list-menu
'
:
undefined
}
>
<
ListItemIcon
>
<
ViewHeadlineIcon
/>
...
...
@@ -115,8 +80,8 @@ export class WorkspaceMenu extends Component {
<
Divider
/>
<
MenuItem
aria
-
haspopup
=
"
true
"
onClick
=
{(
e
)
=>
{
this
.
handle
SettingsClick
(
e
);
handleClose
(
e
);
}}
aria
-
owns
=
{
settingsAnchorEl
?
'
workspace-settings
'
:
undefined
}
onClick
=
{(
e
)
=>
{
this
.
handle
MenuItemClick
(
'
settings
'
,
e
);
handleClose
(
e
);
}}
aria
-
owns
=
{
settings
.
AnchorEl
?
'
workspace-settings
'
:
undefined
}
>
<
ListItemIcon
>
<
SettingsIcon
/>
...
...
@@ -125,8 +90,8 @@ export class WorkspaceMenu extends Component {
<
/MenuItem
>
<
MenuItem
aria
-
haspopup
=
"
true
"
onClick
=
{(
e
)
=>
{
this
.
handle
ExportClick
(
e
);
handleClose
(
e
);
}}
aria
-
owns
=
{
exportAnchorEl
?
'
workspace-export
'
:
undefined
}
onClick
=
{(
e
)
=>
{
this
.
handle
MenuItemClick
(
'
exportWorkspace
'
,
e
);
handleClose
(
e
);
}}
aria
-
owns
=
{
export
Workspace
.
AnchorEl
?
'
workspace-export
'
:
undefined
}
>
<
ListItemIcon
>
<
SaveAltIcon
/>
...
...
@@ -135,17 +100,17 @@ export class WorkspaceMenu extends Component {
<
/MenuItem
>
<
/Menu
>
<
ConnectedWindowList
anchorEl
=
{
windowList
A
nchorEl
}
open
=
{
Boolean
(
windowList
A
nchorEl
)}
handleClose
=
{
this
.
handle
W
indowList
Close
}
anchorEl
=
{
windowList
.
a
nchorEl
}
open
=
{
Boolean
(
windowList
.
a
nchorEl
)}
handleClose
=
{
this
.
handle
MenuItemClose
(
'
w
indowList
'
)
}
/
>
<
ConnectedWorkspaceSettings
open
=
{
Boolean
(
settings
AnchorEl
)}
handleClose
=
{
this
.
handle
SettingsClose
}
open
=
{
Boolean
(
settings
.
open
)}
handleClose
=
{
this
.
handle
MenuItemClose
(
'
settings
'
)
}
/
>
<
ConnectedWorkspaceExport
open
=
{
Boolean
(
export
AnchorEl
)}
handleClose
=
{
this
.
handle
ExportClose
}
open
=
{
Boolean
(
export
Workspace
.
open
)}
handleClose
=
{
this
.
handle
MenuItemClose
(
'
exportWorkspace
'
)
}
/
>
<
/
>
);
...
...
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