Skip to content

Commit

Permalink
fix: add append feature ids and add disabled to feature in group
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <tygao@amazon.com>
  • Loading branch information
raintygao committed Aug 25, 2023
1 parent 154fffb commit b845fa0
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ const isDefaultCheckedFeatureId = (id: string) => {
return DEFAULT_CHECKED_FEATURES_IDS.indexOf(id) > -1;
};

const appendDefaultFeatureIds = (ids: string[]) => {
// concat default checked ids and unique the result
return Array.from(ids.concat(DEFAULT_CHECKED_FEATURES_IDS));
};

const workspaceHtmlIdGenerator = htmlIdGenerator();

const defaultVISThemeOptions = [{ label: 'Categorical', value: 'categorical' }];
Expand All @@ -118,7 +123,7 @@ export const WorkspaceForm = ({
const [defaultVISTheme, setDefaultVISTheme] = useState(defaultValues?.defaultVISTheme);

const [selectedFeatureIds, setSelectedFeatureIds] = useState(
defaultValues?.features || DEFAULT_CHECKED_FEATURES_IDS
appendDefaultFeatureIds(defaultValues?.features || [])
);
const [permissionSettings, setPermissionSettings] = useState<
Array<Partial<WorkspacePermissionSetting>>
Expand Down Expand Up @@ -413,10 +418,8 @@ export const WorkspaceForm = ({
}`}
checked={selectedIds.length > 0}
disabled={
isWorkspaceFeatureGroup(featureOrGroup)
? false
: // If this feature isn't checked, will not disable to allow check to compatible dirty data.
isDefaultCheckedFeatureId(featureOrGroup.id) && selectedIds.length > 0
!isWorkspaceFeatureGroup(featureOrGroup) &&
isDefaultCheckedFeatureId(featureOrGroup.id)
}
indeterminate={
isWorkspaceFeatureGroup(featureOrGroup) &&
Expand All @@ -429,6 +432,7 @@ export const WorkspaceForm = ({
options={featureOrGroup.features.map((item) => ({
id: item.id,
label: item.name,
disabled: isDefaultCheckedFeatureId(item.id),
}))}
idToSelectedMap={selectedIds.reduce(
(previousValue, currentValue) => ({
Expand Down

0 comments on commit b845fa0

Please sign in to comment.