Partition.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { StatusEnum } from '../components/status/Types';
  2. import {
  3. PartitionManageParam,
  4. PartitionParam,
  5. PartitionView,
  6. } from '../pages/partitions/Types';
  7. import { formatNumber } from '../utils/Common';
  8. import BaseModel from './BaseModel';
  9. export class PartitionHttp extends BaseModel implements PartitionView {
  10. private id!: string;
  11. private name!: string;
  12. private rowCount!: string;
  13. private status!: StatusEnum;
  14. constructor(props: {}) {
  15. super(props);
  16. Object.assign(this, props);
  17. }
  18. static URL_BASE = `/partitions`;
  19. static getPartitions(collectionName: string): Promise<PartitionHttp[]> {
  20. const path = this.URL_BASE;
  21. return super.findAll({ path, params: { collection_name: collectionName } });
  22. }
  23. static managePartition(param: PartitionManageParam) {
  24. const { collectionName, partitionName, type } = param;
  25. const path = this.URL_BASE;
  26. return super.create({
  27. path,
  28. data: {
  29. collection_name: collectionName,
  30. partition_name: partitionName,
  31. type,
  32. },
  33. });
  34. }
  35. static loadPartition(param: PartitionParam) {
  36. const { collectionName, partitionNames } = param;
  37. const path = `${this.URL_BASE}/load`;
  38. return super.update({
  39. path,
  40. data: {
  41. collection_name: collectionName,
  42. partition_names: partitionNames,
  43. },
  44. });
  45. }
  46. get _id() {
  47. return this.id;
  48. }
  49. get _name() {
  50. return this.name;
  51. }
  52. get _formatName() {
  53. return this.name === '_default' ? 'Default partition' : this.name;
  54. }
  55. get _rowCount() {
  56. return formatNumber(Number(this.rowCount));
  57. }
  58. get _status() {
  59. // @TODO replace mock data
  60. return StatusEnum.unloaded;
  61. }
  62. }