-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Topic heirarchy. New topic page (#3115)
* Let topics have topics. New topic page (wip) * Add controls to add/remove topics in sidebar * use LiteGroups * Add questions tab * ... and topic header * Remove topic-specific logic from /browse * redirects * fixup LiteGroup * Add dashboards tab * Add leaderboard tab * responsive * Style sidebar better * only get public dashboards * rename group -> topic * remove static paths * Fix about editor * Fix remove topic ui * sort topic sidebar by importance * update merge groups script to delete relations * default to questions tab for signed in
- Loading branch information
Showing
30 changed files
with
954 additions
and
494 deletions.
There are no files selected for viewing
This file contains 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,47 @@ | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
import { APIError, APIHandler } from './helpers/endpoint' | ||
import { isAdminId, isModId } from 'common/envs/constants' | ||
import { revalidateStaticProps } from 'shared/utils' | ||
import { groupPath } from 'common/group' | ||
|
||
export const addOrRemoveTopicFromTopic: APIHandler< | ||
'group/by-id/:topId/group/:bottomId' | ||
> = async (props, auth) => { | ||
const { topId, bottomId, remove } = props | ||
|
||
const pg = createSupabaseDirectClient() | ||
|
||
if (!isModId(auth.uid) && !isAdminId(auth.uid)) { | ||
throw new APIError( | ||
403, | ||
'You do not have permission to update group relationships' | ||
) | ||
} | ||
|
||
if (remove) { | ||
await pg.none( | ||
`delete from group_groups where top_id = $1 and bottom_id = $2`, | ||
[topId, bottomId] | ||
) | ||
} else { | ||
await pg.none( | ||
`insert into group_groups (top_id, bottom_id) values ($1, $2)`, | ||
[topId, bottomId] | ||
) | ||
} | ||
const continuation = async () => { | ||
const data = await pg.many( | ||
`select slug from groups where id = $1 or id = $2`, | ||
[topId, bottomId] | ||
) | ||
await Promise.all([ | ||
revalidateStaticProps(groupPath(data[0].slug)), | ||
revalidateStaticProps(groupPath(data[1].slug)), | ||
]) | ||
} | ||
|
||
return { | ||
result: { status: 'success' }, | ||
continue: continuation, | ||
} | ||
} |
This file contains 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,23 @@ | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
import { APIHandler } from './helpers/endpoint' | ||
|
||
export const getTopicDashboards: APIHandler<'group/:slug/dashboards'> = async ({ | ||
slug, | ||
}) => { | ||
const pg = createSupabaseDirectClient() | ||
|
||
return await pg.map( | ||
`select d.id, d.title, d.slug, d.creator_id from dashboards d | ||
join dashboard_groups dg on d.id = dg.dashboard_id | ||
join groups g on dg.group_id = g.id | ||
where g.slug = $1 | ||
and d.visibility = 'public'`, | ||
[slug], | ||
(row) => ({ | ||
id: row.id, | ||
title: row.title, | ||
slug: row.slug, | ||
creatorId: row.creator_id, | ||
}) | ||
) | ||
} |
This file contains 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,37 @@ | ||
import { createSupabaseDirectClient } from 'shared/supabase/init' | ||
import { convertGroup } from 'common/supabase/groups' | ||
import { APIError } from 'common/api/utils' | ||
|
||
export const getTopicTopics = async ( | ||
props: { slug: string } | { id: string } | ||
) => { | ||
const pg = createSupabaseDirectClient() | ||
|
||
let id | ||
if ('id' in props) { | ||
id = props.id | ||
} else { | ||
const group = await pg.oneOrNone(`select id from groups where slug = $1`, [ | ||
props.slug, | ||
]) | ||
if (!group) throw new APIError(404, 'Group not found') | ||
id = group.id | ||
} | ||
|
||
const [above, below] = await pg.multi( | ||
`select id, slug, name, importance_score, privacy_status, total_members | ||
from groups g join group_groups gg | ||
on g.id = gg.top_id where gg.bottom_id = $1 | ||
order by importance_score desc; | ||
select id, slug, name, importance_score, privacy_status, total_members | ||
from groups g join group_groups gg | ||
on g.id = gg.bottom_id where gg.top_id = $1 | ||
order by importance_score desc`, | ||
[id] | ||
) | ||
|
||
return { | ||
above: above.map(convertGroup), | ||
below: below.map(convertGroup), | ||
} | ||
} |
This file contains 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 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 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 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 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 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,29 @@ | ||
-- This file is autogenerated from regen-schema.ts | ||
create table if not exists | ||
group_groups ( | ||
bottom_id text not null, | ||
top_id text not null, | ||
constraint primary key (top_id, bottom_id) | ||
); | ||
|
||
-- Foreign Keys | ||
alter table group_groups | ||
add constraint group_groups_bottom_id_fkey foreign key (bottom_id) references groups (id) on update cascade on delete cascade; | ||
|
||
alter table group_groups | ||
add constraint group_groups_top_id_fkey foreign key (top_id) references groups (id) on update cascade on delete cascade; | ||
|
||
-- Row Level Security | ||
alter table group_groups enable row level security; | ||
|
||
-- Policies | ||
drop policy if exists "public read" on group_groups; | ||
|
||
create policy "public read" on group_groups for | ||
select | ||
using (true); | ||
|
||
-- Indexes | ||
drop index if exists group_groups_top_id_bottom_id_pkey; | ||
|
||
create unique index group_groups_top_id_bottom_id_pkey on public.group_groups using btree (top_id, bottom_id); |
This file contains 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 |
---|---|---|
@@ -1,15 +1,13 @@ | ||
## Database Migrations and Schema Updates | ||
@@ -18,8 +18,9 @@ | ||
|
||
#### Topics and Groups | ||
- Topics in the UI are called "groups" in the database and code | ||
-- Topics can have hierarchical relationships via the group_groups table | ||
-- Topics use top/bottom terminology for hierarchical relationships, not parent/child | ||
+- Topics can have hierarchical relationships via the group_groups table | ||
+- Topics use top/bottom terminology for hierarchical relationships, not parent/child, to emphasize that relationships are directional but not strictly hierarchical | ||
+- This design allows for more flexible topic organization than traditional parent/child trees, as topics can appear in multiple hierarchies | ||
- A topic can have multiple topics above (top_id) and below (bottom_id) it | ||
- Topics are used to categorize markets/contracts | ||
|
||
|
||
### Applying Migrations | ||
|
||
The project does not use a migrate script. Instead, migrations are typically applied manually by running the SQL directly against the database. | ||
|
||
### Regenerating Types and Schema | ||
|
||
To regenerate TypeScript types and database schema for the development environment, use the following command: | ||
|
||
``` | ||
(cd backend/supabase && make regen-types-dev regen-schema-dev) | ||
``` | ||
|
||
This command should be run after making changes to the database structure or when updating the development environment. |
This file contains 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 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
Oops, something went wrong.