Skip to content

Commit

Permalink
CB-5960 sort features
Browse files Browse the repository at this point in the history
  • Loading branch information
devnaumov committed Nov 20, 2024
1 parent 21a70c3 commit 69b8f6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 11 additions & 1 deletion webapp/packages/core-root/src/FeaturesResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { makeObservable, observable } from 'mobx';
import { computed, makeObservable, observable } from 'mobx';

import { injectable } from '@cloudbeaver/core-di';
import { CachedDataResource } from '@cloudbeaver/core-resource';
Expand All @@ -19,6 +19,11 @@ export type ApplicationFeature = WebFeatureSet;
@injectable()
export class FeaturesResource extends CachedDataResource<ApplicationFeature[]> {
private baseFeatures: string[];

get features(): ApplicationFeature[] {
return this.data.slice().sort(sortFeature);
}

constructor(
private readonly graphQLService: GraphQLService,
permissionsResource: SessionPermissionsResource,
Expand All @@ -30,6 +35,7 @@ export class FeaturesResource extends CachedDataResource<ApplicationFeature[]> {

makeObservable<this, 'baseFeatures'>(this, {
baseFeatures: observable,
features: computed,
});
}

Expand All @@ -47,3 +53,7 @@ export class FeaturesResource extends CachedDataResource<ApplicationFeature[]> {
return features;
}
}

export function sortFeature(a: ApplicationFeature, b: ApplicationFeature): number {
return a.label.localeCompare(b.label);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ export const ServerConfigurationFeaturesForm: PlaceholderComponent<IConfiguratio
throw new Error('Form state should be provided');
}

const features = useResource(ServerConfigurationFeaturesForm, FeaturesResource, configurationWizard ? null : undefined);
const featuresResource = useResource(ServerConfigurationFeaturesForm, FeaturesResource, configurationWizard ? null : undefined);
const translate = useTranslate();

if (features.data.length === 0 || configurationWizard) {
if (configurationWizard || featuresResource.resource.features.length === 0) {
return null;
}

return (
<>
<GroupTitle>{translate('administration_configuration_wizard_configuration_services_group')}</GroupTitle>
{features.data.map(feature => (
{featuresResource.resource.features.map(feature => (
<Switch
key={feature.id}
value={feature.id}
name="enabledFeatures"
state={serverConfig}
description={feature.description}
disabled={features.resource.isBase(feature.id)}
disabled={featuresResource.resource.isBase(feature.id)}
mod={['primary']}
small
>
Expand Down

0 comments on commit 69b8f6f

Please sign in to comment.