Open platform to collect and prioritize feedback
Better tag admin
Matt Roberts93d306569111
diff --git a/public/pages/Administration/components/TagListItem.tsx b/public/pages/Administration/components/TagListItem.tsxindex f841c3e37..43e15e114 100644--- a/public/pages/Administration/components/TagListItem.tsx+++ b/public/pages/Administration/components/TagListItem.tsx@@ -7,10 +7,12 @@ import { useFider } from "@fider/hooks"import IconX from "@fider/assets/images/heroicons-x.svg"import IconPencilAlt from "@fider/assets/images/heroicons-pencil-alt.svg"-import { HStack, VStack } from "@fider/components/layout"+import { VStack } from "@fider/components/layout"interface TagListItemProps {tag: Tag+ gridTemplateColumns: string+ isLast?: booleanonTagEdited: (tag: Tag) => voidonTagDeleted: (tag: Tag) => void}@@ -47,50 +49,65 @@ export const TagListItem = (props: TagListItemProps) => {}}- const renderDeleteMode = () => {+ const rowClass = `border-b border-gray-200 py-4 px-4 bg-white ${props.isLast ? "rounded-md-b" : ""}`++ if (state === "delete") {return (- <VStack spacing={2}>- <div>- <b>Are you sure?</b>{" "}- <span>- The tag <ShowTag tag={tag} /> will be removed from all posts.- </span>- </div>- <div>- <Button variant="danger" onClick={deleteTag}>- Delete tag- </Button>- <Button onClick={resetState} variant="tertiary">- Cancel- </Button>- </div>- </VStack>+ <div className={rowClass}>+ <VStack spacing={2}>+ <div>+ <b>Are you sure?</b>{" "}+ <span>+ The tag <ShowTag tag={tag} /> will be removed from all posts.+ </span>+ </div>+ <div>+ <Button variant="danger" onClick={deleteTag}>+ Delete tag+ </Button>+ <Button onClick={resetState} variant="tertiary">+ Cancel+ </Button>+ </div>+ </VStack>+ </div>)}- const renderViewMode = () => {- const buttons = fider.session.user.isAdministrator && [- <Button size="small" key={0} onClick={startEdit}>- <Icon sprite={IconPencilAlt} />- <span>Edit</span>- </Button>,- <Button size="small" key={1} onClick={startDelete}>- <Icon sprite={IconX} />- <span>Delete</span>- </Button>,- ]-+ if (state === "edit") {return (- <HStack justify="between">- <ShowTag tag={tag} link />- <HStack>{buttons}</HStack>- </HStack>+ <div className={rowClass}>+ <TagForm name={props.tag.name} color={props.tag.color} isPublic={props.tag.isPublic} onSave={updateTag} onCancel={resetState} />+ </div>)}- const renderEditMode = () => {- return <TagForm name={props.tag.name} color={props.tag.color} isPublic={props.tag.isPublic} onSave={updateTag} onCancel={resetState} />- }-- return state === "delete" ? renderDeleteMode() : state === "edit" ? renderEditMode() : renderViewMode()+ return (+ <div className={`${rowClass} grid gap-4 flex-items-center hover`} style={{ gridTemplateColumns: props.gridTemplateColumns }}>+ <div>+ <ShowTag tag={tag} link />+ </div>+ <div>+ {tag.isPublic ? (+ <span className="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded">public</span>+ ) : (+ <span className="text-xs bg-gray-200 text-gray-800 px-2 py-1 rounded">private</span>+ )}+ </div>+ <div className="flex justify-end gap-2">+ {fider.session.user.isAdministrator && (+ <>+ <Button size="small" onClick={startEdit}>+ <Icon sprite={IconPencilAlt} />+ <span>Edit</span>+ </Button>+ <Button size="small" onClick={startDelete}>+ <Icon sprite={IconX} />+ <span>Delete</span>+ </Button>+ </>+ )}+ </div>+ </div>+ )}diff --git a/public/pages/Administration/pages/ManageTags.page.tsx b/public/pages/Administration/pages/ManageTags.page.tsxindex 04072f088..adcb11963 100644--- a/public/pages/Administration/pages/ManageTags.page.tsx+++ b/public/pages/Administration/pages/ManageTags.page.tsx@@ -27,6 +27,9 @@ interface ManageTagsPageState {}const tagSorter = (t1: Tag, t2: Tag) => {+ if (t1.isPublic !== t2.isPublic) {+ return t1.isPublic ? -1 : 1+ }if (t1.name < t2.name) {return -1} else if (t1.name > t2.name) {@@ -87,10 +90,8 @@ export default class ManageTagsPage extends AdminBasePage<ManageTagsPageProps, M})}- private getTagList(filter: (tag: Tag) => boolean) {- return this.state.allTags.filter(filter).map((t) => {- return <TagListItem key={t.id} tag={t} onTagDeleted={this.handleTagDeleted} onTagEdited={this.handleTagEdited} />- })+ private sortedTags(): Tag[] {+ return this.state.allTags.slice().sort(tagSorter)}private handleImportFile = async (e: React.ChangeEvent<HTMLInputElement>) => {@@ -131,39 +132,54 @@ export default class ManageTagsPage extends AdminBasePage<ManageTagsPageProps, M}public content() {- const publicTaglist = this.getTagList((t) => t.isPublic)- const privateTagList = this.getTagList((t) => !t.isPublic)-- const form =- Fider.session.user.isAdministrator &&- (this.state.isAdding ? (- <TagForm onSave={this.saveNewTag} onCancel={this.cancelAdd} />- ) : (- <Button variant="secondary" onClick={this.addNew}>- <Icon sprite={IconPlus} />- <span>Add new</span>- </Button>- ))+ const tags = this.sortedTags()+ const gridTemplateColumns = "minmax(200px, 1fr) minmax(100px, 150px) 200px"+ const canAdd = Fider.session.user.isAdministrator+ const lastTagIsLast = !canAdd++ const addRow = canAdd && (+ <div className="py-3 px-4 bg-white rounded-md-b">+ {this.state.isAdding ? (+ <TagForm onSave={this.saveNewTag} onCancel={this.cancelAdd} />+ ) : (+ <Button variant="tertiary" onClick={this.addNew}>+ <Icon sprite={IconPlus} />+ <span>Add new tag</span>+ </Button>+ )}+ </div>+ )const { importStatus, importResult, importError } = this.statereturn (<VStack spacing={8}>- <div>- <h2 className="text-display">Public Tags</h2>- <p className="text-muted">These tags are visible to all visitors.</p>- <VStack spacing={4} divide={true}>- {publicTaglist.length === 0 ? <p className="text-muted">There aren't any public tags yet.</p> : publicTaglist}- </VStack>- </div>- <div>- <h2 className="text-display">Private Tags</h2>- <p className="text-muted">These tags are only visible for members of this site.</p>- <VStack spacing={4} divide={true}>- {privateTagList.length === 0 ? <p className="text-muted">There aren't any private tags yet.</p> : privateTagList}- </VStack>- </div>- <div>{form}</div>+ <VStack className="rounded-md border border-gray-200 relative">+ <div className="grid rounded-md-t gap-4 py-3 px-4 bg-gray-100 text-category" style={{ gridTemplateColumns }}>+ <div>Tag</div>+ <div>Visibility</div>+ <div></div>+ </div>+ <div>+ {tags.length === 0 ? (+ <div className={`py-4 px-4 bg-white text-muted ${lastTagIsLast ? "rounded-md-b" : "border-b border-gray-200"}`}>+ There aren't any tags yet.+ </div>+ ) : (+ tags.map((tag, index) => (+ <TagListItem+ key={tag.id}+ tag={tag}+ gridTemplateColumns={gridTemplateColumns}+ isLast={lastTagIsLast && index === tags.length - 1}+ onTagDeleted={this.handleTagDeleted}+ onTagEdited={this.handleTagEdited}+ />+ ))+ )}+ </div>+ {addRow}+ </VStack>{Fider.session.user.isAdministrator && (<div className="mt-4">