-
Notifications
You must be signed in to change notification settings - Fork 163
Add a route to show user targets #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TorstenDittmann
merged 14 commits into
fix-create-provider-enabled
from
feat-auth-user-targets
Jan 22, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5019d4c
Add a route to show user targets
stnguyen90 0cb05f1
Allow topics with empty string
stnguyen90 d40cb24
Merge pull request #716 from appwrite/feat-empty-topic-description
TorstenDittmann 5c03c73
Update filterable subscriber columns
stnguyen90 9b686f7
Merge pull request #729 from appwrite/feat-messaging-filtering-subscr…
TorstenDittmann b12e671
Ensure messages table re-renders on filter
stnguyen90 006fff8
Don't allow filtering on message
stnguyen90 46a0103
Update messages search placeholder
stnguyen90 415ca4e
Move the User Targets Filters & Columns buttons to the same row as th…
stnguyen90 c3bc106
Fix user targets modal text
stnguyen90 8914060
Remove bullet points from the topics modal
stnguyen90 c0a8bf9
Update search subscribers placeholder
stnguyen90 6605171
Update wizard to support additional action buttons
stnguyen90 708aaf4
Add support for saving messages as draft
stnguyen90 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/routes/console/project-[project]/auth/user-[user]/targets/+page.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<script lang="ts"> | ||
import { page } from '$app/stores'; | ||
import { Button } from '$lib/elements/forms'; | ||
import { | ||
Empty, | ||
EmptySearch, | ||
PaginationWithLimit, | ||
Heading, | ||
ViewSelector, | ||
EmptyFilter | ||
} from '$lib/components'; | ||
import { Container } from '$lib/layout'; | ||
import type { PageData } from './$types'; | ||
import Table from './table.svelte'; | ||
import { Filters, hasPageQueries } from '$lib/components/filters'; | ||
import { columns } from './store'; | ||
import { View } from '$lib/helpers/load'; | ||
import Create from './create.svelte'; | ||
|
||
export let data: PageData; | ||
let showAdd = false; | ||
</script> | ||
|
||
<Container> | ||
<div class="u-flex u-flex-vertical"> | ||
<div class="u-flex u-main-space-between"> | ||
<Heading tag="h2" size="5">Targets</Heading> | ||
<!-- TODO: Remove u-hide to add creating a target --> | ||
<div class="is-only-mobile u-hide"> | ||
<Button on:click={() => (showAdd = true)} event="create_user_target"> | ||
<span class="icon-plus" aria-hidden="true" /> | ||
<span class="text">Add target</span> | ||
</Button> | ||
</div> | ||
<!-- TODO: Remove when searching is added --> | ||
<div class="u-flex u-main-end u-gap-16 is-not-mobile"> | ||
<Filters query={data.query} {columns} /> | ||
<div> | ||
<ViewSelector | ||
view={View.Table} | ||
{columns} | ||
hideView | ||
allowNoColumns | ||
showColsTextMobile /> | ||
<div class="u-hide"> | ||
<Button on:click={() => (showAdd = true)} event="create_user_target"> | ||
<span class="icon-plus" aria-hidden="true" /> | ||
<span class="text">Add target</span> | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<!-- TODO: Add searching when API supports it --> | ||
<!-- <SearchQuery search={data.search} placeholder="Search by name"> | ||
<div class="u-flex u-gap-16 is-not-mobile"> | ||
<Filters query={data.query} {columns} /> | ||
<ViewSelector | ||
view={View.Table} | ||
{columns} | ||
hideView | ||
allowNoColumns | ||
showColsTextMobile /> | ||
<Button on:click={() => (showAdd = true)} event="create_user_target"> | ||
<span class="icon-plus" aria-hidden="true" /> | ||
<span class="text">Add target</span> | ||
</Button> | ||
</div> | ||
</SearchQuery> --> | ||
<div class="u-flex u-gap-16 is-only-mobile u-margin-block-start-16"> | ||
<div class="u-flex-basis-50-percent"> | ||
<!-- TODO: fix width --> | ||
<ViewSelector | ||
view={View.Table} | ||
{columns} | ||
hideView | ||
allowNoColumns | ||
showColsTextMobile /> | ||
</div> | ||
<div class="u-flex-basis-50-percent"> | ||
<!-- TODO: fix width --> | ||
<Filters query={data.query} {columns} /> | ||
</div> | ||
</div> | ||
</div> | ||
{#if data.targets.total} | ||
<Table {data} /> | ||
|
||
<PaginationWithLimit | ||
name="Targets" | ||
limit={data.limit} | ||
offset={data.offset} | ||
total={data.targets.total} /> | ||
{:else if $hasPageQueries} | ||
<EmptyFilter resource="targets" /> | ||
{:else if data.search} | ||
<EmptySearch> | ||
<div class="u-text-center"> | ||
<b>Sorry, we couldn't find '{data.search}'</b> | ||
<p>There are no targets that match your search.</p> | ||
</div> | ||
<Button | ||
secondary | ||
href={`/console/project-${$page.params.project}/auth/user-${$page.params.user}/targets`}> | ||
Clear Search | ||
</Button> | ||
</EmptySearch> | ||
{:else} | ||
<!-- TODO: update docs link --> | ||
<Empty | ||
single | ||
on:click={() => (showAdd = true)} | ||
href="https://appwrite.io/docs/references/cloud/client-web/teams" | ||
target="subscriber" /> | ||
{/if} | ||
</Container> | ||
|
||
<Create bind:show={showAdd} on:close={() => (showAdd = false)} /> | ||
|
83 changes: 83 additions & 0 deletions
83
src/routes/console/project-[project]/auth/user-[user]/targets/+page.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Query } from '@appwrite.io/console'; | ||
import { sdk } from '$lib/stores/sdk'; | ||
import { getLimit, getPage, getQuery, getSearch, pageToOffset } from '$lib/helpers/load'; | ||
import { Dependencies, PAGE_LIMIT } from '$lib/constants'; | ||
import type { PageLoad } from './$types'; | ||
import { queryParamToMap, queries } from '$lib/components/filters'; | ||
import type { Provider, Target } from '$routes/console/project-[project]/messaging/store'; | ||
|
||
export const load: PageLoad = async ({ params, url, route, depends }) => { | ||
depends(Dependencies.USER_TARGETS); | ||
const page = getPage(url); | ||
const limit = getLimit(url, route, PAGE_LIMIT); | ||
const offset = pageToOffset(page, limit); | ||
const search = getSearch(url); | ||
const query = getQuery(url); | ||
|
||
const parsedQueries = queryParamToMap(query || '[]'); | ||
queries.set(parsedQueries); | ||
|
||
const payload = { | ||
queries: [ | ||
Query.limit(limit), | ||
Query.offset(offset), | ||
Query.orderDesc(''), | ||
...parsedQueries.values() | ||
] | ||
}; | ||
|
||
if (search) { | ||
payload['search'] = search; | ||
} | ||
|
||
// TODO: remove when the API is ready with data | ||
// This allows us to mock w/ data and when search returns 0 results | ||
const targets: { targets: Target[]; total: number } = | ||
await sdk.forProject.client.call( | ||
'GET', | ||
new URL( | ||
`${sdk.forProject.client.config.endpoint}/users/${params.user}/targets` | ||
), | ||
{ | ||
'X-Appwrite-Project': sdk.forProject.client.config.project, | ||
'content-type': 'application/json', | ||
'X-Appwrite-Mode': 'admin' | ||
}, | ||
payload | ||
); | ||
|
||
const promisesById: Record<string, Promise<any>> = {}; | ||
targets.targets.forEach((target) => { | ||
if (target.providerId && !promisesById[target.providerId]) { | ||
promisesById[target.providerId] = sdk.forProject.client.call( | ||
'GET', | ||
new URL( | ||
`${sdk.forProject.client.config.endpoint}/messaging/providers/${target.providerId}` | ||
), | ||
{ | ||
'X-Appwrite-Project': sdk.forProject.client.config.project, | ||
'content-type': 'application/json', | ||
'X-Appwrite-Mode': 'admin' | ||
} | ||
); | ||
} | ||
}); | ||
|
||
const providersById: Record<string, Provider> = {}; | ||
const resolved = await Promise.allSettled(Object.values(promisesById)); | ||
resolved.forEach((result) => { | ||
if (result.status === 'fulfilled') { | ||
const provider = result.value; | ||
providersById[provider.$id] = provider; | ||
} | ||
}); | ||
|
||
return { | ||
offset, | ||
limit, | ||
search, | ||
query, | ||
targets, | ||
providersById, | ||
}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fetching providers here because Jake said: