Skip to content

Commit

Permalink
update tag options
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouwenxuan authored and zhouwenxuan committed Dec 23, 2024
1 parent 1219001 commit dccfe3f
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useTags } from '../../../../tag/hooks';
import { getTagColor, getTagId, getTagName, getTagsByNameOrColor, getTagByNameOrColor } from '../../../../tag/utils/cell/core';
import { getRecordIdFromRecord } from '../../../utils/cell';
import { getRowById } from '../../../utils/table';
import { SELECT_OPTION_COLORS } from '../../../constants';
import { PRIVATE_COLUMN_KEY, SELECT_OPTION_COLORS } from '../../../constants';
import { PRIVATE_COLUMN_KEY as TAG_PRIVATE_COLUMN_KEY } from '../../../../tag/constants';
import DeleteTags from './delete-tags';

Expand Down Expand Up @@ -106,10 +106,10 @@ const TagsEditor = forwardRef(({
updateFileTags([{ record_id: recordId, tags: newValue, old_tags: value }]);
setValue(newValue);
const options = tagsData.rows.map(tag => ({
row_id: getTagId(tag),
id: getTagId(tag),
display_value: getTagName(tag),
})) || [];
modifyColumnData(column.key, { options }, { options: column.data.options || [] });
modifyColumnData(PRIVATE_COLUMN_KEY.TAGS, { options }, { options: column.data.options || [] });
},
fail_callback: () => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FilterSetter, GroupbySetter, SortSetter, HideColumnSetter } from '../..
import { PRIVATE_COLUMN_KEY } from '../../../constants';

const TableViewToolbar = ({
readOnly, view, collaborators, tags,
readOnly, view, collaborators,
modifyFilters, modifySorts, modifyGroupbys, modifyHiddenColumns, modifyColumnOrder
}) => {
const viewType = useMemo(() => view.type, [view]);
Expand Down Expand Up @@ -33,7 +33,6 @@ const TableViewToolbar = ({
modifyFilters={modifyFilters}
collaborators={collaborators}
viewType={viewType}
tags={tags}
/>
<SortSetter
isNeedSubmit={true}
Expand Down Expand Up @@ -78,7 +77,6 @@ TableViewToolbar.propTypes = {
modifyGroupbys: PropTypes.func,
modifyHiddenColumns: PropTypes.func,
modifyColumnOrder: PropTypes.func,
tags: PropTypes.array,
};

export default TableViewToolbar;
2 changes: 1 addition & 1 deletion frontend/src/metadata/constants/column/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CellType = {
GEOLOCATION: 'geolocation',
RATE: 'rate',
LINK: 'link',
TAGS: 'tags',
TAGS: 'tags'
};

export default CellType;
7 changes: 0 additions & 7 deletions frontend/src/metadata/utils/validate/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,6 @@ class ValidateFilter {
const options = getColumnOptions(filterColumn);
return this.isValidSelectedOptions(term, options);
}
case CellType.TAGS: {
if (!this.isValidTermType(term, TERM_TYPE_MAP.ARRAY)) {
return false;
}

return true;
}
default: {
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/tag/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class Context {
return this.api.deleteTagLinks(this.repoId, link_column_key, row_id_map);
};

getTagStatus = () => {
return this.api.getTagsStatus(this.repoId);
};

}

export default Context;
5 changes: 5 additions & 0 deletions frontend/src/tag/hooks/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export const TagsProvider = ({ repoID, currentPath, selectTagsView, children, ..
setTagsData(data);
}, []);

const getTagsStatus = useCallback(() => {
return contextRef.current.api.getTagsStatus(repoID);
}, [repoID]);

const reloadTags = useCallback(() => {
setReloading(true);
storeRef.current.reload(PER_LOAD_NUMBER).then(() => {
Expand Down Expand Up @@ -258,6 +262,7 @@ export const TagsProvider = ({ repoID, currentPath, selectTagsView, children, ..
deleteTagLinks,
updateLocalTag,
selectTag: handelSelectTag,
getTagsStatus,
}}>
{children}
</TagsContext.Provider>
Expand Down
41 changes: 39 additions & 2 deletions seahub/repo_metadata/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,7 @@ def put(self, request, repo_id):

metadata_server_api = MetadataServerAPI(repo_id, request.user.username)

from seafevents.repo_metadata.constants import TAGS_TABLE
from seafevents.repo_metadata.constants import TAGS_TABLE, METADATA_TABLE, MetadataColumn
try:
tags_table = get_table_by_name(metadata_server_api, TAGS_TABLE.name)
except Exception as e:
Expand Down Expand Up @@ -1942,6 +1942,27 @@ def put(self, request, repo_id):
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

try:
columns_data = metadata_server_api.list_columns(METADATA_TABLE.id)
columns = columns_data.get('columns', [])
tags_column = next((col for col in columns if col['key'] == METADATA_TABLE.columns.tags.key), None)
if tags_column:
options = tags_column.get('data', {}).get('options', [])
for tag_data in tags_data:
tag = tag_data.get('tag', {})
tag_id = tag_data.get('tag_id', '')
display_value = tag.get(TAGS_TABLE.columns.name.name)
option = next((opt for opt in options if opt['id'] == tag_id), None)
if option:
option['display_value'] = display_value
new_column_data = {**tags_column.get('data', {}), 'options': options}
new_column = MetadataColumn(tags_column['key'], tags_column['name'], tags_column['type'], new_column_data).to_dict()
metadata_server_api.update_column(METADATA_TABLE.id, new_column)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

return Response({'success': True})

def delete(self, request, repo_id):
Expand All @@ -1967,7 +1988,7 @@ def delete(self, request, repo_id):

metadata_server_api = MetadataServerAPI(repo_id, request.user.username)

from seafevents.repo_metadata.constants import TAGS_TABLE
from seafevents.repo_metadata.constants import TAGS_TABLE, METADATA_TABLE, MetadataColumn
try:
tags_table = get_table_by_name(metadata_server_api, TAGS_TABLE.name)
except Exception as e:
Expand All @@ -1986,6 +2007,22 @@ def delete(self, request, repo_id):
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

try:
columns_data = metadata_server_api.list_columns(METADATA_TABLE.id)
columns = columns_data.get('columns', [])
tags_column = next((col for col in columns if col['key'] == METADATA_TABLE.columns.tags.key), None)
if tags_column:
options = tags_column.get('data', {}).get('options', [])
options = [opt for opt in options if opt['id'] not in tag_ids]
new_column_data = {**tags_column.get('data', {}), 'options': options}
new_column = MetadataColumn(tags_column['key'], tags_column['name'], tags_column['type'], new_column_data).to_dict()
resp = metadata_server_api.update_column(METADATA_TABLE.id, new_column)
print('resp', resp)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)

return Response({'success': True})


Expand Down
2 changes: 1 addition & 1 deletion seahub/repo_metadata/metadata_server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def list_metadata_view_records(repo_id, user, view, start=0, limit=1000):
metadata_server_api = MetadataServerAPI(repo_id, user)
columns = metadata_server_api.list_columns(METADATA_TABLE.id).get('columns')
sql = gen_view_data_sql(METADATA_TABLE, columns, view, start, limit, user)
print(sql)

# Remove face-vectors from the query SQL because they are too large
query_fields_str = ''
for column in columns:
Expand Down

0 comments on commit dccfe3f

Please sign in to comment.