Skip to content

Commit

Permalink
Added status filter to changes page.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Nov 25, 2024
1 parent a62dfc7 commit 25f75dd
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Dates should be in`YYYY-MM-DD` format and versions are in [semantic versioning](

## v0.7.2 2024-11-24

### Added

- Added status filter to changes page.

### Maintenance

- Updated Svelte and Supabase point releases.
Expand Down
21 changes: 6 additions & 15 deletions src/lib/ChangeView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import Visibility from './Visibility.svelte';
import Table from './Table.svelte';
import Labeled from './Labeled.svelte';
import StatusChooser from './StatusChooser.svelte';
import { isStatus } from './status';
interface Props {
change: ChangeRow;
Expand All @@ -38,17 +40,6 @@
const user = getUser();
const db = getDB();
const Statuses = {
triage: 'Triage',
backlog: 'Backlog',
active: 'Active',
blocked: 'Blocked',
done: 'Done',
declined: 'Declined'
} as const;
const isStatus = (x: string): x is keyof typeof Statuses => x in Statuses;
let isAdmin = $derived($user && org?.hasAdminPerson($user.id));
let editable = $derived(
$user && (isAdmin || change.who === $user.id || change.lead === $user.id)
Expand Down Expand Up @@ -87,11 +78,11 @@
>
<Status status={change.status} />
{#if editable}
<Select
<StatusChooser
tip="Change the status of this change"
selection={change.status}
options={Object.entries(Statuses).map(([key, value]) => ({ value: key, label: value }))}
change={async (status) => {
value={change.status}
none={false}
change={async (status: string | undefined) => {
if ($user && status !== undefined && isStatus(status))
return await queryOrError(
db.updateChangeStatus(change, status, $user.id),
Expand Down
35 changes: 30 additions & 5 deletions src/lib/Changes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import Field from './Field.svelte';
import Visibility from './Visibility.svelte';
import Oops from './Oops.svelte';
import Flow from './Flow.svelte';
import StatusChooser from './StatusChooser.svelte';
import Labeled from './Labeled.svelte';
import { type StatusType } from './status';
import Notice from './Notice.svelte';
interface Props {
changes: ChangeRow[];
Expand All @@ -29,9 +34,10 @@
($user !== null && org.hasPerson($user.id))
);
let filter = $state('');
let lowerFilter = $derived(filter.toLocaleLowerCase().trim());
let filteredChanges = $derived(
let filterText = $state('');
let filterStatus = $state<undefined | StatusType>(undefined);
let lowerFilter = $derived(filterText.toLocaleLowerCase().trim());
let textFilteredChanges = $derived(
lowerFilter.length > 0
? changes.filter(
(change) =>
Expand All @@ -41,14 +47,29 @@
)
: changes
);
let statusFilteredChanges = $derived(
filterStatus === undefined
? textFilteredChanges
: textFilteredChanges.filter((change) => change.status === filterStatus)
);
</script>

{#if !visible}
<Oops text="Only showing public changes of this private organization." />
{/if}

{#if changes.length > 0}
<Field label="Filter" bind:text={filter} />
<Flow>
<Field label="Filter by text" bind:text={filterText} />
<Labeled label="Filter by status">
<StatusChooser
none={true}
tip="Filter by status"
change={(value) => (filterStatus = value)}
value={undefined}
/>
</Labeled>
</Flow>
<Table>
<thead>
<tr>
Expand All @@ -59,7 +80,7 @@
</tr>
</thead>
<tbody>
{#each filteredChanges
{#each statusFilteredChanges
.sort((a, b) => timestampToDate(a.when).getTime() - timestampToDate(b.when).getTime())
.sort((a, b) => Levels[a.status] - Levels[b.status]) as change}
<tr>
Expand All @@ -72,6 +93,10 @@
>
<td><ChangeLink id={change.id} /></td>
</tr>
{:else}
<tr>
<td colspan="4"><Notice>All changes filtered.</Notice></td>
</tr>
{/each}
</tbody>
</Table>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Notice.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<style>
div {
display: inline-block;
display: block;
background-color: var(--warning);
color: var(--background);
padding: var(--padding);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Select.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
title={tip}
aria-label={tip}
bind:value={selection}
onchange={change(selection)}
onchange={() => change(selection)}
class:fit={typeof fit === 'boolean' && fit === true ? 'fit' : ''}
style:width={typeof fit === 'string' ? fit : ''}
disabled={active === false}
Expand Down
23 changes: 23 additions & 0 deletions src/lib/StatusChooser.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script lang="ts">
import Select from './Select.svelte';
import { isStatus, Statuses, type StatusType } from './status';
interface Props {
tip: string;
change: (value: StatusType | undefined) => any;
none: boolean;
value: string | undefined;
}
let { tip, change, none, value }: Props = $props();
</script>

<Select
{tip}
selection={value}
options={[
...(none ? [{ value: undefined, label: 'All' }] : []),
...Object.entries(Statuses).map(([key, value]) => ({ value: key, label: value }))
]}
change={(value) => change(value === undefined ? undefined : isStatus(value) ? value : undefined)}
/>
12 changes: 12 additions & 0 deletions src/lib/status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const Statuses = {
triage: 'Triage',
backlog: 'Backlog',
active: 'Active',
blocked: 'Blocked',
done: 'Done',
declined: 'Declined'
} as const;

export type StatusType = keyof typeof Statuses;

export const isStatus = (x: string): x is StatusType => x in Statuses;

0 comments on commit 25f75dd

Please sign in to comment.