Skip to content
Open
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
52 changes: 26 additions & 26 deletions server/activate_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ func (p *Plugin) OnActivate() error {

teams, err := p.API.GetTeams()
if err != nil {
return errors.Wrap(err, "failed to query teams OnActivate")
}

for _, team := range teams {
_, ok := configuration.demoChannelIDs[team.Id]
if !ok {
p.API.LogWarn("No demo channel id for team", "team", team.Id)
continue
}

msg := fmt.Sprintf("OnActivate: %s", manifest.Id)
if err := p.postPluginMessage(team.Id, msg); err != nil {
return errors.Wrap(err, "failed to post OnActivate message")
p.API.LogWarn("Failed to query teams OnActivate, skipping activation messages", "error", err.Error())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strange that GetTeams fails. I wonder if we should still fail loudly as that makes things easier for QA to debug.

} else {
for _, team := range teams {
_, ok := configuration.demoChannelIDs[team.Id]
if !ok {
p.API.LogWarn("No demo channel id for team", "team", team.Id)
continue
}

msg := fmt.Sprintf("OnActivate: %s", manifest.Id)
if err := p.postPluginMessage(team.Id, msg); err != nil {
p.API.LogWarn("Failed to post OnActivate message", "error", err.Error())
}
}
}

Expand Down Expand Up @@ -83,19 +83,19 @@ func (p *Plugin) OnDeactivate() error {

teams, err := p.API.GetTeams()
if err != nil {
return errors.Wrap(err, "failed to query teams OnDeactivate")
}

for _, team := range teams {
_, ok := configuration.demoChannelIDs[team.Id]
if !ok {
p.API.LogWarn("No demo channel id for team", "team", team.Id)
continue
}

msg := fmt.Sprintf("OnDeactivate: %s", manifest.Id)
if err := p.postPluginMessage(team.Id, msg); err != nil {
return errors.Wrap(err, "failed to post OnDeactivate message")
p.API.LogWarn("Failed to query teams OnDeactivate, skipping deactivation messages", "error", err.Error())
} else {
for _, team := range teams {
_, ok := configuration.demoChannelIDs[team.Id]
if !ok {
p.API.LogWarn("No demo channel id for team", "team", team.Id)
continue
}

msg := fmt.Sprintf("OnDeactivate: %s", manifest.Id)
if err := p.postPluginMessage(team.Id, msg); err != nil {
p.API.LogWarn("Failed to post OnDeactivate message", "error", err.Error())
}
}
}

Expand Down
17 changes: 9 additions & 8 deletions server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,13 @@ func (p *Plugin) ensureDemoUser(configuration *configuration) (string, error) {

teams, err := p.API.GetTeams()
if err != nil {
return "", err
}

for _, team := range teams {
_, err := p.API.CreateTeamMember(team.Id, user.Id)
if err != nil {
p.API.LogError("Failed add demo user to team", "teamID", team.Id, "error", err.Error())
p.API.LogWarn("Failed to get teams for demo user setup, skipping team membership", "error", err.Error())
} else {
for _, team := range teams {
_, err := p.API.CreateTeamMember(team.Id, user.Id)
if err != nil {
p.API.LogError("Failed add demo user to team", "teamID", team.Id, "error", err.Error())
}
}
}

Expand All @@ -417,7 +417,8 @@ func (p *Plugin) ensureDemoUser(configuration *configuration) (string, error) {
func (p *Plugin) ensureDemoChannels(configuration *configuration) (map[string]string, error) {
teams, err := p.API.GetTeams()
if err != nil {
return nil, err
p.API.LogWarn("Failed to get teams for demo channel setup, skipping channel creation", "error", err.Error())
return make(map[string]string), nil
}

demoChannelIDs := make(map[string]string)
Expand Down
70 changes: 70 additions & 0 deletions webapp/src/components/channel_settings_smoke_test.jsx
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to see a typescript file. not a blocker

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, {useCallback, useEffect, useState} from 'react';
import PropTypes from 'prop-types';

export default function ChannelSettingsSmokeTest({channel, setAreThereUnsavedChanges, registerSaveBarHandlers}) {
const [value, setValue] = useState('');

const handleSave = useCallback(async () => {
// Smoke test: no server persistence; clearing dirty state matches a successful save.
setAreThereUnsavedChanges?.(false);
}, [setAreThereUnsavedChanges]);

const handleReset = useCallback(() => {
setValue('');
setAreThereUnsavedChanges?.(false);
}, [setAreThereUnsavedChanges]);

/* eslint-disable consistent-return -- useEffect may return cleanup or nothing */
useEffect(() => {
if (!registerSaveBarHandlers) {
return;
}
registerSaveBarHandlers({
save: handleSave,
reset: handleReset,
});
return () => registerSaveBarHandlers(null);
}, [registerSaveBarHandlers, handleSave, handleReset]);
/* eslint-enable consistent-return */

const handleChange = useCallback((e) => {
const newValue = e.target.value;
setValue(newValue);
setAreThereUnsavedChanges?.(newValue.length > 0);
}, [setAreThereUnsavedChanges]);

return (
<div style={{padding: '20px'}}>
<h3>{'Channel Settings Smoke Test'}</h3>
<div style={{marginTop: '12px'}}>
<strong>{'Display Name: '}</strong>{channel.display_name}
</div>
<div style={{marginTop: '4px'}}>
<strong>{'Channel Name: '}</strong>{channel.name}
</div>
<div style={{marginTop: '4px'}}>
<strong>{'Channel ID: '}</strong>{channel.id}
</div>
<div style={{marginTop: '16px'}}>
<label htmlFor='smoke-test-input'>
<strong>{'Dirty-state test (type to mark dirty):'}</strong>
</label>
<br/>
<input
id='smoke-test-input'
type='text'
value={value}
onChange={handleChange}
placeholder='Type here to mark tab as dirty'
style={{marginTop: '4px', padding: '6px', width: '300px'}}
/>
</div>
</div>
);
}

ChannelSettingsSmokeTest.propTypes = {
channel: PropTypes.object.isRequired,
setAreThereUnsavedChanges: PropTypes.func,
registerSaveBarHandlers: PropTypes.func,
};
8 changes: 8 additions & 0 deletions webapp/src/plugin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import RHSView from './components/right_hand_sidebar';
import SecretMessageSetting from './components/admin_settings/secret_message_setting';
import CustomSetting from './components/admin_settings/custom_setting';
import FilePreviewOverride from './components/file_preview_override';
import ChannelSettingsSmokeTest from './components/channel_settings_smoke_test';
import RouterShowcase from './components/router_showcase/router_showcase';
import PostType from './components/post_type';
import EphemeralPostType from './components/ephemeral_post_type';
Expand Down Expand Up @@ -50,6 +51,13 @@ function getTranslations(locale) {

export default class DemoPlugin {
initialize(registry, store) {
registry.registerChannelSettingsTab?.({
uiName: 'Demo Plugin',
component: ChannelSettingsSmokeTest,
icon: `/plugins/${manifest.id}/public/icon.png`,
shouldRender: () => true,
});

registry.registerRootComponent(Root);
registry.registerPopoverUserAttributesComponent(UserAttributes);
registry.registerPopoverUserActionsComponent(UserActions);
Expand Down