Skip to content

Commit

Permalink
Add projects to FlagsService; add conditional Projects navLink (#434)
Browse files Browse the repository at this point in the history
* Add `projects` to FlagsService

* Remove `initialize` function

* Fix projects getter; add projects to Mirage config
  • Loading branch information
jeffdaley authored Nov 21, 2023
1 parent a4dfa04 commit 27196b7
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 19 deletions.
9 changes: 9 additions & 0 deletions web/app/components/header/nav.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
>
All Docs
</LinkTo>
{{#if this.flags.projects}}
<LinkTo
data-test-nav-link="projects"
@route="authenticated.projects"
@current-when="authenticated.projects"
>
Projects
</LinkTo>
{{/if}}
<LinkTo
data-test-nav-link="my"
@route="authenticated.my"
Expand Down
2 changes: 2 additions & 0 deletions web/app/components/header/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import AuthenticatedUserService, {
import window from "ember-window-mock";
import { tracked } from "@glimmer/tracking";
import { HERMES_GITHUB_REPO_URL } from "hermes/utils/hermes-urls";
import FlagsService from "hermes/services/flags";

interface HeaderNavComponentSignature {
Args: {};
}

export default class HeaderNavComponent extends Component<HeaderNavComponentSignature> {
@service("config") declare configSvc: ConfigService;
@service declare flags: FlagsService;
@service declare session: SessionService;
@service declare router: RouterService;
@service declare authenticatedUser: AuthenticatedUserService;
Expand Down
8 changes: 6 additions & 2 deletions web/app/config/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Type declarations for
* import config from 'my-app/config/environment'
*/
declare const config: {
export interface HermesConfig {
environment: string;
modulePrefix: string;
podModulePrefix: string;
Expand All @@ -24,6 +24,10 @@ declare const config: {
skipGoogleAuth: boolean;
showEmberAnimatedTools: boolean;
supportLinkURL: string;
};
version: string;
shortRevision: string;
}

declare const config: HermesConfig;

export default config;
3 changes: 0 additions & 3 deletions web/app/routes/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import MetricsService from "hermes/services/_metrics";
export default class ApplicationRoute extends Route {
@service declare config: ConfigService;
@service("fetch") declare fetchSvc: FetchService;
@service declare flags: any;
@service declare session: SessionService;
@service declare router: RouterService;
@service declare metrics: MetricsService;
Expand Down Expand Up @@ -65,8 +64,6 @@ export default class ApplicationRoute extends Route {

await this.session.setup();

this.flags.initialize();

await this.fetchSvc
.fetch(`/api/${this.config.config.api_version}/web/config`)
.then((response) => response?.json())
Expand Down
7 changes: 2 additions & 5 deletions web/app/services/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// @ts-nocheck
// TODO: Type this file.

import Service from "@ember/service";
import config from "hermes/config/environment";
import config, { HermesConfig } from "hermes/config/environment";

export default class ConfigService extends Service {
config = {
Expand All @@ -20,7 +17,7 @@ export default class ConfigService extends Service {
short_revision: config.shortRevision,
};

setConfig(param) {
setConfig(param: HermesConfig) {
this.set("config", param);

// Set API version.
Expand Down
8 changes: 0 additions & 8 deletions web/app/services/flags.js

This file was deleted.

10 changes: 10 additions & 0 deletions web/app/services/flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Service, { inject as service } from "@ember/service";
import ConfigService from "./config";

export default class FlagsService extends Service {
@service("config") declare configSvc: ConfigService;

get projects() {
return this.configSvc.config.feature_flags?.["projects"];
}
}
4 changes: 3 additions & 1 deletion web/mirage/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ export default function (mirageConfig) {
algolia_docs_index_name: config.algolia.docsIndexName,
algolia_drafts_index_name: config.algolia.draftsIndexName,
algolia_internal_index_name: config.algolia.internalIndexName,
feature_flags: null,
feature_flags: {
projects: true,
},
google_doc_folders: "",
short_link_base_url: TEST_SHORT_LINK_BASE_URL,
skip_google_auth: false,
Expand Down

0 comments on commit 27196b7

Please sign in to comment.