Skip to content
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

improve dictionary rows in admin panel #539

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/site/src/lib/components/shell/User.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { mode } from '$lib/supabase'
import { api_update_dev_admin_role } from '$api/db/update-dev-admin-role/_call'
import { invalidateAll } from '$app/navigation'
import { dev } from '$app/environment'

$: ({ user, admin } = $page.data)
let show_menu = false
Expand Down Expand Up @@ -72,7 +73,7 @@
{/if}
<a href="/account"> {$page.data.t('account.account_settings')} </a>
<button type="button" on:click={sign_out}>{$page.data.t('account.log_out')}</button>
{#if mode === 'development'}
{#if dev || mode === 'development'}
<button
type="button"
on:click={setAdminRole}>
Expand Down
2 changes: 1 addition & 1 deletion packages/site/src/routes/admin/dictionaries/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<Filter
items={dictionaries_with_editors_invites}
let:filteredItems={filteredDictionaries}
placeholder="Search dictionaries">
placeholder="Search dictionaries and users">
<div slot="right" let:filteredItems={filteredDictionaries}>
<Button
form="filled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

$: ({ admin, supabase, add_editor, remove_editor, inviteHelper } = $page.data as PageData)

$: managers = dictionary.editors.filter(({ dictionary_roles }) => dictionary_roles.some(({ role }) => role === 'manager'))
$: contributors = dictionary.editors.filter(({ dictionary_roles }) => dictionary_roles.some(({ role }) => role === 'contributor'))
$: managers = dictionary.editors.filter(({ dictionary_roles }) => dictionary_roles.some(({ role, dictionary_id }) => role === 'manager' && dictionary_id === dictionary.id))
$: contributors = dictionary.editors.filter(({ dictionary_roles }) => dictionary_roles.some(({ role, dictionary_id }) => role === 'contributor' && dictionary_id === dictionary.id))
</script>

<td class="relative">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
on:additem={toggle} />

{#if show}
{@const users_without_editors = users.filter(({ id: user_id }) => !editors.some(({ id: editor_id }) => editor_id === user_id))}
{#await import('./SelectUserModal.svelte') then { default: SelectUserModal }}
<SelectUserModal {users} {add_editor} {invite_editor} on_close={toggle} />
<SelectUserModal users={users_without_editors} {add_editor} {invite_editor} on_close={toggle} />
{/await}
{/if}
</ShowHide>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { RequestHandler } from './$types'
import { ResponseCodes } from '$lib/constants'
import { mode } from '$lib/supabase'
import { getAdminSupabaseClient } from '$lib/supabase/admin'
import { dev } from '$app/environment'

export interface UpdateDevAdminRoleRequestBody {
role_level: number
Expand All @@ -11,8 +12,10 @@ export interface UpdateDevAdminRoleRequestBody {
export const POST: RequestHandler = async ({ request, locals: { getSession } }) => {
const { role_level } = await request.json() as UpdateDevAdminRoleRequestBody

if (mode !== 'development')
error(ResponseCodes.BAD_REQUEST, `Only works on dev`)
if (!dev) {
if (mode !== 'development')
error(ResponseCodes.BAD_REQUEST, `Only works on dev`)
}

if (typeof role_level !== 'number')
error(ResponseCodes.BAD_REQUEST, `Role must be a number`)
Expand Down
10 changes: 5 additions & 5 deletions supabase/seed.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INSERT INTO auth.users ("aud", "email", "id", "instance_id", "role") VALUES
('authenticated', '[email protected]', 'de2d3715-6337-45a3-a81a-d82c3210b2a7', '00000000-0000-0000-0000-000000000000', 'authenticated'),
('authenticated', '[email protected]', 'be43b1dd-6c64-494d-b5da-10d70c384433', '00000000-0000-0000-0000-000000000000', 'authenticated');
-- INSERT INTO auth.users ("aud", "email", "id", "instance_id", "role", "confirmation_token", "recovery_token", "email_change_token_new", "email_change") VALUES
-- ('authenticated', '[email protected]', 'de2d3715-6337-45a3-a81a-d82c3210b2a7', '00000000-0000-0000-0000-000000000000', 'authenticated', '', '', '', ''),
-- ('authenticated', '[email protected]', 'be43b1dd-6c64-494d-b5da-10d70c384433', '00000000-0000-0000-0000-000000000000', 'authenticated', '', '', '', '');

INSERT INTO "public"."dictionaries" ("id", "name", "gloss_languages", "created_at", "created_by", "updated_at", "updated_by") VALUES
('test', 'Test Dictionary', '{"en"}', '2024-03-18 14:16:22.367188+00', 'de2d3715-6337-45a3-a81a-d82c3210b2a7', '2024-03-18 14:16:22.367188+00', 'de2d3715-6337-45a3-a81a-d82c3210b2a7');
-- INSERT INTO "public"."dictionaries" ("id", "name", "gloss_languages", "created_at", "created_by", "updated_at", "updated_by") VALUES
-- ('test', 'Test Dictionary', '{"en"}', '2024-03-18 14:16:22.367188+00', 'de2d3715-6337-45a3-a81a-d82c3210b2a7', '2024-03-18 14:16:22.367188+00', 'de2d3715-6337-45a3-a81a-d82c3210b2a7');
Loading