overleaf/services/web/frontend/stylesheets/app/editor/history-react.less
M Fahru 0648b8aa6c Implement deleted file restore for history react (#12753)
* Add strikethrough to deleted file tree item in history file tree

* Add "restore file" button on toolbar if the selected file have a `removed` operation.

* Implement "restore file" functionality on removed file:

- Refactor the `Selection` object in history context value since we need the `deletedAtV` data which currently is not passed through the state.
- Refactor and clean up file tree type system to support passing through the whole `FileDiff` object for getting the `deletedAtV` data which only appear on `removed` operation
- Implement `postJSON` with file restoration API and pass it on restore file onClick handler at toolbar

* Implement loading behaviour while restoring file is inflight:

- Add `loadingRestoreFile` to `LoadingState`
- Change restore file button to `Restoring...` when in loading state.

* Refactor:

- Rename `DiffOperation` to `FileOperation`
- Extract `isFileRemoved` and `isFileRenamed` to its own file
- Extract `Toolbar` components into small files

GitOrigin-RevId: 2e32ebd2165f73fc6533ff282a9c084162efd682
2023-04-28 08:04:59 +00:00

456 lines
8.5 KiB
Text

@versions-list-width: 320px;
@history-toolbar-height: 40px;
history-root {
height: 100%;
display: block;
}
.history-react {
display: flex;
height: 100%;
background-color: @history-main-bg;
.history-header {
height: @history-toolbar-height;
background-color: @history-react-header-bg;
color: @history-react-header-color;
font-size: @font-size-small;
display: flex;
flex-direction: column;
justify-content: center;
box-sizing: border-box;
}
.doc-panel {
flex: 1;
display: flex;
flex-direction: column;
.toolbar-container {
border-bottom: 1px solid @history-react-separator-color;
padding: 0 8px;
}
.doc-container {
flex: 1;
overflow-y: auto;
}
}
.change-list {
display: flex;
flex-direction: column;
width: @versions-list-width;
font-size: @font-size-small;
border-left: 1px solid @history-react-separator-color;
box-sizing: content-box;
}
.toggle-switch-label {
flex: 1;
span {
display: block;
}
}
.history-version-list-container {
flex: 1;
overflow-y: auto;
}
.history-all-versions-scroller {
overflow-y: auto;
height: 100%;
}
.history-all-versions-container {
position: relative;
}
.history-versions-bottom {
position: absolute;
height: 8em;
bottom: 0;
}
.history-toggle-switch-container,
.history-version-day,
.history-version-details {
padding: 0 16px;
}
.history-version-day {
position: sticky;
z-index: 1;
top: 0;
display: block;
padding-top: 12px;
padding-bottom: 4px;
line-height: 20px;
background-color: @white;
}
.history-version-details {
display: flex;
align-items: flex-start;
padding-top: 8px;
padding-bottom: 8px;
&:hover {
cursor: pointer;
background-color: @neutral-10;
}
}
.history-version-selected {
background-color: @green-10;
}
.history-version-metadata-time {
display: block;
margin-bottom: 4px;
color: @neutral-90;
&:last-child {
margin-bottom: initial;
}
}
.history-version-metadata-users,
.history-version-changes {
margin: 0;
padding: 0;
list-style: none;
}
.history-version-metadata-users {
display: inline;
> li {
display: inline-flex;
align-items: center;
margin-right: 8px;
}
}
.history-version-changes {
> li {
margin-bottom: 4px;
}
}
.history-version-user-badge-color {
@size: 8px;
display: inline-block;
width: @size;
height: @size;
margin-right: 4px;
border-radius: 2px;
}
.history-version-day,
.history-version-change-action,
.history-version-metadata-users,
.history-version-origin,
.history-version-saved-by {
color: @neutral-70;
}
.history-version-change-doc {
color: @neutral-90;
}
.history-version-divider {
margin: 6px 8px;
border-color: @neutral-20;
}
.history-version-badge {
margin-bottom: 4px;
margin-right: 10px;
}
.history-version-label {
margin-bottom: 4px;
&:last-child {
margin-bottom: initial;
}
}
.loading {
padding-top: 10rem;
font-family: @font-family-serif;
text-align: center;
}
& > .loading {
flex: 1;
}
.history-all-versions-scroller .loading {
position: sticky;
bottom: 0;
padding: @line-height-computed / 2 0;
background-color: @gray-lightest;
}
.history-version-saved-by {
&-label {
margin-right: 8px;
}
}
.dropdown.open {
.history-version-dropdown-menu-btn {
background-color: rgba(@neutral-90, 0.08);
box-shadow: initial;
}
}
.history-version-dropdown-menu-btn {
@size: 30px;
padding: 0;
width: @size;
height: @size;
font-size: @font-size-small;
color: @neutral-90;
background-color: transparent;
&:hover,
&:active {
z-index: initial;
background-color: rgba(@neutral-90, 0.08);
box-shadow: initial;
}
}
.history-version-main-details {
flex: 1;
}
.history-loading-panel {
padding-top: 10rem;
font-family: @font-family-serif;
text-align: center;
}
.history-file-entity-operation-badge {
flex: 0 0 auto;
text-transform: lowercase;
margin-left: 0.5em;
font-size: 0.7em;
background: @history-file-badge-bg;
color: @history-file-badge-color;
border-radius: 8px;
line-height: 1;
padding: 2px 4px 3px;
margin-top: 2px;
}
.history-react-toolbar {
display: flex;
align-items: center;
.history-react-toolbar-file-info {
flex: 1;
text-align: right;
}
.history-react-toolbar-time {
font-weight: 700;
}
.history-react-toolbar-restore-file-button {
margin-left: 5px;
}
}
}
.history-version-label-tooltip {
padding: 6px;
text-align: initial;
&-row {
margin-bottom: 6.25px;
&:last-child {
margin-bottom: initial;
}
}
}
.history-version-dropdown-menu {
[role='menuitem'] {
padding: 10px 12px;
color: @neutral-90;
&:hover,
&:focus {
color: @neutral-90;
background-color: @neutral-10;
}
}
}
.document-diff-container {
height: 100%;
display: flex;
flex-direction: column;
position: relative;
.cm-viewer-container,
.cm-editor {
height: 100%;
}
.previous-highlight-button,
.next-highlight-button {
position: absolute;
right: 16px;
}
.previous-highlight-button {
top: 16px;
}
.next-highlight-button {
bottom: 16px;
}
}
.history-file-tree {
display: flex !important; // To work around jQuery layout's inline styles
flex-direction: column;
flex-grow: 1;
max-height: 100%;
ul.history-file-tree-list {
margin: 0;
overflow-x: hidden;
height: 100%;
flex-grow: 1;
position: relative;
overflow-y: auto;
.history-file-tree-item > ul,
ul[role='tree'] {
margin-left: 22px;
}
li.bottom-buffer {
min-height: @line-height-computed;
}
li {
line-height: @file-tree-line-height;
position: relative;
&:focus {
outline: none;
}
.history-file-tree-item {
color: @file-tree-item-color;
cursor: pointer;
white-space: nowrap;
overflow: hidden;
text-overflow: clip;
user-select: none;
&:focus {
outline: none;
}
&:hover {
background-color: @file-tree-item-hover-bg;
// When the entity is a subfolder, the DOM element is "indented" via margin-left. This makes the
// element not fill the entire file-tree width (as it's spaced from the left-hand side via margin)
// and, in consequence, the background gets clipped. The ::before pseudo-selector is used to fill
// the empty space.
.fake-full-width-bg(@file-tree-item-hover-bg);
}
.history-file-tree-folder-button,
.history-file-tree-item-button {
.reset-button;
&:focus {
outline: none;
}
}
.history-file-tree-item-button {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
padding-right: 40px;
font-weight: normal;
display: inline-flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
.history-file-tree-item-button-text {
display: inline-flex;
margin-right: 5px;
&.strikethrough {
text-decoration: line-through;
}
}
.history-file-tree-item-button-badge {
text-transform: capitalize;
&:hover {
background-color: @neutral-20;
}
}
}
}
i.fa {
color: @file-tree-item-icon-color;
font-size: 14px;
&.file-tree-icon {
margin-right: 4px;
margin-left: 8px;
}
&.file-tree-folder-icon {
margin-right: 4px;
}
&.file-tree-expand-icon {
margin-left: 8px;
}
}
i.fa-folder-open,
i.fa-folder {
color: @file-tree-item-folder-color;
font-size: 14px;
}
}
li.selected > .history-file-tree-item {
color: @file-tree-item-selected-color;
background-color: @file-tree-item-selected-bg;
font-weight: bold;
> div > i.fa,
> button > i.fa,
> i.fa {
color: @file-tree-item-selected-color;
}
.fake-full-width-bg(@file-tree-item-selected-bg);
}
}
}