Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public record Config(
@JsonProperty("help_pages") Optional<Map<String, String>> helpPages,
Optional<Login> login,
Optional<Welcome> welcome,
Optional<Onboarding> onboarding,
Optional<Navigation> navigation,
Optional<Footer> footer,
Optional<Resources> resources,
Expand All @@ -49,6 +50,11 @@ public record Welcome(Optional<WelcomeItem> news,
public record WelcomeItem(Optional<Boolean> enabled, Optional<String> feed) {}
}

@JsonInclude(JsonInclude.Include.NON_ABSENT)
public record Onboarding(Optional<OnboardingItem> resources) {
public record OnboardingItem(Optional<Boolean> enabled) {}
}

@JsonInclude(JsonInclude.Include.NON_ABSENT)
public record Resources(@JsonProperty("stream_rule_matcher_code") Optional<ResourceItem> streamRuleMatcherCode,
@JsonProperty("contact_support") Optional<ResourceItem> contactSupport,
Expand Down Expand Up @@ -79,15 +85,17 @@ public record FeaturesItem(Optional<Boolean> enabled) {}

public static Config empty() {
return new Config(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty());
}

public static Config forProductName(String productName) {
return new Config(Optional.of(productName), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty());
}

public Config withWelcome(Welcome welcome) {
return new Config(productName, favicon, logo, helpUrl, helpPages, login, Optional.of(welcome), navigation, footer, resources, features);
return new Config(productName, favicon, logo, helpUrl, helpPages, login, Optional.of(welcome), onboarding, navigation, footer, resources, features);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
package org.graylog2.web.customization;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.graylog2.shared.bindings.providers.ObjectMapperProvider;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class ConfigTest {
private final ObjectMapper objectMapper = new ObjectMapperProvider().get();

@Test
void deserializesDisabledOnboardingResources() throws Exception {
final var config = objectMapper.readValue("""
{"onboarding": {"resources": {"enabled": false}}}
""", Config.class);

assertThat(config.onboarding()
.flatMap(Config.Onboarding::resources)
.flatMap(Config.Onboarding.OnboardingItem::enabled))
.contains(false);
}

@Test
void leavesOnboardingAbsentWhenNotConfigured() throws Exception {
final var config = objectMapper.readValue("""
{"product_name": "AwesomeLog"}
""", Config.class);

assertThat(config.onboarding()).isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/

import AppConfig from 'util/AppConfig';

const useOnboardingCustomization = () => ({
isResourceSectionEnabledForBrand: AppConfig?.branding?.()?.onboarding?.resources?.enabled !== false,
});

export default useOnboardingCustomization;
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ beforeEach(() => {
typeof useDismissOnboarding
>);
asMock(AppConfig.isCloud).mockReturnValue(false);
asMock(AppConfig.branding).mockReturnValue(undefined);
});

describe('FirstUseWelcome', () => {
Expand Down Expand Up @@ -105,4 +106,20 @@ describe('FirstUseWelcome', () => {

expect(screen.queryByRole('heading', { name: /set up input/i })).not.toBeInTheDocument();
});

it('shows the resources section when enabled in branding', () => {
asMock(AppConfig.branding).mockReturnValue({ onboarding: { resources: { enabled: true } } });
render(<FirstUseWelcome />);

expect(screen.getByRole('heading', { name: /^resources$/i })).toBeInTheDocument();
expect(screen.getByRole('heading', { name: /quickstart guide/i })).toBeInTheDocument();
});

it('hides the resources section when disabled in branding', () => {
asMock(AppConfig.branding).mockReturnValue({ onboarding: { resources: { enabled: false } } });
render(<FirstUseWelcome />);

expect(screen.queryByRole('heading', { name: /^resources$/i })).not.toBeInTheDocument();
expect(screen.queryByRole('heading', { name: /quickstart guide/i })).not.toBeInTheDocument();
});
});
66 changes: 36 additions & 30 deletions graylog2-web-interface/src/components/welcome/FirstUseWelcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useState } from 'react';
import styled, { css } from 'styled-components';

import useProductName from 'brand-customization/useProductName';
import useOnboardingCustomization from 'brand-customization/useOnboardingCustomization';
import useSendTelemetry from 'logic/telemetry/useSendTelemetry';
import { TELEMETRY_EVENT_TYPE } from 'logic/telemetry/Constants';
import LinkContainer from 'components/common/LinkContainer';
Expand Down Expand Up @@ -164,6 +165,7 @@ const SourcesBoxActions = styled(BoxActions)(

const FirstUseWelcome = () => {
const productName = useProductName();
const { isResourceSectionEnabledForBrand } = useOnboardingCustomization();
const { mutate: dismiss } = useDismissOnboarding();
const [showDismissConfirm, setShowDismissConfirm] = useState(false);
const sendTelemetry = useSendTelemetry('welcome');
Expand Down Expand Up @@ -256,37 +258,41 @@ const FirstUseWelcome = () => {
</Col>
</Row>

<SecondaryHeadline>Resources</SecondaryHeadline>
{isResourceSectionEnabledForBrand && (
<>
<SecondaryHeadline>Resources</SecondaryHeadline>

<Container>
{resources.map((resource) => (
<ResourceTile className="content" key={resource.title}>
<StyledResourceCol>
<ResourceTileContent>
<IconCard>
<Icon name={resource.iconName} />
</IconCard>
<ResourceTileBody>
<ResourceTitle>{resource.title}</ResourceTitle>
<ResourceDescription>{resource.description}</ResourceDescription>
<BoxActions>
<ExternalLinkButton
href={resource.link}
bsSize="xs"
onClick={() =>
sendTelemetry(TELEMETRY_EVENT_TYPE.WELCOME.RESOURCE_CONTINUE_CLICKED, {
app_action_value: resource.title,
})
}>
Continue
</ExternalLinkButton>
</BoxActions>
</ResourceTileBody>
</ResourceTileContent>
</StyledResourceCol>
</ResourceTile>
))}
</Container>
<Container>
{resources.map((resource) => (
<ResourceTile className="content" key={resource.title}>
<StyledResourceCol>
<ResourceTileContent>
<IconCard>
<Icon name={resource.iconName} />
</IconCard>
<ResourceTileBody>
<ResourceTitle>{resource.title}</ResourceTitle>
<ResourceDescription>{resource.description}</ResourceDescription>
<BoxActions>
<ExternalLinkButton
href={resource.link}
bsSize="xs"
onClick={() =>
sendTelemetry(TELEMETRY_EVENT_TYPE.WELCOME.RESOURCE_CONTINUE_CLICKED, {
app_action_value: resource.title,
})
}>
Continue
</ExternalLinkButton>
</BoxActions>
</ResourceTileBody>
</ResourceTileContent>
</StyledResourceCol>
</ResourceTile>
))}
</Container>
</>
)}
</>
);
};
Expand Down
3 changes: 3 additions & 0 deletions graylog2-web-interface/src/util/AppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export type Branding = {
news?: { enabled: boolean; feed?: string };
releases?: { enabled: boolean };
};
onboarding?: {
resources?: { enabled: boolean };
};
navigation?: {
home?: { icon: string };
user_menu?: { icon: string };
Expand Down
Loading