Skip to content

Commit

Permalink
[Gitar] Updating TypeScript files
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitar committed Sep 20, 2024
1 parent bb32336 commit 0e6d062
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 88 deletions.
1 change: 0 additions & 1 deletion frontend/src/interfaces/uiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export type UiFlags = {
enableLegacyVariants?: boolean;
navigationSidebar?: boolean;
flagCreator?: boolean;
archiveProjects?: boolean;
projectListImprovements?: boolean;
onboardingUI?: boolean;
eventTimeline?: boolean;
Expand Down
21 changes: 7 additions & 14 deletions src/lib/features/feature-toggle/feature-toggle-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,14 +1230,12 @@ class FeatureToggleService {
}

private async validateActiveProject(projectId: string) {
if (this.flagResolver.isEnabled('archiveProjects')) {
const hasActiveProject =
await this.projectStore.hasActiveProject(projectId);
if (!hasActiveProject) {
throw new NotFoundError(
`Active project with id ${projectId} does not exist`,
);
}
const hasActiveProject =
await this.projectStore.hasActiveProject(projectId);
if (!hasActiveProject) {
throw new NotFoundError(
`Active project with id ${projectId} does not exist`,
);
}
}

Expand All @@ -1253,12 +1251,7 @@ class FeatureToggleService {
await this.validateName(value.name);
await this.validateFeatureFlagNameAgainstPattern(value.name, projectId);

let projectExists: boolean;
if (this.flagResolver.isEnabled('archiveProjects')) {
projectExists = await this.projectStore.hasActiveProject(projectId);
} else {
projectExists = await this.projectStore.hasProject(projectId);
}
let projectExists = await this.projectStore.hasActiveProject(projectId);

if (await this.projectStore.isFeatureLimitReached(projectId)) {
throw new InvalidOperationError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ let segmentService: ISegmentService;
let eventService: EventService;
let environmentService: EnvironmentService;
let unleashConfig: IUnleashConfig;
const TEST_USER_ID = -9999;
const mockConstraints = (): IConstraint[] => {
return Array.from({ length: 5 }).map(() => ({
values: ['x', 'y', 'z'],
Expand All @@ -51,7 +50,7 @@ const irrelevantDate = new Date();

beforeAll(async () => {
const config = createTestConfig({
experimental: { flags: { archiveProjects: true } },
experimental: { flags: {} },
});
db = await dbInit(
'feature_toggle_service_v2_service_serial',
Expand All @@ -77,7 +76,6 @@ beforeEach(async () => {
});
test('Should create feature flag strategy configuration', async () => {
const projectId = 'default';
const username = 'feature-flag';
const config: Omit<FeatureStrategySchema, 'id'> = {
name: 'default',
constraints: [],
Expand All @@ -104,7 +102,6 @@ test('Should create feature flag strategy configuration', async () => {

test('Should be able to update existing strategy configuration', async () => {
const projectId = 'default';
const username = 'existing-strategy';
const featureName = 'update-existing-strategy';
const config: Omit<FeatureStrategySchema, 'id'> = {
name: 'default',
Expand Down Expand Up @@ -139,8 +136,6 @@ test('Should be able to update existing strategy configuration', async () => {
test('Should be able to get strategy by id', async () => {
const featureName = 'get-strategy-by-id';
const projectId = 'default';

const userName = 'strategy';
const config: Omit<FeatureStrategySchema, 'id'> = {
name: 'default',
constraints: [],
Expand Down Expand Up @@ -168,8 +163,6 @@ test('Should be able to get strategy by id', async () => {
test('should ignore name in the body when updating feature flag', async () => {
const featureName = 'body-name-update';
const projectId = 'default';

const userName = 'strategy';
const secondFeatureName = 'body-name-update2';

await service.createFeatureToggle(
Expand Down Expand Up @@ -213,8 +206,6 @@ test('should ignore name in the body when updating feature flag', async () => {
test('should not get empty rows as features', async () => {
const projectId = 'default';

const userName = 'strategy';

await service.createFeatureToggle(
projectId,
{
Expand Down Expand Up @@ -505,7 +496,6 @@ test('If change requests are enabled, cannot change variants without going via C
});

test('If CRs are protected for any environment in the project stops bulk update of variants', async () => {
const user = { email: '[email protected]', username: 'test-user' } as User;
const project = await stores.projectStore.create({
id: 'crOnVariantsProject',
name: 'crOnVariantsProject',
Expand Down Expand Up @@ -599,7 +589,6 @@ test('getPlaygroundFeatures should return ids and titles (if they exist) on clie
const projectId = 'default';

const title = 'custom strategy title';
const userName = 'strategy';
const config: Omit<FeatureStrategySchema, 'id'> = {
name: 'default',
constraints: [],
Expand Down Expand Up @@ -819,7 +808,6 @@ test('Should enable disabled strategies on feature environment enabled', async (
const flagName = 'enableThisFlag';
const project = 'default';
const environment = 'default';
const shouldActivateDisabledStrategies = true;
await service.createFeatureToggle(
project,
{
Expand Down Expand Up @@ -856,7 +844,7 @@ test('Should enable disabled strategies on feature environment enabled', async (
true,
TEST_AUDIT_USER,
{ email: '[email protected]' } as User,
shouldActivateDisabledStrategies,
true,
);

const strategy = await service.getStrategy(createdConfig.id);
Expand Down
28 changes: 10 additions & 18 deletions src/lib/features/project/project-read-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,10 @@ export class ProjectReadModel implements IProjectReadModel {
})
.orderBy('projects.name', 'asc');

if (this.flagResolver.isEnabled('archiveProjects')) {
if (query?.archived === true) {
projects = projects.whereNot(`${TABLE}.archived_at`, null);
} else {
projects = projects.where(`${TABLE}.archived_at`, null);
}
if (query?.archived === true) {
projects = projects.whereNot(`${TABLE}.archived_at`, null);
} else {
projects = projects.where(`${TABLE}.archived_at`, null);
}

if (query?.id) {
Expand All @@ -126,9 +124,7 @@ export class ProjectReadModel implements IProjectReadModel {
'project_settings.project_mode',
] as (string | Raw<any>)[];

if (this.flagResolver.isEnabled('archiveProjects')) {
selectColumns.push(`${TABLE}.archived_at`);
}
selectColumns.push(`${TABLE}.archived_at`);

let groupByColumns = ['projects.id', 'project_settings.project_mode'];

Expand Down Expand Up @@ -179,12 +175,10 @@ export class ProjectReadModel implements IProjectReadModel {
.leftJoin('project_stats', 'project_stats.project', 'projects.id')
.orderBy('projects.name', 'asc');

if (this.flagResolver.isEnabled('archiveProjects')) {
if (query?.archived === true) {
projects = projects.whereNot(`${TABLE}.archived_at`, null);
} else {
projects = projects.where(`${TABLE}.archived_at`, null);
}
if (query?.archived === true) {
projects = projects.whereNot(`${TABLE}.archived_at`, null);
} else {
projects = projects.where(`${TABLE}.archived_at`, null);
}

if (query?.id) {
Expand All @@ -201,9 +195,7 @@ export class ProjectReadModel implements IProjectReadModel {
'project_stats.avg_time_to_prod_current_window',
] as (string | Raw<any>)[];

if (this.flagResolver.isEnabled('archiveProjects')) {
selectColumns.push(`${TABLE}.archived_at`);
}
selectColumns.push(`${TABLE}.archived_at`);

const groupByColumns = [
'projects.id',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/features/project/project-service.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ beforeAll(async () => {
const config = createTestConfig({
getLogger,
experimental: {
flags: { archiveProjects: true, useProjectReadModel: true },
flags: { useProjectReadModel: true },
},
});
eventService = createEventsService(db.rawDatabase, config);
Expand Down
18 changes: 7 additions & 11 deletions src/lib/features/project/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,12 @@ export default class ProjectService {
}

private async validateActiveProject(projectId: string) {
if (this.flagResolver.isEnabled('archiveProjects')) {
const hasActiveProject =
await this.projectStore.hasActiveProject(projectId);
if (!hasActiveProject) {
throw new NotFoundError(
`Active project with id ${projectId} does not exist`,
);
}
const hasActiveProject =
await this.projectStore.hasActiveProject(projectId);
if (!hasActiveProject) {
throw new NotFoundError(
`Active project with id ${projectId} does not exist`,
);
}
}

Expand Down Expand Up @@ -1552,9 +1550,7 @@ export default class ProjectService {
health: project.health || 0,
favorite: favorite,
updatedAt: project.updatedAt,
...(this.flagResolver.isEnabled('archiveProjects')
? { archivedAt: project.archivedAt }
: {}),
archivedAt: project.archivedAt,
createdAt: project.createdAt,
onboardingStatus,
environments,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/features/project/project-store.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let environmentStore: IEnvironmentStore;

beforeAll(async () => {
db = await dbInit('project_store_serial', getLogger, {
experimental: { flags: { archiveProjects: true } },
experimental: { flags: {} },
});
stores = db.stores;
projectStore = stores.projectStore;
Expand Down
33 changes: 10 additions & 23 deletions src/lib/features/project/project-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,10 @@ class ProjectStore implements IProjectStore {
.leftJoin('project_stats', 'project_stats.project', 'projects.id')
.orderBy('projects.name', 'asc');

if (this.flagResolver.isEnabled('archiveProjects')) {
if (query?.archived === true) {
projects = projects.whereNot(`${TABLE}.archived_at`, null);
} else {
projects = projects.where(`${TABLE}.archived_at`, null);
}
if (query?.archived === true) {
projects = projects.whereNot(`${TABLE}.archived_at`, null);
} else {
projects = projects.where(`${TABLE}.archived_at`, null);
}

if (query?.id) {
Expand All @@ -156,9 +154,7 @@ class ProjectStore implements IProjectStore {
'project_stats.avg_time_to_prod_current_window',
] as (string | Raw<any>)[];

if (this.flagResolver.isEnabled('archiveProjects')) {
selectColumns.push(`${TABLE}.archived_at`);
}
selectColumns.push(`${TABLE}.archived_at`);

let groupByColumns = [
'projects.id',
Expand Down Expand Up @@ -237,9 +233,7 @@ class ProjectStore implements IProjectStore {
.where(query)
.orderBy('name', 'asc');

if (this.flagResolver.isEnabled('archiveProjects')) {
projects = projects.where(`${TABLE}.archived_at`, null);
}
projects = projects.where(`${TABLE}.archived_at`, null);

const rows = await projects;

Expand All @@ -248,9 +242,7 @@ class ProjectStore implements IProjectStore {

async get(id: string): Promise<IProject> {
let extraColumns: string[] = [];
if (this.flagResolver.isEnabled('archiveProjects')) {
extraColumns = ['archived_at'];
}
extraColumns = ['archived_at'];

return this.db
.first([...COLUMNS, ...SETTINGS_COLUMNS, ...extraColumns])
Expand Down Expand Up @@ -634,8 +626,7 @@ class ProjectStore implements IProjectStore {
async getApplicationsByProject(
params: IProjectApplicationsSearchParams,
): Promise<IProjectApplications> {
const { project, limit, sortOrder, sortBy, searchParams, offset } =
params;
const { project, limit, sortOrder, searchParams, offset } = params;
const validatedSortOrder =
sortOrder === 'asc' || sortOrder === 'desc' ? sortOrder : 'asc';
const query = this.db
Expand Down Expand Up @@ -741,9 +732,7 @@ class ProjectStore implements IProjectStore {
async count(): Promise<number> {
let count = this.db.from(TABLE).count('*');

if (this.flagResolver.isEnabled('archiveProjects')) {
count = count.where(`${TABLE}.archived_at`, null);
}
count = count.where(`${TABLE}.archived_at`, null);

return count.then((res) => Number(res[0].count));
}
Expand All @@ -766,9 +755,7 @@ class ProjectStore implements IProjectStore {
this.db.raw(`COALESCE(${SETTINGS_TABLE}.project_mode, 'open')`),
);

if (this.flagResolver.isEnabled('archiveProjects')) {
query = query.where(`${TABLE}.archived_at`, null);
}
query = query.where(`${TABLE}.archived_at`, null);

const result: ProjectModeCount[] = await query;

Expand Down
5 changes: 0 additions & 5 deletions src/lib/types/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export type IFlagKey =
| 'extendedMetrics'
| 'removeUnsafeInlineStyleSrc'
| 'originMiddleware'
| 'archiveProjects'
| 'projectListImprovements'
| 'useProjectReadModel'
| 'addonUsageMetrics'
Expand Down Expand Up @@ -281,10 +280,6 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_ORIGIN_MIDDLEWARE,
false,
),
archiveProjects: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_ARCHIVE_PROJECTS,
false,
),
projectListImprovements: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_PROJECT_LIST_IMPROVEMENTS,
false,
Expand Down

0 comments on commit 0e6d062

Please sign in to comment.