added command with interactive dialog
Some checks failed
ci / plugin-ci (push) Has been cancelled

This commit is contained in:
Felipe M 2024-08-08 15:52:29 +02:00
parent 09c4f13f2c
commit 2d962d18d2
Signed by: fmartingr
GPG key ID: CCFBC5637D4000A8
16 changed files with 520 additions and 89 deletions

View file

@ -1,15 +1,31 @@
import {Store, Action} from 'redux';
import {GlobalState} from '@mattermost/types/lib/store';
import {GlobalState} from 'mattermost-redux/types/store';
import {getPost} from 'mattermost-redux/selectors/entities/posts';
import manifest from '@/manifest';
import {PluginRegistry} from '@/types/mattermost-webapp';
import {triggerRemoveAttachmentsCommand} from './actions';
export default class Plugin {
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
public async initialize(registry: PluginRegistry, store: Store<GlobalState, Action<Record<string, unknown>>>) {
// @see https://developers.mattermost.com/extend/plugins/webapp/reference/
registry.registerPostDropdownMenuAction(
'Remove attachments',
async (postID) => {
store.dispatch(triggerRemoveAttachmentsCommand(postID) as any);
},
(postID) => {
const state = store.getState();
const post = getPost(state, postID);
// Don't show up if the post has no attachments. Permissions are checked server-side.
return typeof post.file_ids?.length !== 'undefined' && post.file_ids?.length > 0;
},
);
}
}