2022-09-26 23:22:19 -06:00
|
|
|
<script>
|
|
|
|
import DiffFileTreeItem from './DiffFileTreeItem.vue';
|
2023-05-30 04:53:15 -06:00
|
|
|
import {loadMoreFiles} from '../features/repo-diff.js';
|
2023-03-30 06:06:10 -06:00
|
|
|
import {toggleElem} from '../utils/dom.js';
|
2023-05-30 04:53:15 -06:00
|
|
|
import {diffTreeStore} from '../modules/stores.js';
|
2023-04-12 01:06:39 -06:00
|
|
|
import {setFileFolding} from '../features/file-fold.js';
|
2022-09-26 23:22:19 -06:00
|
|
|
|
|
|
|
const LOCAL_STORAGE_KEY = 'diff_file_tree_visible';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {DiffFileTreeItem},
|
|
|
|
data: () => {
|
2023-05-30 04:53:15 -06:00
|
|
|
return {store: diffTreeStore()};
|
2022-09-26 23:22:19 -06:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
fileTree() {
|
|
|
|
const result = [];
|
2023-05-30 04:53:15 -06:00
|
|
|
for (const file of this.store.files) {
|
2022-09-26 23:22:19 -06:00
|
|
|
// Split file into directories
|
|
|
|
const splits = file.Name.split('/');
|
|
|
|
let index = 0;
|
|
|
|
let parent = null;
|
|
|
|
let isFile = false;
|
|
|
|
for (const split of splits) {
|
|
|
|
index += 1;
|
|
|
|
// reached the end
|
|
|
|
if (index === splits.length) {
|
|
|
|
isFile = true;
|
|
|
|
}
|
|
|
|
let newParent = {
|
|
|
|
name: split,
|
|
|
|
children: [],
|
2024-03-22 08:06:53 -06:00
|
|
|
isFile,
|
2022-09-26 23:22:19 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
if (isFile === true) {
|
|
|
|
newParent.file = file;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
// check if the folder already exists
|
|
|
|
const existingFolder = parent.children.find(
|
2024-03-22 08:06:53 -06:00
|
|
|
(x) => x.name === split,
|
2022-09-26 23:22:19 -06:00
|
|
|
);
|
|
|
|
if (existingFolder) {
|
|
|
|
newParent = existingFolder;
|
|
|
|
} else {
|
|
|
|
parent.children.push(newParent);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const existingFolder = result.find((x) => x.name === split);
|
|
|
|
if (existingFolder) {
|
|
|
|
newParent = existingFolder;
|
|
|
|
} else {
|
|
|
|
result.push(newParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parent = newParent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const mergeChildIfOnlyOneDir = (entries) => {
|
|
|
|
for (const entry of entries) {
|
|
|
|
if (entry.children) {
|
|
|
|
mergeChildIfOnlyOneDir(entry.children);
|
|
|
|
}
|
|
|
|
if (entry.children.length === 1 && entry.children[0].isFile === false) {
|
|
|
|
// Merge it to the parent
|
|
|
|
entry.name = `${entry.name}/${entry.children[0].name}`;
|
|
|
|
entry.children = entry.children[0].children;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// Merge folders with just a folder as children in order to
|
|
|
|
// reduce the depth of our tree.
|
|
|
|
mergeChildIfOnlyOneDir(result);
|
|
|
|
return result;
|
2024-03-22 08:06:53 -06:00
|
|
|
},
|
2022-09-26 23:22:19 -06:00
|
|
|
},
|
|
|
|
mounted() {
|
2023-06-02 09:39:01 -06:00
|
|
|
// Default to true if unset
|
|
|
|
this.store.fileTreeIsVisible = localStorage.getItem(LOCAL_STORAGE_KEY) !== 'false';
|
2022-09-26 23:22:19 -06:00
|
|
|
document.querySelector('.diff-toggle-file-tree-button').addEventListener('click', this.toggleVisibility);
|
2023-04-07 12:27:10 -06:00
|
|
|
|
|
|
|
this.hashChangeListener = () => {
|
2023-04-11 18:44:26 -06:00
|
|
|
this.store.selectedItem = window.location.hash;
|
2023-04-12 01:06:39 -06:00
|
|
|
this.expandSelectedFile();
|
2023-04-07 12:27:10 -06:00
|
|
|
};
|
2023-04-11 18:44:26 -06:00
|
|
|
this.hashChangeListener();
|
|
|
|
window.addEventListener('hashchange', this.hashChangeListener);
|
2022-09-26 23:22:19 -06:00
|
|
|
},
|
|
|
|
unmounted() {
|
|
|
|
document.querySelector('.diff-toggle-file-tree-button').removeEventListener('click', this.toggleVisibility);
|
2023-04-07 12:27:10 -06:00
|
|
|
window.removeEventListener('hashchange', this.hashChangeListener);
|
2022-09-26 23:22:19 -06:00
|
|
|
},
|
|
|
|
methods: {
|
2023-04-12 01:06:39 -06:00
|
|
|
expandSelectedFile() {
|
|
|
|
// expand file if the selected file is folded
|
|
|
|
if (this.store.selectedItem) {
|
|
|
|
const box = document.querySelector(this.store.selectedItem);
|
|
|
|
const folded = box?.getAttribute('data-folded') === 'true';
|
|
|
|
if (folded) setFileFolding(box, box.querySelector('.fold-file'), false);
|
|
|
|
}
|
|
|
|
},
|
2022-09-26 23:22:19 -06:00
|
|
|
toggleVisibility() {
|
2023-05-30 04:53:15 -06:00
|
|
|
this.updateVisibility(!this.store.fileTreeIsVisible);
|
2022-09-26 23:22:19 -06:00
|
|
|
},
|
|
|
|
updateVisibility(visible) {
|
2023-05-30 04:53:15 -06:00
|
|
|
this.store.fileTreeIsVisible = visible;
|
|
|
|
localStorage.setItem(LOCAL_STORAGE_KEY, this.store.fileTreeIsVisible);
|
|
|
|
this.updateState(this.store.fileTreeIsVisible);
|
2022-09-26 23:22:19 -06:00
|
|
|
},
|
2023-03-30 06:06:10 -06:00
|
|
|
updateState(visible) {
|
|
|
|
const btn = document.querySelector('.diff-toggle-file-tree-button');
|
|
|
|
const [toShow, toHide] = btn.querySelectorAll('.icon');
|
|
|
|
const tree = document.getElementById('diff-file-tree');
|
|
|
|
const newTooltip = btn.getAttribute(visible ? 'data-hide-text' : 'data-show-text');
|
|
|
|
btn.setAttribute('data-tooltip-content', newTooltip);
|
|
|
|
toggleElem(tree, visible);
|
|
|
|
toggleElem(toShow, !visible);
|
|
|
|
toggleElem(toHide, visible);
|
2022-09-26 23:22:19 -06:00
|
|
|
},
|
|
|
|
loadMoreData() {
|
2023-05-30 04:53:15 -06:00
|
|
|
loadMoreFiles(this.store.linkLoadMore);
|
2022-12-23 09:03:11 -07:00
|
|
|
},
|
2022-09-26 23:22:19 -06:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
2023-09-02 08:59:07 -06:00
|
|
|
<template>
|
2023-10-21 04:38:19 -06:00
|
|
|
<div v-if="store.fileTreeIsVisible" class="diff-file-tree-items">
|
2023-09-02 08:59:07 -06:00
|
|
|
<!-- only render the tree if we're visible. in many cases this is something that doesn't change very often -->
|
|
|
|
<DiffFileTreeItem v-for="item in fileTree" :key="item.name" :item="item"/>
|
Migrate margin and padding helpers to tailwind (#30043)
This will conclude the refactor of 1:1 class replacements to tailwind,
except `gt-hidden`. Commands ran:
```bash
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-0#tw-$1$2-0#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-1#tw-$1$2-0.5#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-2#tw-$1$2-1#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-3#tw-$1$2-2#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-4#tw-$1$2-4#g' {web_src/js,templates,routers,services}/**/*
perl -p -i -e 's#gt-(p|m)([lrtbxy])?-5#tw-$1$2-8#g' {web_src/js,templates,routers,services}/**/*
```
2024-03-24 10:42:49 -06:00
|
|
|
<div v-if="store.isIncomplete" class="tw-pt-1">
|
2023-09-02 08:59:07 -06:00
|
|
|
<a :class="['ui', 'basic', 'tiny', 'button', store.isLoadingNewData ? 'disabled' : '']" @click.stop="loadMoreData">{{ store.showMoreMessage }}</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2023-10-21 04:38:19 -06:00
|
|
|
<style scoped>
|
|
|
|
.diff-file-tree-items {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
gap: 1px;
|
|
|
|
margin-right: .5rem;
|
|
|
|
}
|
|
|
|
</style>
|