Skip to content

Commit

Permalink
autofollow view preview
Browse files Browse the repository at this point in the history
  • Loading branch information
ma542 committed Dec 22, 2023
1 parent 6bcccb2 commit 6bd7fda
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 47 deletions.
47 changes: 1 addition & 46 deletions web/components/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -93,52 +93,7 @@
}
async function saveFilters(isNew: boolean = false) {
if (!filters.name) {
isNew = true;
}
if (isNew) {
const filterToSave = { ...filters, default: true };
const { data } = await clickupService.showInput({
placeHolder: 'Configuration name',
prompt: 'Choose a name',
value: '',
});
filterToSave.name = data.trim();
if (!filterToSave.name || configFilters.find((f) => f.name === data)) {
clickupService.showToast('error', 'Invalid name');
return;
}
if (!viewMode) {
filterToSave.selectedView = undefined;
} else {
filterToSave.selectedLists = [];
}
const config: WorkspaceConfig = {
filters: [
...configFilters.map((f) => ({ ...f, default: false })),
filterToSave,
],
ganttMode,
};
const res = await clickupService.saveConfig(config, configName);
if (res.ok) {
filters = filterToSave;
configFilters = config.filters;
clickupService.showToast('info', 'Configuration saved');
}
} else {
const idx = configFilters.findIndex((e) => e.name === filters.name);
if (idx >= 0) {
configFilters[idx] = { ...filters };
const res = await clickupService.saveConfig(
{ filters: configFilters, ganttMode },
configName
);
if (res.ok) {
clickupService.showToast('info', 'Configuration saved');
}
}
}
dispatch('saveFilters', isNew);
}
</script>

Expand Down
107 changes: 106 additions & 1 deletion web/components/Page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<script lang="ts">
import { onMount } from 'svelte';
import type { Interval, PageFilters, Task } from '../interfaces/clickup';
import type {
Interval,
PageFilters,
Space,
Task,
WorkspaceConfig,
} from '../interfaces/clickup';
import clickupService from '../services/clickup-service';
import { user, userList } from '../store/users';
import Board from './kanban/Board.svelte';
Expand Down Expand Up @@ -132,6 +138,7 @@
throw new Error();
}
await updateSelectorsCache();
await updateFollowedViews();
} catch (error) {
initErrors = true;
}
Expand Down Expand Up @@ -184,6 +191,103 @@
]);
}
async function updateFollowedViews() {
const followed = configFilters.filter((f) => f.follow);
for (let follow of followed) {
const newList = getLastFollowed(follow, $spacesTree.spaces);
if (newList) {
const { data } = await clickupService.getListViews(newList.id);
if (data.length && data[0]?.id !== follow.selectedView?.id) {
data[0].list = newList;
const redoSearch =
filters.selectedView?.id === follow.selectedView?.id;
filters.selectedView = data[0];
follow.selectedView = data[0];
if (redoSearch) {
search();
}
saveFilters(follow);
}
}
}
}
function getLastFollowed(filter: PageFilters, spaces: Space[]) {
const space = spaces.find(
(s) => s.id === filter.selectedView.list.space.id
);
for (let folder of space.folders) {
if (folder.lists.find((l) => l.id === filter.selectedView.list.id)) {
const follow = [...folder.lists]
.sort((a, b) => a.name.localeCompare(b.name))
.findLast((l) => l.name.startsWith(filter.follow));
if (follow && follow.id !== filter.selectedView.list.id) {
return follow;
}
}
}
if (space.lists.find((l) => l.id === filter.selectedView.list.id)) {
const follow = [...space.lists]
.sort((a, b) => a.name.localeCompare(b.name))
.findLast((l) => l.name.startsWith(filter.follow));
if (follow) {
return follow;
}
}
return null;
}
$: configName = mode === 'timesheet' ? 'ts-config' : 'vs-config';
async function saveFilters(filters: PageFilters, isNew: boolean = false) {
if (!filters.name) {
isNew = true;
}
if (isNew) {
const filterToSave = { ...filters, default: true };
const { data } = await clickupService.showInput({
placeHolder: 'Configuration name',
prompt: 'Choose a name',
value: '',
});
filterToSave.name = data.trim();
if (!filterToSave.name || configFilters.find((f) => f.name === data)) {
clickupService.showToast('error', 'Invalid name');
return;
}
if (!viewMode) {
filterToSave.selectedView = undefined;
} else {
filterToSave.selectedLists = [];
}
const config: WorkspaceConfig = {
filters: [
...configFilters.map((f) => ({ ...f, default: false })),
filterToSave,
],
ganttMode,
};
const res = await clickupService.saveConfig(config, configName);
if (res.ok) {
filters = filterToSave;
configFilters = config.filters;
clickupService.showToast('info', 'Configuration saved');
}
} else {
const idx = configFilters.findIndex((e) => e.name === filters.name);
if (idx >= 0) {
configFilters[idx] = { ...filters };
const res = await clickupService.saveConfig(
{ filters: configFilters, ganttMode },
configName
);
if (res.ok) {
clickupService.showToast('info', 'Configuration saved');
}
}
}
}
async function search(load = true) {
await Promise.all([
load ? suspend(refreshTasks()) : refreshTasks(),
Expand Down Expand Up @@ -434,6 +538,7 @@
on:search={() => search()}
on:updateTrack={({ detail }) => updateTrack(detail.track, detail.time)}
on:deleteTrack={(e) => deleteTrack(e.detail)}
on:saveFilters={({ detail }) => saveFilters(filters, detail)}
/>
<Filters bind:filters bind:viewMode bind:term on:search={() => search()} />
</div>
Expand Down
8 changes: 8 additions & 0 deletions web/components/filters/AdditionalFilters.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
<div class="flex items-center mt-2">
<small class="w-10 flex-none">Tags:</small>
<TagPicker bind:selected={filters.tags} on:change={onChange} />
{#if viewMode}
<input
class="ml-2 !w-14"
placeholder="Follow..."
bind:value={filters.follow}
on:change={onChange}
/>
{/if}
</div>
<div class="flex items-center mt-2">
<small class="w-10 flex-none">Statuses:</small>
Expand Down
1 change: 1 addition & 0 deletions web/interfaces/clickup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export interface PageFilters {
subtasks: boolean;
include_closed: boolean;
allTracking: boolean;
follow?: string;
}

export interface View {
Expand Down

0 comments on commit 6bd7fda

Please sign in to comment.