Skip to content
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
52 changes: 52 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,52 @@
import React, {useCallback, useState} from 'react';
import PropTypes from 'prop-types';

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

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>
{showTabSwitchError && (
<div style={{marginTop: '12px', padding: '8px', backgroundColor: '#fdecea', color: '#d32f2f', borderRadius: '4px'}}>
{'You have unsaved changes. Please save or discard before switching tabs.'}
</div>
)}
</div>
);
}

ChannelSettingsSmokeTest.propTypes = {
channel: PropTypes.object.isRequired,
setAreThereUnsavedChanges: PropTypes.func,
showTabSwitchError: PropTypes.bool,
};
7 changes: 7 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,12 @@ function getTranslations(locale) {

export default class DemoPlugin {
initialize(registry, store) {
registry.registerChannelSettingsTab?.({
uiName: 'Demo Plugin',
component: ChannelSettingsSmokeTest,
shouldRender: () => true,
});

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