Skip to content

Commit

Permalink
chore(core): sort locks, commit files, submit files by display name (#71
Browse files Browse the repository at this point in the history
)
  • Loading branch information
rdunnington authored Jun 14, 2024
1 parent 8f766c8 commit b368289
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
15 changes: 8 additions & 7 deletions core/ui/src/lib/components/repo/CommitTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
let loadingCommitFiles = false;
let commitFiles: CommitFileInfo[] = [];
const getFileDisplayName = (file: CommitFileInfo): string => {
if (file.displayName === '') {
return file.file;
}
return file.displayName;
};
const isCommitLatestLocal = (sha: string): boolean => {
if (commits.length === 0) {
return false;
Expand All @@ -41,6 +48,7 @@
loadingCommitFiles = true;
commitFiles = await showFilesHandler(commit, false);
commitFiles.sort((a, b) => (getFileDisplayName(a) < getFileDisplayName(b) ? -1 : 1));
loadingCommitFiles = false;
};
Expand All @@ -57,13 +65,6 @@
return '';
};
const getFileDisplayName = (file: CommitFileInfo): string => {
if (file.displayName === '') {
return file.file;
}
return file.displayName;
};
</script>

<Table color="custom" striped={true}>
Expand Down
6 changes: 5 additions & 1 deletion friendshipper/src/lib/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ export const allModifiedFiles = derived(repoStatus, ($repoStatus) => {
const modified = $repoStatus?.modifiedFiles ?? [];

const all: ModifiedFile[] = [...untracked, ...modified];
all.sort((a, b) => (a.path < b.path ? -1 : 1));
all.sort((a, b) => {
const aName = a.displayName === '' ? a.path : a.displayName;
const bName = b.displayName === '' ? b.path : b.displayName;
return aName < bName ? -1 : 1;
});

return all;
});
Expand Down
52 changes: 31 additions & 21 deletions friendshipper/src/routes/source/locks/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Toggle,
Tooltip
} from 'flowbite-svelte';
import { derived } from 'svelte/store';
import { emit } from '@tauri-apps/api/event';
import { onMount } from 'svelte';
import { RefreshOutline } from 'flowbite-svelte-icons';
Expand All @@ -29,15 +30,36 @@
let allowReleaseOtherLocks = false;
let searchTerm = '';
$: filteredOurs = $locks.ours.filter((item) =>
const formatPath = (path: string) => {
if (path === '/') return path;
return path.replace(/\/$/, '').split('/').pop();
};
const getLockDisplayName = (lock: Lock): string => {
if (lock.display_name === null || lock.display_name === '') {
return formatPath(lock.path);
}
return lock.display_name;
};
const sortLocksFunc = (a, b) => {
const aName = getLockDisplayName(a);
const bName = getLockDisplayName(b);
return aName < bName ? -1 : 1;
};
$: sortedOurs = derived(locks, ($locks) => $locks.ours.sort(sortLocksFunc), []);
$: sortedTheirs = derived(locks, ($locks) => $locks.theirs.sort(sortLocksFunc), []);
$: filteredOurs = $sortedOurs.filter((item) =>
item.path.toLowerCase().includes(searchTerm.toLowerCase())
);
$: filteredTheirs = $locks.theirs.filter(
$: filteredTheirs = $sortedTheirs.filter(
(item) =>
item.path.toLowerCase().includes(searchTerm.toLowerCase()) ||
item.owner?.name.toLowerCase().includes(searchTerm.toLowerCase())
);
$: unmodifiedLockedFiles = $locks.ours.filter(
$: unmodifiedLockedFiles = $sortedOurs.filter(
(lock) => !$allModifiedFiles.find((file) => file.path === lock.path)
);
Expand All @@ -57,33 +79,33 @@
if (!allowReleaseOtherLocks) return;
if ((e.target as HTMLInputElement).checked) {
const paths = $locks.theirs.map((lock) => lock.path);
const paths = $sortedTheirs.map((lock) => lock.path);
selectedForRelease = selectedForRelease.concat(paths);
numOthersSelected += $locks.theirs.length;
numOthersSelected += $sortedTheirs.length;
selectedForRelease = selectedForRelease.filter(
(item, index) => selectedForRelease.indexOf(item) === index
);
} else {
numOthersSelected -= $locks.theirs.length;
numOthersSelected -= $sortedTheirs.length;
selectedForRelease = selectedForRelease.filter(
(path) => !$locks.theirs.map((lock) => lock.path).includes(path)
(path) => !$sortedTheirs.map((lock) => lock.path).includes(path)
);
}
};
const handleReleaseAllOurs = (e: Event) => {
if ((e.target as HTMLInputElement).checked) {
const paths = $locks.ours.map((lock) => lock.path);
const paths = $sortedOurs.map((lock) => lock.path);
selectedForRelease = selectedForRelease.concat(paths);
selectedForRelease = selectedForRelease.filter(
(item, index) => selectedForRelease.indexOf(item) === index
);
} else {
selectedForRelease = selectedForRelease.filter(
(path) => !$locks.ours.map((lock) => lock.path).includes(path)
(path) => !$sortedOurs.map((lock) => lock.path).includes(path)
);
}
};
Expand Down Expand Up @@ -129,18 +151,6 @@
loading = false;
};
const formatPath = (path: string) => {
if (path === '/') return path;
return path.replace(/\/$/, '').split('/').pop();
};
const getLockDisplayName = (lock: Lock): string => {
if (lock.display_name === null || lock.display_name === '') {
return formatPath(lock.path);
}
return lock.display_name;
};
const getLockTimestamp = (locked_at: string): string => {
const date = new Date(locked_at);
return date.toLocaleString();
Expand Down

0 comments on commit b368289

Please sign in to comment.