Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
channel_folder_ui: Add channel folder preview modal for non admins.
Pratik Chandaf97c88e4611d
diff --git a/web/src/channel_folders_ui.ts b/web/src/channel_folders_ui.tsindex 3ac535b08d4..ff8a8133d64 100644--- a/web/src/channel_folders_ui.ts+++ b/web/src/channel_folders_ui.ts@@ -22,7 +22,7 @@ import * as ListWidget from "./list_widget.ts";import type {ListWidget as ListWidgetType} from "./list_widget.ts";import * as modals from "./modals.ts";import * as people from "./people.ts";-import {realm} from "./state_data.ts";+import {current_user, realm} from "./state_data.ts";import * as stream_data from "./stream_data.ts";import type {StreamSubscription} from "./sub_store.ts";import * as ui_report from "./ui_report.ts";@@ -36,6 +36,10 @@ function compare_by_name(a: dropdown_widget.Option, b: dropdown_widget.Option):return util.strcmp(a.name, b.name);}+function can_user_manage_folder(): boolean {+ return current_user.is_admin;+}+export function add_channel_folder(): void {const html_body = render_create_channel_folder_modal({max_channel_folder_name_length: realm.max_channel_folder_name_length,@@ -200,6 +204,7 @@ function format_channel_item_html(stream: StreamSubscription): string {is_web_public: stream.is_web_public,stream_edit_url: hash_util.channels_settings_edit_url(stream, "general"),show_remove_channel_from_folder: true,+ can_manage_folder: can_user_manage_folder(),});}@@ -417,9 +422,33 @@ export function update_channel_folder_channels_list(}}+function update_channel_folder(folder_id: number): void {+ const url = "/json/channel_folders/" + folder_id.toString();+ const new_name = $<HTMLInputElement>("input#edit_channel_folder_name").val()!.trim();+ const new_description = $<HTMLTextAreaElement>("textarea#edit_channel_folder_description")+ .val()!+ .trim();+ const data = {+ name: new_name,+ description: new_description,+ };+ const opts = {+ success_continuation() {+ // Update the channel folders data so that+ // the folder dropdown shows updated folder+ // names immediately even if client receives+ // the update event after some delay.+ channel_folders.update_channel_folder(folder_id, "name", new_name);+ channel_folders.update_channel_folder(folder_id, "description", new_description);+ },+ };+ dialog_widget.submit_api_request(channel.patch, url, data, opts);+}+export function handle_editing_channel_folder(folder_id: number): void {const folder = channel_folders.get_channel_folder_by_id(folder_id);const subs = channel_folders.get_sorted_streams_in_folder(folder_id);+ const can_manage_folder = can_user_manage_folder();const html_body = render_edit_channel_folder_modal({name: folder.name,@@ -427,50 +456,46 @@ export function handle_editing_channel_folder(folder_id: number): void {folder_id,max_channel_folder_name_length: realm.max_channel_folder_name_length,max_channel_folder_description_length: realm.max_channel_folder_description_length,+ can_manage_folder,});+ const html_heading = can_manage_folder+ ? $t_html({defaultMessage: "Manage channel folder"})+ : $t_html({defaultMessage: "Channel folder details"});++ function on_shown(): void {+ if (!can_manage_folder) {+ return;+ }++ $("#edit_channel_folder_name").trigger("focus");+ }+dialog_widget.launch({- html_heading: $t_html({defaultMessage: "Manage channel folder"}),+ html_heading,html_body,id: "edit_channel_folder",on_click() {- const url = "/json/channel_folders/" + folder_id.toString();- const new_name = $<HTMLInputElement>("input#edit_channel_folder_name").val()!.trim();- const new_description = $<HTMLTextAreaElement>(- "textarea#edit_channel_folder_description",- )- .val()!- .trim();- const data = {- name: new_name,- description: new_description,- };- const opts = {- success_continuation() {- // Update the channel folders data so that- // the folder dropdown shows updated folder- // names immediately even if client receives- // the update event after some delay.- channel_folders.update_channel_folder(folder_id, "name", new_name);- channel_folders.update_channel_folder(- folder_id,- "description",- new_description,- );- },- };- dialog_widget.submit_api_request(channel.patch, url, data, opts);+ if (!can_manage_folder) {+ // We don't show any submit button for non-admin users+ // so we don't want to do anything here and return.+ return;+ }+ update_channel_folder(folder_id);},- loading_spinner: true,- on_shown: () => $("#edit_channel_folder_name").trigger("focus"),+ loading_spinner: can_manage_folder,+ on_shown,on_hidden() {stream_list_widget_stream_ids = undefined;add_channel_folder_widget = undefined;},- update_submit_disabled_state_on_change: true,+ hide_footer: !can_manage_folder,+ update_submit_disabled_state_on_change: can_manage_folder,post_render() {render_channel_list(subs, folder_id);- render_add_channel_folder_widget();+ if (can_manage_folder) {+ render_add_channel_folder_widget();+ }},});}diff --git a/web/src/dropdown_widget.ts b/web/src/dropdown_widget.tsindex 0696af1b2f2..aa18b851616 100644--- a/web/src/dropdown_widget.ts+++ b/web/src/dropdown_widget.ts@@ -42,6 +42,7 @@ export type Option = {delete_icon_label?: string;edit_icon_label?: string;manage_folder_icon_label?: string;+ manage_folder_icon?: string;};export type DropdownWidgetOptions = {diff --git a/web/src/stream_settings_components.ts b/web/src/stream_settings_components.tsindex 09f685b0043..18703740107 100644--- a/web/src/stream_settings_components.ts+++ b/web/src/stream_settings_components.ts@@ -348,13 +348,18 @@ export function folder_filter_includes_channel(sub: StreamSubscription): booleanexport function set_up_folder_dropdown_widget(sub?: StreamSubscription): DropdownWidget {const folder_options = (): dropdown_widget.Option[] => {const folders = channel_folders.get_channel_folders();+ const can_manage_folder = current_user.is_admin;+ const manage_folder_icon_label = can_manage_folder+ ? $t({defaultMessage: "Manage folder"})+ : $t({defaultMessage: "Preview folder"});const options: dropdown_widget.Option[] = folders.map((folder) => ({name: folder.name,unique_id: folder.id,has_delete_icon: true,+ manage_folder_icon: can_manage_folder ? "folder-cog" : "preview",has_manage_folder_icon: true,delete_icon_label: $t({defaultMessage: "Delete folder"}),- manage_folder_icon_label: $t({defaultMessage: "Manage folder"}),+ manage_folder_icon_label,}));const disabled_option = {diff --git a/web/src/tippyjs.ts b/web/src/tippyjs.tsindex 13b7d57e112..e7c9ed6d4a4 100644--- a/web/src/tippyjs.ts+++ b/web/src/tippyjs.ts@@ -840,7 +840,12 @@ export function initialize(): void {tippy.delegate("body", {target: ".folder_id-dropdown-list-container .dropdown-list-manage-folder, .new_channel_folder_id-dropdown-list-container .dropdown-list-manage-folder",- content: $t({defaultMessage: "Manage folder"}),+ content(reference) {+ if (reference.querySelector(".zulip-icon-preview")) {+ return $t({defaultMessage: "View details"});+ }+ return $t({defaultMessage: "Manage folder"});+ },delay: LONG_HOVER_DELAY,appendTo: () => document.body,onHidden(instance) {diff --git a/web/styles/settings.css b/web/styles/settings.cssindex e4c58b4d5ab..2a831317ba7 100644--- a/web/styles/settings.css+++ b/web/styles/settings.css@@ -1585,6 +1585,10 @@ label.preferences-radio-choice-label {overflow: auto;background-color: hsl(0deg 0% 0% / 2%);++ #channel-folder-settings .zulip-icon-preview {+ font-size: 1.25em;+ }}}}diff --git a/web/styles/zulip.css b/web/styles/zulip.cssindex 306e9da53e4..9267c3e36f7 100644--- a/web/styles/zulip.css+++ b/web/styles/zulip.css@@ -2206,6 +2206,10 @@ body:not(.spectator-view) {.dropdown-list {list-style: none;margin: 0;++ .zulip-icon-preview {+ font-size: 1.125em;+ }}}diff --git a/web/templates/dropdown_list.hbs b/web/templates/dropdown_list.hbsindex e0bbf23c60f..db9a8c355a0 100644--- a/web/templates/dropdown_list.hbs+++ b/web/templates/dropdown_list.hbs@@ -11,7 +11,7 @@{{> components/icon_button custom_classes="dropdown-list-edit dropdown-list-control-button" intent="neutral" icon="edit" aria-label=edit_icon_label }}{{/if}}{{#if has_manage_folder_icon}}- {{> components/icon_button custom_classes="dropdown-list-manage-folder dropdown-list-control-button" intent="neutral" icon="folder-cog" aria-label=manage_folder_icon_label }}+ {{> components/icon_button custom_classes="dropdown-list-manage-folder dropdown-list-control-button" intent="neutral" icon=manage_folder_icon aria-label=manage_folder_icon_label }}{{/if}}{{#if has_delete_icon}}{{> components/icon_button custom_classes="dropdown-list-delete dropdown-list-control-button" intent="danger" icon="trash" aria-label=delete_icon_label }}@@ -65,7 +65,7 @@{{> components/icon_button custom_classes="dropdown-list-edit dropdown-list-control-button" intent="neutral" icon="edit" aria-label=(t "Edit folder") }}{{/if}}{{#if has_manage_folder_icon}}- {{> components/icon_button custom_classes="dropdown-list-manage-folder dropdown-list-control-button" intent="neutral" icon="folder-cog" aria-label=manage_folder_icon_label }}+ {{> components/icon_button custom_classes="dropdown-list-manage-folder dropdown-list-control-button" intent="neutral" icon=manage_folder_icon aria-label=manage_folder_icon_label }}{{/if}}{{#if has_delete_icon}}{{> components/icon_button custom_classes="dropdown-list-delete dropdown-list-control-button" intent="danger" icon="trash" aria-label=(t "Delete folder") }}diff --git a/web/templates/settings/admin_channel_folder_list_item.hbs b/web/templates/settings/admin_channel_folder_list_item.hbsindex 0338d792343..044c6937550 100644--- a/web/templates/settings/admin_channel_folder_list_item.hbs+++ b/web/templates/settings/admin_channel_folder_list_item.hbs@@ -27,5 +27,14 @@aria-label=(t "Delete")}}</td>+ {{else}}+ <td class="actions">+ {{> ../components/icon_button+ icon="preview"+ intent="neutral"+ custom_classes="tippy-zulip-delayed-tooltip edit-channel-folder-button"+ data-tippy-content=(t "View details")+ }}+ </td>{{/if}}</tr>diff --git a/web/templates/settings/admin_channel_folders.hbs b/web/templates/settings/admin_channel_folders.hbsindex 05c82fea9e2..636f034652d 100644--- a/web/templates/settings/admin_channel_folders.hbs+++ b/web/templates/settings/admin_channel_folders.hbs@@ -17,9 +17,7 @@<tr><th>{{t "Name" }}</th><th>{{t "Description" }}</th>- {{#if is_admin}}<th class="actions">{{t "Actions" }}</th>- {{/if}}</tr></thead><tbody id="admin_channel_folders_table" data-empty="{{t 'No channel folders configured.' }}"></tbody>diff --git a/web/templates/stream_list_item.hbs b/web/templates/stream_list_item.hbsindex 2975203b475..1e897db4707 100644--- a/web/templates/stream_list_item.hbs+++ b/web/templates/stream_list_item.hbs@@ -1,11 +1,12 @@<li class="stream-list-item" role="presentation" data-stream-id="{{stream_id}}">- <a class="stream-row hidden-remove-button-row" href="{{stream_edit_url}}">+ <a class="stream-row {{#if can_manage_folder}}hidden-remove-button-row{{/if}}" href="{{stream_edit_url}}"><span class="stream-row-content"><span class="stream-privacy-original-color-{{stream_id}} stream-privacy filter-icon" style="color: {{stream_color}}">{{> stream_privacy . }}</span><span class="stream-name">{{name}}</span></span>+ {{#if can_manage_folder}}<div class="remove-button-wrapper">{{#if show_unsubscribe_button}}{{#if show_private_stream_unsub_tooltip}}@@ -20,5 +21,6 @@{{> components/icon_button icon="close" custom_classes="hidden-remove-button remove-button tippy-zulip-delayed-tooltip" intent="danger" aria-label=(t "Remove channel") data-tippy-content=(t "Remove channel") }}{{/if}}</div>+ {{/if}}</a></li>diff --git a/web/templates/stream_settings/edit_channel_folder_modal.hbs b/web/templates/stream_settings/edit_channel_folder_modal.hbsindex b1abb2edf52..08082776bef 100644--- a/web/templates/stream_settings/edit_channel_folder_modal.hbs+++ b/web/templates/stream_settings/edit_channel_folder_modal.hbs@@ -3,13 +3,13 @@<label for="edit_channel_folder_name" class="modal-field-label">{{t 'Channel folder name' }}</label>- <input type="text" id="edit_channel_folder_name" class="modal_text_input" name="channel_folder_name" maxlength="{{ max_channel_folder_name_length }}" value="{{name}}" />+ <input type="text" id="edit_channel_folder_name" class="modal_text_input" name="channel_folder_name" maxlength="{{ max_channel_folder_name_length }}" value="{{name}}" {{#unless can_manage_folder}} disabled {{/unless}}/></div><div><label for="edit_channel_folder_description" class="modal-field-label">{{t 'Description' }}</label>- <textarea id="edit_channel_folder_description" class="modal-textarea" name="channel_folder_description" maxlength="{{ max_channel_folder_description_length }}">{{~description~}}</textarea>+ <textarea id="edit_channel_folder_description" class="modal-textarea" name="channel_folder_description" maxlength="{{ max_channel_folder_description_length }}" {{#unless can_manage_folder}} disabled {{/unless}}>{{~description~}}</textarea></div><div><div>@@ -30,6 +30,7 @@</div></div></div>+{{#if can_manage_folder}}<div><div><h3 class="folder-channels-list-header">@@ -41,3 +42,4 @@{{> ../components/action_button label=(t "Add") custom_classes="add-channel-button" attention="quiet" intent="brand" aria-label=(t "Add") }}</div></div>+{{/if}}